[systemd-commits] 2 commits - src/manager.c src/systemctl.c src/update-utmp.c src/util.h

Lennart Poettering lennart at kemper.freedesktop.org
Wed Aug 11 06:21:04 PDT 2010


 src/manager.c     |    3 ++
 src/systemctl.c   |   74 +++++++++++++++++++++++++++++++++---------------------
 src/update-utmp.c |   10 +++++--
 src/util.h        |    1 
 4 files changed, 57 insertions(+), 31 deletions(-)

New commits:
commit 830f6caa77edbdafabba0869a205f2ba5095f758
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Aug 11 15:19:50 2010 +0200

    audit: smaller fixes to audit hookup

diff --git a/src/manager.c b/src/manager.c
index e32b24f..9c962ca 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -36,7 +36,10 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
+
+#ifdef HAVE_AUDIT
 #include <libaudit.h>
+#endif
 
 #include "manager.h"
 #include "hashmap.h"
diff --git a/src/update-utmp.c b/src/update-utmp.c
index b8b0d36..d023686 100644
--- a/src/update-utmp.c
+++ b/src/update-utmp.c
@@ -28,6 +28,10 @@
 
 #include <dbus/dbus.h>
 
+#ifdef HAVE_AUDIT
+#include <libaudit.h>
+#endif
+
 #include "log.h"
 #include "macro.h"
 #include "util.h"
@@ -244,7 +248,7 @@ static int on_reboot(Context *c) {
 
 #ifdef HAVE_AUDIT
         if (c->audit_fd >= 0)
-                if (audit_log_user_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", NULL, NULL, NULL, 1) < 0) {
+                if (audit_log_user_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "init", NULL, NULL, NULL, 1) < 0) {
                         log_error("Failed to send audit message: %m");
                         r = -errno;
                 }
@@ -272,7 +276,7 @@ static int on_shutdown(Context *c) {
 
 #ifdef HAVE_AUDIT
         if (c->audit_fd >= 0)
-                if (audit_log_user_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", NULL, NULL, NULL, 1) < 0) {
+                if (audit_log_user_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "init", NULL, NULL, NULL, 1) < 0) {
                         log_error("Failed to send audit message: %m");
                         r = -errno;
                 }
@@ -308,7 +312,7 @@ static int on_runlevel(Context *c) {
                 previous = 0;
         }
 
-        /* Second get new runlevel */
+        /* Secondly, get new runlevel */
         if ((runlevel = get_current_runlevel(c)) < 0)
                 return runlevel;
 
commit 2ee68f721168378a037a112a5400af0b92805432
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Aug 11 15:19:31 2010 +0200

    systemctl: beef up highlighting of service states a little

diff --git a/src/systemctl.c b/src/systemctl.c
index 490ef64..8ef1add 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -96,18 +96,31 @@ static bool private_bus = false;
 
 static int daemon_reload(DBusConnection *bus, char **args, unsigned n);
 
-static const char *ansi_highlight(bool b) {
+static bool on_tty(void) {
         static int t = -1;
 
         if (_unlikely_(t < 0))
                 t = isatty(STDOUT_FILENO) > 0;
 
-        if (!t)
+        return t;
+}
+
+static const char *ansi_highlight(bool b) {
+
+        if (!on_tty())
                 return "";
 
         return b ? ANSI_HIGHLIGHT_ON : ANSI_HIGHLIGHT_OFF;
 }
 
+static const char *ansi_highlight_green(bool b) {
+
+        if (!on_tty())
+                return "";
+
+        return b ? ANSI_HIGHLIGHT_GREEN_ON : ANSI_HIGHLIGHT_OFF;
+}
+
 static bool error_is_no_service(DBusError *error) {
 
         assert(error);
@@ -246,14 +259,20 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
                     (arg_all || !(streq(active_state, "inactive") || following[0]) || job_id > 0)) {
                         char *e;
                         int a = 0, b = 0;
+                        const char *on, *off;
 
-                        if (streq(active_state, "maintenance"))
-                                fputs(ansi_highlight(true), stdout);
+                        if (streq(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 %-12s %-12s%n", e ? e : id, load_state, active_state, sub_state, &a);
+                        printf("%-45s %-6s %s%-12s %-12s%s%n", e ? e : id, load_state, on, active_state, sub_state, off, &a);
                         free(e);
 
+                        a -= strlen(on) + strlen(off);
+
                         if (job_id != 0)
                                 printf(" => %-12s%n", job_type, &b);
                         else
@@ -266,9 +285,6 @@ static int list_units(DBusConnection *bus, char **args, unsigned n) {
                                 printf(" %.*s", columns() - a - b - 2, description);
                         }
 
-                        if (streq(active_state, "maintenance"))
-                                fputs(ansi_highlight(false), stdout);
-
                         fputs("\n", stdout);
                         k++;
                 }
@@ -1435,6 +1451,7 @@ typedef struct UnitStatusInfo {
 
 static void print_status_info(UnitStatusInfo *i) {
         ExecStatusInfo *p;
+        const char *on, *off, *ss;
 
         assert(i);
 
@@ -1458,27 +1475,28 @@ static void print_status_info(UnitStatusInfo *i) {
         else
                 printf("\t  Loaded: %s\n", strna(i->load_state));
 
+        ss = streq_ptr(i->active_state, i->sub_state) ? NULL : i->sub_state;
+
         if (streq_ptr(i->active_state, "maintenance")) {
-                        if (streq_ptr(i->active_state, i->sub_state))
-                                printf("\t  Active: %s%s%s\n",
-                                       ansi_highlight(true),
-                                       strna(i->active_state),
-                                       ansi_highlight(false));
-                        else
-                                printf("\t  Active: %s%s (%s)%s\n",
-                                       ansi_highlight(true),
-                                       strna(i->active_state),
-                                       strna(i->sub_state),
-                                       ansi_highlight(false));
-        } else {
-                if (streq_ptr(i->active_state, i->sub_state))
-                        printf("\t  Active: %s\n",
-                               strna(i->active_state));
-                else
-                        printf("\t  Active: %s (%s)\n",
-                               strna(i->active_state),
-                               strna(i->sub_state));
-        }
+                on = ansi_highlight(true);
+                off = ansi_highlight(false);
+        } else if (streq_ptr(i->active_state, "active") || streq_ptr(i->active_state, "reloading")) {
+                on = ansi_highlight_green(true);
+                off = ansi_highlight_green(false);
+        } else
+                on = off = "";
+
+        if (ss)
+                printf("\t  Active: %s%s (%s)%s\n",
+                       on,
+                       strna(i->active_state),
+                       ss,
+                       off);
+        else
+                printf("\t  Active: %s%s%s\n",
+                       on,
+                       strna(i->active_state),
+                       off);
 
         if (i->sysfs_path)
                 printf("\t  Device: %s\n", i->sysfs_path);
diff --git a/src/util.h b/src/util.h
index b097dc9..d08c7b0 100644
--- a/src/util.h
+++ b/src/util.h
@@ -61,6 +61,7 @@ typedef struct dual_timestamp {
 #define FORMAT_TIMESPAN_MAX 64
 
 #define ANSI_HIGHLIGHT_ON "\x1B[1;31m"
+#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
 #define ANSI_HIGHLIGHT_OFF "\x1B[0m"
 
 usec_t now(clockid_t clock);


More information about the systemd-commits mailing list