diff options
author | Roy Marples <roy@marples.name> | 2007-10-22 19:33:42 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-10-22 19:33:42 +0000 |
commit | 9dddb43eb49d07d8c1b87e11c8d259fd41a34ae4 (patch) | |
tree | bb4d9e3908468f9a4347c19842afd7da62850525 /src | |
parent | 6b0c28039d051af85f009cb2cbc4c77a3d93bdb0 (diff) |
Wait for plugins to finish before moving on.
Diffstat (limited to 'src')
-rw-r--r-- | src/rc-plugin.c | 19 | ||||
-rw-r--r-- | src/rc-plugin.h | 1 | ||||
-rw-r--r-- | src/rc.c | 21 | ||||
-rw-r--r-- | src/runscript.c | 36 |
4 files changed, 32 insertions, 45 deletions
diff --git a/src/rc-plugin.c b/src/rc-plugin.c index 1cdf5690..605ced68 100644 --- a/src/rc-plugin.c +++ b/src/rc-plugin.c @@ -5,6 +5,8 @@ Released under the GPLv2 */ +#include <sys/types.h> +#include <sys/wait.h> #include <dirent.h> #include <dlfcn.h> #include <errno.h> @@ -99,6 +101,21 @@ void rc_plugin_load (void) closedir (dp); } +int rc_waitpid (pid_t pid) +{ + int status = 0; + pid_t savedpid = pid; + int retval = -1; + + errno = 0; + while ((pid = waitpid (savedpid, &status, 0)) > 0) { + if (pid == savedpid) + retval = WIFEXITED (status) ? WEXITSTATUS (status) : EXIT_FAILURE; + } + + return (retval); +} + void rc_plugin_run (rc_hook_t hook, const char *value) { plugin_t *plugin = plugins; @@ -176,6 +193,8 @@ void rc_plugin_run (rc_hook_t hook, const char *value) free (buffer); close (pfd[0]); + + rc_waitpid (pid); } } plugin = plugin->next; diff --git a/src/rc-plugin.h b/src/rc-plugin.h index b15a11c7..56b012ba 100644 --- a/src/rc-plugin.h +++ b/src/rc-plugin.h @@ -12,6 +12,7 @@ * Mainly used in atexit code. */ extern bool rc_in_plugin; +int rc_waitpid (pid_t pid); void rc_plugin_load (); void rc_plugin_unload (); void rc_plugin_run (rc_hook_t, const char *value); @@ -629,21 +629,6 @@ static void remove_pid (pid_t pid) } } -static int wait_pid (pid_t pid) -{ - int status = 0; - pid_t savedpid = pid; - int retval = -1; - - errno = 0; - while ((pid = waitpid (savedpid, &status, 0)) > 0) { - if (pid == savedpid) - retval = WIFEXITED (status) ? WEXITSTATUS (status) : EXIT_FAILURE; - } - - return (retval); -} - static void handle_signal (int sig) { int serrno = errno; @@ -1223,7 +1208,7 @@ int main (int argc, char **argv) if (going_down) { pid_t pid = rc_service_stop (service); if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) - wait_pid (pid); + rc_waitpid (pid); continue; } @@ -1289,7 +1274,7 @@ int main (int argc, char **argv) if (! found) { pid_t pid = rc_service_stop (service); if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) - wait_pid (pid); + rc_waitpid (pid); } } @@ -1385,7 +1370,7 @@ interactive_option: add_pid (pid); if (! rc_env_bool ("RC_PARALLEL")) { - wait_pid (pid); + rc_waitpid (pid); remove_pid (pid); } } diff --git a/src/runscript.c b/src/runscript.c index a375b70b..30288218 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -13,7 +13,6 @@ #include <sys/ioctl.h> #include <sys/param.h> #include <sys/stat.h> -#include <sys/wait.h> #include <dlfcn.h> #include <errno.h> #include <fcntl.h> @@ -132,9 +131,8 @@ static void handle_signal (int sig) if (signal_pipe[1] > -1) { if (write (signal_pipe[1], &sig, sizeof (sig)) == -1) eerror ("%s: send: %s", service, strerror (errno)); - } else { - wait (0); - } + } else + rc_waitpid (-1); break; case SIGWINCH: @@ -356,21 +354,6 @@ static int write_prefix (const char *buffer, size_t bytes, bool *prefixed) { return (ret); } -static int wait_pid (pid_t pid) -{ - int status = 0; - pid_t savedpid = pid; - int retval = -1; - - errno = 0; - while ((pid = waitpid (savedpid, &status, 0)) > 0) { - if (pid == savedpid) - retval = WIFEXITED (status) ? WEXITSTATUS (status) : EXIT_FAILURE; - } - - return (retval); -} - static bool svc_exec (const char *arg1, const char *arg2) { bool execok; @@ -419,7 +402,6 @@ static bool svc_exec (const char *arg1, const char *arg2) * good for us */ close (master_tty); - dup2 (fileno (stdin), 0); dup2 (slave_tty, 1); dup2 (slave_tty, 2); if (slave_tty > 2) @@ -457,14 +439,14 @@ static bool svc_exec (const char *arg1, const char *arg2) } if (s > 0) { - /* Only SIGCHLD signals come down this pipe */ - if (FD_ISSET (signal_pipe[0], &rset)) - break; - if (master_tty >= 0 && FD_ISSET (master_tty, &rset)) { bytes = read (master_tty, buffer, RC_LINEBUFFER); write_prefix (buffer, bytes, &prefixed); } + + /* Only SIGCHLD signals come down this pipe */ + if (FD_ISSET (signal_pipe[0], &rset)) + break; } } @@ -479,7 +461,7 @@ static bool svc_exec (const char *arg1, const char *arg2) master_tty = -1; } - execok = wait_pid (service_pid) == 0 ? true : false; + execok = rc_waitpid (service_pid) == 0 ? true : false; service_pid = 0; return (execok); @@ -650,7 +632,7 @@ static void svc_start (bool deps) if (rc_service_state (svc) & RC_SERVICE_STOPPED) { pid_t pid = rc_service_start (svc); if (! rc_env_bool ("RC_PARALLEL")) - wait_pid (pid); + rc_waitpid (pid); } } @@ -857,7 +839,7 @@ static void svc_stop (bool deps) { pid_t pid = rc_service_stop (svc); if (! rc_env_bool ("RC_PARALLEL")) - wait_pid (pid); + rc_waitpid (pid); rc_strlist_add (&tmplist, svc); } } |