mirror of
https://github.com/troglobit/finit.git
synced 2026-11-28 20:58:24 +00:00
initctl: show pid file and condition for foo in 'status foo' command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
572291a1d9
commit
cbec78dbbc
1 file changed
+37
-17
+37
-17
@@ -278,7 +278,7 @@ static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, st
|
|||||||
pid = 1;
|
pid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%-*d %-*s %-6s %s\n", pw, pid, iw, nm, asserted, cond);
|
printf("%-*d %-*s %-6s <%s>\n", pw, pid, iw, nm, asserted, cond);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -334,41 +334,61 @@ static int do_cond_act(char *arg, int creat)
|
|||||||
static int do_cond_set(char *arg) { return do_cond_act(arg, 1); }
|
static int do_cond_set(char *arg) { return do_cond_act(arg, 1); }
|
||||||
static int do_cond_clr(char *arg) { return do_cond_act(arg, 0); }
|
static int do_cond_clr(char *arg) { return do_cond_act(arg, 0); }
|
||||||
|
|
||||||
static void show_cond_one(const char *_conds)
|
static char *svc_cond(svc_t *svc, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
static char conds[MAX_COND_LEN];
|
char *cond, *conds;
|
||||||
char *cond;
|
|
||||||
|
|
||||||
strlcpy(conds, _conds, sizeof(conds));
|
memset(buf, 0, len);
|
||||||
|
|
||||||
putchar('<');
|
if (!svc->cond[0])
|
||||||
|
return buf;
|
||||||
|
|
||||||
|
conds = strdup(svc->cond);
|
||||||
|
if (!conds)
|
||||||
|
return buf;
|
||||||
|
|
||||||
|
strlcat(buf, "<", len);
|
||||||
|
|
||||||
for (cond = strtok(conds, ","); cond; cond = strtok(NULL, ",")) {
|
for (cond = strtok(conds, ","); cond; cond = strtok(NULL, ",")) {
|
||||||
if (cond != conds)
|
if (cond != conds)
|
||||||
putchar(',');
|
strlcat(buf, ",", len);
|
||||||
|
|
||||||
switch (cond_get(cond)) {
|
switch (cond_get(cond)) {
|
||||||
case COND_ON:
|
case COND_ON:
|
||||||
printf("+%s", cond);
|
strlcat(buf, "+", len);
|
||||||
|
strlcat(buf, cond, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COND_FLUX:
|
case COND_FLUX:
|
||||||
printf("\e[1m~%s\e[0m", cond);
|
if (!plain)
|
||||||
|
strlcat(buf, "\e[1m", len);
|
||||||
|
strlcat(buf, "~", len);
|
||||||
|
strlcat(buf, cond, len);
|
||||||
|
if (!plain)
|
||||||
|
strlcat(buf, "\e[0m", len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COND_OFF:
|
case COND_OFF:
|
||||||
printf("\e[1m-%s\e[0m", cond);
|
if (!plain)
|
||||||
|
strlcat(buf, "\e[1m", len);
|
||||||
|
strlcat(buf, "-", len);
|
||||||
|
strlcat(buf, cond, len);
|
||||||
|
if (!plain)
|
||||||
|
strlcat(buf, "\e[0m", len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar('>');
|
strlcat(buf, ">", len);
|
||||||
|
free(conds);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_cond_show(char *arg)
|
static int do_cond_show(char *arg)
|
||||||
{
|
{
|
||||||
char ident[MAX_IDENT_LEN];
|
|
||||||
enum cond_state cond;
|
enum cond_state cond;
|
||||||
|
char buf[512];
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
col_widths();
|
col_widths();
|
||||||
@@ -386,16 +406,15 @@ static int do_cond_show(char *arg)
|
|||||||
|
|
||||||
cond = cond_get_agg(svc->cond);
|
cond = cond_get_agg(svc->cond);
|
||||||
|
|
||||||
svc_ident(svc, ident, sizeof(ident));
|
svc_ident(svc, buf, sizeof(buf));
|
||||||
printf("%-*d %-*s ", pw, svc->pid, iw, ident);
|
printf("%-*d %-*s ", pw, svc->pid, iw, buf);
|
||||||
|
|
||||||
if (cond == COND_ON)
|
if (cond == COND_ON)
|
||||||
printf("%-6.6s ", condstr(cond));
|
printf("%-6.6s ", condstr(cond));
|
||||||
else
|
else
|
||||||
printf("\e[1m%-6.6s\e[0m ", condstr(cond));
|
printf("\e[1m%-6.6s\e[0m ", condstr(cond));
|
||||||
|
|
||||||
show_cond_one(svc->cond);
|
puts(svc_cond(svc, buf, sizeof(buf)));
|
||||||
puts("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -609,8 +628,9 @@ static int show_status(char *arg)
|
|||||||
printf("Description : %s\n", svc->desc);
|
printf("Description : %s\n", svc->desc);
|
||||||
printf("Origin : %s\n", svc->file[0] ? svc->file : "built-in");
|
printf("Origin : %s\n", svc->file[0] ? svc->file : "built-in");
|
||||||
printf("Environment : %s\n", svc_environ(svc, buf, sizeof(buf)));
|
printf("Environment : %s\n", svc_environ(svc, buf, sizeof(buf)));
|
||||||
printf("Condition(s): %s\n", svc->cond);
|
printf("Condition(s): %s\n", svc_cond(svc, buf, sizeof(buf)));
|
||||||
printf("Command : %s\n", svc_command(svc, buf, sizeof(buf)));
|
printf("Command : %s\n", svc_command(svc, buf, sizeof(buf)));
|
||||||
|
printf("PID file : %s\n", svc->pidfile);
|
||||||
printf("PID : %d\n", svc->pid);
|
printf("PID : %d\n", svc->pid);
|
||||||
printf("User : %s\n", svc->username);
|
printf("User : %s\n", svc->username);
|
||||||
printf("Group : %s\n", svc->group);
|
printf("Group : %s\n", svc->group);
|
||||||
|
|||||||
Reference in new issue
Block a user