[systemd-commits] 7 commits - shell-completion/bash shell-completion/zsh src/core src/login src/shared

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Wed Aug 28 05:22:56 PDT 2013


 shell-completion/bash/systemd-analyze |    9 +++
 shell-completion/zsh/_systemd-analyze |   19 ++++++-
 src/core/dbus-cgroup.c                |   32 ++++++++----
 src/core/dbus-unit.c                  |    2 
 src/core/load-fragment.c              |    1 
 src/login/logind-session.c            |   20 ++-----
 src/login/logind.c                    |   29 ++++++++---
 src/shared/fileio.c                   |   88 ++++++++++++++++++++++------------
 8 files changed, 138 insertions(+), 62 deletions(-)

New commits:
commit a255a7f1442590b95a54227636ed0e66398fb4ff
Author: Gao feng <gaofeng at cn.fujitsu.com>
Date:   Mon Aug 26 10:36:45 2013 +0800

    cgroup: only check once when mode is UNIT_CHECK
    
    If the mode is UNIT_CHECK,it means we only want to check if
    the paramaters are valid. the first round of cycle already
    did this check, no need to check again.

diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 4cd3a13..2ea59b2 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -981,7 +981,7 @@ int bus_unit_set_properties(
 
                 if (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_INVALID) {
 
-                        if (for_real)
+                        if (for_real || mode == UNIT_CHECK)
                                 break;
 
                         /* Reached EOF. Let's try again, and this time for realz... */

commit ad7bfffde594bf141e13f17e8d8214bfa29ea635
Author: Gao feng <gaofeng at cn.fujitsu.com>
Date:   Wed Aug 28 09:49:11 2013 +0800

    device cgroup: don't create a new CGroupDeviceAllow when it already in the list
    
    If a device node is already in the device_allow list of
    CGroupContext, we should replace it instead of create a
    new one and append this new one to the end of device_allow
    list.
    
    change from v1: use streq to replace !strcmp

diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index 9e97b20..4ce7dc5 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -314,21 +314,35 @@ int bus_cgroup_set_property(
                         }
 
                         if (mode != UNIT_CHECK) {
-                                a = new0(CGroupDeviceAllow, 1);
-                                if (!a)
-                                        return -ENOMEM;
-
-                                a->path = strdup(path);
-                                if (!a->path) {
-                                        free(a);
-                                        return -ENOMEM;
+                                CGroupDeviceAllow *b;
+                                bool exist = false;
+
+                                LIST_FOREACH(device_allow, b, c->device_allow) {
+                                        if (streq(b->path, path)) {
+                                                a = b;
+                                                exist = true;
+                                                break;
+                                        }
+                                }
+
+                                if (!exist) {
+                                        a = new0(CGroupDeviceAllow, 1);
+                                        if (!a)
+                                                return -ENOMEM;
+
+                                        a->path = strdup(path);
+                                        if (!a->path) {
+                                                free(a);
+                                                return -ENOMEM;
+                                        }
                                 }
 
                                 a->r = !!strchr(rwm, 'r');
                                 a->w = !!strchr(rwm, 'w');
                                 a->m = !!strchr(rwm, 'm');
 
-                                LIST_PREPEND(CGroupDeviceAllow, device_allow, c->device_allow, a);
+                                if (!exist)
+                                        LIST_PREPEND(CGroupDeviceAllow, device_allow, c->device_allow, a);
                         }
 
                         n++;

commit e862b60f1c77bc12bf49475930f79ce68489828a
Author: Gao feng <gaofeng at cn.fujitsu.com>
Date:   Wed Aug 28 12:10:16 2013 +0800

    blcokio bandwidth: add missing set of CGroupBlockIODeviceBandwidth's read
    
    BlockIOReadBandwidth and BlockIOWriteBandwidth both use
    config_parse_blockio_bandwidth to set up CGroupBlockIODeviceBandwidth,
    We should set the read value based on the left values
    in config files.

diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index e5fc4a3..4714687 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2253,6 +2253,7 @@ int config_parse_blockio_bandwidth(
         b->path = path;
         path = NULL;
         b->bandwidth = (uint64_t) bytes;
+        b->read = streq("BlockIOReadBandwidth", lvalue);
 
         LIST_PREPEND(CGroupBlockIODeviceBandwidth, device_bandwidths, c->blockio_device_bandwidths, b);
 

commit 5af726cced7f87d6f7b7d6bd1dd5ee44ded5aa7b
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Aug 24 23:48:34 2013 -0400

    logind-session.c: use _cleanup_

diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index dac50e8..a726fb1 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -381,7 +381,8 @@ int session_activate(Session *s) {
 }
 
 static int session_link_x11_socket(Session *s) {
-        char *t, *f, *c;
+        _cleanup_free_ char *t = NULL, *f = NULL;
+        char *c;
         size_t k;
 
         assert(s);
@@ -405,7 +406,6 @@ static int session_link_x11_socket(Session *s) {
 
         if (access(f, F_OK) < 0) {
                 log_warning("Session %s has display %s with non-existing socket %s.", s->id, s->display, f);
-                free(f);
                 return -ENOENT;
         }
 
@@ -414,10 +414,8 @@ static int session_link_x11_socket(Session *s) {
          * path is owned by the user */
 
         t = strappend(s->user->runtime_path, "/X11-display");
-        if (!t) {
-                free(f);
+        if (!t)
                 return log_oom();
-        }
 
         if (link(f, t) < 0) {
                 if (errno == EEXIST) {
@@ -437,17 +435,12 @@ static int session_link_x11_socket(Session *s) {
                         }
 
                         log_error("Failed to link %s to %s: %m", f, t);
-                        free(f);
-                        free(t);
                         return -errno;
                 }
         }
 
 done:
         log_info("Linked %s to %s.", f, t);
-        free(f);
-        free(t);
-
         s->user->display = s;
 
         return 0;
@@ -585,7 +578,7 @@ static int session_stop_scope(Session *s) {
 }
 
 static int session_unlink_x11_socket(Session *s) {
-        char *t;
+        _cleanup_free_ char *t = NULL;
         int r;
 
         assert(s);
@@ -601,8 +594,6 @@ static int session_unlink_x11_socket(Session *s) {
                 return log_oom();
 
         r = unlink(t);
-        free(t);
-
         return r < 0 ? -errno : 0;
 }
 

commit 042f598892e2587d735e4de1f4aabcb3d89d05f1
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Aug 24 10:52:23 2013 -0400

    logind: be more verbose on errors

diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 1fea474..dac50e8 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -480,7 +480,8 @@ static int session_start_scope(Session *s) {
 
                 r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "systemd-user-sessions.service", kill_mode, &error, &job);
                 if (r < 0) {
-                        log_error("Failed to start session scope: %s %s", bus_error(&error, r), error.name);
+                        log_error("Failed to start session scope %s: %s %s",
+                                  scope, bus_error(&error, r), error.name);
                         dbus_error_free(&error);
 
                         free(scope);
diff --git a/src/login/logind.c b/src/login/logind.c
index 0002d26..9094567 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1423,12 +1423,29 @@ int manager_startup(Manager *m) {
                 return r;
 
         /* Deserialize state */
-        manager_enumerate_devices(m);
-        manager_enumerate_seats(m);
-        manager_enumerate_users(m);
-        manager_enumerate_sessions(m);
-        manager_enumerate_inhibitors(m);
-        manager_enumerate_buttons(m);
+        r = manager_enumerate_devices(m);
+        if (r < 0)
+                log_warning("Device enumeration failed: %s", strerror(-r));
+
+        r = manager_enumerate_seats(m);
+        if (r < 0)
+                log_warning("Seat enumeration failed: %s", strerror(-r));
+
+        r = manager_enumerate_users(m);
+        if (r < 0)
+                log_warning("User enumeration failed: %s", strerror(-r));
+
+        r = manager_enumerate_sessions(m);
+        if (r < 0)
+                log_warning("Session enumeration failed: %s", strerror(-r));
+
+        r = manager_enumerate_inhibitors(m);
+        if (r < 0)
+                log_warning("Inhibitor enumeration failed: %s", strerror(-r));
+
+        r = manager_enumerate_buttons(m);
+        if (r < 0)
+                log_warning("Button enumeration failed: %s", strerror(-r));
 
         /* Remove stale objects before we start them */
         manager_gc(m, false);

commit 335c46b59888d431e5a57cddcf7ceecd09ec8e4a
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Aug 24 10:51:55 2013 -0400

    Disallow invalid UTF-8 configuration
    
    It is best to catch such errors early. If invalid UTF-8 ends up being
    given to dbus methods, the program will crash:
    
    process 20801: arguments to dbus_message_iter_append_basic() were incorrect, assertion "_dbus_check_is_valid_utf8 (*string_p)" failed in file dbus-message.c line 2598.

diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index 2b1dab8..77fd059 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -23,6 +23,7 @@
 #include "fileio.h"
 #include "util.h"
 #include "strv.h"
+#include "utf8.h"
 
 int write_string_to_file(FILE *f, const char *line) {
         errno = 0;
@@ -177,13 +178,15 @@ int read_full_file(const char *fn, char **contents, size_t *size) {
 static int parse_env_file_internal(
                 const char *fname,
                 const char *newline,
-                int (*push) (const char *key, char *value, void *userdata),
+                int (*push) (const char *filename, unsigned line,
+                             const char *key, char *value, void *userdata),
                 void *userdata) {
 
         _cleanup_free_ char *contents = NULL, *key = NULL;
         size_t key_alloc = 0, n_key = 0, value_alloc = 0, n_value = 0, last_value_whitespace = (size_t) -1, last_key_whitespace = (size_t) -1;
         char *p, *value = NULL;
         int r;
+        unsigned line = 1;
 
         enum {
                 PRE_KEY,
@@ -230,6 +233,7 @@ static int parse_env_file_internal(
                 case KEY:
                         if (strchr(newline, c)) {
                                 state = PRE_KEY;
+                                line ++;
                                 n_key = 0;
                         } else if (c == '=') {
                                 state = PRE_VALUE;
@@ -253,6 +257,7 @@ static int parse_env_file_internal(
                 case PRE_VALUE:
                         if (strchr(newline, c)) {
                                 state = PRE_KEY;
+                                line ++;
                                 key[n_key] = 0;
 
                                 if (value)
@@ -262,7 +267,7 @@ static int parse_env_file_internal(
                                 if (last_key_whitespace != (size_t) -1)
                                         key[last_key_whitespace] = 0;
 
-                                r = push(key, value, userdata);
+                                r = push(fname, line, key, value, userdata);
                                 if (r < 0)
                                         goto fail;
 
@@ -292,6 +297,7 @@ static int parse_env_file_internal(
                 case VALUE:
                         if (strchr(newline, c)) {
                                 state = PRE_KEY;
+                                line ++;
 
                                 key[n_key] = 0;
 
@@ -306,7 +312,7 @@ static int parse_env_file_internal(
                                 if (last_key_whitespace != (size_t) -1)
                                         key[last_key_whitespace] = 0;
 
-                                r = push(key, value, userdata);
+                                r = push(fname, line, key, value, userdata);
                                 if (r < 0)
                                         goto fail;
 
@@ -408,8 +414,10 @@ static int parse_env_file_internal(
                 case COMMENT:
                         if (c == '\\')
                                 state = COMMENT_ESCAPE;
-                        else if (strchr(newline, c))
+                        else if (strchr(newline, c)) {
                                 state = PRE_KEY;
+                                line ++;
+                        }
                         break;
 
                 case COMMENT_ESCAPE:
@@ -439,7 +447,7 @@ static int parse_env_file_internal(
                 if (last_key_whitespace != (size_t) -1)
                         key[last_key_whitespace] = 0;
 
-                r = push(key, value, userdata);
+                r = push(fname, line, key, value, userdata);
                 if (r < 0)
                         goto fail;
         }
@@ -451,27 +459,36 @@ fail:
         return r;
 }
 
-static int parse_env_file_push(const char *key, char *value, void *userdata) {
-        const char *k;
-        va_list* ap = (va_list*) userdata;
-        va_list aq;
+static int parse_env_file_push(const char *filename, unsigned line,
+                               const char *key, char *value, void *userdata) {
+        assert(utf8_is_valid(key));
+
+        if (value && !utf8_is_valid(value))
+                /* FIXME: filter UTF-8 */
+                log_error("%s:%u: invalid UTF-8 for key %s: '%s', ignoring.",
+                          filename, line, key, value);
+        else {
+                const char *k;
+                va_list* ap = (va_list*) userdata;
+                va_list aq;
 
-        va_copy(aq, *ap);
+                va_copy(aq, *ap);
 
-        while ((k = va_arg(aq, const char *))) {
-                char **v;
+                while ((k = va_arg(aq, const char *))) {
+                        char **v;
 
-                v = va_arg(aq, char **);
+                        v = va_arg(aq, char **);
 
-                if (streq(key, k)) {
-                        va_end(aq);
-                        free(*v);
-                        *v = value;
-                        return 1;
+                        if (streq(key, k)) {
+                                va_end(aq);
+                                free(*v);
+                                *v = value;
+                                return 1;
+                        }
                 }
-        }
 
-        va_end(aq);
+                va_end(aq);
+        }
 
         free(value);
         return 0;
@@ -494,19 +511,28 @@ int parse_env_file(
         return r;
 }
 
-static int load_env_file_push(const char *key, char *value, void *userdata) {
-        char ***m = userdata;
-        char *p;
-        int r;
+static int load_env_file_push(const char *filename, unsigned line,
+                              const char *key, char *value, void *userdata) {
+        assert(utf8_is_valid(key));
 
-        p = strjoin(key, "=", strempty(value), NULL);
-        if (!p)
-                return -ENOMEM;
+        if (value && !utf8_is_valid(value))
+                /* FIXME: filter UTF-8 */
+                log_error("%s:%u: invalid UTF-8 for key %s: '%s', ignoring.",
+                          filename, line, key, value);
+        else {
+                char ***m = userdata;
+                char *p;
+                int r;
 
-        r = strv_push(m, p);
-        if (r < 0) {
-                free(p);
-                return r;
+                p = strjoin(key, "=", strempty(value), NULL);
+                if (!p)
+                        return -ENOMEM;
+
+                r = strv_push(m, p);
+                if (r < 0) {
+                        free(p);
+                        return r;
+                }
         }
 
         free(value);

commit fe05567c31cb88593a09ce5d8961d8b20627feb1
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Aug 22 23:25:28 2013 -0400

    shell-completions: systemd-analyze set-log-level

diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze
index 33833aa..5bd6768 100644
--- a/shell-completion/bash/systemd-analyze
+++ b/shell-completion/bash/systemd-analyze
@@ -34,6 +34,7 @@ _systemd_analyze() {
                 [NO_OPTION]='time blame plot'
                 [CRITICAL_CHAIN]='critical-chain'
                 [DOT]='dot'
+                [LOG_LEVEL]='set-log-level'
         )
 
         _init_completion || return
@@ -68,6 +69,14 @@ _systemd_analyze() {
                 if [[ $cur = -* ]]; then
                         comps='--help --version --system --user --from-pattern --to-pattern --order --require'
                 fi
+
+        elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
+                if [[ $cur = -* ]]; then
+                        comps='--help --version --system --user'
+                else
+                        comps='debug info notice warning err crit alert emerg'
+                fi
+
         fi
 
         COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
diff --git a/shell-completion/zsh/_systemd-analyze b/shell-completion/zsh/_systemd-analyze
index 13e96c0..37c60f5 100644
--- a/shell-completion/zsh/_systemd-analyze
+++ b/shell-completion/zsh/_systemd-analyze
@@ -1,5 +1,11 @@
 #compdef systemd-analyze
 
+_systemd_analyze_set-log-level() {
+    local -a _levels
+    _levels=(debug info notice warning err crit alert emerg)
+    _describe -t level 'logging level' _levels || compadd "$@"
+}
+
 _systemd_analyze_command(){
     local -a _systemd_analyze_cmds
     # Descriptions taken from systemd-analyze --help.
@@ -9,12 +15,23 @@ _systemd_analyze_command(){
         'critical-chain:Print a tree of the time critical chain of units'
         'plot:Output SVG graphic showing service initialization'
         'dot:Dump dependency graph (in dot(1) format)'
+        'set-log-level:Set systemd log threshold'
     )
 
     if (( CURRENT == 1 )); then
         _describe "options" _systemd_analyze_cmds
     else
-        _message "no more options"
+        local curcontext="$curcontext"
+        cmd="${${_systemd_analyze_cmds[(r)$words[1]:*]%%:*}}"
+        if (( $#cmd )); then
+            if (( $+functions[_systemd_analyze_$cmd] )) && (( CURRENT == 2 )); then
+                _systemd_analyze_$cmd
+            else
+                _message "no more options"
+            fi
+        else
+            _message "unknown systemd-analyze command: $words[1]"
+        fi
     fi
 }
 



More information about the systemd-commits mailing list