diff options
author | Roy Marples <roy@marples.name> | 2007-07-04 16:02:01 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-07-04 16:02:01 +0000 |
commit | f28763d4928a5ffb2c288388299ccf69ee26f26e (patch) | |
tree | fb84a019286f470bdb41c1370634ef229371e393 /src | |
parent | 46156cc8cdfcdcc676d5d5d0a1a753978e412018 (diff) |
As we're running each plugin in a fork, we need to call our cleanup code so we don't leak memory. To this extent, we now have the global boolean rc_in_plugin and the cleanup code can act accordingly.
Diffstat (limited to 'src')
-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); |