Punt rc_waitpid
This commit is contained in:
parent
3bfba57f5b
commit
9ff89f8027
16
src/librc.c
16
src/librc.c
@ -603,22 +603,6 @@ static pid_t _exec_service (const char *service, const char *arg)
|
|||||||
return (pid);
|
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)
|
pid_t rc_service_stop (const char *service)
|
||||||
{
|
{
|
||||||
if (rc_service_state (service) & RC_SERVICE_STOPPED)
|
if (rc_service_state (service) & RC_SERVICE_STOPPED)
|
||||||
|
@ -105,9 +105,5 @@ librc_hidden_proto(rc_strlist_delete)
|
|||||||
librc_hidden_proto(rc_strlist_free)
|
librc_hidden_proto(rc_strlist_free)
|
||||||
librc_hidden_proto(rc_strlist_join)
|
librc_hidden_proto(rc_strlist_join)
|
||||||
librc_hidden_proto(rc_strlist_reverse)
|
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
|
#endif
|
||||||
|
21
src/rc.c
21
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)
|
static void handle_signal (int sig)
|
||||||
{
|
{
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
@ -1212,7 +1227,7 @@ int main (int argc, char **argv)
|
|||||||
if (going_down) {
|
if (going_down) {
|
||||||
pid_t pid = rc_service_stop (service);
|
pid_t pid = rc_service_stop (service);
|
||||||
if (pid > 0 && ! rc_env_bool ("RC_PARALLEL"))
|
if (pid > 0 && ! rc_env_bool ("RC_PARALLEL"))
|
||||||
rc_waitpid (pid);
|
wait_pid (pid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1277,7 +1292,7 @@ int main (int argc, char **argv)
|
|||||||
if (! found) {
|
if (! found) {
|
||||||
pid_t pid = rc_service_stop (service);
|
pid_t pid = rc_service_stop (service);
|
||||||
if (pid > 0 && ! rc_env_bool ("RC_PARALLEL"))
|
if (pid > 0 && ! rc_env_bool ("RC_PARALLEL"))
|
||||||
rc_waitpid (pid);
|
wait_pid (pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc_strlist_free (types);
|
rc_strlist_free (types);
|
||||||
@ -1379,7 +1394,7 @@ interactive_option:
|
|||||||
add_pid (pid);
|
add_pid (pid);
|
||||||
|
|
||||||
if (! rc_env_bool ("RC_PARALLEL")) {
|
if (! rc_env_bool ("RC_PARALLEL")) {
|
||||||
rc_waitpid (pid);
|
wait_pid (pid);
|
||||||
remove_pid (pid);
|
remove_pid (pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46
src/rc.h
46
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 */
|
* @return true if all daemons started are still running, otherwise false */
|
||||||
bool rc_service_daemons_crashed (const char *service);
|
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
|
/*! @name Dependency options
|
||||||
* These options can change the services found by the rc_get_depinfo and
|
* These options can change the services found by the rc_get_depinfo and
|
||||||
* rc_get_depends functions. */
|
* rc_get_depends functions. */
|
||||||
@ -359,6 +342,13 @@ char **rc_env_filter (void);
|
|||||||
* our configuration files. */
|
* our configuration files. */
|
||||||
char **rc_env_config (void);
|
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
|
/*! @name String List functions
|
||||||
* Handy functions for dealing with string arrays of char **.
|
* Handy functions for dealing with string arrays of char **.
|
||||||
* It's safe to assume that any function here that uses char ** is a string
|
* 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 */
|
* @param list to free */
|
||||||
void rc_strlist_free (char **list);
|
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
|
/*! Concatenate paths adding '/' if needed. The resultant pointer should be
|
||||||
* freed when finished with.
|
* freed when finished with.
|
||||||
* @param path1 starting path
|
* @param path1 starting path
|
||||||
@ -431,11 +417,17 @@ void rc_strlist_free (char **list);
|
|||||||
* @return pointer to the new path */
|
* @return pointer to the new path */
|
||||||
char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
|
char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
|
||||||
|
|
||||||
/*! Check if an environment variable is a boolean and return it's value.
|
/*! Find processes based on criteria.
|
||||||
* If variable is not a boolean then we set errno to be ENOENT when it does
|
* All of these are optional.
|
||||||
* not exist or EINVAL if it's not a boolean.
|
* pid overrides anything else.
|
||||||
* @param variable to check
|
* If both exec and cmd are given then we ignore exec.
|
||||||
* @return true if it matches true, yes or 1, false if otherwise. */
|
* @param exec to check for
|
||||||
bool rc_env_bool (const char *variable);
|
* @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
|
#endif
|
||||||
|
@ -54,7 +54,6 @@ global:
|
|||||||
rc_strlist_free;
|
rc_strlist_free;
|
||||||
rc_strlist_join;
|
rc_strlist_join;
|
||||||
rc_strlist_reverse;
|
rc_strlist_reverse;
|
||||||
rc_waitpid;
|
|
||||||
|
|
||||||
local:
|
local:
|
||||||
*;
|
*;
|
||||||
|
@ -331,6 +331,21 @@ static int write_prefix (const char *buffer, size_t bytes, bool *prefixed) {
|
|||||||
return (ret);
|
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)
|
static bool svc_exec (const char *arg1, const char *arg2)
|
||||||
{
|
{
|
||||||
bool execok;
|
bool execok;
|
||||||
@ -437,7 +452,7 @@ static bool svc_exec (const char *arg1, const char *arg2)
|
|||||||
master_tty = -1;
|
master_tty = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
execok = rc_waitpid (service_pid) == 0 ? true : false;
|
execok = wait_pid (service_pid) == 0 ? true : false;
|
||||||
service_pid = 0;
|
service_pid = 0;
|
||||||
|
|
||||||
return (execok);
|
return (execok);
|
||||||
@ -618,7 +633,7 @@ static void svc_start (bool deps)
|
|||||||
if (rc_service_state (svc) & RC_SERVICE_STOPPED) {
|
if (rc_service_state (svc) & RC_SERVICE_STOPPED) {
|
||||||
pid_t pid = rc_service_start (svc);
|
pid_t pid = rc_service_start (svc);
|
||||||
if (! rc_env_bool ("RC_PARALLEL"))
|
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);
|
pid_t pid = rc_service_stop (svc);
|
||||||
if (! rc_env_bool ("RC_PARALLEL"))
|
if (! rc_env_bool ("RC_PARALLEL"))
|
||||||
rc_waitpid (pid);
|
wait_pid (pid);
|
||||||
rc_strlist_add (&tmplist, svc);
|
rc_strlist_add (&tmplist, svc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user