[systemd-commits] 8 commits - man/systemctl.xml shell-completion/bash shell-completion/zsh src/core src/udev TODO

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Mon Oct 27 20:18:31 PDT 2014


 TODO                               |    6 +
 man/systemctl.xml                  |   63 +++++++++++++++++--
 shell-completion/bash/systemctl.in |    3 
 shell-completion/zsh/_systemctl.in |   16 ++++-
 src/core/failure-action.c          |   20 ++++--
 src/core/job.c                     |    2 
 src/core/macros.systemd.in         |   13 ++++
 src/core/manager.c                 |  117 ++++++++++++++++++++++++++++++++++---
 src/core/manager.h                 |   13 +++-
 src/core/selinux-access.c          |   18 +++--
 src/core/unit.c                    |    3 
 src/udev/cdrom_id/cdrom_id.c       |    2 
 12 files changed, 240 insertions(+), 36 deletions(-)

New commits:
commit ebc5788e88eb9e1ebd032bd61507c196142acbab
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 23:14:23 2014 -0400

    manager: print warning on console before reboot
    
    It will be printed even if a prompt is blocking other messages.

diff --git a/src/core/failure-action.c b/src/core/failure-action.c
index 9417474..ce522a4 100644
--- a/src/core/failure-action.c
+++ b/src/core/failure-action.c
@@ -29,6 +29,13 @@
 #include "special.h"
 #include "failure-action.h"
 
+static void log_and_status(Manager *m, const char *message) {
+        log_warning("%s", message);
+        manager_status_printf(m, STATUS_TYPE_EMERGENCY,
+                              ANSI_HIGHLIGHT_RED_ON " !!  " ANSI_HIGHLIGHT_OFF,
+                              "%s", message);
+}
+
 int failure_action(
                 Manager *m,
                 FailureAction action,
@@ -57,7 +64,7 @@ int failure_action(
         case FAILURE_ACTION_REBOOT: {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
-                log_warning("Rebooting as result of failure.");
+                log_and_status(m, "Rebooting as result of failure.");
 
                 update_reboot_param_file(reboot_arg);
                 r = manager_add_job_by_name(m, JOB_START, SPECIAL_REBOOT_TARGET, JOB_REPLACE, true, &error, NULL);
@@ -68,13 +75,14 @@ int failure_action(
         }
 
         case FAILURE_ACTION_REBOOT_FORCE:
-                log_warning("Forcibly rebooting as result of failure.");
+                log_and_status(m, "Forcibly rebooting as result of failure.");
+
                 update_reboot_param_file(reboot_arg);
                 m->exit_code = MANAGER_REBOOT;
                 break;
 
         case FAILURE_ACTION_REBOOT_IMMEDIATE:
-                log_warning("Rebooting immediately as result of failure.");
+                log_and_status(m, "Rebooting immediately as result of failure.");
 
                 sync();
 
@@ -90,7 +98,7 @@ int failure_action(
         case FAILURE_ACTION_POWEROFF: {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
-                log_warning("Powering off as result of failure.");
+                log_and_status(m, "Powering off as result of failure.");
 
                 r = manager_add_job_by_name(m, JOB_START, SPECIAL_POWEROFF_TARGET, JOB_REPLACE, true, &error, NULL);
                 if (r < 0)
@@ -100,12 +108,12 @@ int failure_action(
         }
 
         case FAILURE_ACTION_POWEROFF_FORCE:
-                log_warning("Forcibly powering off as result of failure.");
+                log_and_status(m, "Forcibly powering off as result of failure.");
                 m->exit_code = MANAGER_POWEROFF;
                 break;
 
         case FAILURE_ACTION_POWEROFF_IMMEDIATE:
-                log_warning("Powering off immediately as result of failure.");
+                log_and_status(m, "Powering off immediately as result of failure.");
 
                 sync();
 
diff --git a/src/core/manager.c b/src/core/manager.c
index 859631d..d427d88 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2944,7 +2944,7 @@ static bool manager_get_show_status(Manager *m, StatusType type) {
                 return false;
 
         /* If we cannot find out the status properly, just proceed. */
-        if (manager_check_ask_password(m) > 0)
+        if (type != STATUS_TYPE_EMERGENCY && manager_check_ask_password(m) > 0)
                 return false;
 
         if (m->show_status > 0)
diff --git a/src/core/manager.h b/src/core/manager.h
index d0c0f58..ab72548 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -63,6 +63,7 @@ typedef enum ManagerExitCode {
 typedef enum StatusType {
         STATUS_TYPE_EPHEMERAL,
         STATUS_TYPE_NORMAL,
+        STATUS_TYPE_EMERGENCY,
 } StatusType;
 
 #include "unit.h"

commit 127d5fd1563a74411aaceeadd251f98fd52216d7
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 23:02:54 2014 -0400

    manager: convert ephemeral to enum
    
    In preparation for subsequent changes.

diff --git a/src/core/job.c b/src/core/job.c
index aa205ba..eaa4bb1 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -639,7 +639,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
 
                         manager_flip_auto_status(u->manager, true);
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format);
-                        manager_status_printf(u->manager, false, NULL,
+                        manager_status_printf(u->manager, STATUS_TYPE_NORMAL, NULL,
                                               "See \"systemctl status %s%s%s\" for details.",
                                               quotes ? "'" : "", u->id, quotes ? "'" : "");
                         break;
diff --git a/src/core/manager.c b/src/core/manager.c
index 7a5ecb7..859631d 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -194,7 +194,7 @@ static void manager_print_jobs_in_progress(Manager *m) {
         if (job_get_timeout(j, &x) > 0)
                 format_timespan(limit, sizeof(limit), x - j->begin_usec, 1*USEC_PER_SEC);
 
-        manager_status_printf(m, true, cylon,
+        manager_status_printf(m, STATUS_TYPE_EPHEMERAL, cylon,
                               "%sA %s job is running for %s (%s / %s)",
                               strempty(job_of_n),
                               job_type_to_string(j->type),
@@ -2931,7 +2931,7 @@ void manager_set_show_status(Manager *m, ShowStatus mode) {
                 unlink("/run/systemd/show-status");
 }
 
-static bool manager_get_show_status(Manager *m) {
+static bool manager_get_show_status(Manager *m, StatusType type) {
         assert(m);
 
         if (m->running_as != SYSTEMD_SYSTEM)
@@ -2969,19 +2969,19 @@ void manager_set_first_boot(Manager *m, bool b) {
                 unlink("/run/systemd/first-boot");
 }
 
-void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) {
+void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) {
         va_list ap;
 
-        if (!manager_get_show_status(m))
+        if (!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 (ephemeral && m->n_on_console > 0)
+        if (type == STATUS_TYPE_EPHEMERAL && m->n_on_console > 0)
                 return;
 
         va_start(ap, format);
-        status_vprintf(status, true, ephemeral, format, ap);
+        status_vprintf(status, true, type == STATUS_TYPE_EPHEMERAL, format, ap);
         va_end(ap);
 }
 
diff --git a/src/core/manager.h b/src/core/manager.h
index 782b85d..d0c0f58 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -60,6 +60,11 @@ typedef enum ManagerExitCode {
         _MANAGER_EXIT_CODE_INVALID = -1
 } ManagerExitCode;
 
+typedef enum StatusType {
+        STATUS_TYPE_EPHEMERAL,
+        STATUS_TYPE_NORMAL,
+} StatusType;
+
 #include "unit.h"
 #include "job.h"
 #include "hashmap.h"
@@ -349,7 +354,7 @@ void manager_recheck_journal(Manager *m);
 void manager_set_show_status(Manager *m, ShowStatus mode);
 void manager_set_first_boot(Manager *m, bool b);
 
-void manager_status_printf(Manager *m, bool ephemeral, const char *status, const char *format, ...) _printf_(4,5);
+void manager_status_printf(Manager *m, StatusType type, const char *status, const char *format, ...) _printf_(4,5);
 void manager_flip_auto_status(Manager *m, bool enable);
 
 Set *manager_get_units_requiring_mounts_for(Manager *m, const char *path);
diff --git a/src/core/unit.c b/src/core/unit.c
index afb760d..489ea1e 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2768,7 +2768,8 @@ int unit_coldplug(Unit *u) {
 
 void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) {
         DISABLE_WARNING_FORMAT_NONLITERAL;
-        manager_status_printf(u->manager, false, status, unit_status_msg_format, unit_description(u));
+        manager_status_printf(u->manager, STATUS_TYPE_NORMAL,
+                              status, unit_status_msg_format, unit_description(u));
         REENABLE_WARNING;
 }
 

commit 2de51fdc5218d6c4f148989f8907cf0fc842abea
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 22:16:11 2014 -0400

    man: add table of manager states

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 61a23de..a486c73 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1327,13 +1327,62 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
           <term><command>is-system-running</command></term>
 
           <listitem>
-            <para>Checks whether the system is running. This returns
-            success when the system is fully up and running, meaning
-            not in startup, shutdown or maintenance mode. Failure is
-            returned otherwise. In addition, the current state is
-            printed in a short string to standard output. Use
-            <option>--quiet</option> to suppress output of this state
-            string.</para>
+            <para>Checks whether the system is operational. This
+            returns success when the system is fully up and running,
+            meaning not in startup, shutdown or maintenance
+            mode. Failure is returned otherwise. In addition, the
+            current state is printed in a short string to standard
+            output, see table below. Use <option>--quiet</option> to
+            suppress this output.</para>
+
+            <table>
+              <title>Manager Operational States</title>
+              <tgroup cols='2'>
+                <colspec colname='name' />
+                <colspec colname='description' />
+                <thead>
+                  <row>
+                    <entry>Name</entry>
+                    <entry>Description</entry>
+                  </row>
+                </thead>
+                <tbody>
+                  <row>
+                    <entry><varname>initializing</varname></entry>
+                    <entry><para>Early bootup, before
+                    <filename>sysinit.target</filename> is reached
+                    or <varname>maintenance</varname> state entered.
+                    </para></entry>
+                  </row>
+                  <row>
+                    <entry><varname>starting</varname></entry>
+                    <entry><para>Late bootup, before the default
+                    target or one of the rescue targets are
+                    reached.</para></entry>
+                  </row>
+                  <row>
+                    <entry><varname>running</varname></entry>
+                    <entry><para>The system is fully
+                    operational.</para></entry>
+                  </row>
+                  <row>
+                    <entry><varname>degraded</varname></entry>
+                    <entry><para>The system is operational but one or more
+                    units failed.</para></entry>
+                  </row>
+                  <row>
+                    <entry><varname>maintenance</varname></entry>
+                    <entry><para>One of the rescue targets is
+                    active.</para></entry>
+                  </row>
+                  <row>
+                    <entry><varname>stopping</varname></entry>
+                    <entry><para>The manager is shutting
+                    down.</para></entry>
+                  </row>
+                </tbody>
+              </tgroup>
+            </table>
           </listitem>
         </varlistentry>
 

commit 1cf3c30c0787f941b0f6d0b11ab504ddee3b0b8f
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 21:34:28 2014 -0500

    shell-completion: systemctl set-default,get-default,is-system-running

diff --git a/TODO b/TODO
index ac70ec5..acac4e3 100644
--- a/TODO
+++ b/TODO
@@ -792,8 +792,10 @@ External:
 
 * register catalog database signature as file magic
 
-* zsh shell completion: <command> <verb> -<TAB> should complete options, but currently
-  does not
+* zsh shell completion:
+  - <command> <verb> -<TAB> should complete options, but currently does not
+  - systemctl add-wants,add-requires
+
 
 Regularly:
 
diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index 8c1ecd4..1c44a8d 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -148,7 +148,8 @@ _systemctl () {
                [STANDALONE]='daemon-reexec daemon-reload default
                              emergency exit halt hibernate hybrid-sleep kexec list-jobs
                              list-sockets list-timers list-units list-unit-files poweroff
-                             reboot rescue show-environment suspend get-default'
+                             reboot rescue show-environment suspend get-default
+                             is-system-running'
                      [NAME]='snapshot'
                      [FILE]='link'
                   [TARGETS]='set-default'
diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index 1435dee..44981fe 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -31,6 +31,9 @@
     "disable:Disable one or more unit files"
     "reenable:Reenable one or more unit files"
     "preset:Enable/disable one or more unit files based on preset configuration"
+    "set-default:Set the default target"
+    "get-default:Query the default target"
+    "is-system-running:Query overall status of the system"
     "help:Show documentation for specified units"
     "list-dependencies:Show unit dependency tree"
     "mask:Mask one or more units"
@@ -237,21 +240,28 @@ done
 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
 {
   _systemctl_masked_units
-  compadd "$@" -a - _sys_masked_units || _message "no masked unit found"
+  compadd "$@" -a - _sys_masked_units || _message "no masked units found"
 }
 
 # Completion functions for JOBS
 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
 {
   compadd "$@" - $(__systemctl list-jobs \
-    | cut -d' ' -f1  2>/dev/null ) || _message "no job found"
+    | cut -d' ' -f1  2>/dev/null ) || _message "no jobs found"
 }
 
 # Completion functions for SNAPSHOTS
 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
 {
   compadd "$@" - $(__systemctl list-units --type snapshot --all \
-    | cut -d' ' -f1  2>/dev/null ) || _message "no snapshot found"
+    | cut -d' ' -f1  2>/dev/null ) || _message "no snapshots found"
+}
+
+# Completion functions for TARGETS
+(( $+functions[_systemctl_set-default] )) || _systemctl_set-default()
+{
+  compadd "$@" - $(__systemctl list-unit-files --type target --all \
+    | cut -d' ' -f1  2>/dev/null ) || _message "no targets found"
 }
 
 # Completion functions for ENVS

commit 7c67f0f71a2a4e64264e925977645e306816a3ab
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 21:34:09 2014 -0500

    rpm: add user macros

diff --git a/src/core/macros.systemd.in b/src/core/macros.systemd.in
index 333f222..bea6ef1 100644
--- a/src/core/macros.systemd.in
+++ b/src/core/macros.systemd.in
@@ -43,6 +43,8 @@ if [ $1 -eq 1 ] ; then \
 fi \
 %{nil}
 
+%systemd_user_post() %systemd_post --user --global %{?*}
+
 %systemd_preun() \
 if [ $1 -eq 0 ] ; then \
         # Package removal, not upgrade \
@@ -51,10 +53,19 @@ if [ $1 -eq 0 ] ; then \
 fi \
 %{nil}
 
+%systemd_user_preun() \
+if [ $1 -eq 0 ] ; then \
+        # Package removal, not upgrade \
+        systemctl --no-reload --user --global disable %{?*} > /dev/null 2>&1 || : \
+fi \
+%{nil}
+
 %systemd_postun() \
 systemctl daemon-reload >/dev/null 2>&1 || : \
 %{nil}
 
+%systemd_user_postun() %{nil}
+
 %systemd_postun_with_restart() \
 systemctl daemon-reload >/dev/null 2>&1 || : \
 if [ $1 -ge 1 ] ; then \
@@ -63,6 +74,8 @@ if [ $1 -ge 1 ] ; then \
 fi \
 %{nil}
 
+%systemd_user_postun_with_restart() %{nil}
+
 %udev_hwdb_update() \
 udevadm hwdb --update >/dev/null 2>&1 || : \
 %{nil}

commit e46b13c8c7f48f81d4e09912f2265daaa7f6d27e
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Oct 25 20:30:51 2014 -0400

    manager: do not print anything while passwords are being queried
    
    https://bugs.freedesktop.org/show_bug.cgi?id=73942

diff --git a/src/core/manager.c b/src/core/manager.c
index 7091789..7a5ecb7 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -25,6 +25,8 @@
 #include <signal.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <sys/inotify.h>
+#include <sys/epoll.h>
 #include <sys/poll.h>
 #include <sys/reboot.h>
 #include <sys/ioctl.h>
@@ -201,6 +203,96 @@ static void manager_print_jobs_in_progress(Manager *m) {
 
 }
 
+static int have_ask_password(void) {
+        _cleanup_closedir_ DIR *dir;
+
+        dir = opendir("/run/systemd/ask-password");
+        if (!dir) {
+                if (errno == ENOENT)
+                        return false;
+                else
+                        return -errno;
+        }
+
+        for (;;) {
+                struct dirent *de;
+
+                errno = 0;
+                de = readdir(dir);
+                if (!de && errno != 0)
+                        return -errno;
+                if (!de)
+                        return false;
+
+                if (startswith(de->d_name, "ask."))
+                        return true;
+        }
+}
+
+static int manager_dispatch_ask_password_fd(sd_event_source *source,
+                                            int fd, uint32_t revents, void *userdata) {
+        Manager *m = userdata;
+
+        assert(m);
+
+        flush_fd(fd);
+
+        m->have_ask_password = have_ask_password();
+        if (m->have_ask_password < 0)
+                /* Log error but continue. Negative have_ask_password
+                 * is treated as unknown status. */
+                log_error("Failed to list /run/systemd/ask-password: %s", strerror(m->have_ask_password));
+
+        return 0;
+}
+
+static void manager_close_ask_password(Manager *m) {
+        assert(m);
+
+        m->ask_password_inotify_fd = safe_close(m->ask_password_inotify_fd);
+        m->ask_password_event_source = sd_event_source_unref(m->ask_password_event_source);
+        m->have_ask_password = -EINVAL;
+}
+
+static int manager_check_ask_password(Manager *m) {
+        int r;
+
+        assert(m);
+
+        if (!m->ask_password_event_source) {
+                assert(m->ask_password_inotify_fd < 0);
+
+                mkdir_p_label("/run/systemd/ask-password", 0755);
+
+                m->ask_password_inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
+                if (m->ask_password_inotify_fd < 0) {
+                        log_error("inotify_init1() failed: %m");
+                        return -errno;
+                }
+
+                if (inotify_add_watch(m->ask_password_inotify_fd, "/run/systemd/ask-password", IN_CREATE|IN_DELETE|IN_MOVE) < 0) {
+                        log_error("Failed to add watch on /run/systemd/ask-password: %m");
+                        manager_close_ask_password(m);
+                        return -errno;
+                }
+
+                r = sd_event_add_io(m->event, &m->ask_password_event_source,
+                                    m->ask_password_inotify_fd, EPOLLIN,
+                                    manager_dispatch_ask_password_fd, m);
+                if (r < 0) {
+                        log_error("Failed to add event source for /run/systemd/ask-password: %m");
+                        manager_close_ask_password(m);
+                        return -errno;
+                }
+
+                /* Queries might have been added meanwhile... */
+                manager_dispatch_ask_password_fd(m->ask_password_event_source,
+                                                 m->ask_password_inotify_fd, EPOLLIN, m);
+        }
+
+        return m->have_ask_password;
+}
+
 static int manager_watch_idle_pipe(Manager *m) {
         int r;
 
@@ -465,6 +557,9 @@ int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) {
         m->pin_cgroupfs_fd = m->notify_fd = m->signal_fd = m->time_change_fd = m->dev_autofs_fd = m->private_listen_fd = m->kdbus_fd = -1;
         m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
 
+        m->ask_password_inotify_fd = -1;
+        m->have_ask_password = -EINVAL; /* we don't know */
+
         m->test_run = test_run;
 
         r = manager_default_environment(m);
@@ -859,6 +954,8 @@ void manager_free(Manager *m) {
         safe_close(m->time_change_fd);
         safe_close(m->kdbus_fd);
 
+        manager_close_ask_password(m);
+
         manager_close_idle_pipe(m);
 
         udev_unref(m->udev);
@@ -2515,6 +2612,9 @@ void manager_check_finished(Manager *m) {
         /* Turn off confirm spawn now */
         m->confirm_spawn = false;
 
+        /* No need to update ask password status when we're going non-interactive */
+        manager_close_ask_password(m);
+
         /* This is no longer the first boot */
         manager_set_first_boot(m, false);
 
@@ -2843,12 +2943,15 @@ static bool manager_get_show_status(Manager *m) {
         if (!IN_SET(manager_state(m), MANAGER_INITIALIZING, MANAGER_STARTING, MANAGER_STOPPING))
                 return false;
 
+        /* If we cannot find out the status properly, just proceed. */
+        if (manager_check_ask_password(m) > 0)
+                return false;
+
         if (m->show_status > 0)
                 return true;
 
         /* If Plymouth is running make sure we show the status, so
          * that there's something nice to see when people press Esc */
-
         return plymouth_running();
 }
 
diff --git a/src/core/manager.h b/src/core/manager.h
index 6582167..782b85d 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -265,6 +265,11 @@ struct Manager {
         unsigned n_on_console;
         unsigned jobs_in_progress_iteration;
 
+        /* Do we have any outstanding password prompts? */
+        int have_ask_password;
+        int ask_password_inotify_fd;
+        sd_event_source *ask_password_event_source;
+
         /* Type=idle pipes */
         int idle_pipe[4];
         sd_event_source *idle_pipe_event_source;

commit 3fcd09602c0dfff8c0fafe6c4f9bba6b0fd72c30
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 21:52:38 2014 -0400

    cdrom_id: do not attempt to read past end of buffer
    
    CID #1238437

diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c
index c93a7bf..7a4b987 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -606,7 +606,7 @@ static int cd_profiles(struct udev *udev, int fd)
                 switch (feature) {
                 case 0x00:
                         log_debug("GET CONFIGURATION: feature 'profiles', with %i entries", features[i+3] / 4);
-                        feature_profiles(udev, &features[i]+4, features[i+3]);
+                        feature_profiles(udev, &features[i]+4, MIN(features[i+3], len - i - 4));
                         break;
                 default:
                         log_debug("GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes", feature, features[i+3]);

commit dec23413ecc90d4a547aa41f02af0482b4513495
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Oct 27 21:31:29 2014 -0400

    selinux: make sure we do not try to print missing fields
    
    UID or GID of 0 is valid, so we cannot use that to distinguish whether
    calls to sd_bus_creds_get_* succeeded, and the return value from the
    function is the only way to know about missing fields. Print "n/a" if
    the fields are missing.
    
    CID #1238779

diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
index 08ea6ef..351d48f 100644
--- a/src/core/selinux-access.c
+++ b/src/core/selinux-access.c
@@ -53,7 +53,7 @@ struct audit_info {
 
 /*
    Any time an access gets denied this callback will be called
-   with the aduit data.  We then need to just copy the audit data into the msgbuf.
+   with the audit data.  We then need to just copy the audit data into the msgbuf.
 */
 static int audit_callback(
                 void *auditdata,
@@ -64,14 +64,20 @@ static int audit_callback(
         const struct audit_info *audit = auditdata;
         uid_t uid = 0, login_uid = 0;
         gid_t gid = 0;
+        char login_uid_buf[DECIMAL_STR_MAX(uid_t)] = "n/a";
+        char uid_buf[DECIMAL_STR_MAX(uid_t)] = "n/a";
+        char gid_buf[DECIMAL_STR_MAX(gid_t)] = "n/a";
 
-        sd_bus_creds_get_audit_login_uid(audit->creds, &login_uid);
-        sd_bus_creds_get_uid(audit->creds, &uid);
-        sd_bus_creds_get_gid(audit->creds, &gid);
+        if (sd_bus_creds_get_audit_login_uid(audit->creds, &login_uid) >= 0)
+                snprintf(login_uid_buf, sizeof(login_uid_buf), UID_FMT, login_uid);
+        if (sd_bus_creds_get_uid(audit->creds, &uid) >= 0)
+                snprintf(uid_buf, sizeof(uid_buf), UID_FMT, uid);
+        if (sd_bus_creds_get_gid(audit->creds, &gid) >= 0)
+                snprintf(gid_buf, sizeof(gid_buf), GID_FMT, gid);
 
         snprintf(msgbuf, msgbufsize,
-                 "auid=%d uid=%d gid=%d%s%s%s%s%s%s",
-                 login_uid, uid, gid,
+                 "auid=%s uid=%s gid=%s%s%s%s%s%s%s",
+                 login_uid_buf, uid_buf, gid_buf,
                  audit->path ? " path=\"" : "", strempty(audit->path), audit->path ? "\"" : "",
                  audit->cmdline ? " cmdline=\"" : "", strempty(audit->cmdline), audit->cmdline ? "\"" : "");
 



More information about the systemd-commits mailing list