initctl: change layout to put (name,id) tuple in focus

With the recent change in the condition handling we've decided to put
the (name,id) tuple in focus for everything Finit.

This patch changes from job:id in the status listing to name:id instead.
In verbose mode we change to show the job:id and the command + args.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-02-11 14:07:43 +01:00
1 parent e88a9b14ff
commit a226c93539
2 files changed
+45 -16

No files matched your search

+19 -15
View File
@@ -392,6 +392,7 @@ char *runlevel_string(int runlevel, int levels)
*/
static int show_status(char *arg)
{
char ident[MAX_IDENT_LEN];
svc_t *svc;
/* Fetch UTMP runlevel, needed for svc_status() call below */
@@ -407,6 +408,7 @@ static int show_status(char *arg)
printf("Service : %s\n", svc->cmd);
printf("Description : %s\n", svc->desc);
printf("Identity : %s\n", svc_ident(svc, ident, sizeof(ident)));
printf("PID : %d\n", svc->pid);
printf("Uptime : %s\n", svc->pid ? uptime(now - svc->start_time, buf, sizeof(buf)) : buf);
printf("Runlevels : %s\n", runlevel_string(runlevel, svc->runlevels));
@@ -417,18 +419,20 @@ static int show_status(char *arg)
}
if (!verbose)
printheader(NULL, "# STATUS PID RUNLEVELS SERVICE DESCRIPTION", 0);
printheader(NULL, "IDENT STATUS PID RUNLEVELS DESCRIPTION", 0);
else
printheader(NULL, "IDENT STATUS PID RUNLEVELS COMMAND", 0);
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
char jobid[20], args[512] = "", *lvls;
char *lvls;
int i;
if (!svc->id[0])
snprintf(jobid, sizeof(jobid), "%d", svc->job);
if (!verbose)
printf("%-16s ", svc_ident(svc, ident, sizeof(ident)));
else
snprintf(jobid, sizeof(jobid), "%d:%s", svc->job, svc->id);
printf("%-9s ", svc_jobid(svc, ident, sizeof(ident)));
printf("%-9s %8s %-6d ", jobid, svc_status(svc), svc->pid);
printf("%8s %-6d ", svc_status(svc), svc->pid);
lvls = runlevel_string(runlevel, svc->runlevels);
if (strchr(lvls, '\e'))
@@ -437,17 +441,17 @@ static int show_status(char *arg)
printf("%-12.12s ", lvls);
if (!verbose) {
int adj = screen_cols - 60;
printf("%-16.16s %-*.*s\n", svc->name, adj, adj, svc->desc);
continue;
}
printf("%s\n", svc->desc);
} else {
char args[512] = "";
for (i = 1; i < MAX_NUM_SVC_ARGS; i++) {
strlcat(args, svc->args[i], sizeof(args));
strlcat(args, " ", sizeof(args));
}
for (i = 1; i < MAX_NUM_SVC_ARGS; i++) {
strlcat(args, svc->args[i], sizeof(args));
strlcat(args, " ", sizeof(args));
}
printf("%s %s\n", svc->cmd, args);
printf("%s %s\n", svc->cmd, args);
}
}
return 0;
+26 -1
View File
@@ -67,6 +67,7 @@ typedef enum {
#define MAX_ID_LEN 16
#define MAX_ARG_LEN 64
#define MAX_IDENT_LEN (MAX_ARG_LEN + MAX_ID_LEN + 1)
#define MAX_STR_LEN 64
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
#define MAX_USER_LEN 16
@@ -278,7 +279,7 @@ static inline const char *svc_dirtystr(svc_t *svc)
*/
static inline char *svc_ident(svc_t *svc, char *buf, size_t len)
{
static char ident[sizeof(svc->name) + sizeof(svc->id) + 2];
static char ident[MAX_IDENT_LEN];
if (!buf) {
buf = ident;
@@ -297,6 +298,30 @@ static inline char *svc_ident(svc_t *svc, char *buf, size_t len)
return buf;
}
/*
* Returns svc unique identifier tuple 'job:id', or just 'job',
* if that's enough to identify the service.
*/
static inline char *svc_jobid(svc_t *svc, char *buf, size_t len)
{
static char ident[MAX_IDENT_LEN];
if (!buf) {
buf = ident;
len = sizeof(ident);
}
if (!svc)
return "nul";
if (strlen(svc->id))
snprintf(buf, len, "%d:%s", svc->job, svc->id);
else
snprintf(buf, len, "%d", svc->job);
return buf;
}
#endif /* FINIT_SVC_H_ */
/**