diff options
| author | Rob Landley <rob@landley.net> | 2005-08-30 18:50:37 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2005-08-30 18:50:37 +0000 |
| commit | c3386a43048907fb07fb28f2723c1efbacf4bd79 (patch) | |
| tree | e16eabe2df3ef6680f7d2f41a72b883b19f8e2dd /init | |
| parent | 7a8f6792f3a360756efccd6fbdb1f72db0108118 (diff) | |
| download | busybox-w32-c3386a43048907fb07fb28f2723c1efbacf4bd79.tar.gz busybox-w32-c3386a43048907fb07fb28f2723c1efbacf4bd79.tar.bz2 busybox-w32-c3386a43048907fb07fb28f2723c1efbacf4bd79.zip | |
Why have a separate CONFIG_INIT_SWAPON when we already have CONFIG_SWAPONOFF?
Diffstat (limited to 'init')
| -rw-r--r-- | init/Config.in | 8 | ||||
| -rw-r--r-- | init/init.c | 78 |
2 files changed, 14 insertions, 72 deletions
diff --git a/init/Config.in b/init/Config.in index a3584aaf5..91d990c38 100644 --- a/init/Config.in +++ b/init/Config.in | |||
| @@ -35,14 +35,6 @@ config CONFIG_FEATURE_INIT_COREDUMPS | |||
| 35 | core file sizes. If this option is disabled, processes | 35 | core file sizes. If this option is disabled, processes |
| 36 | will not generate any core files. | 36 | will not generate any core files. |
| 37 | 37 | ||
| 38 | config CONFIG_FEATURE_INIT_SWAPON | ||
| 39 | bool " Should init run swapon if short on memory?" | ||
| 40 | default y | ||
| 41 | depends on CONFIG_INIT | ||
| 42 | help | ||
| 43 | If the system has less than one megabyte of total memory, init | ||
| 44 | will run '/sbin/swapon -a' to add swap memory. | ||
| 45 | |||
| 46 | config CONFIG_FEATURE_INIT_SCTTY | 38 | config CONFIG_FEATURE_INIT_SCTTY |
| 47 | bool " Support running commands with a controlling-tty?" | 39 | bool " Support running commands with a controlling-tty?" |
| 48 | default n | 40 | default n |
diff --git a/init/init.c b/init/init.c index 7656bf334..058a47a83 100644 --- a/init/init.c +++ b/init/init.c | |||
| @@ -308,37 +308,6 @@ static void set_term(int fd) | |||
| 308 | tcsetattr(fd, TCSANOW, &tty); | 308 | tcsetattr(fd, TCSANOW, &tty); |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | #ifdef CONFIG_FEATURE_INIT_SWAPON | ||
| 312 | /* How much memory does this machine have? | ||
| 313 | Units are kBytes to avoid overflow on 4GB machines */ | ||
| 314 | static unsigned int check_free_memory(void) | ||
| 315 | { | ||
| 316 | struct sysinfo info; | ||
| 317 | unsigned int result, u, s = 10; | ||
| 318 | |||
| 319 | if (sysinfo(&info) != 0) { | ||
| 320 | bb_perror_msg("Error checking free memory"); | ||
| 321 | return -1; | ||
| 322 | } | ||
| 323 | |||
| 324 | /* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes. | ||
| 325 | * Kernels 2.4.0 return info.mem_unit in bytes. */ | ||
| 326 | u = info.mem_unit; | ||
| 327 | if (u == 0) | ||
| 328 | u = 1; | ||
| 329 | while ((u & 1) == 0 && s > 0) { | ||
| 330 | u >>= 1; | ||
| 331 | s--; | ||
| 332 | } | ||
| 333 | result = (info.totalram >> s) + (info.totalswap >> s); | ||
| 334 | if (((unsigned long long)result * (unsigned long long)u) > UINT_MAX) { | ||
| 335 | return(UINT_MAX); | ||
| 336 | } else { | ||
| 337 | return(result * u); | ||
| 338 | } | ||
| 339 | } | ||
| 340 | #endif /* CONFIG_FEATURE_INIT_SWAPON */ | ||
| 341 | |||
| 342 | static void console_init(void) | 311 | static void console_init(void) |
| 343 | { | 312 | { |
| 344 | int fd; | 313 | int fd; |
| @@ -918,38 +887,6 @@ static void delete_init_action(struct init_action *action) | |||
| 918 | } | 887 | } |
| 919 | } | 888 | } |
| 920 | 889 | ||
| 921 | #ifdef CONFIG_FEATURE_INIT_SWAPON | ||
| 922 | /* Make sure there is enough memory to do something useful. * | ||
| 923 | * Calls "swapon -a" if needed so be sure /etc/fstab is present... */ | ||
| 924 | static void check_memory(void) | ||
| 925 | { | ||
| 926 | struct stat statBuf; | ||
| 927 | |||
| 928 | if (check_free_memory() > 1000) | ||
| 929 | return; | ||
| 930 | |||
| 931 | #if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__) | ||
| 932 | if (stat("/etc/fstab", &statBuf) == 0) { | ||
| 933 | /* swapon -a requires /proc typically */ | ||
| 934 | new_init_action(SYSINIT, "/bin/mount -t proc proc /proc", ""); | ||
| 935 | /* Try to turn on swap */ | ||
| 936 | new_init_action(SYSINIT, "/sbin/swapon -a", ""); | ||
| 937 | run_actions(SYSINIT); /* wait and removing */ | ||
| 938 | if (check_free_memory() < 1000) | ||
| 939 | goto goodnight; | ||
| 940 | } else | ||
| 941 | goto goodnight; | ||
| 942 | return; | ||
| 943 | #endif | ||
| 944 | |||
| 945 | goodnight: | ||
| 946 | message(CONSOLE, "Sorry, your computer does not have enough memory."); | ||
| 947 | loop_forever(); | ||
| 948 | } | ||
| 949 | #else | ||
| 950 | # define check_memory() | ||
| 951 | #endif /* CONFIG_FEATURE_INIT_SWAPON */ | ||
| 952 | |||
| 953 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, | 890 | /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, |
| 954 | * then parse_inittab() simply adds in some default | 891 | * then parse_inittab() simply adds in some default |
| 955 | * actions(i.e., runs INIT_SCRIPT and then starts a pair | 892 | * actions(i.e., runs INIT_SCRIPT and then starts a pair |
| @@ -1149,7 +1086,20 @@ extern int init_main(int argc, char **argv) | |||
| 1149 | message(MAYBE_CONSOLE | LOG, "init started: %s", bb_msg_full_version); | 1086 | message(MAYBE_CONSOLE | LOG, "init started: %s", bb_msg_full_version); |
| 1150 | 1087 | ||
| 1151 | /* Make sure there is enough memory to do something useful. */ | 1088 | /* Make sure there is enough memory to do something useful. */ |
| 1152 | check_memory(); | 1089 | if (ENABLE_SWAPONOFF) { |
| 1090 | struct sysinfo info; | ||
| 1091 | |||
| 1092 | if (!sysinfo(&info) && | ||
| 1093 | (info.mem_unit ? : 1) * (long long)info.totalram < MEGABYTE) | ||
| 1094 | { | ||
| 1095 | message(CONSOLE,"Low memory: forcing swapon."); | ||
| 1096 | /* swapon -a requires /proc typically */ | ||
| 1097 | new_init_action(SYSINIT, "/bin/mount -t proc proc /proc", ""); | ||
| 1098 | /* Try to turn on swap */ | ||
| 1099 | new_init_action(SYSINIT, "/sbin/swapon -a", ""); | ||
| 1100 | run_actions(SYSINIT); /* wait and removing */ | ||
| 1101 | } | ||
| 1102 | } | ||
| 1153 | 1103 | ||
| 1154 | /* Check if we are supposed to be in single user mode */ | 1104 | /* Check if we are supposed to be in single user mode */ |
| 1155 | if (argc > 1 && (!strcmp(argv[1], "single") || | 1105 | if (argc > 1 && (!strcmp(argv[1], "single") || |
