aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-01-19 06:26:02 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-01-19 06:26:02 +0000
commita4771a151ba75934b2864e886139d6a25ee81c5f (patch)
treeefb831a3ed5c48b7dee1f78952ab184948f078b5
parentdd36cb69015160ddcb2a5cb5ff554b4408e20193 (diff)
downloads6-frontend-a4771a151ba75934b2864e886139d6a25ee81c5f.tar.gz
Lots of code cleanup; refactor pretty-printing
-rw-r--r--src/s6-frontend/live_install.c2
-rw-r--r--src/s6-frontend/live_start_everything.c5
-rw-r--r--src/s6-frontend/live_status.c37
-rw-r--r--src/s6-frontend/live_stop_everything.c5
-rw-r--r--src/s6-frontend/process.c5
-rw-r--r--src/s6-frontend/process_kill.c4
-rw-r--r--src/s6-frontend/repository_check.c5
-rw-r--r--src/s6-frontend/repository_init.c5
-rw-r--r--src/s6-frontend/repository_list.c3
-rw-r--r--src/s6-frontend/repository_sync.c4
-rw-r--r--src/s6-frontend/s6-frontend-internal.h2
-rw-r--r--src/s6-frontend/s6-frontend.c35
-rw-r--r--src/s6-frontend/set_change.c2
-rw-r--r--src/s6-frontend/set_check.c4
-rw-r--r--src/s6-frontend/set_commit.c4
-rw-r--r--src/s6-frontend/set_copy.c5
-rw-r--r--src/s6-frontend/set_list.c4
-rw-r--r--src/s6-frontend/set_status.c16
-rw-r--r--src/s6-frontend/system_boot.c2
-rw-r--r--src/s6-frontend/system_hpr.c4
20 files changed, 75 insertions, 78 deletions
diff --git a/src/s6-frontend/live_install.c b/src/s6-frontend/live_install.c
index fb13e1b..e83be20 100644
--- a/src/s6-frontend/live_install.c
+++ b/src/s6-frontend/live_install.c
@@ -66,5 +66,5 @@ void live_install (char const *const *argv)
newargv[m++] = "--" ;
newargv[m++] = "current" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/live_start_everything.c b/src/s6-frontend/live_start_everything.c
index 3c5e45b..4e6bcf9 100644
--- a/src/s6-frontend/live_start_everything.c
+++ b/src/s6-frontend/live_start_everything.c
@@ -5,7 +5,8 @@
#include <skalibs/uint64.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/strerr.h>
+#include <skalibs/gol.h>
#include <skalibs/cspawn.h>
#include <skalibs/djbunix.h>
@@ -52,7 +53,7 @@ void exec_live_start_everything (unsigned int timeout, int dryrun, char const *d
argv[m++] = "start" ;
argv[m++] = defbundle ;
argv[m++] = 0 ;
- xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(argv) ;
}
void live_start_everything (char const *const *argv)
diff --git a/src/s6-frontend/live_status.c b/src/s6-frontend/live_status.c
index 831174a..e657bc2 100644
--- a/src/s6-frontend/live_status.c
+++ b/src/s6-frontend/live_status.c
@@ -4,7 +4,10 @@
#include <sys/wait.h>
#include <skalibs/gccattributes.h>
-#include <skalibs/envexec.h>
+#include <skalibs/posixplz.h>
+#include <skalibs/env.h>
+#include <skalibs/gol.h>
+#include <skalibs/strerr.h>
#include <skalibs/cspawn.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
@@ -24,19 +27,8 @@
static void live_status_all (int withe) gccattr_noreturn ;
static void live_status_all (int withe)
{
- char const *argv[23] ;
+ char const *argv[17] ;
unsigned int m = 0 ;
-#ifdef S6_FRONTEND_USE_UTIL_LINUX
- if (g->color)
- {
- argv[m++] = EXECLINE_EXTBINPREFIX "pipeline" ;
- argv[m++] = "-w" ;
- argv[m++] = "--" ;
- argv[m++] = " column" ;
- argv[m++] = " -ts/" ;
- argv[m++] = "" ;
- }
-#endif
argv[m++] = EXECLINE_EXTBINPREFIX "if" ;
argv[m++] = " " EXECLINE_EXTBINPREFIX "pipeline" ;
argv[m++] = " " S6RC_EXTBINPREFIX "s6-rc" ;
@@ -54,7 +46,7 @@ static void live_status_all (int withe)
argv[m++] = "sed" ;
argv[m++] = "s|$|/down" ;
argv[m++] = 0 ;
- xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_pretty_exec(argv) ;
}
static int get_list_of_up (stralloc *storage, int withe)
@@ -136,7 +128,7 @@ static void live_status_some (char const *const *services, int withe)
unsigned int m = 0 ;
size_t uplistpos ;
int e ;
- char const *argv[59] ;
+ char const *argv[53] ;
if (!stralloc_catb(&sa, " ", 1)) dienomem() ;
e = get_atomics(services, env_len(services), &sa, withe) ;
if (e) _exit(e) ;
@@ -146,17 +138,6 @@ static void live_status_some (char const *const *services, int withe)
if (e) _exit(e) ;
if (!stralloc_0(&sa)) dienomem() ;
-#ifdef S6_FRONTEND_USE_UTIL_LINUX
- if (g->color)
- {
- argv[m++] = EXECLINE_EXTBINPREFIX "pipeline" ;
- argv[m++] = "-w" ;
- argv[m++] = "--" ;
- argv[m++] = " column" ;
- argv[m++] = " -ts/" ;
- argv[m++] = "" ;
- }
-#endif
argv[m++] = EXECLINE_EXTBINPREFIX "if" ;
argv[m++] = " " EXECLINE_EXTBINPREFIX "piperw" ;
argv[m++] = " 3" ;
@@ -210,7 +191,7 @@ static void live_status_some (char const *const *services, int withe)
argv[m++] = "sed" ;
argv[m++] = "s|$|/down" ;
argv[m++] = 0 ;
- xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_pretty_exec(argv) ;
}
enum golb_e
@@ -218,7 +199,6 @@ enum golb_e
GOLB_INCLUDE_ESSENTIALS = 0x01,
} ;
-
void live_status (char const *const *argv)
{
static gol_bool const rgolb[] =
@@ -231,5 +211,4 @@ void live_status (char const *const *argv)
argv += gol_argv(argv, rgolb, 2, 0, 0, &wgolb, 0) ;
if (!argv) live_status_all(wgolb & GOLB_INCLUDE_ESSENTIALS) ;
else live_status_some(argv, wgolb & GOLB_INCLUDE_ESSENTIALS) ;
- _exit(0) ;
}
diff --git a/src/s6-frontend/live_stop_everything.c b/src/s6-frontend/live_stop_everything.c
index be9a40a..335b11a 100644
--- a/src/s6-frontend/live_stop_everything.c
+++ b/src/s6-frontend/live_stop_everything.c
@@ -2,7 +2,8 @@
#include <skalibs/uint64.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/strerr.h>
+#include <skalibs/gol.h>
#include "s6-frontend-internal.h"
@@ -64,5 +65,5 @@ void live_stop_everything (char const *const *argv)
newargv[m++] = "change" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/process.c b/src/s6-frontend/process.c
index 7cea951..666e57e 100644
--- a/src/s6-frontend/process.c
+++ b/src/s6-frontend/process.c
@@ -8,7 +8,8 @@
#include <skalibs/stat.h>
#include <skalibs/types.h>
#include <skalibs/posixplz.h>
-#include <skalibs/envexec.h>
+#include <skalibs/strerr.h>
+#include <skalibs/gol.h>
#include <skalibs/djbunix.h>
#include <s6/config.h>
@@ -73,7 +74,7 @@ void process_send_svc (char const *svcopt, char const *const *argv, unsigned int
memcpy(s + len, argv[i], l + 1) ; len += l + 1 ;
}
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
void process (char const *const *argv)
diff --git a/src/s6-frontend/process_kill.c b/src/s6-frontend/process_kill.c
index 73820f2..a17a141 100644
--- a/src/s6-frontend/process_kill.c
+++ b/src/s6-frontend/process_kill.c
@@ -8,8 +8,8 @@
#include <skalibs/uint64.h>
#include <skalibs/posixplz.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
#include <skalibs/sig.h>
+#include <skalibs/envexec.h>
#include <s6/config.h>
#include <s6/supervise.h>
@@ -67,7 +67,7 @@ static void process_kill_hack_kill (int sig, char const *const *argv, unsigned i
}
}
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
enum golb_e
diff --git a/src/s6-frontend/repository_check.c b/src/s6-frontend/repository_check.c
index a2c2cb8..525d874 100644
--- a/src/s6-frontend/repository_check.c
+++ b/src/s6-frontend/repository_check.c
@@ -2,7 +2,7 @@
#include <skalibs/uint64.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/gol.h>
#include <execline/config.h>
@@ -48,6 +48,5 @@ void repository_check (char const *const *argv)
newargv[m++] = wgolb & GOLB_FIXUP ? "--fix-up" : "--fix-down" ;
if (!(wgolb & GOLB_FIX)) newargv[m++] = "--dry-run" ;
newargv[m++] = 0 ;
-
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/repository_init.c b/src/s6-frontend/repository_init.c
index 548c1fd..7732154 100644
--- a/src/s6-frontend/repository_init.c
+++ b/src/s6-frontend/repository_init.c
@@ -78,8 +78,7 @@ void repository_init (char const *const *argv)
len += strlen(storage + len) + 1 ;
}
newargv[m++] = 0 ;
- if (wgolb & GOLB_UPDATE)
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ if (wgolb & GOLB_UPDATE) main_exec(newargv) ;
else
{
int wstat ;
@@ -98,6 +97,6 @@ void repository_init (char const *const *argv)
newargv[m++] = "--" ;
newargv[m++] = "current" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
}
diff --git a/src/s6-frontend/repository_list.c b/src/s6-frontend/repository_list.c
index fc734d2..b34ac71 100644
--- a/src/s6-frontend/repository_list.c
+++ b/src/s6-frontend/repository_list.c
@@ -1,6 +1,5 @@
/* ISC license. */
-#include <skalibs/envexec.h>
#include <skalibs/types.h>
#include <s6-rc/config.h>
@@ -26,5 +25,5 @@ void repository_list (char const *const *argv)
newargv[m++] = "--" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/repository_sync.c b/src/s6-frontend/repository_sync.c
index 1799c7c..f3e25df 100644
--- a/src/s6-frontend/repository_sync.c
+++ b/src/s6-frontend/repository_sync.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/gol.h>
#include <s6-rc/config.h>
@@ -42,5 +42,5 @@ void repository_sync (char const *const *argv)
}
newargv[m++] = "--" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/s6-frontend-internal.h b/src/s6-frontend/s6-frontend-internal.h
index 253303d..42ab11b 100644
--- a/src/s6-frontend/s6-frontend-internal.h
+++ b/src/s6-frontend/s6-frontend-internal.h
@@ -104,6 +104,8 @@ extern void system_reboot (char const *const *) gccattr_noreturn ;
extern void main_help (char const *const *) gccattr_noreturn ;
extern void main_version (char const *const *) gccattr_noreturn ;
+extern void main_exec (char const *const *) gccattr_noreturn ;
+extern void main_pretty_exec (char const *const *) gccattr_noreturn ;
struct global_s
{
diff --git a/src/s6-frontend/s6-frontend.c b/src/s6-frontend/s6-frontend.c
index 98314bf..6933b57 100644
--- a/src/s6-frontend/s6-frontend.c
+++ b/src/s6-frontend/s6-frontend.c
@@ -6,13 +6,14 @@
#include <skalibs/uint64.h>
#include <skalibs/types.h>
#include <skalibs/buffer.h>
-#include <skalibs/prog.h>
-#include <skalibs/strerr.h>
-#include <skalibs/gol.h>
+#include <skalibs/envexec.h>
+
+#include <execline/config.h>
#include <s6/config.h>
#include <s6-rc/config.h>
+#include "s6f.h"
#include "s6-frontend-internal.h"
#define USAGE "s6 [ generic options ] command [ command options ] command_arguments... Type \"s6 help\" for details."
@@ -48,6 +49,34 @@ enum gola_e
struct global_s *g ;
+void main_exec (char const *const *argv)
+{
+ xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+}
+
+void main_pretty_exec (char const *const *argv)
+{
+#ifdef S6_FRONTEND_USE_UTIL_LINUX
+ if (g->color)
+ {
+ unsigned int m = 0 ;
+ unsigned int argc = env_len(argv) ;
+ size_t len = s6f_equote_space(argv, argc, 0) ;
+ char const *newargv[argc + 6] ;
+ char espace[len] ;
+ newargv[m++] = EXECLINE_EXTBINPREFIX "pipeline" ;
+ newargv[m++] = "--" ;
+ m += s6f_equote(newargv + m, argv, argc, 0, espace) ;
+ newargv[m++] = " column" ;
+ newargv[m++] = " -ts/" ;
+ newargv[m++] = 0 ;
+ main_exec(newargv) ;
+ }
+ else
+#endif
+ main_exec(argv) ;
+}
+
int main (int argc, char const *const *argv)
{
static gol_bool const rgolb[] =
diff --git a/src/s6-frontend/set_change.c b/src/s6-frontend/set_change.c
index b74d6ae..4017329 100644
--- a/src/s6-frontend/set_change.c
+++ b/src/s6-frontend/set_change.c
@@ -75,7 +75,7 @@ static void set_change (char const *const *argv, char const *newsub, char const
for (unsigned int i = 0 ; i < argc ; i++)
newargv[m++] = argv[i] ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
void set_disable (char const *const *argv)
diff --git a/src/s6-frontend/set_check.c b/src/s6-frontend/set_check.c
index b6f4924..54c8a7c 100644
--- a/src/s6-frontend/set_check.c
+++ b/src/s6-frontend/set_check.c
@@ -2,7 +2,7 @@
#include <skalibs/uint64.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/gol.h>
#include <execline/config.h>
@@ -51,5 +51,5 @@ void set_check (char const *const *argv)
newargv[m++] = "current" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/set_commit.c b/src/s6-frontend/set_commit.c
index b9a6d7a..887d5d9 100644
--- a/src/s6-frontend/set_commit.c
+++ b/src/s6-frontend/set_commit.c
@@ -2,7 +2,7 @@
#include <skalibs/uint64.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/gol.h>
#include <s6-rc/config.h>
@@ -64,5 +64,5 @@ void set_commit (char const *const *argv)
newargv[m++] = "--" ;
newargv[m++] = "current" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/set_copy.c b/src/s6-frontend/set_copy.c
index 1cbfbaf..07b9e24 100644
--- a/src/s6-frontend/set_copy.c
+++ b/src/s6-frontend/set_copy.c
@@ -5,7 +5,8 @@
#include <skalibs/gccattributes.h>
#include <skalibs/uint64.h>
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/strerr.h>
+#include <skalibs/gol.h>
#include <s6-rc/config.h>
@@ -36,7 +37,7 @@ static void set_copy (char const *from, char const *to, int force)
argv[m++] = from ;
argv[m++] = to ;
argv[m++] = 0 ;
- xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(argv) ;
}
void set_save (char const *const *argv)
diff --git a/src/s6-frontend/set_list.c b/src/s6-frontend/set_list.c
index f01ef47..f5eeeb1 100644
--- a/src/s6-frontend/set_list.c
+++ b/src/s6-frontend/set_list.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/types.h>
-#include <skalibs/envexec.h>
+#include <skalibs/gol.h>
#include <execline/config.h>
@@ -38,5 +38,5 @@ void set_list (char const *const *argv)
newargv[m++] = "--" ;
newargv[m++] = "current" ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
diff --git a/src/s6-frontend/set_status.c b/src/s6-frontend/set_status.c
index baead01..a5dd094 100644
--- a/src/s6-frontend/set_status.c
+++ b/src/s6-frontend/set_status.c
@@ -33,19 +33,7 @@ void set_status (char const *const *argv)
if (!set_check_service_names(argv, argc))
strerr_dief1x(100, "invalid service name") ;
- char const *newargv[15 + argc] ;
-
-#ifdef S6_FRONTEND_USE_UTIL_LINUX
- if (g->color)
- {
- newargv[m++] = EXECLINE_EXTBINPREFIX "pipeline" ;
- newargv[m++] = "-w" ;
- newargv[m++] = "--" ;
- newargv[m++] = " column" ;
- newargv[m++] = " -ts/" ;
- newargv[m++] = "" ;
- }
-#endif
+ char const *newargv[9 + argc] ;
newargv[m++] = S6RC_EXTBINPREFIX "s6-rc-set-status" ;
fmtv[uint_fmt(fmtv, g->verbosity)] = 0 ;
newargv[m++] = "-v" ;
@@ -58,5 +46,5 @@ void set_status (char const *const *argv)
for (unsigned int i = 0 ; i < argc ; i++) newargv[m++] = argv[i] ;
newargv[m++] = 0 ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_pretty_exec(newargv) ;
}
diff --git a/src/s6-frontend/system_boot.c b/src/s6-frontend/system_boot.c
index 109605a..49dd2bf 100644
--- a/src/s6-frontend/system_boot.c
+++ b/src/s6-frontend/system_boot.c
@@ -61,7 +61,7 @@ void system_init (char const *const *argv)
char const *newargv[13] ;
argv += gol_argv(argv, 0, 0, rgola, 1, 0, wgola) ;
system_init_fill(newargv, wgola[GOLA_PREFIX]) ;
- xmexec_n(newargv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(newargv) ;
}
static void system_init_spawn (char const *prefix)
diff --git a/src/s6-frontend/system_hpr.c b/src/s6-frontend/system_hpr.c
index 5d50d28..6730cf7 100644
--- a/src/s6-frontend/system_hpr.c
+++ b/src/s6-frontend/system_hpr.c
@@ -5,8 +5,6 @@
#ifdef S6_FRONTEND_USE_S6LI
-#include <skalibs/exec.h>
-
static void system_hpr (char const *arg) gccattr_noreturn ;
static void system_hpr (char const *arg)
{
@@ -16,7 +14,7 @@ static void system_hpr (char const *arg)
argv[m++] = arg ;
argv[m++] = "--" ;
argv[m++] = 0 ;
- xmexec_n(argv, cleanup_modif.s, cleanup_modif.len, cleanup_modif.n) ;
+ main_exec(argv) ;
}
void system_halt (char const *const *argv)