diff --git a/src/cond-w.c b/src/cond-w.c index 8ed0f98d..e68e2b92 100644 --- a/src/cond-w.c +++ b/src/cond-w.c @@ -21,6 +21,7 @@ * THE SOFTWARE. */ +#include #include #include #include @@ -132,6 +133,25 @@ static int cond_checkpath(const char *path) return 0; } +/* Intended for 'service/foo/`, nothing else */ +static void cond_delpath(const char *path) +{ + char fn[PATH_MAX]; + struct dirent *d; + DIR *dir; + + dir = opendir(path); + if (!dir) + return; + + while ((d = readdir(dir))) { + paste(fn, sizeof(fn), path, d->d_name); + remove(fn); + } + closedir(dir); + unlink(path); +} + int cond_set_path(const char *path, enum cond_state next) { enum cond_state prev; @@ -155,8 +175,12 @@ int cond_set_path(const char *path, enum cond_state next) break; case COND_OFF: - if (unlink(path) && errno != ENOENT) - _pe("Failed removing condition '%s'", path); + if (unlink(path)) { + if (errno == ENOENT) + _pe("Failed removing condition '%s'", path); + if (errno == EISDIR) + cond_delpath(path); + } break; default: diff --git a/src/service.c b/src/service.c index be25aecb..12629067 100644 --- a/src/service.c +++ b/src/service.c @@ -1776,6 +1776,24 @@ static void svc_set_state(svc_t *svc, svc_state_t new) cond_clear(failure); } } + + if (svc_is_daemon(svc)) { + char cond[MAX_COND_LEN]; + + snprintf(cond, sizeof(cond), "service/%s/", svc_ident(svc, NULL, 0)); + cond_clear(cond); + + switch (svc->state) { + case SVC_HALTED_STATE: + case SVC_RUNNING_STATE: + strlcat(cond, svc_status(svc), sizeof(cond)); + cond_set_oneshot(cond); + break; + + default: + break; + } + } } /*