Refactor svc_status() used by 'initctl show'

Leverage new svc_t states in initctl status/show output.  Also, ensure
different svc_t types have correct start state.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2015-11-26 20:51:04 +01:00
parent b4ccc8b008
commit 1f88e1ff8a
3 changed files with 28 additions and 6 deletions
+1
View File
@@ -145,6 +145,7 @@ void conf_parse_events(svc_t *svc, char *events)
return;
}
svc->state = SVC_CONDHALT_STATE;
strlcpy(svc->events, ptr, sizeof(svc->events));
}
+1
View File
@@ -804,6 +804,7 @@ int service_register(int type, char *line, time_t mtime, char *username)
if (svc_is_inetd(svc)) {
char *iface, *name = service;
svc->state = SVC_WAITING_STATE;
if (svc->inetd.cmd && plugin)
name = plugin->name;
+26 -6
View File
@@ -379,16 +379,36 @@ int svc_clean_bootstrap(svc_t *svc)
char *svc_status(svc_t *svc)
{
if (svc->pid)
return "running";
if (!svc_in_runlevel(svc, runlevel))
return "halted";
return "stopped";
if (svc_is_inetd(svc))
switch (svc->state) {
case SVC_WAITING_STATE:
return "waiting";
return "stopped";
case SVC_PAUSED_STATE:
return "paused";
case SVC_CONDHALT_STATE:
return "nocond";
case SVC_RESTART_STATE:
return "restart";
case SVC_RELOAD_STATE:
return "reload";
case SVC_RUNNING_STATE:
if (svc->pid)
return "running";
/* Fall through */
case SVC_HALTED_STATE:
default:
break;
}
return "halted";
}
/* Same base service, return unique ID */