mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
initctl: add the settings of a service to the JSON status
initctl -j status had the state of a service but little of how it is
set up. A program reading it could not tell how the service is
stopped, what scripts it runs, or how it signals readiness.
Add the settings: stop, reload, notify, remain, scripts, directories,
cgroup-config, rlimits, log or tty, provides, conflicts, if, groups,
capabilities, pam, name, id, protected, and nowarn. The restart
object also gets sec, respawn, and oncrash, and the state Finit keeps
for its own use goes in internal:
"stop": {
"signal": "SIGTERM",
"timeout": 3,
"scope": "pgroup"
},
"scripts": {
"exec-stop-post": { "command": "/bin/true", "timeout": 7 }
},
initctl reads the status over D-Bus first, so each setting is also a
property of org.finit.Service1. The new test checks that the JSON is
the same over D-Bus as over the initctl socket.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
12 files changed
+893
-29
No files matched your search
+166
@@ -804,6 +804,107 @@ SVC_PROP_BOOL(svc_prop_manual, manual)
|
||||
SVC_PROP_BOOL(svc_prop_forking, forking)
|
||||
SVC_PROP_BOOL(svc_prop_started, started)
|
||||
|
||||
/* The settings of the service, for initctl -j status */
|
||||
#define SVC_PROP_EXPR(fn, writer, expr) \
|
||||
static int fn(link_writer_t *w, void *arg) \
|
||||
{ \
|
||||
svc_t *svc = arg; \
|
||||
\
|
||||
writer(w, expr); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
static int svc_prop_provides(link_writer_t *w, void *arg)
|
||||
{
|
||||
char buf[MAX_NUM_PROVIDES * MAX_COND_LEN];
|
||||
|
||||
link_w_string(w, svc_provides_str(arg, buf, sizeof(buf)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int svc_prop_rlimits(link_writer_t *w, void *arg)
|
||||
{
|
||||
svc_t *svc = arg;
|
||||
char buf[1024];
|
||||
|
||||
link_w_string(w, rlimits2str(svc->rlimit, buf, sizeof(buf)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int svc_prop_stop_signal(link_writer_t *w, void *arg)
|
||||
{
|
||||
svc_t *svc = arg;
|
||||
char buf[16];
|
||||
|
||||
/* Not sig_name(), initctl has only sig2str() for its own transport */
|
||||
snprintf(buf, sizeof(buf), "SIG%s", sig2str(svc->sighalt));
|
||||
link_w_string(w, buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SVC_PROP_BOOL(svc_prop_remain, remain)
|
||||
SVC_PROP_STR (svc_prop_if, ifstmt)
|
||||
SVC_PROP_STR (svc_prop_conflicts, conflict)
|
||||
SVC_PROP_STR (svc_prop_extra_groups, supgroups)
|
||||
SVC_PROP_STR (svc_prop_capabilities, capabilities)
|
||||
SVC_PROP_STR (svc_prop_pam, pam)
|
||||
SVC_PROP_U32 (svc_prop_stop_timeout, killdelay / 1000)
|
||||
SVC_PROP_U32 (svc_prop_restart_sec, restart_saved / 1000)
|
||||
SVC_PROP_BOOL(svc_prop_respawn, respawn)
|
||||
SVC_PROP_BOOL(svc_prop_protected, protect)
|
||||
SVC_PROP_STR (svc_prop_id, id)
|
||||
SVC_PROP_U32 (svc_prop_job, job)
|
||||
SVC_PROP_U32 (svc_prop_old_pid, oldpid)
|
||||
SVC_PROP_BOOL(svc_prop_dirty, dirty)
|
||||
SVC_PROP_BOOL(svc_prop_removed, removed)
|
||||
SVC_PROP_BOOL(svc_prop_starting, starting)
|
||||
SVC_PROP_BOOL(svc_prop_no_warn, nowarn)
|
||||
SVC_PROP_BOOL(svc_prop_reload_propagate, flux_reload)
|
||||
SVC_PROP_STR (svc_prop_cgroup_name, cgroup.name)
|
||||
SVC_PROP_STR (svc_prop_cgroup_config, cgroup.cfg)
|
||||
SVC_PROP_BOOL(svc_prop_cgroup_delegate, cgroup.delegate)
|
||||
SVC_PROP_U32 (svc_prop_runtime_dir_mode, dir_mode[0])
|
||||
SVC_PROP_U32 (svc_prop_state_dir_mode, dir_mode[1])
|
||||
SVC_PROP_U32 (svc_prop_cache_dir_mode, dir_mode[2])
|
||||
SVC_PROP_U32 (svc_prop_logs_dir_mode, dir_mode[3])
|
||||
SVC_PROP_U32 (svc_prop_config_dir_mode, dir_mode[4])
|
||||
SVC_PROP_STR (svc_prop_runtime_dir, runtime_dir)
|
||||
SVC_PROP_STR (svc_prop_state_dir, state_dir)
|
||||
SVC_PROP_STR (svc_prop_cache_dir, cache_dir)
|
||||
SVC_PROP_STR (svc_prop_logs_dir, logs_dir)
|
||||
SVC_PROP_STR (svc_prop_config_dir, config_dir)
|
||||
SVC_PROP_STR (svc_prop_exec_start_pre, pre_script)
|
||||
SVC_PROP_U32 (svc_prop_exec_start_pre_timeout, pre_tmo / 1000)
|
||||
SVC_PROP_STR (svc_prop_exec_start_ready, ready_script)
|
||||
SVC_PROP_U32 (svc_prop_exec_start_ready_timeout, ready_tmo / 1000)
|
||||
SVC_PROP_STR (svc_prop_exec_stop, stop_script)
|
||||
SVC_PROP_U32 (svc_prop_exec_stop_timeout, stop_tmo / 1000)
|
||||
SVC_PROP_STR (svc_prop_exec_stop_post, post_script)
|
||||
SVC_PROP_U32 (svc_prop_exec_stop_post_timeout, post_tmo / 1000)
|
||||
SVC_PROP_STR (svc_prop_exec_reload, reload_script)
|
||||
SVC_PROP_U32 (svc_prop_exec_reload_timeout, reload_tmo / 1000)
|
||||
SVC_PROP_STR (svc_prop_exec_cleanup, cleanup_script)
|
||||
SVC_PROP_U32 (svc_prop_exec_cleanup_timeout, cleanup_tmo / 1000)
|
||||
SVC_PROP_EXPR(svc_prop_notify, link_w_string, svc_notify_str(svc))
|
||||
SVC_PROP_EXPR(svc_prop_stop_scope, link_w_string, svc_scope_str(svc->stop_scope))
|
||||
SVC_PROP_EXPR(svc_prop_reload_signal, link_w_string, svc->sighup ? "SIGHUP" : "none")
|
||||
SVC_PROP_EXPR(svc_prop_on_crash, link_w_string, svc_oncrash_str(svc))
|
||||
SVC_PROP_EXPR(svc_prop_runtime_dir_preserve, link_w_string, svc_preserve_str(svc))
|
||||
SVC_PROP_EXPR(svc_prop_log, link_w_bool, !svc_is_tty(svc) ? svc->log.enabled : 0)
|
||||
SVC_PROP_EXPR(svc_prop_log_null, link_w_bool, !svc_is_tty(svc) ? svc->log.null : 0)
|
||||
SVC_PROP_EXPR(svc_prop_log_console, link_w_bool, !svc_is_tty(svc) ? svc->log.console : 0)
|
||||
SVC_PROP_EXPR(svc_prop_log_file, link_w_string, !svc_is_tty(svc) ? svc->log.file : "")
|
||||
SVC_PROP_EXPR(svc_prop_log_priority, link_w_string, !svc_is_tty(svc) ? svc->log.prio : "")
|
||||
SVC_PROP_EXPR(svc_prop_log_identity, link_w_string, !svc_is_tty(svc) ? svc->log.ident : "")
|
||||
SVC_PROP_EXPR(svc_prop_tty_device, link_w_string, svc_is_tty(svc) ? svc->dev : "")
|
||||
SVC_PROP_EXPR(svc_prop_tty_baud, link_w_string, svc_is_tty(svc) ? svc->baud : "")
|
||||
SVC_PROP_EXPR(svc_prop_tty_term, link_w_string, svc_is_tty(svc) ? svc->term : "")
|
||||
SVC_PROP_EXPR(svc_prop_tty_no_clear, link_w_bool, svc_is_tty(svc) ? svc->noclear : 0)
|
||||
SVC_PROP_EXPR(svc_prop_tty_no_wait, link_w_bool, svc_is_tty(svc) ? svc->nowait : 0)
|
||||
SVC_PROP_EXPR(svc_prop_tty_no_login, link_w_bool, svc_is_tty(svc) ? svc->nologin : 0)
|
||||
SVC_PROP_EXPR(svc_prop_tty_no_tty, link_w_bool, svc_is_tty(svc) ? svc->notty : 0)
|
||||
SVC_PROP_EXPR(svc_prop_tty_rescue, link_w_bool, svc_is_tty(svc) ? svc->rescue : 0)
|
||||
|
||||
static const link_property_t service_properties[] = {
|
||||
{ .name = "Identity", .sig = "s", .getter = svc_prop_identity },
|
||||
{ .name = "Name", .sig = "s", .getter = svc_prop_name },
|
||||
@@ -830,6 +931,71 @@ static const link_property_t service_properties[] = {
|
||||
{ .name = "ManualStart", .sig = "b", .getter = svc_prop_manual },
|
||||
{ .name = "Forking", .sig = "b", .getter = svc_prop_forking },
|
||||
{ .name = "Started", .sig = "b", .getter = svc_prop_started },
|
||||
{ .name = "Notify", .sig = "s", .getter = svc_prop_notify },
|
||||
{ .name = "Remain", .sig = "b", .getter = svc_prop_remain },
|
||||
{ .name = "If", .sig = "s", .getter = svc_prop_if },
|
||||
{ .name = "Provides", .sig = "s", .getter = svc_prop_provides },
|
||||
{ .name = "Conflicts", .sig = "s", .getter = svc_prop_conflicts },
|
||||
{ .name = "ExtraGroups", .sig = "s", .getter = svc_prop_extra_groups },
|
||||
{ .name = "Capabilities", .sig = "s", .getter = svc_prop_capabilities },
|
||||
{ .name = "Pam", .sig = "s", .getter = svc_prop_pam },
|
||||
{ .name = "StopSignal", .sig = "s", .getter = svc_prop_stop_signal },
|
||||
{ .name = "StopTimeout", .sig = "u", .getter = svc_prop_stop_timeout },
|
||||
{ .name = "StopScope", .sig = "s", .getter = svc_prop_stop_scope },
|
||||
{ .name = "ReloadSignal", .sig = "s", .getter = svc_prop_reload_signal },
|
||||
{ .name = "RestartSec", .sig = "u", .getter = svc_prop_restart_sec },
|
||||
{ .name = "Respawn", .sig = "b", .getter = svc_prop_respawn },
|
||||
{ .name = "OnCrash", .sig = "s", .getter = svc_prop_on_crash },
|
||||
{ .name = "RuntimeDir", .sig = "s", .getter = svc_prop_runtime_dir },
|
||||
{ .name = "StateDir", .sig = "s", .getter = svc_prop_state_dir },
|
||||
{ .name = "CacheDir", .sig = "s", .getter = svc_prop_cache_dir },
|
||||
{ .name = "LogsDir", .sig = "s", .getter = svc_prop_logs_dir },
|
||||
{ .name = "ConfigDir", .sig = "s", .getter = svc_prop_config_dir },
|
||||
{ .name = "RuntimeDirPreserve", .sig = "s", .getter = svc_prop_runtime_dir_preserve },
|
||||
{ .name = "RuntimeDirMode", .sig = "u", .getter = svc_prop_runtime_dir_mode },
|
||||
{ .name = "StateDirMode", .sig = "u", .getter = svc_prop_state_dir_mode },
|
||||
{ .name = "CacheDirMode", .sig = "u", .getter = svc_prop_cache_dir_mode },
|
||||
{ .name = "LogsDirMode", .sig = "u", .getter = svc_prop_logs_dir_mode },
|
||||
{ .name = "ConfigDirMode", .sig = "u", .getter = svc_prop_config_dir_mode },
|
||||
{ .name = "Protected", .sig = "b", .getter = svc_prop_protected },
|
||||
{ .name = "Id", .sig = "s", .getter = svc_prop_id },
|
||||
{ .name = "Job", .sig = "u", .getter = svc_prop_job },
|
||||
{ .name = "OldPid", .sig = "u", .getter = svc_prop_old_pid },
|
||||
{ .name = "Dirty", .sig = "b", .getter = svc_prop_dirty },
|
||||
{ .name = "Removed", .sig = "b", .getter = svc_prop_removed },
|
||||
{ .name = "Starting", .sig = "b", .getter = svc_prop_starting },
|
||||
{ .name = "NoWarn", .sig = "b", .getter = svc_prop_no_warn },
|
||||
{ .name = "ReloadPropagate", .sig = "b", .getter = svc_prop_reload_propagate },
|
||||
{ .name = "CgroupName", .sig = "s", .getter = svc_prop_cgroup_name },
|
||||
{ .name = "CgroupConfig", .sig = "s", .getter = svc_prop_cgroup_config },
|
||||
{ .name = "CgroupDelegate", .sig = "b", .getter = svc_prop_cgroup_delegate },
|
||||
{ .name = "Rlimits", .sig = "s", .getter = svc_prop_rlimits },
|
||||
{ .name = "ExecStartPre", .sig = "s", .getter = svc_prop_exec_start_pre },
|
||||
{ .name = "ExecStartPreTimeout", .sig = "u", .getter = svc_prop_exec_start_pre_timeout },
|
||||
{ .name = "ExecStartReady", .sig = "s", .getter = svc_prop_exec_start_ready },
|
||||
{ .name = "ExecStartReadyTimeout", .sig = "u", .getter = svc_prop_exec_start_ready_timeout },
|
||||
{ .name = "ExecStop", .sig = "s", .getter = svc_prop_exec_stop },
|
||||
{ .name = "ExecStopTimeout", .sig = "u", .getter = svc_prop_exec_stop_timeout },
|
||||
{ .name = "ExecStopPost", .sig = "s", .getter = svc_prop_exec_stop_post },
|
||||
{ .name = "ExecStopPostTimeout", .sig = "u", .getter = svc_prop_exec_stop_post_timeout },
|
||||
{ .name = "ExecReload", .sig = "s", .getter = svc_prop_exec_reload },
|
||||
{ .name = "ExecReloadTimeout", .sig = "u", .getter = svc_prop_exec_reload_timeout },
|
||||
{ .name = "ExecCleanup", .sig = "s", .getter = svc_prop_exec_cleanup },
|
||||
{ .name = "ExecCleanupTimeout", .sig = "u", .getter = svc_prop_exec_cleanup_timeout },
|
||||
{ .name = "Log", .sig = "b", .getter = svc_prop_log },
|
||||
{ .name = "LogNull", .sig = "b", .getter = svc_prop_log_null },
|
||||
{ .name = "LogConsole", .sig = "b", .getter = svc_prop_log_console },
|
||||
{ .name = "LogFile", .sig = "s", .getter = svc_prop_log_file },
|
||||
{ .name = "LogPriority", .sig = "s", .getter = svc_prop_log_priority },
|
||||
{ .name = "LogIdentity", .sig = "s", .getter = svc_prop_log_identity },
|
||||
{ .name = "TtyDevice", .sig = "s", .getter = svc_prop_tty_device },
|
||||
{ .name = "TtyBaud", .sig = "s", .getter = svc_prop_tty_baud },
|
||||
{ .name = "TtyTerm", .sig = "s", .getter = svc_prop_tty_term },
|
||||
{ .name = "TtyNoClear", .sig = "b", .getter = svc_prop_tty_no_clear },
|
||||
{ .name = "TtyNoWait", .sig = "b", .getter = svc_prop_tty_no_wait },
|
||||
{ .name = "TtyNoLogin", .sig = "b", .getter = svc_prop_tty_no_login },
|
||||
{ .name = "TtyNoTty", .sig = "b", .getter = svc_prop_tty_no_tty },
|
||||
{ .name = "TtyRescue", .sig = "b", .getter = svc_prop_tty_rescue },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
+383
-8
@@ -1475,6 +1475,16 @@ static int svc_compare(svc_t *svc, char *arg)
|
||||
* from a raw svc_t on the legacy socket path or from Service1
|
||||
* properties on the D-Bus path, rendered by the same printers.
|
||||
*/
|
||||
/* In the order of the script[] and dir[] members of svc_row */
|
||||
#define NUM_SCRIPTS 6
|
||||
static const char *script_names[NUM_SCRIPTS] = {
|
||||
"exec-start-pre", "exec-start-ready", "exec-stop",
|
||||
"exec-stop-post", "exec-reload", "exec-cleanup",
|
||||
};
|
||||
static const char *dir_names[NUM_SVCDIRS] = {
|
||||
"runtime", "state", "cache", "logs", "config",
|
||||
};
|
||||
|
||||
struct svc_row {
|
||||
char ident[MAX_IDENT_LEN];
|
||||
char state[16];
|
||||
@@ -1500,6 +1510,56 @@ struct svc_row {
|
||||
int manual;
|
||||
int forking;
|
||||
int started;
|
||||
|
||||
/* Settings, only in the JSON output */
|
||||
char name[MAX_ARG_LEN];
|
||||
char id[MAX_ID_LEN];
|
||||
uint32_t job;
|
||||
uint32_t oldpid;
|
||||
int dirty;
|
||||
int removed;
|
||||
int starting;
|
||||
char rlimits[1024]; /* name=soft:hard,... */
|
||||
char cgroup_name[16];
|
||||
char cgroup_cfg[128];
|
||||
uint32_t dir_mode[NUM_SVCDIRS];
|
||||
int cgroup_delegate;
|
||||
int protect;
|
||||
int nowarn;
|
||||
int flux_reload;
|
||||
char notify[8];
|
||||
char ifstmt[MAX_IDENT_LEN];
|
||||
char provides[MAX_NUM_PROVIDES * MAX_COND_LEN];
|
||||
char conflicts[MAX_ARG_LEN];
|
||||
char supgroups[MAX_SUPGROUPS_LEN];
|
||||
char caps[MAX_CMD_LEN];
|
||||
char pam[MAX_ARG_LEN];
|
||||
char stop_signal[16];
|
||||
char stop_scope[8];
|
||||
char reload_signal[8];
|
||||
char oncrash[8];
|
||||
char dir[NUM_SVCDIRS][MAX_ARG_LEN];
|
||||
char preserve[8];
|
||||
char script[NUM_SCRIPTS][MAX_CMD_LEN];
|
||||
uint32_t script_tmo[NUM_SCRIPTS]; /* seconds */
|
||||
char log_file[64];
|
||||
char log_prio[20];
|
||||
char log_ident[20];
|
||||
char tty_dev[32];
|
||||
char tty_baud[10];
|
||||
char tty_term[10];
|
||||
uint32_t stop_timeout; /* seconds */
|
||||
uint32_t restart_sec; /* restart-sec, 0 = not set */
|
||||
int remain;
|
||||
int respawn;
|
||||
int log;
|
||||
int log_null;
|
||||
int log_console;
|
||||
int tty_noclear;
|
||||
int tty_nowait;
|
||||
int tty_nologin;
|
||||
int tty_notty;
|
||||
int tty_rescue;
|
||||
};
|
||||
|
||||
static void fill_row_from_svc(struct svc_row *r, svc_t *svc)
|
||||
@@ -1532,6 +1592,73 @@ static void fill_row_from_svc(struct svc_row *r, svc_t *svc)
|
||||
r->manual = svc->manual;
|
||||
r->forking = svc->forking;
|
||||
r->started = svc->started;
|
||||
|
||||
strlcpy(r->notify, svc_notify_str(svc), sizeof(r->notify));
|
||||
r->remain = svc->remain;
|
||||
strlcpy(r->ifstmt, svc->ifstmt, sizeof(r->ifstmt));
|
||||
svc_provides_str(svc, r->provides, sizeof(r->provides));
|
||||
strlcpy(r->conflicts, svc->conflict, sizeof(r->conflicts));
|
||||
strlcpy(r->supgroups, svc->supgroups, sizeof(r->supgroups));
|
||||
strlcpy(r->caps, svc->capabilities, sizeof(r->caps));
|
||||
strlcpy(r->pam, svc->pam, sizeof(r->pam));
|
||||
snprintf(r->stop_signal, sizeof(r->stop_signal), "SIG%s", sig2str(svc->sighalt));
|
||||
r->stop_timeout = (uint32_t)(svc->killdelay / 1000);
|
||||
strlcpy(r->stop_scope, svc_scope_str(svc->stop_scope), sizeof(r->stop_scope));
|
||||
strlcpy(r->reload_signal, svc->sighup ? "SIGHUP" : "none", sizeof(r->reload_signal));
|
||||
r->restart_sec = (uint32_t)(svc->restart_saved / 1000);
|
||||
r->respawn = svc->respawn;
|
||||
strlcpy(r->name, svc->name, sizeof(r->name));
|
||||
strlcpy(r->id, svc->id, sizeof(r->id));
|
||||
r->job = (uint32_t)svc->job;
|
||||
r->oldpid = (uint32_t)svc->oldpid;
|
||||
r->dirty = svc->dirty;
|
||||
r->removed = svc->removed;
|
||||
r->starting = svc->starting;
|
||||
rlimits2str(svc->rlimit, r->rlimits, sizeof(r->rlimits));
|
||||
strlcpy(r->cgroup_name, svc->cgroup.name, sizeof(r->cgroup_name));
|
||||
strlcpy(r->cgroup_cfg, svc->cgroup.cfg, sizeof(r->cgroup_cfg));
|
||||
r->cgroup_delegate = svc->cgroup.delegate;
|
||||
for (int i = 0; i < NUM_SVCDIRS; i++)
|
||||
r->dir_mode[i] = (uint32_t)svc->dir_mode[i];
|
||||
r->protect = svc->protect;
|
||||
r->nowarn = svc->nowarn;
|
||||
r->flux_reload = svc->flux_reload;
|
||||
strlcpy(r->oncrash, svc_oncrash_str(svc), sizeof(r->oncrash));
|
||||
strlcpy(r->dir[0], svc->runtime_dir, sizeof(r->dir[0]));
|
||||
strlcpy(r->dir[1], svc->state_dir, sizeof(r->dir[1]));
|
||||
strlcpy(r->dir[2], svc->cache_dir, sizeof(r->dir[2]));
|
||||
strlcpy(r->dir[3], svc->logs_dir, sizeof(r->dir[3]));
|
||||
strlcpy(r->dir[4], svc->config_dir, sizeof(r->dir[4]));
|
||||
strlcpy(r->preserve, svc_preserve_str(svc), sizeof(r->preserve));
|
||||
strlcpy(r->script[0], svc->pre_script, sizeof(r->script[0]));
|
||||
r->script_tmo[0] = (uint32_t)(svc->pre_tmo / 1000);
|
||||
strlcpy(r->script[1], svc->ready_script, sizeof(r->script[1]));
|
||||
r->script_tmo[1] = (uint32_t)(svc->ready_tmo / 1000);
|
||||
strlcpy(r->script[2], svc->stop_script, sizeof(r->script[2]));
|
||||
r->script_tmo[2] = (uint32_t)(svc->stop_tmo / 1000);
|
||||
strlcpy(r->script[3], svc->post_script, sizeof(r->script[3]));
|
||||
r->script_tmo[3] = (uint32_t)(svc->post_tmo / 1000);
|
||||
strlcpy(r->script[4], svc->reload_script, sizeof(r->script[4]));
|
||||
r->script_tmo[4] = (uint32_t)(svc->reload_tmo / 1000);
|
||||
strlcpy(r->script[5], svc->cleanup_script, sizeof(r->script[5]));
|
||||
r->script_tmo[5] = (uint32_t)(svc->cleanup_tmo / 1000);
|
||||
if (svc_is_tty(svc)) {
|
||||
strlcpy(r->tty_dev, svc->dev, sizeof(r->tty_dev));
|
||||
strlcpy(r->tty_baud, svc->baud, sizeof(r->tty_baud));
|
||||
strlcpy(r->tty_term, svc->term, sizeof(r->tty_term));
|
||||
r->tty_noclear = svc->noclear;
|
||||
r->tty_nowait = svc->nowait;
|
||||
r->tty_nologin = svc->nologin;
|
||||
r->tty_notty = svc->notty;
|
||||
r->tty_rescue = svc->rescue;
|
||||
} else {
|
||||
r->log = svc->log.enabled;
|
||||
r->log_null = svc->log.null;
|
||||
r->log_console = svc->log.console;
|
||||
strlcpy(r->log_file, svc->log.file, sizeof(r->log_file));
|
||||
strlcpy(r->log_prio, svc->log.prio, sizeof(r->log_prio));
|
||||
strlcpy(r->log_ident, svc->log.ident, sizeof(r->log_ident));
|
||||
}
|
||||
}
|
||||
|
||||
static const char *pidfile_str(struct svc_row *r)
|
||||
@@ -1700,6 +1827,176 @@ static char *json_escape(const char *str)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static const char *json_bool(int val)
|
||||
{
|
||||
return val ? "true" : "false";
|
||||
}
|
||||
|
||||
/* "a,b" as [ "a", "b" ], nothing when the list is empty */
|
||||
static void json_list(FILE *fp, const char *indent, const char *key, const char *list)
|
||||
{
|
||||
char *buf = strdupa(list), *tok, *ptr;
|
||||
const char *sep = "";
|
||||
|
||||
if (!list[0])
|
||||
return;
|
||||
|
||||
fprintf(fp, "%s \"%s\": [", indent, key);
|
||||
for (tok = strtok_r(buf, ",", &ptr); tok; tok = strtok_r(NULL, ",", &ptr)) {
|
||||
fprintf(fp, "%s \"%s\"", sep, json_escape(tok));
|
||||
sep = ",";
|
||||
}
|
||||
fprintf(fp, " ],\n");
|
||||
}
|
||||
|
||||
/* "nofile=1024:unlimited,..." from rlimits2str() as an object */
|
||||
static void json_rlimits(FILE *fp, const char *indent, const char *rlimits)
|
||||
{
|
||||
char *buf = strdupa(rlimits), *tok, *ptr;
|
||||
const char *sep = "";
|
||||
|
||||
fprintf(fp, "%s \"rlimits\": {", indent);
|
||||
for (tok = strtok_r(buf, ",", &ptr); tok; tok = strtok_r(NULL, ",", &ptr)) {
|
||||
char *soft = strchr(tok, '='), *hard;
|
||||
const char *q[2];
|
||||
|
||||
if (!soft || !(hard = strchr(soft, ':')))
|
||||
continue;
|
||||
*soft++ = 0;
|
||||
*hard++ = 0;
|
||||
|
||||
/* unlimited is the only value that is not a number */
|
||||
q[0] = soft[0] == 'u' ? "\"" : "";
|
||||
q[1] = hard[0] == 'u' ? "\"" : "";
|
||||
fprintf(fp, "%s\n%s \"%s\": { \"soft\": %s%s%s, \"hard\": %s%s%s }",
|
||||
sep, indent, tok, q[0], soft, q[0], q[1], hard, q[1]);
|
||||
sep = ",";
|
||||
}
|
||||
if (sep[0])
|
||||
fprintf(fp, "\n%s ", indent);
|
||||
fprintf(fp, "},\n");
|
||||
}
|
||||
|
||||
/* The settings of a service, what the plain view leaves out */
|
||||
static void json_settings(FILE *fp, struct svc_row *r, const char *indent)
|
||||
{
|
||||
const char *sep = "";
|
||||
int i;
|
||||
|
||||
fprintf(fp, "%s \"name\": \"%s\",\n", indent, json_escape(r->name));
|
||||
fprintf(fp, "%s \"id\": \"%s\",\n", indent, json_escape(r->id));
|
||||
fprintf(fp,
|
||||
"%s \"internal\": {\n"
|
||||
"%s \"job\": %u,\n"
|
||||
"%s \"oldpid\": %u,\n"
|
||||
"%s \"starting\": %s,\n"
|
||||
"%s \"dirty\": %s,\n"
|
||||
"%s \"removed\": %s\n"
|
||||
"%s },\n",
|
||||
indent,
|
||||
indent, r->job,
|
||||
indent, r->oldpid,
|
||||
indent, json_bool(r->starting),
|
||||
indent, json_bool(r->dirty),
|
||||
indent, json_bool(r->removed),
|
||||
indent);
|
||||
fprintf(fp, "%s \"protected\": %s,\n", indent, json_bool(r->protect));
|
||||
fprintf(fp, "%s \"nowarn\": %s,\n", indent, json_bool(r->nowarn));
|
||||
fprintf(fp, "%s \"notify\": \"%s\",\n", indent, r->notify);
|
||||
fprintf(fp, "%s \"remain\": %s,\n", indent, json_bool(r->remain));
|
||||
if (r->ifstmt[0])
|
||||
fprintf(fp, "%s \"if\": \"%s\",\n", indent, json_escape(r->ifstmt));
|
||||
json_list(fp, indent, "provides", r->provides);
|
||||
json_list(fp, indent, "conflicts", r->conflicts);
|
||||
|
||||
fprintf(fp,
|
||||
"%s \"stop\": {\n"
|
||||
"%s \"signal\": \"%s\",\n"
|
||||
"%s \"timeout\": %u,\n"
|
||||
"%s \"scope\": \"%s\"\n"
|
||||
"%s },\n"
|
||||
"%s \"reload\": {\n"
|
||||
"%s \"signal\": \"%s\",\n"
|
||||
"%s \"propagate\": %s\n"
|
||||
"%s },\n",
|
||||
indent,
|
||||
indent, r->stop_signal,
|
||||
indent, r->stop_timeout,
|
||||
indent, r->stop_scope,
|
||||
indent,
|
||||
indent,
|
||||
indent, r->reload_signal,
|
||||
indent, json_bool(r->flux_reload),
|
||||
indent);
|
||||
|
||||
fprintf(fp, "%s \"scripts\": {", indent);
|
||||
for (i = 0; i < NUM_SCRIPTS; i++) {
|
||||
if (!r->script[i][0])
|
||||
continue;
|
||||
|
||||
fprintf(fp, "%s\n%s \"%s\": { \"command\": \"%s\", \"timeout\": %u }",
|
||||
sep, indent, script_names[i], json_escape(r->script[i]), r->script_tmo[i]);
|
||||
sep = ",";
|
||||
}
|
||||
if (sep[0])
|
||||
fprintf(fp, "\n%s ", indent);
|
||||
fprintf(fp, "},\n");
|
||||
sep = "";
|
||||
|
||||
fprintf(fp, "%s \"directories\": {", indent);
|
||||
for (i = 0; i < NUM_SVCDIRS; i++) {
|
||||
if (!r->dir[i][0])
|
||||
continue;
|
||||
|
||||
fprintf(fp, "%s\n%s \"%s\": { \"name\": \"%s\", \"mode\": \"%04o\" }",
|
||||
sep, indent, dir_names[i], json_escape(r->dir[i]), r->dir_mode[i]);
|
||||
sep = ",";
|
||||
}
|
||||
if (sep[0])
|
||||
fprintf(fp, ",\n%s \"preserve\": \"%s\"\n%s ", indent, r->preserve, indent);
|
||||
fprintf(fp, "},\n");
|
||||
|
||||
fprintf(fp, "%s \"cgroup-config\": {\n", indent);
|
||||
fprintf(fp, "%s \"group\": \"%s\",\n", indent, json_escape(r->cgroup_name));
|
||||
fprintf(fp, "%s \"config\": \"%s\",\n", indent, json_escape(r->cgroup_cfg));
|
||||
fprintf(fp, "%s \"delegate\": %s\n%s },\n", indent, json_bool(r->cgroup_delegate), indent);
|
||||
|
||||
json_rlimits(fp, indent, r->rlimits);
|
||||
|
||||
if (!strcmp(r->type, "tty")) {
|
||||
fprintf(fp, "%s \"tty\": {\n", indent);
|
||||
fprintf(fp, "%s \"device\": \"%s\",\n", indent, json_escape(r->tty_dev));
|
||||
fprintf(fp, "%s \"baud\": \"%s\",\n", indent, r->tty_baud);
|
||||
fprintf(fp, "%s \"term\": \"%s\",\n", indent, json_escape(r->tty_term));
|
||||
fprintf(fp,
|
||||
"%s \"noclear\": %s,\n"
|
||||
"%s \"nowait\": %s,\n"
|
||||
"%s \"nologin\": %s,\n"
|
||||
"%s \"notty\": %s,\n"
|
||||
"%s \"rescue\": %s\n"
|
||||
"%s },\n",
|
||||
indent, json_bool(r->tty_noclear),
|
||||
indent, json_bool(r->tty_nowait),
|
||||
indent, json_bool(r->tty_nologin),
|
||||
indent, json_bool(r->tty_notty),
|
||||
indent, json_bool(r->tty_rescue),
|
||||
indent);
|
||||
} else {
|
||||
fprintf(fp,
|
||||
"%s \"log\": {\n"
|
||||
"%s \"enabled\": %s,\n"
|
||||
"%s \"null\": %s,\n"
|
||||
"%s \"console\": %s,\n",
|
||||
indent,
|
||||
indent, json_bool(r->log),
|
||||
indent, json_bool(r->log_null),
|
||||
indent, json_bool(r->log_console));
|
||||
fprintf(fp, "%s \"file\": \"%s\",\n", indent, json_escape(r->log_file));
|
||||
fprintf(fp, "%s \"priority\": \"%s\",\n", indent, json_escape(r->log_prio));
|
||||
fprintf(fp, "%s \"identity\": \"%s\"\n%s },\n", indent, json_escape(r->log_ident), indent);
|
||||
}
|
||||
}
|
||||
|
||||
static int json_status_one(FILE *fp, struct svc_row *r, char *indent, int prev)
|
||||
{
|
||||
const char *pidfn = pidfile_str(r);
|
||||
@@ -1763,19 +2060,26 @@ static int json_status_one(FILE *fp, struct svc_row *r, char *indent, int prev)
|
||||
"%s \"restart\": {\n"
|
||||
"%s \"count\": %d,\n"
|
||||
"%s \"max\": %d,\n"
|
||||
"%s \"sec\": %u,\n"
|
||||
"%s \"delay\": %u,\n"
|
||||
"%s \"limit\": %u\n"
|
||||
"%s \"limit\": %u,\n"
|
||||
"%s \"respawn\": %s,\n"
|
||||
"%s \"oncrash\": \"%s\"\n"
|
||||
"%s },\n",
|
||||
indent, r->manual ? "true" : "false",
|
||||
indent, r->started ? "true" : "false",
|
||||
indent, json_bool(r->manual),
|
||||
indent, json_bool(r->started),
|
||||
indent, r->starts,
|
||||
indent, r->restart_tot,
|
||||
indent,
|
||||
indent, r->restart_cnt,
|
||||
indent, r->restart_max,
|
||||
indent, r->restart_sec,
|
||||
indent, r->restart_delay,
|
||||
indent, r->restart_delay_max,
|
||||
indent, json_bool(r->respawn),
|
||||
indent, r->oncrash,
|
||||
indent);
|
||||
json_settings(fp, r, indent);
|
||||
|
||||
/* Add memory and CPU information if cgroup support is available */
|
||||
if (cgrp && r->pid > 1) {
|
||||
@@ -1885,14 +2189,19 @@ static int json_status_one(FILE *fp, struct svc_row *r, char *indent, int prev)
|
||||
"%s \"pidfile\": \"%s\",\n"
|
||||
"%s \"pid\": %u,\n"
|
||||
"%s \"user\": \"%s\",\n"
|
||||
"%s \"group\": \"%s\",\n"
|
||||
"%s \"uptime\": %ld,\n"
|
||||
"%s \"runlevels\": %s\n"
|
||||
"%s}",
|
||||
"%s \"group\": \"%s\",\n",
|
||||
indent, pidfn,
|
||||
indent, r->pid,
|
||||
indent, r->user,
|
||||
indent, r->grp,
|
||||
indent, r->grp);
|
||||
json_list(fp, indent, "groups", r->supgroups);
|
||||
json_list(fp, indent, "capabilities", r->caps);
|
||||
if (r->pam[0])
|
||||
fprintf(fp, "%s \"pam\": \"%s\",\n", indent, json_escape(r->pam));
|
||||
fprintf(fp,
|
||||
"%s \"uptime\": %ld,\n"
|
||||
"%s \"runlevels\": %s\n"
|
||||
"%s}",
|
||||
indent, (long)r->uptime,
|
||||
indent, runlevel_arr((int)r->runlevels),
|
||||
indent);
|
||||
@@ -2082,6 +2391,72 @@ static const struct row_field {
|
||||
ROW_BOOL("ManualStart", manual),
|
||||
ROW_BOOL("Forking", forking),
|
||||
ROW_BOOL("Started", started),
|
||||
ROW_STR ("Notify", notify),
|
||||
ROW_BOOL("Remain", remain),
|
||||
ROW_STR ("If", ifstmt),
|
||||
ROW_STR ("Provides", provides),
|
||||
ROW_STR ("Conflicts", conflicts),
|
||||
ROW_STR ("ExtraGroups", supgroups),
|
||||
ROW_STR ("Capabilities", caps),
|
||||
ROW_STR ("Pam", pam),
|
||||
ROW_STR ("StopSignal", stop_signal),
|
||||
ROW_U32 ("StopTimeout", stop_timeout),
|
||||
ROW_STR ("StopScope", stop_scope),
|
||||
ROW_STR ("ReloadSignal", reload_signal),
|
||||
ROW_U32 ("RestartSec", restart_sec),
|
||||
ROW_BOOL("Respawn", respawn),
|
||||
ROW_STR ("Name", name),
|
||||
ROW_STR ("Id", id),
|
||||
ROW_U32 ("Job", job),
|
||||
ROW_U32 ("OldPid", oldpid),
|
||||
ROW_BOOL("Dirty", dirty),
|
||||
ROW_BOOL("Removed", removed),
|
||||
ROW_BOOL("Starting", starting),
|
||||
ROW_STR ("Rlimits", rlimits),
|
||||
ROW_STR ("CgroupName", cgroup_name),
|
||||
ROW_STR ("CgroupConfig", cgroup_cfg),
|
||||
ROW_BOOL("CgroupDelegate", cgroup_delegate),
|
||||
ROW_U32 ("RuntimeDirMode", dir_mode[0]),
|
||||
ROW_U32 ("StateDirMode", dir_mode[1]),
|
||||
ROW_U32 ("CacheDirMode", dir_mode[2]),
|
||||
ROW_U32 ("LogsDirMode", dir_mode[3]),
|
||||
ROW_U32 ("ConfigDirMode", dir_mode[4]),
|
||||
ROW_BOOL("Protected", protect),
|
||||
ROW_BOOL("NoWarn", nowarn),
|
||||
ROW_BOOL("ReloadPropagate", flux_reload),
|
||||
ROW_STR ("OnCrash", oncrash),
|
||||
ROW_STR ("RuntimeDir", dir[0]),
|
||||
ROW_STR ("StateDir", dir[1]),
|
||||
ROW_STR ("CacheDir", dir[2]),
|
||||
ROW_STR ("LogsDir", dir[3]),
|
||||
ROW_STR ("ConfigDir", dir[4]),
|
||||
ROW_STR ("RuntimeDirPreserve", preserve),
|
||||
ROW_STR ("ExecStartPre", script[0]),
|
||||
ROW_U32 ("ExecStartPreTimeout", script_tmo[0]),
|
||||
ROW_STR ("ExecStartReady", script[1]),
|
||||
ROW_U32 ("ExecStartReadyTimeout", script_tmo[1]),
|
||||
ROW_STR ("ExecStop", script[2]),
|
||||
ROW_U32 ("ExecStopTimeout", script_tmo[2]),
|
||||
ROW_STR ("ExecStopPost", script[3]),
|
||||
ROW_U32 ("ExecStopPostTimeout", script_tmo[3]),
|
||||
ROW_STR ("ExecReload", script[4]),
|
||||
ROW_U32 ("ExecReloadTimeout", script_tmo[4]),
|
||||
ROW_STR ("ExecCleanup", script[5]),
|
||||
ROW_U32 ("ExecCleanupTimeout", script_tmo[5]),
|
||||
ROW_BOOL("Log", log),
|
||||
ROW_BOOL("LogNull", log_null),
|
||||
ROW_BOOL("LogConsole", log_console),
|
||||
ROW_STR ("LogFile", log_file),
|
||||
ROW_STR ("LogPriority", log_prio),
|
||||
ROW_STR ("LogIdentity", log_ident),
|
||||
ROW_STR ("TtyDevice", tty_dev),
|
||||
ROW_STR ("TtyBaud", tty_baud),
|
||||
ROW_STR ("TtyTerm", tty_term),
|
||||
ROW_BOOL("TtyNoClear", tty_noclear),
|
||||
ROW_BOOL("TtyNoWait", tty_nowait),
|
||||
ROW_BOOL("TtyNoLogin", tty_nologin),
|
||||
ROW_BOOL("TtyNoTty", tty_notty),
|
||||
ROW_BOOL("TtyRescue", tty_rescue),
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
+5
-12
@@ -2013,23 +2013,16 @@ static void parse_sighalt(svc_t *svc, char *arg)
|
||||
svc->sighalt = signo;
|
||||
}
|
||||
|
||||
static const char *scopes[] = {
|
||||
[SVC_SCOPE_PGROUP] = "pgroup",
|
||||
[SVC_SCOPE_PROCESS] = "process",
|
||||
[SVC_SCOPE_CGROUP] = "cgroup",
|
||||
[SVC_SCOPE_MIXED] = "mixed",
|
||||
};
|
||||
|
||||
static svc_scope_t parse_scope(svc_t *svc, const char *arg)
|
||||
{
|
||||
size_t i;
|
||||
svc_scope_t i;
|
||||
|
||||
if (!arg)
|
||||
return SVC_SCOPE_PGROUP;
|
||||
|
||||
for (i = 0; i < NELEMS(scopes); i++) {
|
||||
if (!strcmp(arg, scopes[i]))
|
||||
return (svc_scope_t)i;
|
||||
for (i = SVC_SCOPE_PGROUP; i <= SVC_SCOPE_MIXED; i++) {
|
||||
if (!strcmp(arg, svc_scope_str(i)))
|
||||
return i;
|
||||
}
|
||||
|
||||
warnx("%s: unknown stop-scope '%s', using pgroup", svc_ident(svc, NULL, 0), arg);
|
||||
@@ -2059,7 +2052,7 @@ static void scope_check(svc_t *svc)
|
||||
continue;
|
||||
|
||||
logit(LOG_WARNING, "%s: stop-scope %s also reaches %s, give it a cgroup name of its own",
|
||||
svc_ident(scoped, a, sizeof(a)), scopes[scoped->stop_scope],
|
||||
svc_ident(scoped, a, sizeof(a)), svc_scope_str(scoped->stop_scope),
|
||||
svc_ident(scoped == svc ? s : svc, b, sizeof(b)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -379,6 +379,77 @@ static inline int svc_has_cond(svc_t *svc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const char *svc_scope_str(svc_scope_t scope)
|
||||
{
|
||||
switch (scope) {
|
||||
case SVC_SCOPE_PGROUP:
|
||||
return "pgroup";
|
||||
case SVC_SCOPE_PROCESS:
|
||||
return "process";
|
||||
case SVC_SCOPE_CGROUP:
|
||||
return "cgroup";
|
||||
case SVC_SCOPE_MIXED:
|
||||
return "mixed";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static inline const char *svc_notify_str(svc_t *svc)
|
||||
{
|
||||
switch (svc->notify) {
|
||||
case SVC_NOTIFY_NONE:
|
||||
return "none";
|
||||
case SVC_NOTIFY_PID:
|
||||
return "pid";
|
||||
case SVC_NOTIFY_SYSTEMD:
|
||||
return "systemd";
|
||||
case SVC_NOTIFY_S6:
|
||||
return "s6";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static inline const char *svc_oncrash_str(svc_t *svc)
|
||||
{
|
||||
switch (svc->oncrash_action) {
|
||||
case SVC_ONCRASH_REBOOT:
|
||||
return "reboot";
|
||||
case SVC_ONCRASH_SCRIPT:
|
||||
return "script";
|
||||
}
|
||||
|
||||
return "ignore";
|
||||
}
|
||||
|
||||
static inline const char *svc_preserve_str(svc_t *svc)
|
||||
{
|
||||
switch (svc->dir_preserve) {
|
||||
case SVC_DIR_PRESERVE_RESTART:
|
||||
return "restart";
|
||||
case SVC_DIR_PRESERVE_YES:
|
||||
return "yes";
|
||||
}
|
||||
|
||||
return "no";
|
||||
}
|
||||
|
||||
/* The conditions in provides, comma separated */
|
||||
static inline char *svc_provides_str(svc_t *svc, char *buf, size_t len)
|
||||
{
|
||||
int i;
|
||||
|
||||
buf[0] = 0;
|
||||
for (i = 0; i < svc->num_provides; i++) {
|
||||
if (i)
|
||||
strlcat(buf, ",", len);
|
||||
strlcat(buf, svc->provides[i], len);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline const char *svc_typestr(svc_t *svc)
|
||||
{
|
||||
switch (svc->type) {
|
||||
|
||||
+24
@@ -722,6 +722,30 @@ char *rlim2str(int rlim)
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/* All of @rlimit as "name=soft:hard,...", a value is a number or unlimited */
|
||||
char *rlimits2str(struct rlimit *rlimit, char *buf, size_t len)
|
||||
{
|
||||
const struct rlimit_name *rn;
|
||||
size_t pos = 0;
|
||||
|
||||
buf[0] = 0;
|
||||
for (rn = rlimit_names; rn->name && pos < len; rn++) {
|
||||
rlim_t lim[2] = { rlimit[rn->val].rlim_cur, rlimit[rn->val].rlim_max };
|
||||
int i;
|
||||
|
||||
pos += snprintf(&buf[pos], len - pos, "%s%s", pos ? "," : "", rn->name);
|
||||
for (i = 0; i < 2 && pos < len; i++) {
|
||||
if (lim[i] == RLIM_INFINITY)
|
||||
pos += snprintf(&buf[pos], len - pos, "%cunlimited", i ? ':' : '=');
|
||||
else
|
||||
pos += snprintf(&buf[pos], len - pos, "%c%llu", i ? ':' : '=',
|
||||
(unsigned long long)lim[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *lim2str(struct rlimit *rlim)
|
||||
{
|
||||
char tmp[25];
|
||||
|
||||
@@ -95,6 +95,7 @@ char *code2str (int code);
|
||||
int str2rlim (char *str);
|
||||
char *rlim2str (int rlim);
|
||||
char *lim2str (struct rlimit *rlim);
|
||||
char *rlimits2str (struct rlimit *rlimit, char *buf, size_t len);
|
||||
|
||||
void do_sleep (unsigned int sec);
|
||||
void do_usleep (unsigned int usec);
|
||||
|
||||
Reference in new issue
Block a user