#include "strv.h"
#include "unit-name.h"
#include "utmp-wtmp.h"
+#include "verbs.h"
typedef struct Context {
sd_bus *bus;
return 0;
}
-static int on_reboot(Context *c) {
+static int on_reboot(int argc, char *argv[], void *userdata) {
+ Context *c = ASSERT_PTR(userdata);
+ usec_t t, boottime;
int r = 0, q;
- usec_t t;
- usec_t boottime;
-
- assert(c);
/* We finished start-up, so let's write the utmp
* record and send the audit msg */
return r;
}
-static int on_shutdown(Context *c) {
+static int on_shutdown(int argc, char *argv[], void *userdata) {
int r = 0, q;
- assert(c);
-
/* We started shut-down, so let's write the utmp
* record and send the audit msg */
#if HAVE_AUDIT
+ Context *c = ASSERT_PTR(userdata);
+
if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM)
return r;
}
-static int on_runlevel(Context *c) {
+static int on_runlevel(int argc, char *argv[], void *userdata) {
+ Context *c = ASSERT_PTR(userdata);
int r = 0, q, previous, runlevel;
- assert(c);
-
/* We finished changing runlevel, so let's write the
* utmp record and send the audit msg */
}
static int run(int argc, char *argv[]) {
+ static const Verb verbs[] = {
+ { "reboot", 1, 1, 0, on_reboot },
+ { "shutdown", 1, 1, 0, on_shutdown },
+ { "runlevel", 1, 1, 0, on_runlevel },
+ {}
+ };
+
_cleanup_(context_clear) Context c = {
#if HAVE_AUDIT
.audit_fd = -EBADF,
};
int r;
- if (argc != 2)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "This program requires one argument.");
-
log_setup();
umask(0022);
if (r < 0)
return log_error_errno(r, "Failed to get D-Bus connection: %m");
- if (streq(argv[1], "reboot"))
- return on_reboot(&c);
- if (streq(argv[1], "shutdown"))
- return on_shutdown(&c);
- if (streq(argv[1], "runlevel"))
- return on_runlevel(&c);
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown command %s", argv[1]);
+ return dispatch_verb(argc, argv, verbs, &c);
}
DEFINE_MAIN_FUNCTION(run);