summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-08-11 04:38:55 +0200
committerLennart Poettering <lennart@poettering.net>2010-08-11 04:38:55 +0200
commitcd6d0a456bc9c45fa79316fc5896e4a3ae75a30b (patch)
tree92f326220de29f3c7eac7909e6b244fcba8086ab
parent41b02ec77e54871eaa593c50fb31809814f627a7 (diff)
utmp: enable systemd-update-utmp by default
-rw-r--r--Makefile.am35
-rw-r--r--fixme2
-rw-r--r--src/initctl.c9
-rw-r--r--src/logger.c9
-rw-r--r--src/manager.c2
-rw-r--r--src/systemctl.c2
-rw-r--r--src/unit.c25
-rw-r--r--src/unit.h2
-rw-r--r--src/update-utmp.c20
-rw-r--r--units/.gitignore2
-rw-r--r--units/systemd-update-utmp-runlevel.service.in15
-rw-r--r--units/systemd-update-utmp-shutdown.service.in16
12 files changed, 109 insertions, 30 deletions
diff --git a/Makefile.am b/Makefile.am
index cb2318406d..038b72e1e1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 be771ab025..20a95cbc45 100644
--- 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
diff --git a/src/initctl.c b/src/initctl.c
index 83a560a14a..74eccac557 100644
--- a/src/initctl.c
+++ b/src/initctl.c
@@ -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;
diff --git a/src/logger.c b/src/logger.c
index d4d964d1bb..3d69fcf2cd 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -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;
}
diff --git a/src/manager.c b/src/manager.c
index 25eb4e70be..e32b24ff51 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -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"
diff --git a/src/systemctl.c b/src/systemctl.c
index e49c5b8671..490ef64d87 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -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;
}
diff --git a/src/unit.c b/src/unit.c
index b93777bec6..33e9cef865 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -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
diff --git a/src/unit.h b/src/unit.h
index 00e929ac4e..82ef952451 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -210,6 +210,8 @@ struct Meta {
bool sent_dbus_new_signal:1;
bool no_gc:1;
+
+ bool in_audit:1;
};
#include "service.h"
diff --git a/src/update-utmp.c b/src/update-utmp.c
index e64a819aa4..b8b0d36ae7 100644
--- a/src/update-utmp.c
+++ b/src/update-utmp.c
@@ -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);
diff --git a/units/.gitignore b/units/.gitignore
index 5de1b5c7c4..0c3dc17fe8 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -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
index 0000000000..9b7677f3a1
--- /dev/null
+++ b/units/systemd-update-utmp-runlevel.service.in
@@ -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
index 0000000000..0551a9b7e2
--- /dev/null
+++ b/units/systemd-update-utmp-shutdown.service.in
@@ -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