]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
update-utmp: convert verbs to VERB macros
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 15 May 2026 19:19:28 +0000 (21:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Sat, 16 May 2026 16:36:08 +0000 (18:36 +0200)
There is no --help implemented, so both verbs don't get help strings.
We should probably add --help + --version, and a proper description
of the program, but I'm leaving that for later.

Co-developed-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
src/update-utmp/update-utmp.c

index 875ae9a09bcadba352df2210d84f89e0b4104e0d..bd10f42ea5d8598f45f8df9e07e225cc648cf44f 100644 (file)
@@ -10,6 +10,7 @@
 #include "libaudit-util.h"
 #include "log.h"
 #include "main-func.h"
+#include "strv.h"
 #include "time-util.h"
 #include "utmp-wtmp.h"
 #include "verbs.h"
@@ -51,6 +52,7 @@ static int get_startup_monotonic_time(Context *c, usec_t *ret) {
         return 0;
 }
 
+VERB_NOARG(verb_on_reboot, "reboot", /* help= */ NULL);
 static int verb_on_reboot(int argc, char *argv[], uintptr_t _data, void *userdata) {
         Context *c = ASSERT_PTR(userdata);
         usec_t t = 0, boottime;
@@ -80,6 +82,7 @@ static int verb_on_reboot(int argc, char *argv[], uintptr_t _data, void *userdat
         return q;
 }
 
+VERB_NOARG(verb_on_shutdown, "shutdown", /* help= */ NULL);
 static int verb_on_shutdown(int argc, char *argv[], uintptr_t _data, void *userdata) {
         int r, q = 0;
 
@@ -102,12 +105,6 @@ static int verb_on_shutdown(int argc, char *argv[], uintptr_t _data, void *userd
 }
 
 static int run(int argc, char *argv[]) {
-        static const Verb verbs[] = {
-                { "reboot",   1, 1, 0, verb_on_reboot   },
-                { "shutdown", 1, 1, 0, verb_on_shutdown },
-                {}
-        };
-
         _cleanup_(context_clear) Context c = {
                 .audit_fd = -EBADF,
         };
@@ -118,7 +115,7 @@ static int run(int argc, char *argv[]) {
 
         c.audit_fd = open_audit_fd_or_warn();
 
-        return dispatch_verb(argc, argv, verbs, &c);
+        return dispatch_verb_with_args(strv_skip(argv, 1), &c);
 }
 
 DEFINE_MAIN_FUNCTION(run);