From 9ff89f8027fa904737f15d59e2c3b26950391933 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 5 Oct 2007 11:04:49 +0000 Subject: Punt rc_waitpid --- src/librc.c | 16 ---------------- src/librc.h | 4 ---- src/rc.c | 21 ++++++++++++++++++--- src/rc.h | 46 +++++++++++++++++++--------------------------- src/rc.map | 1 - src/runscript.c | 21 ++++++++++++++++++--- 6 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/librc.c b/src/librc.c index 8c27b56a..b52329fc 100644 --- a/src/librc.c +++ b/src/librc.c @@ -603,22 +603,6 @@ static pid_t _exec_service (const char *service, const char *arg) return (pid); } -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); -} -librc_hidden_def(rc_waitpid) - pid_t rc_service_stop (const char *service) { if (rc_service_state (service) & RC_SERVICE_STOPPED) diff --git a/src/librc.h b/src/librc.h index 152e7fc6..7d88ab28 100644 --- a/src/librc.h +++ b/src/librc.h @@ -105,9 +105,5 @@ librc_hidden_proto(rc_strlist_delete) librc_hidden_proto(rc_strlist_free) librc_hidden_proto(rc_strlist_join) librc_hidden_proto(rc_strlist_reverse) -librc_hidden_proto(rc_waitpid) -librc_hidden_proto(rc_xmalloc) -librc_hidden_proto(rc_xrealloc) -librc_hidden_proto(rc_xstrdup) #endif diff --git a/src/rc.c b/src/rc.c index ffcfffe5..9472edb5 100644 --- a/src/rc.c +++ b/src/rc.c @@ -623,6 +623,21 @@ 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; @@ -1212,7 +1227,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")) - rc_waitpid (pid); + wait_pid (pid); continue; } @@ -1277,7 +1292,7 @@ int main (int argc, char **argv) if (! found) { pid_t pid = rc_service_stop (service); if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) - rc_waitpid (pid); + wait_pid (pid); } } rc_strlist_free (types); @@ -1379,7 +1394,7 @@ interactive_option: add_pid (pid); if (! rc_env_bool ("RC_PARALLEL")) { - rc_waitpid (pid); + wait_pid (pid); remove_pid (pid); } } diff --git a/src/rc.h b/src/rc.h index 6d0a127e..1ca1c33a 100644 --- a/src/rc.h +++ b/src/rc.h @@ -220,23 +220,6 @@ char **rc_services_scheduled (const char *service); * @return true if all daemons started are still running, otherwise false */ bool rc_service_daemons_crashed (const char *service); -/*! Wait for a process to finish - * @param pid to wait for - * @return exit status of the process */ -int rc_waitpid (pid_t pid); - -/*! Find processes based on criteria. - * All of these are optional. - * pid overrides anything else. - * If both exec and cmd are given then we ignore exec. - * @param exec to check for - * @param cmd to check for - * @param uid to check for - * @param pid to check for - * @return NULL terminated list of pids */ -pid_t *rc_find_pids (const char *exec, const char *cmd, - uid_t uid, pid_t pid); - /*! @name Dependency options * These options can change the services found by the rc_get_depinfo and * rc_get_depends functions. */ @@ -359,6 +342,13 @@ char **rc_env_filter (void); * our configuration files. */ char **rc_env_config (void); +/*! Check if an environment variable is a boolean and return it's value. + * If variable is not a boolean then we set errno to be ENOENT when it does + * not exist or EINVAL if it's not a boolean. + * @param variable to check + * @return true if it matches true, yes or 1, false if otherwise. */ +bool rc_env_bool (const char *variable); + /*! @name String List functions * Handy functions for dealing with string arrays of char **. * It's safe to assume that any function here that uses char ** is a string @@ -420,10 +410,6 @@ void rc_strlist_reverse (char **list); * @param list to free */ void rc_strlist_free (char **list); -/*! @name Utility - * Although not RC specific functions, they are used by the supporting - * applications */ - /*! Concatenate paths adding '/' if needed. The resultant pointer should be * freed when finished with. * @param path1 starting path @@ -431,11 +417,17 @@ void rc_strlist_free (char **list); * @return pointer to the new path */ char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL; -/*! Check if an environment variable is a boolean and return it's value. - * If variable is not a boolean then we set errno to be ENOENT when it does - * not exist or EINVAL if it's not a boolean. - * @param variable to check - * @return true if it matches true, yes or 1, false if otherwise. */ -bool rc_env_bool (const char *variable); +/*! Find processes based on criteria. + * All of these are optional. + * pid overrides anything else. + * If both exec and cmd are given then we ignore exec. + * @param exec to check for + * @param cmd to check for + * @param uid to check for + * @param pid to check for + * @return NULL terminated list of pids */ +pid_t *rc_find_pids (const char *exec, const char *cmd, + uid_t uid, pid_t pid); + #endif diff --git a/src/rc.map b/src/rc.map index eb9479f7..8dc35c76 100644 --- a/src/rc.map +++ b/src/rc.map @@ -54,7 +54,6 @@ global: rc_strlist_free; rc_strlist_join; rc_strlist_reverse; - rc_waitpid; local: *; diff --git a/src/runscript.c b/src/runscript.c index 1a038602..bfec680c 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -331,6 +331,21 @@ 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; @@ -437,7 +452,7 @@ static bool svc_exec (const char *arg1, const char *arg2) master_tty = -1; } - execok = rc_waitpid (service_pid) == 0 ? true : false; + execok = wait_pid (service_pid) == 0 ? true : false; service_pid = 0; return (execok); @@ -618,7 +633,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")) - rc_waitpid (pid); + wait_pid (pid); } } @@ -849,7 +864,7 @@ static void svc_stop (bool deps) { pid_t pid = rc_service_stop (svc); if (! rc_env_bool ("RC_PARALLEL")) - rc_waitpid (pid); + wait_pid (pid); rc_strlist_add (&tmplist, svc); } } -- cgit v1.2.3