[systemd-commits] 6 commits - fixme Makefile.am src/fdset.c src/systemctl.c units/fedora units/systemd-random-seed-load.service.in units/systemd-random-seed-save.service.in units/systemd-update-utmp-runlevel.service.in units/systemd-update-utmp-shutdown.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Sat Aug 14 10:28:09 PDT 2010


 Makefile.am                                   |   17 +++
 fixme                                         |    8 -
 src/fdset.c                                   |    1 
 src/systemctl.c                               |  123 +++++++++++++++++++-------
 units/fedora/plymouth-halt.service            |    1 
 units/fedora/plymouth-poweroff.service        |    1 
 units/fedora/plymouth-reboot.service          |    1 
 units/fedora/prefdm.service                   |    2 
 units/systemd-random-seed-load.service.in     |   20 ++++
 units/systemd-random-seed-save.service.in     |   19 ++++
 units/systemd-update-utmp-runlevel.service.in |    2 
 units/systemd-update-utmp-shutdown.service.in |    2 
 12 files changed, 155 insertions(+), 42 deletions(-)

New commits:
commit 0dcc78574905ca0e31694238662002bd36ca65d4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 14 19:25:12 2010 +0200

    units: write utmp record before we kill all processes

diff --git a/units/systemd-update-utmp-runlevel.service.in b/units/systemd-update-utmp-runlevel.service.in
index 90bb937..0b4c83d 100644
--- a/units/systemd-update-utmp-runlevel.service.in
+++ b/units/systemd-update-utmp-runlevel.service.in
@@ -9,6 +9,8 @@
 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
+Conflicts=shutdown.target
+Before=shutdown.target
 
 [Service]
 Type=oneshot
diff --git a/units/systemd-update-utmp-shutdown.service.in b/units/systemd-update-utmp-shutdown.service.in
index f5d1342..4c48c8b 100644
--- a/units/systemd-update-utmp-shutdown.service.in
+++ b/units/systemd-update-utmp-shutdown.service.in
@@ -8,7 +8,7 @@
 [Unit]
 Description=Notify Audit System and Update UTMP about System Shutdown
 DefaultDependencies=no
-Before=killall.service
+Before=poweroff.service reboot.service halt.service killall.service
 Conflicts=systemd-update-utmp-runlevel.service
 
 [Service]
commit 2a2387d8a9628765e7eb25cbcb21fa8b428199c8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 14 19:24:08 2010 +0200

    units: X 1.8 doesn't need HAL anymore, so avoid synchronization on that

diff --git a/units/fedora/prefdm.service b/units/fedora/prefdm.service
index 233e00d..931b47f 100644
--- a/units/fedora/prefdm.service
+++ b/units/fedora/prefdm.service
@@ -7,7 +7,7 @@
 
 [Unit]
 Description=Display Manager
-After=syslog.target haldaemon.service livesys-late.service
+After=syslog.target livesys-late.service
 
 # On Fedora gdm/X11 is on tty1. We explicitly cancel the getty here to
 # avoid any races around that.
commit 86b846b6971518cfcffc35d9f34f833b164a4b46
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 14 19:23:16 2010 +0200

    units: make sure plymouth shutdown screen is shown before we kill all processes/shut down

diff --git a/units/fedora/plymouth-halt.service b/units/fedora/plymouth-halt.service
index 9b77c5d..69a9197 100644
--- a/units/fedora/plymouth-halt.service
+++ b/units/fedora/plymouth-halt.service
@@ -8,6 +8,7 @@
 [Unit]
 Description=Show Plymouth Halt Screen
 After=getty at tty1.service prefdm.service
+Before=killall.service halt.service
 DefaultDependencies=no
 
 [Service]
diff --git a/units/fedora/plymouth-poweroff.service b/units/fedora/plymouth-poweroff.service
index 538a0c5..be699ba 100644
--- a/units/fedora/plymouth-poweroff.service
+++ b/units/fedora/plymouth-poweroff.service
@@ -8,6 +8,7 @@
 [Unit]
 Description=Show Plymouth Power Off Screen
 After=getty at tty1.service prefdm.service
+Before=killall.service poweroff.service
 DefaultDependencies=no
 
 [Service]
diff --git a/units/fedora/plymouth-reboot.service b/units/fedora/plymouth-reboot.service
index 286c8ab..5d252ad 100644
--- a/units/fedora/plymouth-reboot.service
+++ b/units/fedora/plymouth-reboot.service
@@ -8,6 +8,7 @@
 [Unit]
 Description=Show Plymouth Reboot Screen
 After=getty at tty1.service prefdm.service
+Before=killall.service reboot.service
 DefaultDependencies=no
 
 [Service]
commit ca2cab5dcd3d29f45992a439f54e48faad764c6e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 14 19:17:37 2010 +0200

    random-seed: add little tool for saving/loading random seed on shutdown/boot, but don't enable it by default

diff --git a/Makefile.am b/Makefile.am
index 2c1caa5..384778e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ AM_CPPFLAGS = \
 	-DSYSTEMD_BINARY_PATH=\"$(rootbindir)/systemd\" \
 	-DSYSTEMCTL_BINARY_PATH=\"$(rootbindir)/systemctl\" \
 	-DRUNTIME_DIR=\"$(localstatedir)/run\" \
+	-DRANDOM_SEED=\"$(localstatedir)/lib/random-seed\" \
 	-I $(top_srcdir)/src
 
 rootbin_PROGRAMS = \
@@ -69,7 +70,8 @@ rootlibexec_PROGRAMS = \
 	systemd-logger \
 	systemd-cgroups-agent \
 	systemd-initctl \
-	systemd-update-utmp
+	systemd-update-utmp \
+	systemd-random-seed
 
 noinst_PROGRAMS = \
 	test-engine \
@@ -161,6 +163,8 @@ nodist_systemunit_DATA = \
 	units/systemd-logger.service \
 	units/systemd-update-utmp-runlevel.service \
 	units/systemd-update-utmp-shutdown.service \
+	units/systemd-random-seed-save.service \
+	units/systemd-random-seed-load.service \
 	units/syslog.target
 
 dist_sessionunit_DATA = \
@@ -180,6 +184,8 @@ EXTRA_DIST = \
 	units/systemd-logger.service.in \
 	units/systemd-update-utmp-runlevel.service.in \
 	units/systemd-update-utmp-shutdown.service.in \
+	units/systemd-random-seed-save.service.in \
+	units/systemd-random-seed-load.service.in \
 	units/syslog.target.in \
 	units/session/exit.service.in \
 	systemd.pc.in
@@ -514,6 +520,15 @@ systemd_update_utmp_LDADD = \
 	$(DBUS_LIBS) \
 	$(AUDIT_LIBS)
 
+systemd_random_seed_SOURCES = \
+	src/random-seed.c
+
+systemd_random_seed_CFLAGS = \
+	$(AM_CFLAGS)
+
+systemd_random_seed_LDADD = \
+	libsystemd-basic.la
+
 systemd_cgroups_agent_SOURCES = \
 	src/cgroups-agent.c \
 	src/dbus-common.c
diff --git a/fixme b/fixme
index e9acede..2df43c3 100644
--- a/fixme
+++ b/fixme
@@ -23,7 +23,7 @@
 
 * add #ifdefs for non-sysv builds
 
-* reinvestigate random seed, hwclock
+* reinvestigate hwclock
 
 * "disabled" load state?
 
diff --git a/units/systemd-random-seed-load.service.in b/units/systemd-random-seed-load.service.in
new file mode 100644
index 0000000..4d5841d
--- /dev/null
+++ b/units/systemd-random-seed-load.service.in
@@ -0,0 +1,20 @@
+#  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=Load Random Seed
+DefaultDependencies=no
+After=local-fs.target
+Conflicts=shutdown.target
+Before=shutdown.target
+
+[Service]
+Type=oneshot
+ExecStart=- at rootlibexecdir@/systemd-random-seed load
+
+[Install]
+WantedBy=sysinit.target
diff --git a/units/systemd-random-seed-save.service.in b/units/systemd-random-seed-save.service.in
new file mode 100644
index 0000000..654c859
--- /dev/null
+++ b/units/systemd-random-seed-save.service.in
@@ -0,0 +1,19 @@
+#  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=Save Random Seed
+DefaultDependencies=no
+Before=poweroff.service reboot.service halt.service killall.service
+Conflicts=systemd-random-seed-save.service
+
+[Service]
+Type=oneshot
+ExecStart=- at rootlibexecdir@/systemd-random-seed save
+
+[Install]
+WantedBy=shutdown.target
commit d90e1a301d61c3808ac5c0aa3093b2ec913e406b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 14 19:14:52 2010 +0200

    systemctl: skip writing of utmp if we booted using systemd, under the assumption that systemd-update-utmp is used

diff --git a/fixme b/fixme
index 26a9787..e9acede 100644
--- a/fixme
+++ b/fixme
@@ -1,7 +1,7 @@
 * dot output for --test showing the 'initial transaction'
 
 * check 'disable'
-  <Viking-Ice>    "Warning: Unit file changed in disk, 'systemctl --system daemon-reload' recomended
+  <Viking-Ice>    "Warning: Unit file changed in disk, 'systemctl --system daemon-reload' recommended
   <kay>           when does it do that?
   <Viking-Ice>    if you disable the service
 
diff --git a/src/fdset.c b/src/fdset.c
index b6d5286..ad7cd29 100644
--- a/src/fdset.c
+++ b/src/fdset.c
@@ -144,7 +144,6 @@ finish:
                 set_free(MAKE_SET(s));
 
         return r;
-
 }
 
 int fdset_cloexec(FDSet *fds, bool b) {
diff --git a/src/systemctl.c b/src/systemctl.c
index 9a85383..167c6a5 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -4680,9 +4680,12 @@ static int halt_main(DBusConnection *bus) {
         if (!arg_dry && !arg_immediate)
                 return start_with_fallback(bus);
 
-        if (!arg_no_wtmp)
-                if ((r = utmp_put_shutdown(0)) < 0)
+        if (!arg_no_wtmp) {
+                if (sd_booted() > 0)
+                        log_debug("Not writing utmp record, assuming that systemd-update-utmp is used.");
+                else if ((r = utmp_put_shutdown(0)) < 0)
                         log_warning("Failed to write utmp record: %s", strerror(-r));
+        }
 
         if (!arg_no_sync)
                 sync();
commit 36c32ba297a5296227902cef15730a0e55fec8e7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 14 03:40:10 2010 +0200

    systemctl: sort 'list-units' output

diff --git a/fixme b/fixme
index 31ebbbb..26a9787 100644
--- a/fixme
+++ b/fixme
@@ -65,16 +65,12 @@
 
 * if a service fails too often, make the service enter maintainence mode, and the socket, too.
 
-* j->installed issue
-
 * Ray: plymouth after/before getty? https://bugzilla.redhat.com/show_bug.cgi?id=623430
 
 * be more forgiving when parsing unit files, when encountering incorrect lines with assignments
 
 * agetty darf nicht mit emergency.service kollidieren
 
-* sort systemctl list-units/lis-jobs output
-
 External:
 
 * sysv functions should color when stdout is tty, not stdin
diff --git a/src/systemctl.c b/src/systemctl.c
index 2e7a6a8..9a85383 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -188,12 +188,43 @@ static void warn_wall(enum action action) {
         utmp_wall(table[action]);
 }
 
+struct unit_info {
+        const char *id;
+        const char *description;
+        const char *load_state;
+        const char *active_state;
+        const char *sub_state;
+        const char *following;
+        const char *unit_path;
+        uint32_t job_id;
+        const char *job_type;
+        const char *job_path;
+};
+
+static int compare_unit_info(const void *a, const void *b) {
+        const char *d1, *d2;
+        const struct unit_info *u = a, *v = b;
+
+        d1 = strrchr(u->id, '.');
+        d2 = strrchr(v->id, '.');
+
+        if (d1 && d2) {
+                int r;
+
+                if ((r = strcmp(d1, d2)) != 0)
+                        return r;
+        }
+
+        return strcmp(u->id, v->id);
+}
+
 static int list_units(DBusConnection *bus, char **args, unsigned n) {
         DBusMessage *m = NULL, *reply = NULL;
         DBusError error;
         int r;
         DBusMessageIter iter, sub, sub2;
-        unsigned k = 0;
+        unsigned c = 0, k, n_units = 0;
+        struct unit_info *unit_infos = NULL;
 
         dbus_error_init(&error);
 
@@ -224,12 +255,8 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_message_iter_recurse(&iter, &sub);
 
-        if (isatty(STDOUT_FILENO))
-                printf("%-45s %-6s %-12s %-12s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
-
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
-                const char *id, *description, *load_state, *active_state, *sub_state, *following, *unit_path, *job_type, *job_path, *dot;
-                uint32_t job_id;
+                struct unit_info *u;
 
                 if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
                         log_error("Failed to parse reply.");
@@ -237,59 +264,86 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
                         goto finish;
                 }
 
+                if (c >= n_units) {
+                        struct unit_info *w;
+
+                        n_units = MAX(2*c, 16);
+                        w = realloc(unit_infos, sizeof(struct unit_info) * n_units);
+
+                        if (!w) {
+                                log_error("Failed to allocate unit array.");
+                                r = -ENOMEM;
+                                goto finish;
+                        }
+
+                        unit_infos = w;
+                }
+
+                u = unit_infos+c;
+
                 dbus_message_iter_recurse(&sub, &sub2);
 
-                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &id, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &description, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &load_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &active_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &sub_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &following, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &unit_path, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &job_id, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &job_type, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &job_path, false) < 0) {
+                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->id, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->description, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->load_state, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->active_state, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->sub_state, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->following, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &u->unit_path, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &u->job_id, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->job_type, true) < 0 ||
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &u->job_path, false) < 0) {
                         log_error("Failed to parse reply.");
                         r = -EIO;
                         goto finish;
                 }
 
-                if ((!arg_type || ((dot = strrchr(id, '.')) &&
+                dbus_message_iter_next(&sub);
+                c++;
+        }
+
+        qsort(unit_infos, c, sizeof(struct unit_info), compare_unit_info);
+
+        if (isatty(STDOUT_FILENO))
+                printf("%-45s %-6s %-12s %-12s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
+
+        for (k = 0; k < c; k++) {
+                const char *dot;
+                struct unit_info *u = unit_infos+k;
+
+                if ((!arg_type || ((dot = strrchr(u->id, '.')) &&
                                    streq(dot+1, arg_type))) &&
-                    (arg_all || !(streq(active_state, "inactive") || following[0]) || job_id > 0)) {
+                    (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0)) {
                         char *e;
                         int a = 0, b = 0;
                         const char *on, *off;
 
-                        if (streq(active_state, "maintenance")) {
+                        if (streq(u->active_state, "maintenance")) {
                                 on = ansi_highlight(true);
                                 off = ansi_highlight(false);
                         } else
                                 on = off = "";
 
-                        e = arg_full ? NULL : ellipsize(id, 45, 33);
-                        printf("%-45s %-6s %s%-12s %-12s%s%n", e ? e : id, load_state, on, active_state, sub_state, off, &a);
+                        e = arg_full ? NULL : ellipsize(u->id, 45, 33);
+                        printf("%-45s %-6s %s%-12s %-12s%s%n", e ? e : u->id, u->load_state, on, u->active_state, u->sub_state, off, &a);
                         free(e);
 
                         a -= strlen(on) + strlen(off);
 
-                        if (job_id != 0)
-                                printf(" => %-12s%n", job_type, &b);
+                        if (u->job_id != 0)
+                                printf(" => %-12s%n", u->job_type, &b);
                         else
                                 b = 1 + 15;
 
                         if (a + b + 2 < columns()) {
-                                if (job_id == 0)
+                                if (u->job_id == 0)
                                         printf("                ");
 
-                                printf(" %.*s", columns() - a - b - 2, description);
+                                printf(" %.*s", columns() - a - b - 2, u->description);
                         }
 
                         fputs("\n", stdout);
-                        k++;
                 }
-
-                dbus_message_iter_next(&sub);
         }
 
         if (isatty(STDOUT_FILENO)) {
@@ -300,9 +354,9 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
                        "JOB    = Job, shows pending jobs for the unit.\n");
 
                 if (arg_all)
-                        printf("\n%u units listed.\n", k);
+                        printf("\n%u units listed.\n", c);
                 else
-                        printf("\n%u units listed. Pass --all to see inactive units, too.\n", k);
+                        printf("\n%u units listed. Pass --all to see inactive units, too.\n", c);
         }
 
         r = 0;
@@ -314,6 +368,8 @@ finish:
         if (reply)
                 dbus_message_unref(reply);
 
+        free(unit_infos);
+
         dbus_error_free(&error);
 
         return r;


More information about the systemd-commits mailing list