summaryrefslogtreecommitdiff
path: root/src/update-utmp/update-utmp.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-08-05 15:53:28 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-09-16 09:15:05 +0200
commit7268295765ff423a1dbbdad2db4544d3680e718a (patch)
tree43001f409ff51df448dd15899f651a545bdde22b /src/update-utmp/update-utmp.c
parent134075bf30560e3ec6893126f1ae9ed1146cd653 (diff)
downloadsystemd-7268295765ff423a1dbbdad2db4544d3680e718a.tar.gz
update-utmp: define main() through macro
Update logging a bit: drop logging of the pid, nowadays pid1 and journald do a very good job of logging that. Always log about failure to open audit fd, but at DEBUG_LEVEL if not important.
Diffstat (limited to 'src/update-utmp/update-utmp.c')
-rw-r--r--src/update-utmp/update-utmp.c55
1 files changed, 22 insertions, 33 deletions
diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c
index 56fb937647..f0fc181b57 100644
--- a/src/update-utmp/update-utmp.c
+++ b/src/update-utmp/update-utmp.c
@@ -18,6 +18,7 @@
#include "format-util.h"
#include "log.h"
#include "macro.h"
+#include "main-func.h"
#include "process-util.h"
#include "special.h"
#include "strv.h"
@@ -220,7 +221,7 @@ static int on_runlevel(Context *c) {
return r;
}
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
_cleanup_(context_clear) Context c = {
#if HAVE_AUDIT
.audit_fd = -1
@@ -228,47 +229,35 @@ int main(int argc, char *argv[]) {
};
int r;
- if (getppid() != 1) {
- log_error("This program should be invoked by init only.");
- return EXIT_FAILURE;
- }
-
- if (argc != 2) {
- log_error("This program requires one argument.");
- return EXIT_FAILURE;
- }
+ if (getppid() != 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program should be invoked by init only.");
+ if (argc != 2)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "This program requires one argument.");
log_setup_service();
umask(0022);
#if HAVE_AUDIT
- /* If the kernel lacks netlink or audit support,
- * don't worry about it. */
+ /* If the kernel lacks netlink or audit support, don't worry about it. */
c.audit_fd = audit_open();
- if (c.audit_fd < 0 && !IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT))
- log_error_errno(errno, "Failed to connect to audit log: %m");
+ if (c.audit_fd < 0)
+ log_full_errno(IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT) ? LOG_DEBUG : LOG_ERR,
+ errno, "Failed to connect to audit log: %m");
#endif
r = bus_connect_system_systemd(&c.bus);
- if (r < 0) {
- log_error_errno(r, "Failed to get D-Bus connection: %m");
- return EXIT_FAILURE;
- }
-
- log_debug("systemd-update-utmp running as pid "PID_FMT, getpid_cached());
+ if (r < 0)
+ return log_error_errno(r, "Failed to get D-Bus connection: %m");
if (streq(argv[1], "reboot"))
- r = on_reboot(&c);
- else if (streq(argv[1], "shutdown"))
- r = on_shutdown(&c);
- else if (streq(argv[1], "runlevel"))
- r = on_runlevel(&c);
- else {
- log_error("Unknown command %s", argv[1]);
- return EXIT_FAILURE;
- }
-
- log_debug("systemd-update-utmp stopped as pid "PID_FMT, getpid_cached());
-
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ 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]);
}
+
+DEFINE_MAIN_FUNCTION(run);