[systemd-commits] 4 commits - man/systemd.mount.xml man/systemd.swap.xml src/core src/fstab-generator src/journal src/shared

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Wed Nov 26 12:22:43 PST 2014


 man/systemd.mount.xml                 |   37 ++++++------
 man/systemd.swap.xml                  |   40 +++++++++++--
 src/core/main.c                       |   99 +++++++++++++++++++++++-----------
 src/core/manager.c                    |    6 +-
 src/core/selinux-setup.c              |    2 
 src/core/shutdown.c                   |    2 
 src/core/swap.c                       |   16 -----
 src/fstab-generator/fstab-generator.c |   27 +++++----
 src/journal/journald-server.c         |    6 --
 src/shared/log.h                      |   13 ++--
 10 files changed, 154 insertions(+), 94 deletions(-)

New commits:
commit 3d82301321afdcc4f2f8786883bd15b1a64c6e83
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Nov 26 15:05:55 2014 -0500

    journald: proceed even if some sockets are unknown
    
    systemd-journald would refuse to start if it received an unknown
    socket from systemd. This is annoying, because the failure more for
    systemd-journald is unpleasant: systemd will keep restarting journald,
    but most likely the same error will occur every time. It is better
    to continue. journald will try to open missing sockets on its own,
    so things should mostly work.
    
    One question is whether to close the sockets which cannot be parsed or
    to keep them open. Either way we might lose some messages. This
    failure is most likely for the audit socket (selinux issues), which
    can be opened multiple times so this not a problem, so I decided to
    keep them open because it makes it easier to debug the issue after the
    system is fully started.

diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 62ae79a..cd4843c 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1566,10 +1566,8 @@ int server_init(Server *s) {
 
                         s->audit_fd = fd;
 
-                } else {
-                        log_error("Unknown socket passed.");
-                        return -EINVAL;
-                }
+                } else
+                        log_error("Unknown socket passed as file descriptor %d, ignoring.", fd);
         }
 
         r = server_open_syslog_socket(s);

commit 5607d856b8606ba75446a07ab5e9048753e1d7a6
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Nov 26 10:36:52 2014 -0500

    swap: restore support for nofail
    
    systemd stops adding automatic dependencies on swap.target to swap
    units. If a dependency is required, it has to be added by unit
    configuration. fstab-generator did that already, except that now it is
    modified to create a Requires or Wants type dependency, depending on
    whether nofail is specified in /etc/fstab. This makes .swap units
    obey the nofail/noauto options more or less the same as .mount units.
    
    Documentation is extended to clarify that, and to make
    systemd.mount(5) and system.swap(5) more similar. The gist is not
    changed, because current behaviour actually matches existing
    documentation.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=86488

diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml
index ba841c3..6d8eae6 100644
--- a/man/systemd.mount.xml
+++ b/man/systemd.mount.xml
@@ -124,7 +124,7 @@
         </refsect1>
 
         <refsect1>
-                <title><filename>/etc/fstab</filename></title>
+                <title><filename>fstab</filename></title>
 
                 <para>Mount units may either be configured via unit
                 files, or via <filename>/etc/fstab</filename> (see
@@ -142,8 +142,7 @@
                 <para>When reading <filename>/etc/fstab</filename> a
                 few special mount options are understood by systemd
                 which influence how dependencies are created for mount
-                points from <filename>/etc/fstab</filename>. systemd
-                will create a dependency of type
+                points. systemd will create a dependency of type
                 <option>Wants</option> or <option>Requires</option>
                 (see option <option>nofail</option> below), from
                 either <filename>local-fs.target</filename> or
@@ -181,26 +180,13 @@
                   </varlistentry>
 
                   <varlistentry>
-                    <term><option>nofail</option></term>
-                    <term><option>fail</option></term>
-
-                    <listitem><para>With <option>nofail</option> this
-                    mount will be only wanted, not required, by the
-                    <filename>local-fs.target</filename>. This means
-                    that the boot will continue even if this mount
-                    point is not mounted successfully. Option
-                    <option>fail</option> has the opposite meaning and
-                    is the default.</para>
-                    </listitem>
-                  </varlistentry>
-
-                  <varlistentry>
                     <term><option>noauto</option></term>
                     <term><option>auto</option></term>
 
                     <listitem><para>With <option>noauto</option>, this
                     mount will not be added as a dependency for
-                    <filename>local-fs.target</filename>. This means
+                    <filename>local-fs.target</filename> or
+                    <filename>remote-fs.target</filename>. This means
                     that it will not be mounted automatically during
                     boot, unless it is pulled in by some other
                     unit. Option <option>auto</option> has the
@@ -209,6 +195,21 @@
                   </varlistentry>
 
                   <varlistentry>
+                    <term><option>nofail</option></term>
+                    <term><option>fail</option></term>
+
+                    <listitem><para>With <option>nofail</option> this
+                    mount will be only wanted, not required, by
+                    <filename>local-fs.target</filename> or
+                    <filename>remote-fs.target</filename>. This means
+                    that the boot will continue even if this mount
+                    point is not mounted successfully. Option
+                    <option>fail</option> has the opposite meaning and
+                    is the default.</para>
+                    </listitem>
+                  </varlistentry>
+
+                  <varlistentry>
                     <term><option>x-initrd.mount</option></term>
 
                     <listitem><para>An additional filesystem to be
diff --git a/man/systemd.swap.xml b/man/systemd.swap.xml
index 44c16e7..1155758 100644
--- a/man/systemd.swap.xml
+++ b/man/systemd.swap.xml
@@ -117,12 +117,40 @@
                 <filename>/etc/fstab</filename> and a unit file, the
                 configuration in the latter takes precedence.</para>
 
-                <para>Unless the <option>noauto</option> option is set
-                for them all swap units configured in
-                <filename>/etc/fstab</filename> are also added as
-                requirements to <filename>swap.target</filename>, so
-                that they are waited for and activated during
-                boot.</para>
+                <para>When reading <filename>/etc/fstab</filename> a
+                few special options are understood by systemd which
+                influence how dependencies are created for swap
+                units.</para>
+
+                <variablelist class='fstab-options'>
+                  <varlistentry>
+                    <term><option>noauto</option></term>
+                    <term><option>auto</option></term>
+
+                    <listitem><para>With <option>noauto</option> the
+                    swap unit will not be added as a dependency for
+                    <filename>swap.target</filename>. This means that
+                    it will not be activated automatically during
+                    boot, unless it is pulled in by some other
+                    unit. Option <option>auto</option> has the
+                    opposite meaning and is the default.</para>
+                    </listitem>
+                  </varlistentry>
+
+                  <varlistentry>
+                    <term><option>nofail</option></term>
+                    <term><option>fail</option></term>
+
+                    <listitem><para>With <option>nofail</option> the
+                    swap unit will be only wanted, not required by
+                    <filename>swap.target</filename>. This means that
+                    the boot will continue even if this swap device is
+                    not activated successfully. Option
+                    <option>fail</option> has the opposite meaning and
+                    is the default.</para>
+                    </listitem>
+                  </varlistentry>
+                </variablelist>
         </refsect1>
 
         <refsect1>
diff --git a/src/core/swap.c b/src/core/swap.c
index 0a1cc80..e509a63 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -209,8 +209,6 @@ static int swap_add_device_links(Swap *s) {
 }
 
 static int swap_add_default_dependencies(Swap *s) {
-        int r;
-
         assert(s);
 
         if (UNIT(s)->manager->running_as != SYSTEMD_SYSTEM)
@@ -219,19 +217,7 @@ static int swap_add_default_dependencies(Swap *s) {
         if (detect_container(NULL) > 0)
                 return 0;
 
-        r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
-        if (r < 0)
-                return r;
-
-        if (!s->from_fragment)
-                /* The swap unit can either be for an alternative device name, in which
-                 * case we don't need to add the dependency on swap.target because this unit
-                 * is following a different unit which will have this dependency added,
-                 * or it can be derived from /proc/swaps, in which case it was started
-                 * manually, and should not become a dependency of swap.target. */
-                return 0;
-
-        return unit_add_two_dependencies_by_name_inverse(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SWAP_TARGET, NULL, true);
+        return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
 }
 
 static int swap_verify(Swap *s) {
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index af45c25..14e6642 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -74,11 +74,14 @@ static int mount_find_pri(struct mntent *me, int *ret) {
         return 1;
 }
 
-static int add_swap(const char *what, struct mntent *me) {
+static int add_swap(
+                const char *what,
+                struct mntent *me,
+                bool noauto,
+                bool nofail) {
+
         _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-
-        bool noauto;
         int r, pri = -1;
 
         assert(what);
@@ -95,8 +98,6 @@ static int add_swap(const char *what, struct mntent *me) {
                 return r;
         }
 
-        noauto = !!hasmntopt(me, "noauto");
-
         name = unit_name_from_path(what, ".swap");
         if (!name)
                 return log_oom();
@@ -143,7 +144,8 @@ static int add_swap(const char *what, struct mntent *me) {
                 return r;
 
         if (!noauto) {
-                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
+                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET,
+                              nofail ? ".wants/" : ".requires/", name, NULL);
                 if (!lnk)
                         return log_oom();
 
@@ -357,6 +359,7 @@ static int parse_fstab(bool initrd) {
 
         while ((me = getmntent(f))) {
                 _cleanup_free_ char *where = NULL, *what = NULL;
+                bool noauto, nofail;
                 int k;
 
                 if (initrd && !mount_in_initrd(me))
@@ -378,16 +381,18 @@ static int parse_fstab(bool initrd) {
                 if (is_path(where))
                         path_kill_slashes(where);
 
-                log_debug("Found entry what=%s where=%s type=%s", what, where, me->mnt_type);
+                noauto = !!hasmntopt(me, "noauto");
+                nofail = !!hasmntopt(me, "nofail");
+                log_debug("Found entry what=%s where=%s type=%s nofail=%s noauto=%s",
+                          what, where, me->mnt_type,
+                          yes_no(noauto), yes_no(nofail));
 
                 if (streq(me->mnt_type, "swap"))
-                        k = add_swap(what, me);
+                        k = add_swap(what, me, noauto, nofail);
                 else {
-                        bool noauto, nofail, automount;
+                        bool automount;
                         const char *post;
 
-                        noauto = !!hasmntopt(me, "noauto");
-                        nofail = !!hasmntopt(me, "nofail");
                         automount =
                                   hasmntopt(me, "comment=systemd.automount") ||
                                   hasmntopt(me, "x-systemd.automount");

commit cb6531bee6e6f66c3a9d85b24fed68fae7fad6ad
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Nov 6 00:05:38 2014 -0500

    manager: print fatal errors on the console too
    
    When booting in quiet mode, fatal messages would not be shown at all to the user.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1155468

diff --git a/src/core/main.c b/src/core/main.c
index eb08f3f..486602e 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1233,6 +1233,7 @@ int main(int argc, char *argv[]) {
         bool empty_etc = false;
         char *switch_root_dir = NULL, *switch_root_init = NULL;
         static struct rlimit saved_rlimit_nofile = { 0, 0 };
+        const char *error_message = NULL;
 
 #ifdef HAVE_SYSV_COMPAT
         if (getpid() != 1 && strstr(program_invocation_short_name, "init")) {
@@ -1291,17 +1292,23 @@ int main(int argc, char *argv[]) {
                 if (!skip_setup) {
                         mount_setup_early();
                         dual_timestamp_get(&security_start_timestamp);
-                        if (mac_selinux_setup(&loaded_policy) < 0)
+                        if (mac_selinux_setup(&loaded_policy) < 0) {
+                                error_message = "Failed to load SELinux policy";
                                 goto finish;
-                        if (ima_setup() < 0)
+                        } else if (ima_setup() < 0) {
+                                error_message = "Failed to load IMA policy";
                                 goto finish;
-                        if (mac_smack_setup(&loaded_policy) < 0)
+                        } else if (mac_smack_setup(&loaded_policy) < 0) {
+                                error_message = "Failed to load SMACK policy";
                                 goto finish;
+                        }
                         dual_timestamp_get(&security_finish_timestamp);
                 }
 
-                if (mac_selinux_init(NULL) < 0)
+                if (mac_selinux_init(NULL) < 0) {
+                        error_message = "Failed to initialize SELinux policy";
                         goto finish;
+                }
 
                 if (!skip_setup) {
                         if (clock_is_localtime() > 0) {
@@ -1377,12 +1384,15 @@ int main(int argc, char *argv[]) {
         r = set_default_unit(SPECIAL_DEFAULT_TARGET);
         if (r < 0) {
                 log_emergency("Failed to set default unit %s: %s", SPECIAL_DEFAULT_TARGET, strerror(-r));
+                error_message = "Failed to set default unit";
                 goto finish;
         }
 
         r = initialize_join_controllers();
-        if (r < 0)
+        if (r < 0) {
+                error_message = "Failed to initalize cgroup controllers";
                 goto finish;
+        }
 
         /* Mount /proc, /sys and friends, so that /proc/cmdline and
          * /proc/$PID/fd is available. */
@@ -1393,8 +1403,10 @@ int main(int argc, char *argv[]) {
                         kmod_setup();
 
                 r = mount_setup(loaded_policy);
-                if (r < 0)
+                if (r < 0) {
+                        error_message = "Failed to mount API filesystems";
                         goto finish;
+                }
         }
 
         /* Reset all signal handlers. */
@@ -1402,8 +1414,10 @@ int main(int argc, char *argv[]) {
 
         ignore_signals(SIGNALS_IGNORE, -1);
 
-        if (parse_config_file() < 0)
+        if (parse_config_file() < 0) {
+                error_message = "Failed to parse config file";
                 goto finish;
+        }
 
         if (arg_running_as == SYSTEMD_SYSTEM) {
                 r = parse_proc_cmdline(parse_proc_cmdline_item);
@@ -1415,8 +1429,10 @@ int main(int argc, char *argv[]) {
          * line, including "debug". */
         log_parse_environment();
 
-        if (parse_argv(argc, argv) < 0)
+        if (parse_argv(argc, argv) < 0) {
+                error_message = "Failed to parse commandline arguments";
                 goto finish;
+        }
 
         if (arg_action == ACTION_TEST &&
             geteuid() == 0) {
@@ -1473,6 +1489,7 @@ int main(int argc, char *argv[]) {
         r = fdset_new_fill(&fds);
         if (r < 0) {
                 log_emergency("Failed to allocate fd set: %s", strerror(-r));
+                error_message = "Failed to allocate fd set";
                 goto finish;
         } else
                 fdset_cloexec(fds, true);
@@ -1575,19 +1592,23 @@ int main(int argc, char *argv[]) {
                 r = capability_bounding_set_drop_usermode(arg_capability_bounding_set_drop);
                 if (r < 0) {
                         log_emergency("Failed to drop capability bounding set of usermode helpers: %s", strerror(-r));
+                        error_message = "Failed to drop capability bounding set of usermode helpers";
                         goto finish;
                 }
                 r = capability_bounding_set_drop(arg_capability_bounding_set_drop, true);
                 if (r < 0) {
                         log_emergency("Failed to drop capability bounding set: %s", strerror(-r));
+                        error_message = "Failed to drop capability bounding set";
                         goto finish;
                 }
         }
 
         if (arg_syscall_archs) {
                 r = enforce_syscall_archs(arg_syscall_archs);
-                if (r < 0)
+                if (r < 0) {
+                        error_message = "Failed to set syscall architectures";
                         goto finish;
+                }
         }
 
         if (arg_running_as == SYSTEMD_USER) {
@@ -1614,6 +1635,7 @@ int main(int argc, char *argv[]) {
         r = manager_new(arg_running_as, arg_action == ACTION_TEST, &m);
         if (r < 0) {
                 log_emergency("Failed to allocate manager object: %s", strerror(-r));
+                error_message = "Failed to allocate manager object";
                 goto finish;
         }
 
@@ -1683,12 +1705,15 @@ int main(int argc, char *argv[]) {
                         r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target);
                         if (r < 0) {
                                 log_emergency("Failed to load rescue target: %s", bus_error_message(&error, r));
+                                error_message = "Failed to load rescue target";
                                 goto finish;
                         } else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND) {
                                 log_emergency("Failed to load rescue target: %s", strerror(-target->load_error));
+                                error_message = "Failed to load rescue target";
                                 goto finish;
                         } else if (target->load_state == UNIT_MASKED) {
                                 log_emergency("Rescue target masked.");
+                                error_message = "Rescue target masked";
                                 goto finish;
                         }
                 }
@@ -1707,10 +1732,12 @@ int main(int argc, char *argv[]) {
                         r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &default_unit_job);
                         if (r < 0) {
                                 log_emergency("Failed to start default target: %s", bus_error_message(&error, r));
+                                error_message = "Failed to start default target";
                                 goto finish;
                         }
                 } else if (r < 0) {
                         log_emergency("Failed to isolate default target: %s", bus_error_message(&error, r));
+                        error_message = "Failed to isolate default target";
                         goto finish;
                 }
 
@@ -1733,6 +1760,7 @@ int main(int argc, char *argv[]) {
                 r = manager_loop(m);
                 if (r < 0) {
                         log_emergency("Failed to run main loop: %s", strerror(-r));
+                        error_message = "Failed to run main loop";
                         goto finish;
                 }
 
@@ -1752,8 +1780,10 @@ int main(int argc, char *argv[]) {
 
                 case MANAGER_REEXECUTE:
 
-                        if (prepare_reexecute(m, &arg_serialization, &fds, false) < 0)
+                        if (prepare_reexecute(m, &arg_serialization, &fds, false) < 0) {
+                                error_message = "Failed to prepare for reexection";
                                 goto finish;
+                        }
 
                         reexecute = true;
                         log_notice("Reexecuting.");
@@ -1766,8 +1796,10 @@ int main(int argc, char *argv[]) {
                         m->switch_root = m->switch_root_init = NULL;
 
                         if (!switch_root_init)
-                                if (prepare_reexecute(m, &arg_serialization, &fds, true) < 0)
+                                if (prepare_reexecute(m, &arg_serialization, &fds, true) < 0) {
+                                        error_message = "Failed to prepare for reexection";
                                         goto finish;
+                                }
 
                         reexecute = true;
                         log_notice("Switching root.");
@@ -2012,8 +2044,13 @@ finish:
                           getpid() == 1 ? "freezing" : "quitting");
         }
 
-        if (getpid() == 1)
+        if (getpid() == 1) {
+                if (error_message)
+                        manager_status_printf(NULL, STATUS_TYPE_EMERGENCY,
+                                              ANSI_HIGHLIGHT_RED_ON "!!!!!!" ANSI_HIGHLIGHT_OFF,
+                                              "%s, freezing.", error_message);
                 freeze();
+        }
 
         return retval;
 }
diff --git a/src/core/manager.c b/src/core/manager.c
index 4c3264b..d5d6486 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2956,12 +2956,14 @@ void manager_set_first_boot(Manager *m, bool b) {
 void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) {
         va_list ap;
 
-        if (!manager_get_show_status(m, type))
+        /* If m is NULL, assume we're after shutdown and let the messages through. */
+
+        if (m && !manager_get_show_status(m, type))
                 return;
 
         /* XXX We should totally drop the check for ephemeral here
          * and thus effectively make 'Type=idle' pointless. */
-        if (type == STATUS_TYPE_EPHEMERAL && m->n_on_console > 0)
+        if (type == STATUS_TYPE_EPHEMERAL && m && m->n_on_console > 0)
                 return;
 
         va_start(ap, format);
diff --git a/src/core/selinux-setup.c b/src/core/selinux-setup.c
index 7653ccc..fba915d 100644
--- a/src/core/selinux-setup.c
+++ b/src/core/selinux-setup.c
@@ -113,7 +113,7 @@ int mac_selinux_setup(bool *loaded_policy) {
 
                 if (enforce > 0) {
                         if (!initialized) {
-                                log_emergency("Failed to load SELinux policy. Freezing.");
+                                log_emergency("Failed to load SELinux policy.");
                                 return -EIO;
                         }
 

commit 4104970ef78e40e976215cdb0d1b9170a213cc4b
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Nov 6 00:04:06 2014 -0500

    manager: log some fatal errors at emergency level
    
    This adds a new log_emergency() function, which is equivalent to
    log_error() for non-PID-1, and logs at the highest priority for PID 1.
    Some messages which occur before freezing are converted to use it.

diff --git a/src/core/main.c b/src/core/main.c
index b44e7f9..eb08f3f 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -131,7 +131,7 @@ noreturn static void crash(int sig) {
                 /* Pass this on immediately, if this is not PID 1 */
                 raise(sig);
         else if (!arg_dump_core)
-                log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
+                log_emergency("Caught <%s>, not dumping core.", signal_to_string(sig));
         else {
                 struct sigaction sa = {
                         .sa_handler = nop_handler,
@@ -144,7 +144,7 @@ noreturn static void crash(int sig) {
 
                 pid = fork();
                 if (pid < 0)
-                        log_error("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
+                        log_emergency("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
 
                 else if (pid == 0) {
                         struct rlimit rl = {};
@@ -175,11 +175,11 @@ noreturn static void crash(int sig) {
                         /* Order things nicely. */
                         r = wait_for_terminate(pid, &status);
                         if (r < 0)
-                                log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
+                                log_emergency("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(-r));
                         else if (status.si_code != CLD_DUMPED)
-                                log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
+                                log_emergency("Caught <%s>, core dump failed.", signal_to_string(sig));
                         else
-                                log_error("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
+                                log_emergency("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
                 }
         }
 
@@ -201,19 +201,19 @@ noreturn static void crash(int sig) {
 
                 pid = fork();
                 if (pid < 0)
-                        log_error("Failed to fork off crash shell: %m");
+                        log_emergency("Failed to fork off crash shell: %m");
                 else if (pid == 0) {
                         make_console_stdio();
                         execl("/bin/sh", "/bin/sh", NULL);
 
-                        log_error("execl() failed: %m");
+                        log_emergency("execl() failed: %m");
                         _exit(1);
                 }
 
                 log_info("Successfully spawned crash shell as pid "PID_FMT".", pid);
         }
 
-        log_info("Freezing execution.");
+        log_emergency("Freezing execution.");
         freeze();
 }
 
@@ -1376,7 +1376,7 @@ int main(int argc, char *argv[]) {
         /* Initialize default unit */
         r = set_default_unit(SPECIAL_DEFAULT_TARGET);
         if (r < 0) {
-                log_error("Failed to set default unit %s: %s", SPECIAL_DEFAULT_TARGET, strerror(-r));
+                log_emergency("Failed to set default unit %s: %s", SPECIAL_DEFAULT_TARGET, strerror(-r));
                 goto finish;
         }
 
@@ -1472,7 +1472,7 @@ int main(int argc, char *argv[]) {
         /* Remember open file descriptors for later deserialization */
         r = fdset_new_fill(&fds);
         if (r < 0) {
-                log_error("Failed to allocate fd set: %s", strerror(-r));
+                log_emergency("Failed to allocate fd set: %s", strerror(-r));
                 goto finish;
         } else
                 fdset_cloexec(fds, true);
@@ -1574,12 +1574,12 @@ int main(int argc, char *argv[]) {
         if (arg_capability_bounding_set_drop) {
                 r = capability_bounding_set_drop_usermode(arg_capability_bounding_set_drop);
                 if (r < 0) {
-                        log_error("Failed to drop capability bounding set of usermode helpers: %s", strerror(-r));
+                        log_emergency("Failed to drop capability bounding set of usermode helpers: %s", strerror(-r));
                         goto finish;
                 }
                 r = capability_bounding_set_drop(arg_capability_bounding_set_drop, true);
                 if (r < 0) {
-                        log_error("Failed to drop capability bounding set: %s", strerror(-r));
+                        log_emergency("Failed to drop capability bounding set: %s", strerror(-r));
                         goto finish;
                 }
         }
@@ -1613,7 +1613,7 @@ int main(int argc, char *argv[]) {
 
         r = manager_new(arg_running_as, arg_action == ACTION_TEST, &m);
         if (r < 0) {
-                log_error("Failed to allocate manager object: %s", strerror(-r));
+                log_emergency("Failed to allocate manager object: %s", strerror(-r));
                 goto finish;
         }
 
@@ -1682,13 +1682,13 @@ int main(int argc, char *argv[]) {
 
                         r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target);
                         if (r < 0) {
-                                log_error("Failed to load rescue target: %s", bus_error_message(&error, r));
+                                log_emergency("Failed to load rescue target: %s", bus_error_message(&error, r));
                                 goto finish;
                         } else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND) {
-                                log_error("Failed to load rescue target: %s", strerror(-target->load_error));
+                                log_emergency("Failed to load rescue target: %s", strerror(-target->load_error));
                                 goto finish;
                         } else if (target->load_state == UNIT_MASKED) {
-                                log_error("Rescue target masked.");
+                                log_emergency("Rescue target masked.");
                                 goto finish;
                         }
                 }
@@ -1706,11 +1706,11 @@ int main(int argc, char *argv[]) {
 
                         r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &default_unit_job);
                         if (r < 0) {
-                                log_error("Failed to start default target: %s", bus_error_message(&error, r));
+                                log_emergency("Failed to start default target: %s", bus_error_message(&error, r));
                                 goto finish;
                         }
                 } else if (r < 0) {
-                        log_error("Failed to isolate default target: %s", bus_error_message(&error, r));
+                        log_emergency("Failed to isolate default target: %s", bus_error_message(&error, r));
                         goto finish;
                 }
 
@@ -1732,7 +1732,7 @@ int main(int argc, char *argv[]) {
         for (;;) {
                 r = manager_loop(m);
                 if (r < 0) {
-                        log_error("Failed to run mainloop: %s", strerror(-r));
+                        log_emergency("Failed to run main loop: %s", strerror(-r));
                         goto finish;
                 }
 
diff --git a/src/core/selinux-setup.c b/src/core/selinux-setup.c
index 25e22b6..7653ccc 100644
--- a/src/core/selinux-setup.c
+++ b/src/core/selinux-setup.c
@@ -113,7 +113,7 @@ int mac_selinux_setup(bool *loaded_policy) {
 
                 if (enforce > 0) {
                         if (!initialized) {
-                                log_error("Failed to load SELinux policy. Freezing.");
+                                log_emergency("Failed to load SELinux policy. Freezing.");
                                 return -EIO;
                         }
 
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index 48ed7fa..121998f 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -416,7 +416,7 @@ int main(int argc, char *argv[]) {
         r = -errno;
 
   error:
-        log_error("Critical error while doing system shutdown: %s", strerror(-r));
+        log_emergency("Critical error while doing system shutdown: %s", strerror(-r));
 
         freeze();
 }
diff --git a/src/shared/log.h b/src/shared/log.h
index a3e23a8..8141e9d 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -25,6 +25,8 @@
 #include <stdarg.h>
 #include <syslog.h>
 #include <sys/signalfd.h>
+#include <sys/types.h>
+#include <unistd.h>
 #include <errno.h>
 
 #include "macro.h"
@@ -151,11 +153,12 @@ do { \
                 log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__); \
 } while (0)
 
-#define log_debug(...)   log_full(LOG_DEBUG,   __VA_ARGS__)
-#define log_info(...)    log_full(LOG_INFO,    __VA_ARGS__)
-#define log_notice(...)  log_full(LOG_NOTICE,  __VA_ARGS__)
-#define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__)
-#define log_error(...)   log_full(LOG_ERR,     __VA_ARGS__)
+#define log_debug(...)     log_full(LOG_DEBUG,   __VA_ARGS__)
+#define log_info(...)      log_full(LOG_INFO,    __VA_ARGS__)
+#define log_notice(...)    log_full(LOG_NOTICE,  __VA_ARGS__)
+#define log_warning(...)   log_full(LOG_WARNING, __VA_ARGS__)
+#define log_error(...)     log_full(LOG_ERR,     __VA_ARGS__)
+#define log_emergency(...) log_full(getpid() == 1 ? LOG_EMERG : LOG_ERR, __VA_ARGS__)
 
 #ifdef LOG_TRACE
 #  define log_trace(...) log_debug(__VA_ARGS__)



More information about the systemd-commits mailing list