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 = \
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
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 \
$(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 \
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 && \
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 )
* plymouth boot.log
+* plymouth different shut down msgs
+
External:
* sysv functions should color when stdout is tty, not stdin
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;
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...");
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;
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;
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...");
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;
}
#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>
#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"
int r, runlevel, previous;
if ((r = utmp_get_runlevel(&runlevel, &previous)) < 0) {
- printf("unknown");
+ printf("unknown\n");
return r;
}
* 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);
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 {
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
bool sent_dbus_new_signal:1;
bool no_gc:1;
+
+ bool in_audit:1;
};
#include "service.h"
} 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 },
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) {
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.");
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);
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);
multi-user.target
getty@.service
remote-fs.target
+systemd-update-utmp-runlevel.service
+systemd-update-utmp-shutdown.service
test-env-replace
--- /dev/null
+# 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
--- /dev/null
+# 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