[systemd-commits] 4 commits - man/systemctl.xml shell-completion/bash shell-completion/systemd-zsh-completion.zsh src/libsystemd-bus src/login src/readahead src/shared src/systemctl

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Apr 11 16:14:07 PDT 2013


 man/systemctl.xml                           |   25 ++---
 shell-completion/bash/systemctl             |    7 -
 shell-completion/systemd-zsh-completion.zsh |    2 
 src/libsystemd-bus/bus-kernel.c             |    2 
 src/login/sd-login.c                        |    2 
 src/readahead/sd-readahead.c                |    2 
 src/shared/hwclock.c                        |   12 --
 src/shared/install.c                        |    2 
 src/shared/socket-util.c                    |    2 
 src/shared/util.c                           |    2 
 src/systemctl/systemctl.c                   |  122 ++++++++++++++++------------
 11 files changed, 99 insertions(+), 81 deletions(-)

New commits:
commit 8e2f9ebf28f93241ed36469302e76de498aa8e87
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Apr 11 19:02:37 2013 -0400

    hwclock: use _cleanup_ to simplify function

diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c
index 55b0fa8..9076d8f 100644
--- a/src/shared/hwclock.c
+++ b/src/shared/hwclock.c
@@ -163,8 +163,7 @@ int hwclock_set_time(const struct tm *tm) {
 }
 
 int hwclock_is_localtime(void) {
-        FILE *f;
-        bool local = false;
+        FILE _cleanup_fclose_ *f;
 
         /*
          * The third line of adjtime is "UTC" or "LOCAL" or nothing.
@@ -181,19 +180,16 @@ int hwclock_is_localtime(void) {
                 b = fgets(line, sizeof(line), f) &&
                         fgets(line, sizeof(line), f) &&
                         fgets(line, sizeof(line), f);
-
-                fclose(f);
-
                 if (!b)
                         return -EIO;
 
                 truncate_nl(line);
-                local = streq(line, "LOCAL");
+                return streq(line, "LOCAL");
 
         } else if (errno != ENOENT)
                 return -errno;
 
-        return local;
+        return 0;
 }
 
 int hwclock_set_timezone(int *min) {

commit bcb161b0230fdd1faf9176f95fee76a7db6afd59
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Apr 11 18:57:42 2013 -0400

    errno is positive
    
    Make sure we compare errno against positive error codes.
    The ones in hwclock.c and install.c can have an impact, the
    rest are unlikely to be hit or in code that isn't widely
    used.
    
    Also check that errno > 0, to help gcc know that we are
    returning a negative error code.

diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index e5e3536..b83dfcb 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -339,7 +339,7 @@ int bus_kernel_read_message(sd_bus *bus, sd_bus_message **m) {
                 if (errno == EAGAIN)
                         return 0;
 
-                if (errno != -EMSGSIZE)
+                if (errno != EMSGSIZE)
                         return -errno;
 
                 sz *= 2;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 7513f76..f433e3e 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -730,7 +730,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
 
         fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
         if (fd < 0)
-                return errno;
+                return -errno;
 
         if (!category || streq(category, "seat")) {
                 k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE);
diff --git a/src/readahead/sd-readahead.c b/src/readahead/sd-readahead.c
index 4a096ee..675d82c 100644
--- a/src/readahead/sd-readahead.c
+++ b/src/readahead/sd-readahead.c
@@ -65,7 +65,7 @@ static int touch(const char *path) {
                 if (close(fd) >= 0)
                         break;
 
-                if (errno != -EINTR)
+                if (errno != EINTR)
                         return -errno;
         }
 
diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c
index 488c30e..55b0fa8 100644
--- a/src/shared/hwclock.c
+++ b/src/shared/hwclock.c
@@ -190,7 +190,7 @@ int hwclock_is_localtime(void) {
                 truncate_nl(line);
                 local = streq(line, "LOCAL");
 
-        } else if (errno != -ENOENT)
+        } else if (errno != ENOENT)
                 return -errno;
 
         return local;
diff --git a/src/shared/install.c b/src/shared/install.c
index 9e87039..b368b9f 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1637,7 +1637,7 @@ UnitFileState unit_file_get_state(
                         return state;
 
                 r = unit_file_can_install(&paths, root_dir, path, true);
-                if (r < 0 && errno != -ENOENT)
+                if (r < 0 && errno != ENOENT)
                         return r;
                 else if (r > 0)
                         return UNIT_FILE_DISABLED;
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 5345788..4933fe0 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -204,7 +204,7 @@ int socket_address_parse_netlink(SocketAddress *a, const char *s) {
 
         errno = 0;
         if (sscanf(s, "%ms %u", &sfamily, &group) < 1)
-                return errno ? -errno : -EINVAL;
+                return errno > 0 ? -errno : -EINVAL;
 
         family = netlink_family_from_string(sfamily);
         if (family < 0)
diff --git a/src/shared/util.c b/src/shared/util.c
index 57943b6..5827f6c 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5259,7 +5259,7 @@ int get_home_dir(char **_h) {
         errno = 0;
         p = getpwuid(u);
         if (!p)
-                return errno ? -errno : -ESRCH;
+                return errno > 0 ? -errno : -ESRCH;
 
         if (!path_is_absolute(p->pw_dir))
                 return -EINVAL;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index a950605..1c7edd5 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5260,7 +5260,7 @@ static int talk_initctl(void) {
         r = loop_write(fd, &request, sizeof(request), false) != sizeof(request);
         if (r) {
                 log_error("Failed to write to "INIT_FIFO": %m");
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
         }
 
         return 1;

commit 0ad4e1a872e789c77828d4c4825a56241103650c
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Apr 11 18:11:47 2013 -0400

    systemctl: show the name of failing unit in red
    
    It makes it easier to pick out problematic unit
    names from a long list.

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0e6087c..a950605 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -353,8 +353,8 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
 
         for (u = unit_infos; u < unit_infos + c; u++) {
                 char _cleanup_free_ *e = NULL;
-                const char *on_loaded, *off_loaded;
-                const char *on_active, *off_active;
+                const char *on_loaded, *off_loaded, *on = "";
+                const char *on_active, *off_active, *off = "";
 
                 if (!output_show_unit(u))
                         continue;
@@ -373,21 +373,21 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
                 n_shown++;
 
                 if (streq(u->load_state, "error")) {
-                        on_loaded = ansi_highlight_red(true);
-                        off_loaded = ansi_highlight_red(false);
+                        on_loaded = on = ansi_highlight_red(true);
+                        off_loaded = off = ansi_highlight_red(false);
                 } else
                         on_loaded = off_loaded = "";
 
                 if (streq(u->active_state, "failed")) {
-                        on_active = ansi_highlight_red(true);
-                        off_active = ansi_highlight_red(false);
+                        on_active = on = ansi_highlight_red(true);
+                        off_active = off = ansi_highlight_red(false);
                 } else
                         on_active = off_active = "";
 
                 e = arg_full ? NULL : ellipsize(u->id, id_len, 33);
 
-                printf("%-*s %s%-6s%s %s%-*s %-*s%s %-*s",
-                       id_len, e ? e : u->id,
+                printf("%s%-*s%s %s%-6s%s %s%-*s %-*s%s %-*s",
+                       on, id_len, e ? e : u->id, off,
                        on_loaded, u->load_state, off_loaded,
                        on_active, active_len, u->active_state,
                        sub_len, u->sub_state, off_active,

commit 20b3f379cfd44e61dd1838a107f1d5363fab5b5d
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed Apr 10 22:40:58 2013 -0400

    systemctl: allow multiple arguments to --type
    
    This mirrors --property, and is generally useful.
    
    New functionality is used in bash completion.
    
    In case of zsh completion, new functionality is less useful
    because of caching. Nevertheless, zsh completion for restart
    is made to behave more-or-less the same as bash completion.
    At least sockets can be restarted.

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 5656564..97bc47c 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -92,21 +92,22 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
         <term><option>--type=</option></term>
 
         <listitem>
-          <para>The argument should be a unit type name such as
-          <option>service</option> and <option>socket</option>, or a
-          unit load state such as <option>loaded</option> and
-          <option>masked</option>.
-          </para>
-
-          <para>If the argument is a unit type, when listing units,
-          limit display to certain unit types. If not specified units
+          <para>The argument should be a comma separated list of unit
+          types such as <option>service</option> and
+          <option>socket</option>, or unit load states such as
+          <option>loaded</option> and <option>masked</option>
+          (types and states can be mixed).</para>
+
+          <para>If one of the arguments is a unit type, when listing
+          units, limit display to certain unit types. Otherwise units
           of all types will be shown.</para>
 
-          <para>If the argument is a unit load state, when listing
-          units, limit display to certain unit types. If not specified
-          units of in all load states will be shown.</para>
+          <para>If one of the arguments is a unit load state, when
+          listing units, limit display to certain unit
+          types. Otherwise units of in all load states will be
+          shown.</para>
 
-          <para>As a special case, if the argument is
+          <para>As a special case, if one of the arguments is
           <option>help</option>, a list of allowed values will be
           printed and the program will exit.</para>
         </listitem>
diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl
index aba76f6..f24a145 100644
--- a/shell-completion/bash/systemctl
+++ b/shell-completion/bash/systemctl
@@ -45,7 +45,7 @@ __get_all_units      () { __systemctl $1 list-units --all \
         | { while read -r a b; do echo " $a"; done; }; }
 __get_active_units   () { __systemctl $1 list-units       \
         | { while read -r a b; do echo " $a"; done; }; }
-__get_inactive_units () { __systemctl $1 list-units --all \
+__get_startable_units () { __systemctl $1 list-units --all -t service,timer,socket,mount,automount,path,snapshot,swap \
         | { while read -r a b c d; do [[ $c == "inactive" || $c == "failed " ]] && echo " $a"; done; }; }
 __get_failed_units   () { __systemctl $1 list-units       \
         | { while read -r a b c d; do [[ $c == "failed"   ]] && echo " $a"; done; }; }
@@ -156,10 +156,7 @@ _systemctl () {
 
         elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
                 comps=$( __filter_units_by_property $mode CanStart yes \
-                      $( __get_inactive_units $mode \
-                        | while read -r line; do \
-                                [[ "$line" =~ \.(device|snapshot)$ ]] || echo " $line"; \
-                        done ))
+                      $( __get_startable_units $mode))
 
         elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
                 comps=$( __filter_units_by_property $mode CanStart yes \
diff --git a/shell-completion/systemd-zsh-completion.zsh b/shell-completion/systemd-zsh-completion.zsh
index a54e9d7..8b60859 100644
--- a/shell-completion/systemd-zsh-completion.zsh
+++ b/shell-completion/systemd-zsh-completion.zsh
@@ -536,7 +536,7 @@ for fun in restart reload-or-restart ; do
     _systemctl_all_units
     compadd "$@" - $( _filter_units_by_property CanStart yes \
       ${_sys_all_units[*]} | while read line; do \
-      [[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || echo " $line"; \
+      [[ "$line" =~ \.device$ ]] || echo " $line"; \
       done )
   }
 done
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index af7ecd7..0e6087c 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -68,9 +68,9 @@
 #include "socket-util.h"
 #include "fileio.h"
 
-static const char *arg_type = NULL;
-static const char *arg_load_state = NULL;
-static char **arg_property = NULL;
+static char **arg_types = NULL;
+static char **arg_load_states = NULL;
+static char **arg_properties = NULL;
 static bool arg_all = false;
 static const char *arg_job_mode = "replace";
 static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
@@ -295,9 +295,9 @@ static bool output_show_unit(const struct unit_info *u) {
         if (arg_failed)
                 return streq(u->active_state, "failed");
 
-        return (!arg_type || ((dot = strrchr(u->id, '.')) &&
-                              streq(dot+1, arg_type))) &&
-                (!arg_load_state || streq(u->load_state, arg_load_state)) &&
+        return (!arg_types || ((dot = strrchr(u->id, '.')) &&
+                               strv_find(arg_types, dot+1))) &&
+                (!arg_load_states || strv_find(arg_load_states, u->load_state)) &&
                 (arg_all || !(streq(u->active_state, "inactive")
                               || u->following[0]) || u->job_id > 0);
 }
@@ -524,7 +524,7 @@ static int compare_unit_file_list(const void *a, const void *b) {
 static bool output_show_unit_file(const UnitFileList *u) {
         const char *dot;
 
-        return !arg_type || ((dot = strrchr(u->path, '.')) && streq(dot+1, arg_type));
+        return !arg_types || ((dot = strrchr(u->path, '.')) && strv_find(arg_types, dot+1));
 }
 
 static void output_unit_file_list(const UnitFileList *units, unsigned c) {
@@ -2946,7 +2946,7 @@ static int print_property(const char *name, DBusMessageIter *iter) {
         /* This is a low-level property printer, see
          * print_status_info() for the nicer output */
 
-        if (arg_property && !strv_find(arg_property, name))
+        if (arg_properties && !strv_find(arg_properties, name))
                 return 0;
 
         switch (dbus_message_iter_get_arg_type(iter)) {
@@ -4504,45 +4504,67 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         puts(SYSTEMD_FEATURES);
                         return 0;
 
-                case 't':
-                        if (streq(optarg, "help")) {
-                                help_types();
-                                return 0;
-                        }
+                case 't': {
+                        char *word, *state;
+                        size_t size;
 
-                        if (unit_type_from_string(optarg) >= 0) {
-                                arg_type = optarg;
-                                break;
-                        }
-                        if (unit_load_state_from_string(optarg) >= 0) {
-                                arg_load_state = optarg;
-                                break;
+                        FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
+                                char _cleanup_free_ *type;
+
+                                type = strndup(word, size);
+                                if (!type)
+                                        return -ENOMEM;
+
+                                if (streq(type, "help")) {
+                                        help_types();
+                                        return 0;
+                                }
+
+                                if (unit_type_from_string(type) >= 0) {
+                                        if (strv_push(&arg_types, type))
+                                                return log_oom();
+                                        type = NULL;
+                                        continue;
+                                }
+
+                                if (unit_load_state_from_string(optarg) >= 0) {
+                                        if (strv_push(&arg_load_states, type))
+                                                return log_oom();
+                                        type = NULL;
+                                        continue;
+                                }
+
+                                log_error("Unkown unit type or load state '%s'.", type);
+                                log_info("Use -t help to see a list of allowed values.");
+                                return -EINVAL;
                         }
-                        log_error("Unkown unit type or load state '%s'.",
-                                  optarg);
-                        log_info("Use -t help to see a list of allowed values.");
-                        return -EINVAL;
+
+                        break;
+                }
+
                 case 'p': {
-                        char *word, *state;
-                        size_t size;
                         /* Make sure that if the empty property list
                            was specified, we won't show any properties. */
-                        const char *source = isempty(optarg) ? " " : optarg;
+                        if (isempty(optarg) && !arg_properties) {
+                                arg_properties = strv_new(NULL, NULL);
+                                if (!arg_properties)
+                                        return log_oom();
+                        } else {
+                                char *word, *state;
+                                size_t size;
 
-                        FOREACH_WORD_SEPARATOR(word, size, source, ",", state) {
-                                char _cleanup_free_ *prop;
-                                char **tmp;
+                                FOREACH_WORD_SEPARATOR(word, size, optarg, ",", state) {
+                                        char *prop;
 
-                                prop = strndup(word, size);
-                                if (!prop)
-                                        return -ENOMEM;
+                                        prop = strndup(word, size);
+                                        if (!prop)
+                                                return log_oom();
 
-                                tmp = strv_append(arg_property, prop);
-                                if (!tmp)
-                                        return -ENOMEM;
-
-                                strv_free(arg_property);
-                                arg_property = tmp;
+                                        if (strv_push(&arg_properties, prop)) {
+                                                free(prop);
+                                                return log_oom();
+                                        }
+                                }
                         }
 
                         /* If the user asked for a particular
@@ -5725,7 +5747,9 @@ finish:
 
         dbus_shutdown();
 
-        strv_free(arg_property);
+        strv_free(arg_types);
+        strv_free(arg_load_states);
+        strv_free(arg_properties);
 
         pager_close();
         ask_password_agent_close();



More information about the systemd-commits mailing list