diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-05-12 20:30:05 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-05-12 20:30:05 +0000 |
| commit | 557ff039d9c1018c7100062e587550a9509a2b6d (patch) | |
| tree | a2b41dbe07aab66eef12578172db393e0217d1ec | |
| parent | ee590da542b138577b42ebf68f3ee4924ed7f485 (diff) | |
| download | s6-frontend-557ff039d9c1018c7100062e587550a9509a2b6d.tar.gz | |
Change "s6 version" to "s6 version show|export"
| -rw-r--r-- | package/deps.mak | 6 | ||||
| -rw-r--r-- | src/s6-frontend/deps-exe/s6-frontend | 5 | ||||
| -rw-r--r-- | src/s6-frontend/main.help.txt | 2 | ||||
| -rw-r--r-- | src/s6-frontend/s6-frontend-internal.h | 10 | ||||
| -rw-r--r-- | src/s6-frontend/s6-frontend.c | 17 | ||||
| -rw-r--r-- | src/s6-frontend/version.c | 29 | ||||
| -rw-r--r-- | src/s6-frontend/version.help.txt | 13 | ||||
| -rw-r--r-- | src/s6-frontend/version_export.c | 65 | ||||
| -rw-r--r-- | src/s6-frontend/version_show.c (renamed from src/s6-frontend/main_version.c) | 2 |
9 files changed, 133 insertions, 16 deletions
diff --git a/package/deps.mak b/package/deps.mak index 377de32..856a4ff 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -15,7 +15,6 @@ src/s6-frontend/live_start_everything.o src/s6-frontend/live_start_everything.lo src/s6-frontend/live_startstop.o src/s6-frontend/live_startstop.lo: src/s6-frontend/live_startstop.c src/s6-frontend/s6-frontend-internal.h src/s6-frontend/live_status.o src/s6-frontend/live_status.lo: src/s6-frontend/live_status.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/live_stop_everything.o src/s6-frontend/live_stop_everything.lo: src/s6-frontend/live_stop_everything.c src/s6-frontend/s6-frontend-internal.h -src/s6-frontend/main_version.o src/s6-frontend/main_version.lo: src/s6-frontend/main_version.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/process.o src/s6-frontend/process.lo: src/s6-frontend/process.c src/s6-frontend/s6-frontend-internal.h src/s6-frontend/process_kill.o src/s6-frontend/process_kill.lo: src/s6-frontend/process_kill.c src/s6-frontend/s6-frontend-internal.h src/include-local/s6f.h src/s6-frontend/process_restart.o src/s6-frontend/process_restart.lo: src/s6-frontend/process_restart.c src/s6-frontend/s6-frontend-internal.h @@ -39,6 +38,9 @@ src/s6-frontend/set_status.o src/s6-frontend/set_status.lo: src/s6-frontend/set_ src/s6-frontend/system.o src/s6-frontend/system.lo: src/s6-frontend/system.c src/s6-frontend/s6-frontend-internal.h src/s6-frontend/system_boot.o src/s6-frontend/system_boot.lo: src/s6-frontend/system_boot.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/s6-frontend/system_hpr.o src/s6-frontend/system_hpr.lo: src/s6-frontend/system_hpr.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h +src/s6-frontend/version.o src/s6-frontend/version.lo: src/s6-frontend/version.c src/s6-frontend/s6-frontend-internal.h +src/s6-frontend/version_export.o src/s6-frontend/version_export.lo: src/s6-frontend/version_export.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h src/include-local/s6f.h +src/s6-frontend/version_show.o src/s6-frontend/version_show.lo: src/s6-frontend/version_show.c src/s6-frontend/s6-frontend-internal.h src/include/s6-frontend/config.h s6-frontend-helper-echo: EXTRA_LIBS := s6-frontend-helper-echo: src/helpers/s6-frontend-helper-echo.o -lskarnet @@ -52,5 +54,5 @@ endif s6: EXTRA_LIBS := s6: src/s6-frontend/s6.o -lskarnet s6-frontend: EXTRA_LIBS := ${MAYBEPTHREAD_LIB} -s6-frontend: src/s6-frontend/s6-frontend.o src/s6-frontend/live.o src/s6-frontend/live_help.o src/s6-frontend/live_install.o src/s6-frontend/live_startstop.o src/s6-frontend/live_status.o src/s6-frontend/live_start_everything.o src/s6-frontend/live_stop_everything.o src/s6-frontend/main_help.o src/s6-frontend/main_version.o src/s6-frontend/process.o src/s6-frontend/process_help.o src/s6-frontend/process_kill.o src/s6-frontend/process_restart.o src/s6-frontend/process_startstop.o src/s6-frontend/process_status.o src/s6-frontend/repository.o src/s6-frontend/repository_check.o src/s6-frontend/repository_help.o src/s6-frontend/repository_init.o src/s6-frontend/repository_list.o src/s6-frontend/repository_sync.o src/s6-frontend/set.o src/s6-frontend/set_change.o src/s6-frontend/set_check.o src/s6-frontend/set_commit.o src/s6-frontend/set_copy.o src/s6-frontend/set_delete.o src/s6-frontend/set_help.o src/s6-frontend/set_list.o src/s6-frontend/set_status.o src/s6-frontend/system.o src/s6-frontend/system_boot.o src/s6-frontend/system_help.o src/s6-frontend/system_hpr.o libs6f.a.xyzzy ${LIBNSSS} -ls6rc -ls6 -lskarnet +s6-frontend: src/s6-frontend/s6-frontend.o src/s6-frontend/live.o src/s6-frontend/live_help.o src/s6-frontend/live_install.o src/s6-frontend/live_startstop.o src/s6-frontend/live_status.o src/s6-frontend/live_start_everything.o src/s6-frontend/live_stop_everything.o src/s6-frontend/main_help.o src/s6-frontend/process.o src/s6-frontend/process_help.o src/s6-frontend/process_kill.o src/s6-frontend/process_restart.o src/s6-frontend/process_startstop.o src/s6-frontend/process_status.o src/s6-frontend/repository.o src/s6-frontend/repository_check.o src/s6-frontend/repository_help.o src/s6-frontend/repository_init.o src/s6-frontend/repository_list.o src/s6-frontend/repository_sync.o src/s6-frontend/set.o src/s6-frontend/set_change.o src/s6-frontend/set_check.o src/s6-frontend/set_commit.o src/s6-frontend/set_copy.o src/s6-frontend/set_delete.o src/s6-frontend/set_help.o src/s6-frontend/set_list.o src/s6-frontend/set_status.o src/s6-frontend/system.o src/s6-frontend/system_boot.o src/s6-frontend/system_help.o src/s6-frontend/system_hpr.o src/s6-frontend/version.o src/s6-frontend/version_export.o src/s6-frontend/version_help.o src/s6-frontend/version_show.o libs6f.a.xyzzy ${LIBNSSS} -ls6rc -ls6 -lskarnet INTERNAL_LIBS := libs6f.a.xyzzy diff --git a/src/s6-frontend/deps-exe/s6-frontend b/src/s6-frontend/deps-exe/s6-frontend index 9be433a..8903175 100644 --- a/src/s6-frontend/deps-exe/s6-frontend +++ b/src/s6-frontend/deps-exe/s6-frontend @@ -6,7 +6,6 @@ live_status.o live_start_everything.o live_stop_everything.o main_help.o -main_version.o process.o process_help.o process_kill.o @@ -32,6 +31,10 @@ system.o system_boot.o system_help.o system_hpr.o +version.o +version_export.o +version_help.o +version_show.o libs6f.a.xyzzy ${LIBNSSS} -ls6rc diff --git a/src/s6-frontend/main.help.txt b/src/s6-frontend/main.help.txt index 9adabfe..f7c03eb 100644 --- a/src/s6-frontend/main.help.txt +++ b/src/s6-frontend/main.help.txt @@ -13,7 +13,7 @@ Commands: Global options: -h --help equivalent to "s6 help" - -V --version equivalent to "s6 version" + -u --user override config values with XDG environment --color=yes|no|auto display fancy or boring-but-parsable text. auto is the default: fancy if in a terminal. diff --git a/src/s6-frontend/s6-frontend-internal.h b/src/s6-frontend/s6-frontend-internal.h index 32e0240..843ad41 100644 --- a/src/s6-frontend/s6-frontend-internal.h +++ b/src/s6-frontend/s6-frontend-internal.h @@ -101,6 +101,15 @@ extern void system_poweroff (char const *const *) gccattr_noreturn ; extern void system_reboot (char const *const *) gccattr_noreturn ; + /* version */ + +extern void version (char const *const *) gccattr_noreturn ; +extern void version_help (char const *const *) gccattr_noreturn ; + +extern void version_export (char const *const *) gccattr_noreturn ; +extern void version_show (char const *const *) gccattr_noreturn ; + + /* main */ struct global_s @@ -147,6 +156,5 @@ extern void main_pretty_exec (char const *const *) gccattr_noreturn ; extern pid_t main_spawn (char const *const *argv) ; extern void main_help (char const *const *) gccattr_noreturn ; -extern void main_version (char const *const *) gccattr_noreturn ; #endif diff --git a/src/s6-frontend/s6-frontend.c b/src/s6-frontend/s6-frontend.c index df25e79..6d829ef 100644 --- a/src/s6-frontend/s6-frontend.c +++ b/src/s6-frontend/s6-frontend.c @@ -26,7 +26,7 @@ enum golb_e { GOLB_HELP = 0x01, GOLB_VERSION = 0x02, -// GOLB_USER = 0x04, + GOLB_USER = 0x04, } ; enum gola_e @@ -82,8 +82,7 @@ int main (int argc, char const *const *argv) static gol_bool const rgolb[] = { { .so = 'h', .lo = "help", .clear = 0, .set = GOLB_HELP }, - { .so = 'V', .lo = "version", .clear = 0, .set = GOLB_VERSION }, -// { .so = 0, .lo = "user", .clear = 0, .set = GOLB_USER }, + { .so = 'u', .lo = "user", .clear = 0, .set = GOLB_USER }, } ; static gol_arg const rgola[] = { @@ -109,7 +108,7 @@ int main (int argc, char const *const *argv) { .s = "repository", .f = &repository }, { .s = "set", .f = &set }, { .s = "system", .f = &s6system }, - { .s = "version", .f = &main_version }, + { .s = "version", .f = &version }, } ; struct global_s globals_in_the_stack = GLOBAL_ZERO ; @@ -136,9 +135,10 @@ int main (int argc, char const *const *argv) if (wgola[GOLA_VERBOSITY] && !uint0_scan(wgola[GOLA_VERBOSITY], &g->verbosity)) strerr_dief1x(100, "verbosity must be an unsigned integer") ; - if (wgolb & GOLB_VERSION) main_version(argv) ; - if (wgolb & GOLB_HELP) main_help(argv) ; - if (wgolb & (GOLB_VERSION | GOLB_HELP)) _exit(0) ; + if (wgolb & GOLB_HELP) { main_help(argv) ; _exit(0) ; } + + g->isuser = !!(wgolb & GOLB_USER) ; + if (g->isuser) s6f_user_get_confdirs(&g->dirs, &g->userstorage) ; if (wgola[GOLA_SCANDIR]) g->dirs.scan = wgola[GOLA_SCANDIR] ; if (wgola[GOLA_LIVEDIR]) g->dirs.live = wgola[GOLA_LIVEDIR] ; @@ -168,9 +168,6 @@ int main (int argc, char const *const *argv) if (!force_color) g->color = g->istty ; } -// g->isuser = !!(wgolb & GOLB_USER) ; -// if (g->isuser) s6f_user_get_confdirs(&g->dirs, &g->userstorage) ; - if (!*argv) dieusage() ; cmd = BSEARCH(struct command_s, *argv, commands) ; if (!cmd) dieusage() ; diff --git a/src/s6-frontend/version.c b/src/s6-frontend/version.c new file mode 100644 index 0000000..802b034 --- /dev/null +++ b/src/s6-frontend/version.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <unistd.h> + +#include <skalibs/envexec.h> + +#include <s6/config.h> + +#include "s6-frontend-internal.h" + +#define USAGE "s6 version subcommand [ subcommand options ] Type \"s6 version help\" for details." +#define dieusage() strerr_dieusage(100, USAGE) + +void version (char const *const *argv) +{ + static struct command_s const subcommands[] = + { + { .s = "export", .f = &version_export }, + { .s = "help", .f = &version_help }, + { .s = "show", .f = &version_show }, + } ; + struct command_s *cmd ; + argv += gol_argv(argv, 0, 0, 0, 0, 0, 0) ; + if (!*argv) version_show(argv) ; + cmd = BSEARCH(struct command_s, *argv, subcommands) ; + if (!cmd) dieusage() ; + (*cmd->f)(++argv) ; + _exit(101) ; +} diff --git a/src/s6-frontend/version.help.txt b/src/s6-frontend/version.help.txt new file mode 100644 index 0000000..a7f6982 --- /dev/null +++ b/src/s6-frontend/version.help.txt @@ -0,0 +1,13 @@ +Usage: s6 version subcommand [ options ] [ arguments... ] + +Subcommands: + help this message + show show the current version (default if no subcommand) + export export version and config values to stdout + + +s6 version show options: none + +s6 version export options: + -q, --quote quote printed paths (e.g. for use in a shell script) + diff --git a/src/s6-frontend/version_export.c b/src/s6-frontend/version_export.c new file mode 100644 index 0000000..14e0de3 --- /dev/null +++ b/src/s6-frontend/version_export.c @@ -0,0 +1,65 @@ +/* ISC license. */ + +#include <unistd.h> + +#include <skalibs/buffer.h> +#include <skalibs/gol.h> +#include <skalibs/stralloc.h> +#include <skalibs/strerr.h> +#include <skalibs/skamisc.h> + +#include <s6-frontend/config.h> +#include "s6-frontend-internal.h" +#include "s6f.h" + +#define dieout() strerr_diefusys(111, "write to stdout") ; + +typedef void out_func (char const *, char const *, stralloc *) ; +typedef out_func *out_func_ref ; + +enum golb_e +{ + GOLB_QUOTE = 0x01, +} ; + +static void print_quoted (char const *var, char const *value, stralloc *sa) +{ + sa->len = 0 ; + if (!string_quotes(sa, value)) strerr_diefusys(111, "stralloc_catb") ; + if (buffer_puts(buffer_1, var) == -1 + || buffer_put(buffer_1, "=", 1) < 1 + || buffer_put(buffer_1, sa->s, sa->len) < sa->len + || buffer_put(buffer_1, "\n", 1) < 1) dieout() ; +} + +static void print_unquoted (char const *var, char const *value, stralloc *sa) +{ + if (buffer_puts(buffer_1, var) == -1 + || buffer_put(buffer_1, "=", 1) < 1 + || buffer_puts(buffer_1, value) == -1 + || buffer_put(buffer_1, "\n", 1) < 1) dieout() ; + (void)sa ; +} + +void version_export (char const *const *argv) +{ + static gol_bool const rgolb[] = + { + { .so = 'q', .lo = "quote", .clear = 0, .set = GOLB_QUOTE }, + } ; + stralloc sa = STRALLOC_ZERO ; + uint64_t wgolb = 0 ; + out_func_ref f = &print_unquoted ; + argv += gol_argv(argv, rgolb, 1, 0, 0, &wgolb, 0) ; + if (wgolb & GOLB_QUOTE) f = &print_quoted ; + + if (!buffer_puts(buffer_1, "version=" S6_FRONTEND_VERSION "\n")) dieout() ; + (*f)("scandir", g->dirs.scan, &sa) ; + (*f)("livedir", g->dirs.live, &sa) ; + (*f)("repodir", g->dirs.repo, &sa) ; + (*f)("bootdb", g->dirs.scan, &sa) ; + (*f)("stmpdir", g->dirs.stmp, &sa) ; + (*f)("storelist", g->dirs.stol, &sa) ; + if (!buffer_flush(buffer_1)) dieout() ; + _exit(0) ; +} diff --git a/src/s6-frontend/main_version.c b/src/s6-frontend/version_show.c index c7d7e68..30a2a3e 100644 --- a/src/s6-frontend/main_version.c +++ b/src/s6-frontend/version_show.c @@ -8,7 +8,7 @@ #include <s6-frontend/config.h> #include "s6-frontend-internal.h" -void main_version (char const *const *argv) +void version_show (char const *const *argv) { if (!buffer_putsflush(buffer_1, "s6-frontend v" S6_FRONTEND_VERSION "\n")) strerr_diefu1sys(111, "write to stdout") ; |
