summaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-04-28 16:43:18 +0000
committerDenis Vlasenko2007-04-28 16:43:18 +0000
commit18e19f2b0d36c0d9566d871942dfe282e9cf5a28 (patch)
tree22d3da65f1031bac1833c4f53c24b4f7876d5d6b /libbb/vfork_daemon_rexec.c
parenta6a1785a30d6fe011eeabec3c19e154dc475b1b0 (diff)
downloadbusybox-18e19f2b0d36c0d9566d871942dfe282e9cf5a28.zip
busybox-18e19f2b0d36c0d9566d871942dfe282e9cf5a28.tar.gz
hush: fix nofork + ctrl-Z clobbering of globals
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 78f3c4a..aef74e9 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -100,15 +100,28 @@ int wait_pid(int *wstat, int pid)
return r;
}
-int run_nofork_applet(const struct bb_applet *a, char **argv)
+void save_nofork_data(struct nofork_save_area *save)
{
- int rc, argc;
+ save->current_applet = current_applet;
+ save->xfunc_error_retval = xfunc_error_retval;
+ save->option_mask32 = option_mask32;
+ save->die_sleep = die_sleep;
+ save->saved = 1;
+}
- /* Save some shared globals */
- const struct bb_applet *old_a = current_applet;
- int old_x = xfunc_error_retval;
- uint32_t old_m = option_mask32;
- int old_sleep = die_sleep;
+void restore_nofork_data(struct nofork_save_area *save)
+{
+ current_applet = save->current_applet;
+ xfunc_error_retval = save->xfunc_error_retval;
+ option_mask32 = save->option_mask32;
+ die_sleep = save->die_sleep;
+
+ applet_name = current_applet->name;
+}
+
+int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv)
+{
+ int rc, argc;
current_applet = a;
applet_name = a->name;
@@ -138,14 +151,18 @@ int run_nofork_applet(const struct bb_applet *a, char **argv)
}
/* Restoring globals */
- current_applet = old_a;
- applet_name = old_a->name;
- xfunc_error_retval = old_x;
- option_mask32 = old_m;
- die_sleep = old_sleep;
+ restore_nofork_data(old);
return rc;
}
+int run_nofork_applet(const struct bb_applet *a, char **argv)
+{
+ struct nofork_save_area old;
+ /* Saving globals */
+ save_nofork_data(&old);
+ return run_nofork_applet_prime(&old, a, argv);
+}
+
int spawn_and_wait(char **argv)
{
int rc;