mirror of
https://github.com/troglobit/finit.git
synced 2026-10-25 12:04:36 +00:00
initctl: when svc has status missing, highlight what is missing
To aid with debugging, highlight if env file, binary, or both are the missing component(s) and causing status 'missing'. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
90005235e8
commit
5f026c8149
1 file changed
+40
-9
+40
-9
@@ -527,18 +527,49 @@ char *runlevel_string(int runlevel, int levels)
|
|||||||
return lvl;
|
return lvl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *svc_command(svc_t *svc, char *cmd, size_t len)
|
static int missing(svc_t *svc)
|
||||||
{
|
{
|
||||||
strlcpy(cmd, svc->cmd, len);
|
if (svc->state == SVC_HALTED_STATE && svc_is_missing(svc))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *svc_command(svc_t *svc, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
int bold = missing(svc);
|
||||||
|
|
||||||
|
if (plain || whichp(svc->cmd))
|
||||||
|
bold = 0;
|
||||||
|
|
||||||
|
strlcpy(buf, bold ? "\e[1m" : "", len);
|
||||||
|
strlcat(buf, svc->cmd, len);
|
||||||
|
|
||||||
for (int i = 1; i < MAX_NUM_SVC_ARGS; i++) {
|
for (int i = 1; i < MAX_NUM_SVC_ARGS; i++) {
|
||||||
if (!svc->args[i][0])
|
if (!svc->args[i][0])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
strlcat(cmd, " ", len);
|
strlcat(buf, " ", len);
|
||||||
strlcat(cmd, svc->args[i], len);
|
strlcat(buf, svc->args[i], len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
strlcat(buf, bold ? "\e[0m" : "", len);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *svc_environ(svc_t *svc, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
int bold = missing(svc);
|
||||||
|
|
||||||
|
if (plain || svc_checkenv(svc))
|
||||||
|
bold = 0;
|
||||||
|
|
||||||
|
strlcpy(buf, bold ? "\e[1m" : "", len);
|
||||||
|
strlcat(buf, svc->env, len);
|
||||||
|
strlcat(buf, bold ? "\e[0m" : "", len);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *status(svc_t *svc)
|
static char *status(svc_t *svc)
|
||||||
@@ -560,7 +591,7 @@ static char *status(svc_t *svc)
|
|||||||
static int show_status(char *arg)
|
static int show_status(char *arg)
|
||||||
{
|
{
|
||||||
char ident[MAX_IDENT_LEN];
|
char ident[MAX_IDENT_LEN];
|
||||||
char cmd[512];
|
char buf[512];
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
runlevel = runlevel_get(NULL);
|
runlevel = runlevel_get(NULL);
|
||||||
@@ -577,9 +608,9 @@ static int show_status(char *arg)
|
|||||||
printf("Identity : %s\n", svc_ident(svc, ident, sizeof(ident)));
|
printf("Identity : %s\n", svc_ident(svc, ident, sizeof(ident)));
|
||||||
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->env);
|
printf("Environment : %s\n", svc_environ(svc, buf, sizeof(buf)));
|
||||||
printf("Condition(s): %s\n", svc->cond);
|
printf("Condition(s): %s\n", svc->cond);
|
||||||
printf("Command : %s\n", svc_command(svc, cmd, sizeof(cmd)));
|
printf("Command : %s\n", svc_command(svc, buf, sizeof(buf)));
|
||||||
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);
|
||||||
@@ -621,7 +652,7 @@ static int show_status(char *arg)
|
|||||||
if (!verbose)
|
if (!verbose)
|
||||||
puts(svc->desc);
|
puts(svc->desc);
|
||||||
else
|
else
|
||||||
puts(svc_command(svc, cmd, sizeof(cmd)));
|
puts(svc_command(svc, buf, sizeof(buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in new issue
Block a user