summaryrefslogtreecommitdiff
path: root/src
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 /src
parent41b02ec77e54871eaa593c50fb31809814f627a7 (diff)
utmp: enable systemd-update-utmp by default
Diffstat (limited to 'src')
-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
7 files changed, 42 insertions, 27 deletions
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);