aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-11 07:04:23 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-11 07:04:23 +0000
commit473dae080a8a0089d5d619a56d8943d131aa451e (patch)
tree29763aae84d2c9336d9f34a5dc02c024285af60e
parentf1a7141cfcacf606ae321faa58c45617045460fe (diff)
downloadbusybox-w32-473dae080a8a0089d5d619a56d8943d131aa451e.tar.gz
busybox-w32-473dae080a8a0089d5d619a56d8943d131aa451e.tar.bz2
busybox-w32-473dae080a8a0089d5d619a56d8943d131aa451e.zip
add more convenient defines for [NO]MMU:
"#ifndef BB_NOMMU" is a double negative
-rw-r--r--applets/applets.c4
-rw-r--r--include/libbb.h10
-rw-r--r--include/platform.h12
-rw-r--r--libbb/vfork_daemon_rexec.c25
-rw-r--r--networking/httpd.c2
-rw-r--r--networking/zcip.c4
6 files changed, 30 insertions, 27 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 56e0d2ccc..6f38ccee8 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -51,7 +51,7 @@ const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1;
51 51
52const struct bb_applet *current_applet; 52const struct bb_applet *current_applet;
53const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; 53const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
54#ifdef BB_NOMMU 54#if !BB_MMU
55bool re_execed; 55bool re_execed;
56#endif 56#endif
57 57
@@ -612,7 +612,7 @@ int main(int argc, char **argv)
612{ 612{
613 const char *s; 613 const char *s;
614 614
615#ifdef BB_NOMMU 615#if !BB_MMU
616 /* NOMMU re-exec trick sets high-order bit in first byte of name */ 616 /* NOMMU re-exec trick sets high-order bit in first byte of name */
617 if (argv[0][0] & 0x80) { 617 if (argv[0][0] & 0x80) {
618 re_execed = 1; 618 re_execed = 1;
diff --git a/include/libbb.h b/include/libbb.h
index 04bf6a5cd..11fcd19f2 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -269,6 +269,8 @@ char *xrealloc_getcwd_or_warn(char *cwd);
269char *xmalloc_readlink_or_warn(const char *path); 269char *xmalloc_readlink_or_warn(const char *path);
270char *xmalloc_realpath(const char *path); 270char *xmalloc_realpath(const char *path);
271 271
272
273//TODO: signal(sid, f) is the same? then why?
272extern void sig_catch(int,void (*)(int)); 274extern void sig_catch(int,void (*)(int));
273//#define sig_ignore(s) (sig_catch((s), SIG_IGN)) 275//#define sig_ignore(s) (sig_catch((s), SIG_IGN))
274//#define sig_uncatch(s) (sig_catch((s), SIG_DFL)) 276//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
@@ -278,7 +280,6 @@ extern void sig_unblock(int);
278extern void sig_pause(void); 280extern void sig_pause(void);
279 281
280 282
281
282void xsetgid(gid_t gid); 283void xsetgid(gid_t gid);
283void xsetuid(uid_t uid); 284void xsetuid(uid_t uid);
284void xchdir(const char *path); 285void xchdir(const char *path);
@@ -519,15 +520,14 @@ pid_t xspawn(char **argv);
519 520
520/* Unlike waitpid, waits ONLY for one process, 521/* Unlike waitpid, waits ONLY for one process,
521 * It's safe to pass negative 'pids' from failed [v]fork - 522 * It's safe to pass negative 'pids' from failed [v]fork -
522 * wait4pid will return -1 and ECHILD in errno. 523 * wait4pid will return -1 (and will not clobber [v]fork's errno).
523 * IOW: rc = wait4pid(spawn(argv)); 524 * IOW: rc = wait4pid(spawn(argv));
524 * if (rc < 0) bb_perror_msg("%s", argv[0]); 525 * if (rc < 0) bb_perror_msg("%s", argv[0]);
525 * if (rc > 0) bb_error_msg("exit code: %d", rc); 526 * if (rc > 0) bb_error_msg("exit code: %d", rc);
526 */ 527 */
528int wait4pid(int pid);
527int wait_pid(int *wstat, int pid); 529int wait_pid(int *wstat, int pid);
528int wait_nohang(int *wstat); 530int wait_nohang(int *wstat);
529int wait4pid(int pid);
530//TODO: signal(sid, f) is the same? then why?
531#define wait_crashed(w) ((w) & 127) 531#define wait_crashed(w) ((w) & 127)
532#define wait_exitcode(w) ((w) >> 8) 532#define wait_exitcode(w) ((w) >> 8)
533#define wait_stopsig(w) ((w) >> 8) 533#define wait_stopsig(w) ((w) >> 8)
@@ -564,7 +564,7 @@ enum {
564 DAEMON_CLOSE_EXTRA_FDS = 4, 564 DAEMON_CLOSE_EXTRA_FDS = 4,
565 DAEMON_ONLY_SANITIZE = 8, /* internal use */ 565 DAEMON_ONLY_SANITIZE = 8, /* internal use */
566}; 566};
567#ifndef BB_NOMMU 567#if BB_MMU
568 void forkexit_or_rexec(void); 568 void forkexit_or_rexec(void);
569# define forkexit_or_rexec(argv) forkexit_or_rexec() 569# define forkexit_or_rexec(argv) forkexit_or_rexec()
570# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags) 570# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
diff --git a/include/platform.h b/include/platform.h
index 51add6c0f..d7389f1aa 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -212,7 +212,15 @@ typedef unsigned smalluint;
212 */ 212 */
213#if defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \ 213#if defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
214 __UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__ 214 __UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__
215#define BB_NOMMU 215#define BB_MMU 0
216#define BB_NOMMU 1
217#define USE_FOR_NOMMU(...) __VA_ARGS__
218#define USE_FOR_MMU(...)
219#else
220#define BB_MMU 1
221/* BB_NOMMU is not defined in this case! */
222#define USE_FOR_NOMMU(...)
223#define USE_FOR_MMU(...) __VA_ARGS__
216#endif 224#endif
217 225
218/* Platforms that haven't got dprintf need to implement fdprintf() in 226/* Platforms that haven't got dprintf need to implement fdprintf() in
@@ -232,7 +240,7 @@ static ATTRIBUTE_ALWAYS_INLINE char* strchrnul(const char *s, char c) {
232} 240}
233#endif 241#endif
234 242
235/* Don't use lchown with glibc older than 2.1.x ... uC-libc lacks it */ 243/* Don't use lchown with glibc older than 2.1.x ... uClibc lacks it */
236#if (defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1) || \ 244#if (defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1) || \
237 defined __UC_LIBC__ 245 defined __UC_LIBC__
238# define lchown chown 246# define lchown chown
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 64952225d..281ead4dc 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -107,15 +107,15 @@ int spawn_and_wait(char **argv)
107 const struct bb_applet *a = find_applet_by_name(argv[0]); 107 const struct bb_applet *a = find_applet_by_name(argv[0]);
108 108
109 if (a && (a->nofork 109 if (a && (a->nofork
110#ifndef BB_NOMMU 110#if BB_MMU
111 || a->noexec /* NOEXEC cannot be used on NOMMU */ 111 || a->noexec /* NOEXEC trick needs fork() */
112#endif 112#endif
113 )) { 113 )) {
114 int argc = 1; 114 int argc = 1;
115 char **pp = argv; 115 char **pp = argv;
116 while (*++pp) 116 while (*++pp)
117 argc++; 117 argc++;
118#ifndef BB_NOMMU 118#if BB_MMU
119 if (a->nofork) 119 if (a->nofork)
120#endif 120#endif
121 { 121 {
@@ -136,7 +136,7 @@ int spawn_and_wait(char **argv)
136 applet_name = a->name; 136 applet_name = a->name;
137// what else should we save/restore? 137// what else should we save/restore?
138// TODO: what if applet will mangle argv vector? 138// TODO: what if applet will mangle argv vector?
139// xargs needs argv untouched because it frees the vector! 139// xargs needs argv untouched because it frees argv[i]!
140// shouldn't we pass a copy? 140// shouldn't we pass a copy?
141 rc = a->main(argc, argv); 141 rc = a->main(argc, argv);
142 current_applet = old_a; 142 current_applet = old_a;
@@ -152,29 +152,25 @@ int spawn_and_wait(char **argv)
152 option_mask32 = old_m; 152 option_mask32 = old_m;
153 return rc; 153 return rc;
154 } 154 }
155#ifndef BB_NOMMU /* MMU only */ 155#if BB_MMU
156 /* MMU only */
156 /* a->noexec is true */ 157 /* a->noexec is true */
157 rc = fork(); 158 rc = fork();
158 if (rc) 159 if (rc) /* parent or error */
159 goto w; 160 return wait4pid(rc);
160 /* child */ 161 /* child */
161 xfunc_error_retval = EXIT_FAILURE; 162 xfunc_error_retval = EXIT_FAILURE;
162 current_applet = a; 163 current_applet = a;
163 run_current_applet_and_exit(argc, argv); 164 run_current_applet_and_exit(argc, argv);
164#endif 165#endif
165 } 166 }
167#endif /* FEATURE_PREFER_APPLETS */
166 rc = spawn(argv); 168 rc = spawn(argv);
167#ifndef BB_NOMMU
168 w:
169#endif
170 return wait4pid(rc); 169 return wait4pid(rc);
171#else /* !FEATURE_PREFER_APPLETS */
172 return wait4pid(spawn(argv));
173#endif
174} 170}
175 171
176 172
177#ifdef BB_NOMMU 173#if !BB_MMU
178void forkexit_or_rexec(char **argv) 174void forkexit_or_rexec(char **argv)
179{ 175{
180 pid_t pid; 176 pid_t pid;
@@ -210,7 +206,6 @@ void forkexit_or_rexec(void)
210#define forkexit_or_rexec(argv) forkexit_or_rexec() 206#define forkexit_or_rexec(argv) forkexit_or_rexec()
211#endif 207#endif
212 208
213
214/* Due to a #define in libbb.h on MMU systems we actually have 1 argument - 209/* Due to a #define in libbb.h on MMU systems we actually have 1 argument -
215 * char **argv "vanishes" */ 210 * char **argv "vanishes" */
216void bb_daemonize_or_rexec(int flags, char **argv) 211void bb_daemonize_or_rexec(int flags, char **argv)
diff --git a/networking/httpd.c b/networking/httpd.c
index 7ee62c32a..d80df937a 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -986,7 +986,7 @@ static int sendCgi(const char *url,
986 * since httpd is run from inetd (and it can't run standalone 986 * since httpd is run from inetd (and it can't run standalone
987 * in uClinux). 987 * in uClinux).
988 */ 988 */
989#ifdef BB_NOMMU 989#if !BB_MMU
990 pid = vfork(); 990 pid = vfork();
991#else 991#else
992 pid = fork(); 992 pid = fork();
diff --git a/networking/zcip.c b/networking/zcip.c
index 552833f9f..eb3c869ab 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -220,7 +220,7 @@ int zcip_main(int argc, char **argv)
220 } 220 }
221 } 221 }
222 // On NOMMU reexec early (or else we will rerun things twice) 222 // On NOMMU reexec early (or else we will rerun things twice)
223#ifdef BB_NOMMU 223#if !BB_MMU
224 if (!FOREGROUND) 224 if (!FOREGROUND)
225 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 225 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
226#endif 226#endif
@@ -268,7 +268,7 @@ int zcip_main(int argc, char **argv)
268 268
269 // daemonize now; don't delay system startup 269 // daemonize now; don't delay system startup
270 if (!FOREGROUND) { 270 if (!FOREGROUND) {
271#ifndef BB_NOMMU 271#if BB_MMU
272 bb_daemonize(DAEMON_CHDIR_ROOT); 272 bb_daemonize(DAEMON_CHDIR_ROOT);
273#endif 273#endif
274 bb_info_msg("start, interface %s", intf); 274 bb_info_msg("start, interface %s", intf);