diff options
author | Rob Landley <rob@landley.net> | 2019-12-22 20:57:08 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-12-22 20:57:08 -0600 |
commit | 488f8507dcf4f634952f4f649e7a95d219468b83 (patch) | |
tree | f611990f0561a5b38817fa7075dbd57de7ac2600 | |
parent | f3d4a2c72f315fd3bb0a939f6331ee0465fcfe2f (diff) | |
download | toybox-488f8507dcf4f634952f4f649e7a95d219468b83.tar.gz |
Streamline init for NOFORK (fewer unnecessary syscalls for shell builtins).
-rw-r--r-- | main.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -82,13 +82,7 @@ static void toy_singleinit(struct toy_list *which, char *argv[]) { toys.which = which; toys.argv = argv; - - if (CFG_TOYBOX_I18N) { - // Deliberately try C.UTF-8 before the user's locale to work around users - // that choose non-UTF-8 locales. macOS doesn't support C.UTF-8 though. - if (!setlocale(LC_CTYPE, "C.UTF-8")) setlocale(LC_CTYPE, ""); - } - setlinebuf(stdout); + toys.toycount = ARRAY_LEN(toy_list); // Parse --help and --version for (almost) all commands if (CFG_TOYBOX_HELP_DASHDASH && !(which->flags & TOYFLAG_NOHELP) && argv[1]) { @@ -110,10 +104,17 @@ static void toy_singleinit(struct toy_list *which, char *argv[]) toys.optargs = argv+1; for (toys.optc = 0; toys.optargs[toys.optc]; toys.optc++); } - toys.old_umask = umask(0); - if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask); - toys.signalfd--; - toys.toycount = ARRAY_LEN(toy_list); + + if (!(which->flags & TOYFLAG_NOFORK)) { + toys.old_umask = umask(0); + if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask); + if (CFG_TOYBOX_I18N) { + // Deliberately try C.UTF-8 before the user's locale to work around users + // that choose non-UTF-8 locales. macOS doesn't support C.UTF-8 though. + if (!setlocale(LC_CTYPE, "C.UTF-8")) setlocale(LC_CTYPE, ""); + } + setlinebuf(stdout); + } } // Full init needed by multiplexer or reentrant calls, calls singleinit at end |