summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libbb/getopt32.c22
-rw-r--r--libbb/lineedit.c3
-rw-r--r--libbb/setup_environment.c14
-rw-r--r--libbb/vfork_daemon_rexec.c36
4 files changed, 43 insertions, 32 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 8fb99b6cc..ee85181cd 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -515,28 +515,6 @@ getopt32(char **argv, const char *applet_opts, ...)
515 } 515 }
516 } 516 }
517 517
518 /* In case getopt32 was already called:
519 * reset the libc getopt() function, which keeps internal state.
520 *
521 * BSD-derived getopt() functions require that optind be set to 1 in
522 * order to reset getopt() state. This used to be generally accepted
523 * way of resetting getopt(). However, glibc's getopt()
524 * has additional getopt() state beyond optind, and requires that
525 * optind be set to zero to reset its state. So the unfortunate state of
526 * affairs is that BSD-derived versions of getopt() misbehave if
527 * optind is set to 0 in order to reset getopt(), and glibc's getopt()
528 * will core dump if optind is set 1 in order to reset getopt().
529 *
530 * More modern versions of BSD require that optreset be set to 1 in
531 * order to reset getopt(). Sigh. Standards, anyone?
532 */
533#ifdef __GLIBC__
534 optind = 0;
535#else /* BSD style */
536 optind = 1;
537 /* optreset = 1; */
538#endif
539 /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */
540 pargv = NULL; 518 pargv = NULL;
541 519
542 /* Note: just "getopt() <= 0" will not work well for 520 /* Note: just "getopt() <= 0" will not work well for
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index c2c3ea996..1f21866ca 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1415,7 +1415,8 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
1415 if ((state->flags & SAVE_HISTORY) && state->hist_file) 1415 if ((state->flags & SAVE_HISTORY) && state->hist_file)
1416 load_history(state->hist_file); 1416 load_history(state->hist_file);
1417#endif 1417#endif
1418 state->cur_history = state->cnt_history; 1418 if (state->flags & DO_HISTORY)
1419 state->cur_history = state->cnt_history;
1419 1420
1420 /* prepare before init handlers */ 1421 /* prepare before init handlers */
1421 cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */ 1422 cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index 04e333fed..78318ce62 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -32,16 +32,16 @@
32 32
33void FAST_FUNC setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw) 33void FAST_FUNC setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw)
34{ 34{
35 /* Change the current working directory to be the home directory
36 * of the user */
37 if (chdir(pw->pw_dir)) {
38 xchdir("/");
39 bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
40 }
41
35 if (clear_env) { 42 if (clear_env) {
36 const char *term; 43 const char *term;
37 44
38 /* Change the current working directory to be the home directory
39 * of the user */
40 if (chdir(pw->pw_dir)) {
41 xchdir("/");
42 bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
43 }
44
45 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. 45 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
46 Unset all other environment variables. */ 46 Unset all other environment variables. */
47 term = getenv("TERM"); 47 term = getenv("TERM");
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