aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-12-22 20:57:08 -0600
committerRob Landley <rob@landley.net>2019-12-22 20:57:08 -0600
commit488f8507dcf4f634952f4f649e7a95d219468b83 (patch)
treef611990f0561a5b38817fa7075dbd57de7ac2600
parentf3d4a2c72f315fd3bb0a939f6331ee0465fcfe2f (diff)
downloadtoybox-488f8507dcf4f634952f4f649e7a95d219468b83.tar.gz
Streamline init for NOFORK (fewer unnecessary syscalls for shell builtins).
-rw-r--r--main.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/main.c b/main.c
index 99c53f96..9d892e69 100644
--- a/main.c
+++ b/main.c
@@ -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