mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
utmp: enable systemd-update-utmp by default
This commit is contained in:
parent
41b02ec77e
commit
cd6d0a456b
35
Makefile.am
35
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 )
|
||||
|
2
fixme
2
fixme
@ -83,6 +83,8 @@
|
||||
|
||||
* plymouth boot.log
|
||||
|
||||
* plymouth different shut down msgs
|
||||
|
||||
External:
|
||||
|
||||
* sysv functions should color when stdout is tty, not stdin
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
25
src/unit.c
25
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)) {
|
||||
|
||||
/* Write audit record if we have just finished shutting down */
|
||||
manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE);
|
||||
/* 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);
|
||||
|
||||
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
|
||||
|
@ -210,6 +210,8 @@ struct Meta {
|
||||
bool sent_dbus_new_signal:1;
|
||||
|
||||
bool no_gc:1;
|
||||
|
||||
bool in_audit:1;
|
||||
};
|
||||
|
||||
#include "service.h"
|
||||
|
@ -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);
|
||||
|
2
units/.gitignore
vendored
2
units/.gitignore
vendored
@ -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
|
||||
|
15
units/systemd-update-utmp-runlevel.service.in
Normal file
15
units/systemd-update-utmp-runlevel.service.in
Normal file
@ -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
|
16
units/systemd-update-utmp-shutdown.service.in
Normal file
16
units/systemd-update-utmp-shutdown.service.in
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user