From 3aeb150eefd62e3d895d14428ff86e87ff18412f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 13 Feb 2021 11:22:57 +0100 Subject: [PATCH] initctl: minor refactor and set min column width Signed-off-by: Joachim Wiberg --- src/initctl.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/initctl.c b/src/initctl.c index e2a39222..14be0c5f 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -52,15 +52,17 @@ int heading = 1; int numeric = 0; int verbose = 0; int runlevel = 0; +int iw, pw; /* figure ut width of IDENT and PID columns */ -static void col_widths(int *identw, int *pidw) +static void col_widths(void) { char ident[MAX_IDENT_LEN]; char pid[10]; svc_t *svc; - int iw = 0; - int pw = 0; + + iw = 0; + pw = 0; for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) { int w, p; @@ -79,8 +81,11 @@ static void col_widths(int *identw, int *pidw) pw = p; } - *identw = iw; - *pidw = pw; + /* adjust for min col width */ + if (iw < 5) + iw = 5; + if (pw < 3) + pw = 3; } static int runlevel_get(int *prevlevel) @@ -268,9 +273,8 @@ static int do_cond_show(char *arg) char ident[MAX_IDENT_LEN]; enum cond_state cond; svc_t *svc; - int iw, pw; - col_widths(&iw, &pw); + col_widths(); if (heading) { char title[80]; @@ -437,7 +441,6 @@ static int show_status(char *arg) { char ident[MAX_IDENT_LEN]; svc_t *svc; - int iw, pw; /* Fetch UTMP runlevel, needed for svc_status() call below */ runlevel = runlevel_get(NULL); @@ -463,7 +466,7 @@ static int show_status(char *arg) return do_log(svc->cmd); } - col_widths(&iw, &pw); + col_widths(); if (heading) { char title[80];