diff options
-rw-r--r-- | src/rc-plugin.c | 13 | ||||
-rw-r--r-- | src/rc-plugin.h | 4 | ||||
-rw-r--r-- | src/rc.c | 12 | ||||
-rw-r--r-- | src/runscript.c | 7 |
4 files changed, 27 insertions, 9 deletions
diff --git a/src/rc-plugin.c b/src/rc-plugin.c index 66ffeb5c..5970dc58 100644 --- a/src/rc-plugin.c +++ b/src/rc-plugin.c @@ -19,6 +19,8 @@ #include "rc-plugin.h" #include "strlist.h" +bool rc_in_plugin = false; + typedef struct plugin { char *name; @@ -49,6 +51,10 @@ void rc_plugin_load (void) int i; plugin_t *plugin = plugins; + /* Don't load plugins if we're in one */ + if (rc_in_plugin) + return; + /* Ensure some sanity here */ rc_plugin_unload (); @@ -103,6 +109,10 @@ void rc_plugin_run (rc_hook_t hook, const char *value) { plugin_t *plugin = plugins; + /* Don't run plugins if we're in one */ + if (rc_in_plugin) + return; + while (plugin) { if (plugin->hook) { int i; @@ -135,12 +145,13 @@ void rc_plugin_run (rc_hook_t hook, const char *value) if (pid == 0) { int retval; + rc_in_plugin = true; close (pfd[0]); rc_environ_fd = fdopen (pfd[1], "w"); retval = plugin->hook (hook, value); fclose (rc_environ_fd); rc_environ_fd = NULL; - _exit (retval); + exit (retval); } else { char buffer[RC_LINEBUFFER]; char *token; diff --git a/src/rc-plugin.h b/src/rc-plugin.h index 15d46213..b15a11c7 100644 --- a/src/rc-plugin.h +++ b/src/rc-plugin.h @@ -8,6 +8,10 @@ #ifndef __LIBRC_PLUGIN_H__ #define __LIBRC_PLUGIN_H__ +/* A simple flag to say if we're in a plugin proccess or not. + * Mainly used in atexit code. */ +extern bool rc_in_plugin; + void rc_plugin_load (); void rc_plugin_unload (); void rc_plugin_run (rc_hook_t, const char *value); @@ -83,7 +83,7 @@ static void cleanup (void) rc_plugin_unload (); - if (termios_orig) { + if (! rc_in_plugin && termios_orig) { tcsetattr (STDIN_FILENO, TCSANOW, termios_orig); free (termios_orig); } @@ -103,10 +103,12 @@ static void cleanup (void) rc_strlist_free (types); /* Clean runlevel start, stop markers */ - if (rc_is_dir (RC_SVCDIR "softscripts.new")) - rc_rm_dir (RC_SVCDIR "softscripts.new", true); - if (rc_is_dir (RC_SVCDIR "softscripts.old")) - rc_rm_dir (RC_SVCDIR "softscripts.old", true); + if (! rc_in_plugin) { + if (rc_is_dir (RC_SVCDIR "softscripts.new")) + rc_rm_dir (RC_SVCDIR "softscripts.new", true); + if (rc_is_dir (RC_SVCDIR "softscripts.old")) + rc_rm_dir (RC_SVCDIR "softscripts.old", true); + } free (applet); } diff --git a/src/runscript.c b/src/runscript.c index ad2d69a8..94df6fcc 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -234,7 +234,7 @@ static void start_services (char **list) { static void cleanup (void) { - if (prefix_locked) + if (! rc_in_plugin && prefix_locked) unlink (PREFIX_LOCK); /* Flush our buffered output if any */ @@ -259,7 +259,7 @@ static void cleanup (void) rc_strlist_free (tmplist); free (ibsave); - if (in_control ()) { + if (! rc_in_plugin && in_control ()) { if (rc_service_state (applet, rc_service_stopping)) { /* If the we're shutting down, do it cleanly */ if ((softlevel && @@ -287,7 +287,8 @@ static void cleanup (void) if (mtime_test) { - unlink (mtime_test); + if (! rc_in_plugin) + unlink (mtime_test); free (mtime_test); } free (exclusive); |