aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-21 21:26:32 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-21 21:26:32 +0000
commitd07ee46919e3a8e42b3a8735e1152cc050165934 (patch)
tree8884f7679bef0e0baba2f216372577d314113dcd /init
parentfa4718efcf055d8720ea99be1af237a921232f5a (diff)
downloadbusybox-w32-d07ee46919e3a8e42b3a8735e1152cc050165934.tar.gz
busybox-w32-d07ee46919e3a8e42b3a8735e1152cc050165934.tar.bz2
busybox-w32-d07ee46919e3a8e42b3a8735e1152cc050165934.zip
Removed proc dependancies for init and free (which maintaining exactly
the same functionality). /proc takes up 90k of kernel space, so it is nice to avoid using it at all costs. The only places where it is depended on is for cetain optional mount/umount features, and for ps and lsmod. -Erik
Diffstat (limited to 'init')
-rw-r--r--init/init.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/init/init.c b/init/init.c
index 4a19822ae..6ec811599 100644
--- a/init/init.c
+++ b/init/init.c
@@ -49,15 +49,12 @@
49#include <linux/serial.h> /* for serial_struct */ 49#include <linux/serial.h> /* for serial_struct */
50#include <sys/vt.h> /* for vt_stat */ 50#include <sys/vt.h> /* for vt_stat */
51#include <sys/ioctl.h> 51#include <sys/ioctl.h>
52#include <sys/sysinfo.h> /* For check_free_memory() */
52#include <linux/version.h> 53#include <linux/version.h>
53#ifdef BB_SYSLOGD 54#ifdef BB_SYSLOGD
54#include <sys/syslog.h> 55#include <sys/syslog.h>
55#endif 56#endif
56 57
57#if ! defined BB_FEATURE_USE_PROCFS
58#error Sorry, I depend on the /proc filesystem right now.
59#endif
60
61#ifndef KERNEL_VERSION 58#ifndef KERNEL_VERSION
62#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) 59#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
63#endif 60#endif
@@ -226,25 +223,18 @@ void set_term(int fd)
226} 223}
227 224
228/* How much memory does this machine have? */ 225/* How much memory does this machine have? */
229static int mem_total() 226static int check_free_memory()
230{ 227{
231 char s[80]; 228 struct sysinfo info;
232 char *p = "/proc/meminfo";
233 FILE *f;
234 const char pattern[] = "MemTotal:";
235 229
236 if ((f = fopen(p, "r")) < 0) { 230 sysinfo(&info);
237 message(LOG, "Error opening %s: %s\n", p, strerror(errno)); 231 if (sysinfo(&info) != 0) {
232 message(LOG, "Error checking free memory: %s\n", strerror(errno));
238 return -1; 233 return -1;
239 } 234 }
240 while (NULL != fgets(s, 79, f)) { 235
241 p = strstr(s, pattern); 236 return(info.freeram/1024);
242 if (NULL != p) { 237
243 fclose(f);
244 return (atoi(p + strlen(pattern)));
245 }
246 }
247 return -1;
248} 238}
249 239
250static void console_init() 240static void console_init()
@@ -454,13 +444,13 @@ static void check_memory()
454{ 444{
455 struct stat statBuf; 445 struct stat statBuf;
456 446
457 if (mem_total() > 3500) 447 if (check_free_memory() > 1000)
458 return; 448 return;
459 449
460 if (stat("/etc/fstab", &statBuf) == 0) { 450 if (stat("/etc/fstab", &statBuf) == 0) {
461 /* Try to turn on swap */ 451 /* Try to turn on swap */
462 system("/sbin/swapon -a"); 452 system("/sbin/swapon -a");
463 if (mem_total() < 3500) 453 if (check_free_memory() < 1000)
464 goto goodnight; 454 goto goodnight;
465 } else 455 } else
466 goto goodnight; 456 goto goodnight;
@@ -555,6 +545,11 @@ static void reboot_signal(int sig)
555} 545}
556 546
557#if defined BB_FEATURE_INIT_CHROOT 547#if defined BB_FEATURE_INIT_CHROOT
548
549#if ! defined BB_FEATURE_USE_PROCFS
550#error Sorry, I depend on the /proc filesystem right now.
551#endif
552
558static void check_chroot(int sig) 553static void check_chroot(int sig)
559{ 554{
560 char *argv_init[2] = { "init", NULL, }; 555 char *argv_init[2] = { "init", NULL, };
@@ -853,13 +848,6 @@ extern int init_main(int argc, char **argv)
853#endif 848#endif
854 849
855 850
856 /* Mount /proc */
857 if (mount("proc", "/proc", "proc", 0, 0) == 0) {
858 message(LOG, "Mounting /proc: done.\n");
859 kernelVersion = get_kernel_revision();
860 } else
861 message(LOG | CONSOLE, "Mounting /proc: failed!\n");
862
863 /* Make sure there is enough memory to do something useful. */ 851 /* Make sure there is enough memory to do something useful. */
864 check_memory(); 852 check_memory();
865 853