add more convenient defines for [NO]MMU:
"#ifndef BB_NOMMU" is a double negative
This commit is contained in:
parent
f1a7141cfc
commit
473dae080a
@ -51,7 +51,7 @@ const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1;
|
|||||||
|
|
||||||
const struct bb_applet *current_applet;
|
const struct bb_applet *current_applet;
|
||||||
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||||
#ifdef BB_NOMMU
|
#if !BB_MMU
|
||||||
bool re_execed;
|
bool re_execed;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
#ifdef BB_NOMMU
|
#if !BB_MMU
|
||||||
/* NOMMU re-exec trick sets high-order bit in first byte of name */
|
/* NOMMU re-exec trick sets high-order bit in first byte of name */
|
||||||
if (argv[0][0] & 0x80) {
|
if (argv[0][0] & 0x80) {
|
||||||
re_execed = 1;
|
re_execed = 1;
|
||||||
|
@ -269,6 +269,8 @@ char *xrealloc_getcwd_or_warn(char *cwd);
|
|||||||
char *xmalloc_readlink_or_warn(const char *path);
|
char *xmalloc_readlink_or_warn(const char *path);
|
||||||
char *xmalloc_realpath(const char *path);
|
char *xmalloc_realpath(const char *path);
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: signal(sid, f) is the same? then why?
|
||||||
extern void sig_catch(int,void (*)(int));
|
extern void sig_catch(int,void (*)(int));
|
||||||
//#define sig_ignore(s) (sig_catch((s), SIG_IGN))
|
//#define sig_ignore(s) (sig_catch((s), SIG_IGN))
|
||||||
//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
|
//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
|
||||||
@ -278,7 +280,6 @@ extern void sig_unblock(int);
|
|||||||
extern void sig_pause(void);
|
extern void sig_pause(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void xsetgid(gid_t gid);
|
void xsetgid(gid_t gid);
|
||||||
void xsetuid(uid_t uid);
|
void xsetuid(uid_t uid);
|
||||||
void xchdir(const char *path);
|
void xchdir(const char *path);
|
||||||
@ -519,15 +520,14 @@ pid_t xspawn(char **argv);
|
|||||||
|
|
||||||
/* Unlike waitpid, waits ONLY for one process,
|
/* Unlike waitpid, waits ONLY for one process,
|
||||||
* It's safe to pass negative 'pids' from failed [v]fork -
|
* It's safe to pass negative 'pids' from failed [v]fork -
|
||||||
* wait4pid will return -1 and ECHILD in errno.
|
* wait4pid will return -1 (and will not clobber [v]fork's errno).
|
||||||
* IOW: rc = wait4pid(spawn(argv));
|
* IOW: rc = wait4pid(spawn(argv));
|
||||||
* if (rc < 0) bb_perror_msg("%s", argv[0]);
|
* if (rc < 0) bb_perror_msg("%s", argv[0]);
|
||||||
* if (rc > 0) bb_error_msg("exit code: %d", rc);
|
* if (rc > 0) bb_error_msg("exit code: %d", rc);
|
||||||
*/
|
*/
|
||||||
|
int wait4pid(int pid);
|
||||||
int wait_pid(int *wstat, int pid);
|
int wait_pid(int *wstat, int pid);
|
||||||
int wait_nohang(int *wstat);
|
int wait_nohang(int *wstat);
|
||||||
int wait4pid(int pid);
|
|
||||||
//TODO: signal(sid, f) is the same? then why?
|
|
||||||
#define wait_crashed(w) ((w) & 127)
|
#define wait_crashed(w) ((w) & 127)
|
||||||
#define wait_exitcode(w) ((w) >> 8)
|
#define wait_exitcode(w) ((w) >> 8)
|
||||||
#define wait_stopsig(w) ((w) >> 8)
|
#define wait_stopsig(w) ((w) >> 8)
|
||||||
@ -564,7 +564,7 @@ enum {
|
|||||||
DAEMON_CLOSE_EXTRA_FDS = 4,
|
DAEMON_CLOSE_EXTRA_FDS = 4,
|
||||||
DAEMON_ONLY_SANITIZE = 8, /* internal use */
|
DAEMON_ONLY_SANITIZE = 8, /* internal use */
|
||||||
};
|
};
|
||||||
#ifndef BB_NOMMU
|
#if BB_MMU
|
||||||
void forkexit_or_rexec(void);
|
void forkexit_or_rexec(void);
|
||||||
# define forkexit_or_rexec(argv) forkexit_or_rexec()
|
# define forkexit_or_rexec(argv) forkexit_or_rexec()
|
||||||
# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
|
# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
|
||||||
|
@ -212,7 +212,15 @@ typedef unsigned smalluint;
|
|||||||
*/
|
*/
|
||||||
#if defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
|
#if defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
|
||||||
__UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__
|
__UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__
|
||||||
#define BB_NOMMU
|
#define BB_MMU 0
|
||||||
|
#define BB_NOMMU 1
|
||||||
|
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||||
|
#define USE_FOR_MMU(...)
|
||||||
|
#else
|
||||||
|
#define BB_MMU 1
|
||||||
|
/* BB_NOMMU is not defined in this case! */
|
||||||
|
#define USE_FOR_NOMMU(...)
|
||||||
|
#define USE_FOR_MMU(...) __VA_ARGS__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Platforms that haven't got dprintf need to implement fdprintf() in
|
/* 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) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Don't use lchown with glibc older than 2.1.x ... uC-libc lacks it */
|
/* Don't use lchown with glibc older than 2.1.x ... uClibc lacks it */
|
||||||
#if (defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1) || \
|
#if (defined __GLIBC__ && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 1) || \
|
||||||
defined __UC_LIBC__
|
defined __UC_LIBC__
|
||||||
# define lchown chown
|
# define lchown chown
|
||||||
|
@ -107,15 +107,15 @@ int spawn_and_wait(char **argv)
|
|||||||
const struct bb_applet *a = find_applet_by_name(argv[0]);
|
const struct bb_applet *a = find_applet_by_name(argv[0]);
|
||||||
|
|
||||||
if (a && (a->nofork
|
if (a && (a->nofork
|
||||||
#ifndef BB_NOMMU
|
#if BB_MMU
|
||||||
|| a->noexec /* NOEXEC cannot be used on NOMMU */
|
|| a->noexec /* NOEXEC trick needs fork() */
|
||||||
#endif
|
#endif
|
||||||
)) {
|
)) {
|
||||||
int argc = 1;
|
int argc = 1;
|
||||||
char **pp = argv;
|
char **pp = argv;
|
||||||
while (*++pp)
|
while (*++pp)
|
||||||
argc++;
|
argc++;
|
||||||
#ifndef BB_NOMMU
|
#if BB_MMU
|
||||||
if (a->nofork)
|
if (a->nofork)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -136,7 +136,7 @@ int spawn_and_wait(char **argv)
|
|||||||
applet_name = a->name;
|
applet_name = a->name;
|
||||||
// what else should we save/restore?
|
// what else should we save/restore?
|
||||||
// TODO: what if applet will mangle argv vector?
|
// TODO: what if applet will mangle argv vector?
|
||||||
// xargs needs argv untouched because it frees the vector!
|
// xargs needs argv untouched because it frees argv[i]!
|
||||||
// shouldn't we pass a copy?
|
// shouldn't we pass a copy?
|
||||||
rc = a->main(argc, argv);
|
rc = a->main(argc, argv);
|
||||||
current_applet = old_a;
|
current_applet = old_a;
|
||||||
@ -152,29 +152,25 @@ int spawn_and_wait(char **argv)
|
|||||||
option_mask32 = old_m;
|
option_mask32 = old_m;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#ifndef BB_NOMMU /* MMU only */
|
#if BB_MMU
|
||||||
|
/* MMU only */
|
||||||
/* a->noexec is true */
|
/* a->noexec is true */
|
||||||
rc = fork();
|
rc = fork();
|
||||||
if (rc)
|
if (rc) /* parent or error */
|
||||||
goto w;
|
return wait4pid(rc);
|
||||||
/* child */
|
/* child */
|
||||||
xfunc_error_retval = EXIT_FAILURE;
|
xfunc_error_retval = EXIT_FAILURE;
|
||||||
current_applet = a;
|
current_applet = a;
|
||||||
run_current_applet_and_exit(argc, argv);
|
run_current_applet_and_exit(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif /* FEATURE_PREFER_APPLETS */
|
||||||
rc = spawn(argv);
|
rc = spawn(argv);
|
||||||
#ifndef BB_NOMMU
|
|
||||||
w:
|
|
||||||
#endif
|
|
||||||
return wait4pid(rc);
|
return wait4pid(rc);
|
||||||
#else /* !FEATURE_PREFER_APPLETS */
|
|
||||||
return wait4pid(spawn(argv));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef BB_NOMMU
|
#if !BB_MMU
|
||||||
void forkexit_or_rexec(char **argv)
|
void forkexit_or_rexec(char **argv)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -210,7 +206,6 @@ void forkexit_or_rexec(void)
|
|||||||
#define forkexit_or_rexec(argv) forkexit_or_rexec()
|
#define forkexit_or_rexec(argv) forkexit_or_rexec()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Due to a #define in libbb.h on MMU systems we actually have 1 argument -
|
/* Due to a #define in libbb.h on MMU systems we actually have 1 argument -
|
||||||
* char **argv "vanishes" */
|
* char **argv "vanishes" */
|
||||||
void bb_daemonize_or_rexec(int flags, char **argv)
|
void bb_daemonize_or_rexec(int flags, char **argv)
|
||||||
|
@ -986,7 +986,7 @@ static int sendCgi(const char *url,
|
|||||||
* since httpd is run from inetd (and it can't run standalone
|
* since httpd is run from inetd (and it can't run standalone
|
||||||
* in uClinux).
|
* in uClinux).
|
||||||
*/
|
*/
|
||||||
#ifdef BB_NOMMU
|
#if !BB_MMU
|
||||||
pid = vfork();
|
pid = vfork();
|
||||||
#else
|
#else
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
@ -220,7 +220,7 @@ int zcip_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// On NOMMU reexec early (or else we will rerun things twice)
|
// On NOMMU reexec early (or else we will rerun things twice)
|
||||||
#ifdef BB_NOMMU
|
#if !BB_MMU
|
||||||
if (!FOREGROUND)
|
if (!FOREGROUND)
|
||||||
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
||||||
#endif
|
#endif
|
||||||
@ -268,7 +268,7 @@ int zcip_main(int argc, char **argv)
|
|||||||
|
|
||||||
// daemonize now; don't delay system startup
|
// daemonize now; don't delay system startup
|
||||||
if (!FOREGROUND) {
|
if (!FOREGROUND) {
|
||||||
#ifndef BB_NOMMU
|
#if BB_MMU
|
||||||
bb_daemonize(DAEMON_CHDIR_ROOT);
|
bb_daemonize(DAEMON_CHDIR_ROOT);
|
||||||
#endif
|
#endif
|
||||||
bb_info_msg("start, interface %s", intf);
|
bb_info_msg("start, interface %s", intf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user