diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-09 17:21:26 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-09 17:21:26 +0000 |
commit | 84641942e5366b2e09367ba4f4376c99f15ecc8e (patch) | |
tree | eff2511dcc6cb647e0bf898903f86c94b85466ad /libbb/vfork_daemon_rexec.c | |
parent | bacaff6e5474d6c5f080ce4cd2a55e8ff1ba5c94 (diff) | |
download | busybox-w32-1_12_2.tar.gz busybox-w32-1_12_2.tar.bz2 busybox-w32-1_12_2.zip |
apply post-1.12.1 patches, bump version to 1.12.21_12_2
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index da0dc03e5..17b373cd1 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -125,6 +125,7 @@ int FAST_FUNC run_nofork_applet_prime(struct nofork_save_area *old, int applet_n | |||
125 | int rc, argc; | 125 | int rc, argc; |
126 | 126 | ||
127 | applet_name = APPLET_NAME(applet_no); | 127 | applet_name = APPLET_NAME(applet_no); |
128 | |||
128 | xfunc_error_retval = EXIT_FAILURE; | 129 | xfunc_error_retval = EXIT_FAILURE; |
129 | 130 | ||
130 | /* Special flag for xfunc_die(). If xfunc will "die" | 131 | /* Special flag for xfunc_die(). If xfunc will "die" |
@@ -132,7 +133,30 @@ int FAST_FUNC run_nofork_applet_prime(struct nofork_save_area *old, int applet_n | |||
132 | * die_sleep and longjmp here instead. */ | 133 | * die_sleep and longjmp here instead. */ |
133 | die_sleep = -1; | 134 | die_sleep = -1; |
134 | 135 | ||
135 | /* option_mask32 = 0; - not needed */ | 136 | /* In case getopt() or getopt32() was already called: |
137 | * reset the libc getopt() function, which keeps internal state. | ||
138 | * | ||
139 | * BSD-derived getopt() functions require that optind be set to 1 in | ||
140 | * order to reset getopt() state. This used to be generally accepted | ||
141 | * way of resetting getopt(). However, glibc's getopt() | ||
142 | * has additional getopt() state beyond optind, and requires that | ||
143 | * optind be set to zero to reset its state. So the unfortunate state of | ||
144 | * affairs is that BSD-derived versions of getopt() misbehave if | ||
145 | * optind is set to 0 in order to reset getopt(), and glibc's getopt() | ||
146 | * will core dump if optind is set 1 in order to reset getopt(). | ||
147 | * | ||
148 | * More modern versions of BSD require that optreset be set to 1 in | ||
149 | * order to reset getopt(). Sigh. Standards, anyone? | ||
150 | */ | ||
151 | #ifdef __GLIBC__ | ||
152 | optind = 0; | ||
153 | #else /* BSD style */ | ||
154 | optind = 1; | ||
155 | /* optreset = 1; */ | ||
156 | #endif | ||
157 | /* optarg = NULL; opterr = 1; optopt = 63; - do we need this too? */ | ||
158 | /* (values above are what they initialized to in glibc and uclibc) */ | ||
159 | /* option_mask32 = 0; - not needed, no applet depends on it being 0 */ | ||
136 | 160 | ||
137 | argc = 1; | 161 | argc = 1; |
138 | while (argv[argc]) | 162 | while (argv[argc]) |
@@ -161,8 +185,16 @@ int FAST_FUNC run_nofork_applet_prime(struct nofork_save_area *old, int applet_n | |||
161 | rc = 0; | 185 | rc = 0; |
162 | } | 186 | } |
163 | 187 | ||
164 | /* Restoring globals */ | 188 | /* Restoring some globals */ |
165 | restore_nofork_data(old); | 189 | restore_nofork_data(old); |
190 | |||
191 | /* Other globals can be simply reset to defaults */ | ||
192 | #ifdef __GLIBC__ | ||
193 | optind = 0; | ||
194 | #else /* BSD style */ | ||
195 | optind = 1; | ||
196 | #endif | ||
197 | |||
166 | return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ | 198 | return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ |
167 | } | 199 | } |
168 | 200 | ||