]> err.no Git - systemd/commitdiff
utmp: enable systemd-update-utmp by default
authorLennart Poettering <lennart@poettering.net>
Wed, 11 Aug 2010 02:38:55 +0000 (04:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Aug 2010 02:38:55 +0000 (04:38 +0200)
12 files changed:
Makefile.am
fixme
src/initctl.c
src/logger.c
src/manager.c
src/systemctl.c
src/unit.c
src/unit.h
src/update-utmp.c
units/.gitignore
units/systemd-update-utmp-runlevel.service.in [new file with mode: 0644]
units/systemd-update-utmp-shutdown.service.in [new file with mode: 0644]

index cb2318406da32f9e712286fa1a727a61a0d20f88..038b72e1e14ffea91888fd7531b9af35bd71a0bd 100644 (file)
@@ -159,6 +159,8 @@ nodist_systemunit_DATA = \
        units/multi-user.target \
        units/systemd-initctl.service \
        units/systemd-logger.service \
+       units/systemd-update-utmp-runlevel.service \
+       units/systemd-update-utmp-shutdown.service \
        units/syslog.target
 
 dist_sessionunit_DATA = \
@@ -176,6 +178,8 @@ EXTRA_DIST = \
        units/remote-fs.target.m4 \
        units/systemd-initctl.service.in \
        units/systemd-logger.service.in \
+       units/systemd-update-utmp-runlevel.service.in \
+       units/systemd-update-utmp-shutdown.service.in \
        units/syslog.target.in \
        units/session/exit.service.in \
        systemd.pc.in
@@ -331,7 +335,8 @@ EXTRA_DIST += \
        src/special.h \
        src/dbus-common.h \
        src/bus-errors.h \
-       src/cgroup-show.h
+       src/cgroup-show.h \
+       src/utmp-wtmp.h
 
 MANPAGES = \
        man/systemd.1 \
@@ -722,6 +727,12 @@ install-data-hook:
                $(DESTDIR)$(sessionunitdir) \
                $(DESTDIR)$(systemunitdir)/sockets.target.wants \
                $(DESTDIR)$(systemunitdir)/sysinit.target.wants \
+               $(DESTDIR)$(systemunitdir)/shutdown.target.wants \
+               $(DESTDIR)$(systemunitdir)/runlevel1.target.wants \
+               $(DESTDIR)$(systemunitdir)/runlevel2.target.wants \
+               $(DESTDIR)$(systemunitdir)/runlevel3.target.wants \
+               $(DESTDIR)$(systemunitdir)/runlevel4.target.wants \
+               $(DESTDIR)$(systemunitdir)/runlevel5.target.wants \
                $(DESTDIR)$(pkgsysconfdir)/system \
                $(DESTDIR)$(pkgsysconfdir)/system/getty.target.wants \
                $(DESTDIR)$(pkgsysconfdir)/system/multi-user.target.wants \
@@ -737,6 +748,24 @@ install-data-hook:
                rm -f systemd-initctl.socket systemd-logger.socket && \
                $(LN_S) ../systemd-logger.socket systemd-logger.socket && \
                $(LN_S) ../systemd-initctl.socket systemd-initctl.socket )
+       ( cd $(DESTDIR)$(systemunitdir)/runlevel1.target.wants && \
+               rm -f systemd-update-utmp-runlevel.service && \
+               $(LN_S) ../systemd-update-utmp-runlevel.service )
+       ( cd $(DESTDIR)$(systemunitdir)/runlevel2.target.wants && \
+               rm -f systemd-update-utmp-runlevel.service && \
+               $(LN_S) ../systemd-update-utmp-runlevel.service )
+       ( cd $(DESTDIR)$(systemunitdir)/runlevel3.target.wants && \
+               rm -f systemd-update-utmp-runlevel.service && \
+               $(LN_S) ../systemd-update-utmp-runlevel.service )
+       ( cd $(DESTDIR)$(systemunitdir)/runlevel4.target.wants && \
+               rm -f systemd-update-utmp-runlevel.service && \
+               $(LN_S) ../systemd-update-utmp-runlevel.service )
+       ( cd $(DESTDIR)$(systemunitdir)/runlevel5.target.wants && \
+               rm -f systemd-update-utmp-runlevel.service && \
+               $(LN_S) ../systemd-update-utmp-runlevel.service )
+       ( cd $(DESTDIR)$(systemunitdir)/shutdown.target.wants && \
+               rm -f systemd-update-utmp-shutdown.service && \
+               $(LN_S) ../systemd-update-utmp-shutdown.service )
        ( cd $(DESTDIR)$(sessionunitdir) && \
                rm -f shutdown.target sockets.target local-fs.target swap.target bluetooth.target printer.target && \
                $(LN_S) $(systemunitdir)/shutdown.target shutdown.target && \
@@ -789,8 +818,8 @@ install-data-hook:
 if TARGET_FEDORA
        $(MKDIR_P) -m 0755 \
                $(DESTDIR)$(SYSTEM_SYSVINIT_PATH) \
-               $(DESTDIR)$(systemunitdir)/rescue.target.wants \
-               $(DESTDIR)$(pkgsysconfdir)/system/shutdown.target.wants
+               $(DESTDIR)$(pkgsysconfdir)/system/shutdown.target.wants \
+               $(DESTDIR)$(systemunitdir)/rescue.target.wants
        ( cd $(DESTDIR)$(pkgsysconfdir)/system && \
                rm -f display-manager.service && \
                $(LN_S) $(systemunitdir)/prefdm.service display-manager.service )
diff --git a/fixme b/fixme
index be771ab0250140766b9b211d06a557490fa73a6c..20a95cbc45595beca917eac0512f4e6599770e11 100644 (file)
--- a/fixme
+++ b/fixme
@@ -83,6 +83,8 @@
 
 * plymouth boot.log
 
+* plymouth different shut down msgs
+
 External:
 
 * sysv functions should color when stdout is tty, not stdin
index 83a560a14a538e305d16bb8f45d85cc633fa98f4..74eccac557c769ff0f3577033a75b02e5d8b94bc 100644 (file)
@@ -350,8 +350,6 @@ int main(int argc, char *argv[]) {
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
 
-        log_info("systemd-initctl running as pid %lu", (unsigned long) getpid());
-
         if ((n = sd_listen_fds(true)) < 0) {
                 log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
                 return 1;
@@ -365,6 +363,8 @@ int main(int argc, char *argv[]) {
         if (server_init(&server, (unsigned) n) < 0)
                 return 2;
 
+        log_debug("systemd-initctl running as pid %lu", (unsigned long) getpid());
+
         sd_notify(false,
                   "READY=1\n"
                   "STATUS=Processing requests...");
@@ -390,16 +390,17 @@ int main(int argc, char *argv[]) {
                 if ((k = process_event(&server, &event)) < 0)
                         goto fail;
         }
+
         r = 0;
 
+        log_debug("systemd-initctl stopped as pid %lu", (unsigned long) getpid());
+
 fail:
         sd_notify(false,
                   "STATUS=Shutting down...");
 
         server_done(&server);
 
-        log_info("systemd-initctl stopped as pid %lu", (unsigned long) getpid());
-
         dbus_shutdown();
 
         return r;
index d4d964d1bbfd440c268d57b4578a0920071e2e0a..3d69fcf2cd6de49b809fda124e6dedf274f7c7d6 100644 (file)
@@ -548,8 +548,6 @@ int main(int argc, char *argv[]) {
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
 
-        log_info("systemd-logger running as pid %lu", (unsigned long) getpid());
-
         if ((n = sd_listen_fds(true)) < 0) {
                 log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
                 return 1;
@@ -563,6 +561,8 @@ int main(int argc, char *argv[]) {
         if (server_init(&server, (unsigned) n) < 0)
                 return 3;
 
+        log_debug("systemd-logger running as pid %lu", (unsigned long) getpid());
+
         sd_notify(false,
                   "READY=1\n"
                   "STATUS=Processing requests...");
@@ -588,15 +588,16 @@ int main(int argc, char *argv[]) {
                 if ((k = process_event(&server, &event)) < 0)
                         goto fail;
         }
+
         r = 0;
 
+        log_info("systemd-logger stopped as pid %lu", (unsigned long) getpid());
+
 fail:
         sd_notify(false,
                   "STATUS=Shutting down...");
 
         server_done(&server);
 
-        log_info("systemd-logger stopped as pid %lu", (unsigned long) getpid());
-
         return r;
 }
index 25eb4e70bef568490018b294a2297bd1361d958e..e32b24ff516da78bf895e82044f67b474fbeaa13 100644 (file)
@@ -27,7 +27,6 @@
 #include <sys/signalfd.h>
 #include <sys/wait.h>
 #include <unistd.h>
-#include <utmpx.h>
 #include <sys/poll.h>
 #include <sys/reboot.h>
 #include <sys/ioctl.h>
@@ -48,7 +47,6 @@
 #include "ratelimit.h"
 #include "cgroup.h"
 #include "mount-setup.h"
-#include "utmp-wtmp.h"
 #include "unit-name.h"
 #include "dbus-unit.h"
 #include "dbus-job.h"
index e49c5b8671c3af9c4e5a5e51bdc2e3e5536bd8e2..490ef64d87f8ec80960bc2b8c536598b1219cbe5 100644 (file)
@@ -4612,7 +4612,7 @@ static int runlevel_main(void) {
         int r, runlevel, previous;
 
         if ((r = utmp_get_runlevel(&runlevel, &previous)) < 0) {
-                printf("unknown");
+                printf("unknown\n");
                 return r;
         }
 
index b93777bec68dac245d3d3a87b5d7a036c43278dc..33e9cef86508cc9a6f902de10e1426aac69847a0 100644 (file)
@@ -990,8 +990,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
          * even if they might map to the same high-level
          * UnitActiveState! That means that ns == os is OK an expected
          * behaviour here. For example: if a mount point is remounted
-         * this function will be called too and the utmp code below
-         * relies on that! */
+         * this function will be called too! */
 
         dual_timestamp_get(&ts);
 
@@ -1115,9 +1114,11 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
                         log_open();
 
                 if (u->meta.type == UNIT_SERVICE &&
-                    !UNIT_IS_ACTIVE_OR_RELOADING(os))
+                    !UNIT_IS_ACTIVE_OR_RELOADING(os)) {
                         /* Write audit record if we have just finished starting up */
                         manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, 1);
+                        u->meta.in_audit = true;
+                }
 
         } else {
 
@@ -1132,10 +1133,22 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
 
                 if (u->meta.type == UNIT_SERVICE &&
                     UNIT_IS_INACTIVE_OR_MAINTENANCE(ns) &&
-                    !UNIT_IS_INACTIVE_OR_MAINTENANCE(os))
+                    !UNIT_IS_INACTIVE_OR_MAINTENANCE(os)) {
+
+                        /* Hmm, if there was no start record written
+                         * write it now, so that we always have a nice
+                         * pair */
+                        if (!u->meta.in_audit) {
+                                manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, ns == UNIT_INACTIVE);
 
-                        /* Write audit record if we have just finished shutting down */
-                        manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE);
+                                if (ns == UNIT_INACTIVE)
+                                        manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, true);
+                        } else
+                                /* Write audit record if we have just finished shutting down */
+                                manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE);
+
+                        u->meta.in_audit = false;
+                }
         }
 
         /* Maybe we finished startup and are now ready for being
index 00e929ac4e21e3fa8ed1b3b8e6d1e6eee04f9783..82ef95245185121404bd2d0b49157aeccb990441 100644 (file)
@@ -210,6 +210,8 @@ struct Meta {
         bool sent_dbus_new_signal:1;
 
         bool no_gc:1;
+
+        bool in_audit:1;
 };
 
 #include "service.h"
index e64a819aa4fed54af1675a218974a9d82b616860..b8b0d36ae7536e8518c68d172f55b841c3476221 100644 (file)
@@ -112,8 +112,6 @@ static int get_current_runlevel(Context *c) {
         } table[] = {
                 /* The first target of this list that is active or has
                  * a job scheduled wins */
-                { '0', SPECIAL_POWEROFF_TARGET },
-                { '6', SPECIAL_REBOOT_TARGET },
                 { '5', SPECIAL_RUNLEVEL5_TARGET },
                 { '4', SPECIAL_RUNLEVEL4_TARGET },
                 { '3', SPECIAL_RUNLEVEL3_TARGET },
@@ -321,7 +319,9 @@ static int on_runlevel(Context *c) {
         if (c->audit_fd >= 0) {
                 char *s = NULL;
 
-                if (asprintf(&s, "old-level=%c new-level=%c", previous, runlevel) < 0)
+                if (asprintf(&s, "old-level=%c new-level=%c",
+                             previous > 0 ? previous : 'N',
+                             runlevel > 0 ? runlevel : 'N') < 0)
                         return -ENOMEM;
 
                 if (audit_log_user_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, NULL, NULL, NULL, 1) < 0) {
@@ -353,10 +353,10 @@ int main(int argc, char *argv[]) {
         c.audit_fd = -1;
 #endif
 
-        /* if (getppid() != 1) { */
-        /*         log_error("This program should be invoked by init only."); */
-        /*         return 1; */
-        /* } */
+        if (getppid() != 1) {
+                log_error("This program should be invoked by init only.");
+                return 1;
+        }
 
         if (argc != 2) {
                 log_error("This program requires one argument.");
@@ -377,7 +377,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        log_info("systemd-update-utmp running as pid %lu", (unsigned long) getpid());
+        log_debug("systemd-update-utmp running as pid %lu", (unsigned long) getpid());
 
         if (streq(argv[1], "reboot"))
                 r = on_reboot(&c);
@@ -390,9 +390,9 @@ int main(int argc, char *argv[]) {
                 r = -EINVAL;
         }
 
-        log_info("systemd-update-utmp stopped as pid %lu", (unsigned long) getpid());
-finish:
+        log_debug("systemd-update-utmp stopped as pid %lu", (unsigned long) getpid());
 
+finish:
 #ifdef HAVE_AUDIT
         if (c.audit_fd >= 0)
                 audit_close(c.audit_fd);
index 5de1b5c7c4ee5bd749c2d2b1ca77e5004d8d9a0b..0c3dc17fe8f97172d00bcd4f132ddc24bc8fcde7 100644 (file)
@@ -6,4 +6,6 @@ graphical.target
 multi-user.target
 getty@.service
 remote-fs.target
+systemd-update-utmp-runlevel.service
+systemd-update-utmp-shutdown.service
 test-env-replace
diff --git a/units/systemd-update-utmp-runlevel.service.in b/units/systemd-update-utmp-runlevel.service.in
new file mode 100644 (file)
index 0000000..9b7677f
--- /dev/null
@@ -0,0 +1,15 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Notify Audit System and Update UTMP about System Runlevel Changes
+DefaultDependencies=no
+After=runlevel1.target runlevel2.target runlevel3.target runlevel4.target runlevel5.target auditd.service
+
+[Service]
+Type=finish
+ExecStart=-@rootlibexecdir@/systemd-update-utmp runlevel
diff --git a/units/systemd-update-utmp-shutdown.service.in b/units/systemd-update-utmp-shutdown.service.in
new file mode 100644 (file)
index 0000000..0551a9b
--- /dev/null
@@ -0,0 +1,16 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Notify Audit System and Update UTMP about System Shutdown
+DefaultDependencies=no
+Before=killall.service
+Conflicts=systemd-update-utmp-runlevel.service
+
+[Service]
+Type=finish
+ExecStart=-@rootlibexecdir@/systemd-update-utmp shutdown