diff --git a/service.c b/service.c index 624a0a09..0cddf4a0 100755 --- a/service.c +++ b/service.c @@ -475,8 +475,10 @@ int service_register(int type, char *line, time_t mtime, char *username) } desc = strstr(line, "-- "); - if (desc) + if (desc) { *desc = 0; + desc += 3; + } cmd = strtok(line, " "); if (!cmd) { @@ -574,7 +576,7 @@ recreate: svc->log = log; if (desc) - strlcpy(svc->desc, desc + 3, sizeof(svc->desc)); + strlcpy(svc->desc, desc, sizeof(svc->desc)); if (username) { char *ptr = strchr(username, ':'); @@ -759,8 +761,7 @@ restart: svc_set_state(svc, SVC_HALTED_STATE); } else if (cond_get_agg(svc->cond) == COND_ON) { if (*restart_counter >= RESPAWN_MAX) { - _e("%s keeps crashing, not restarting", - svc->desc ? : svc->cmd); + _e("%s keeps crashing, not restarting", svc->desc); svc->block = SVC_BLOCK_CRASHING; svc_set_state(svc, SVC_HALTED_STATE); break; diff --git a/svc.c b/svc.c index 968b6e30..bfb47094 100644 --- a/svc.c +++ b/svc.c @@ -23,6 +23,7 @@ */ #include +#include #include #include "finit.h" @@ -74,12 +75,22 @@ svc_t *svc_new(char *cmd, int id, int type) svc_t *svc = &list[i]; if (svc->type == SVC_TYPE_FREE) { + char *desc; + memset(svc, 0, sizeof(*svc)); svc->type = type; svc->job = job; svc->id = id; strlcpy(svc->cmd, cmd, sizeof(svc->cmd)); + /* Default description, if missing */ + desc = rindex(cmd, '/'); + if (desc) + desc++; + else + desc = cmd; + strlcpy(svc->desc, desc, sizeof(svc->desc)); + return svc; } }