[systemd-commits] 3 commits - shell-completion/bash shell-completion/zsh src/journal-remote

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Tue Oct 14 18:21:14 PDT 2014


 shell-completion/bash/systemctl.in  |   30 +++++++++++++++++++-----------
 shell-completion/zsh/_systemctl.in  |   36 ++++++++++++++++++++++--------------
 src/journal-remote/journal-remote.c |   14 +++++++-------
 3 files changed, 48 insertions(+), 32 deletions(-)

New commits:
commit e9a19bd882ff8a2c8aef5c63b39525ea231e5fb9
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Oct 14 21:10:02 2014 -0400

    shell-completion: propose templates for disable/[re]enable/[re]start
    
    Templates can be [re]enabled, on their own if the have DefaultInstance set,
    and with an instance suffix in all cases. Propose just the template name
    ending in @, to underline the instance suffix may have to be appended.
    
    Likewise for start/restart.
    
    This means that sometimes superflous units that one will not really
    want to operate on will be proposed, but this seems better than
    proposing a very incomplete set of names.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=66912

diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index bca0231..afa80da 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -53,6 +53,9 @@ __filter_units_by_property () {
 
 __get_all_units      () { { __systemctl $1 list-unit-files; __systemctl $1 list-units --all; } \
         | { while read -r a b; do echo " $a"; done; }; }
+__get_template_names () { __systemctl $1 list-unit-files \
+        | { while read -r a b; do [[ $a =~ @\. ]] && echo " ${a%%@.*}@"; done; }; }
+
 __get_active_units   () { __systemctl $1 list-units       \
         | { while read -r a b; do echo " $a"; done; }; }
 __get_startable_units () {
@@ -169,22 +172,26 @@ _systemctl () {
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[DISABLED_UNITS]}; then
-                comps=$( __get_disabled_units $mode )
+                comps=$( __get_disabled_units $mode;
+                        __get_template_names $mode)
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[REENABLABLE_UNITS]}; then
                 comps=$( __get_disabled_units $mode;
-                         __get_enabled_units $mode )
+                         __get_enabled_units $mode;
+                         __get_template_names $mode)
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
                 comps=$( __filter_units_by_property $mode CanStart yes \
-                      $( __get_startable_units $mode))
+                        $( __get_startable_units $mode);
+                        __get_template_names $mode)
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
                 comps=$( __filter_units_by_property $mode CanStart yes \
-                      $( __get_restartable_units $mode))
+                        $( __get_restartable_units $mode); \
+                        __get_template_names $mode)
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index ca4b899..1435dee 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -139,6 +139,8 @@ _filter_units_by_property() {
 }
 
 _systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do echo -E - " $a"; done; } }
+_systemctl_get_template_names() { __systemctl list-unit-files | { while read -r a b; do  [[ $a =~ @\. ]] && echo -E - " ${a%%@.*}@"; done; } }
+
 
 _systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units          | { while read -r a b; do echo -E - " $a"; done; }) )}
 _systemctl_startable_units(){_sys_startable_units=($(__systemctl list-units --state inactive,failed -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
@@ -158,20 +160,24 @@ for fun in is-active is-failed is-enabled status show cat mask preset help list-
 done
 
 # Completion functions for ENABLED_UNITS
-for fun in disable reenable ; do
-  (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
-  {
+(( $+functions[_systemctl_disable] )) || _systemctl_disable()
+{
+    _systemctl_enabled_units
+    compadd "$@" -a - _sys_enabled_units
+}
+
+(( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
+{
     _systemctl_enabled_units
     _systemctl_disabled_units
-    compadd "$@" -a - _sys_enabled_units _sys_disabled_units
-  }
-done
+    compadd "$@" -a - _sys_enabled_units _sys_disabled_units $(_systemctl_get_template_names)
+}
 
 # Completion functions for DISABLED_UNITS
 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
 {
   _systemctl_disabled_units
-  compadd "$@" -a - _sys_disabled_units
+  compadd "$@" -a - _sys_disabled_units $(_systemctl_get_template_names)
 }
 
 # Completion functions for FAILED_UNITS

commit f29c77bc0179b0fa57407dbe30b495be9f5ad2e8
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Oct 14 20:20:07 2014 -0400

    shell-completion: fix completion of inactive units
    
    Units which not loaded were not proposed properly. OTOH, we should
    filter units from get-unit-files by their state if they are currently
    loaded. Bring zsh completions in line with bash completion, the same
    logic should be used in both implementations.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1024379
    https://bugzilla.redhat.com/show_bug.cgi?id=790768
    https://bugs.freedesktop.org/show_bug.cgi?id=84720

diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index 0150018..bca0231 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -55,10 +55,14 @@ __get_all_units      () { { __systemctl $1 list-unit-files; __systemctl $1 list-
         | { 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_startable_units () { {
-        __systemctl $1 list-units --all -t service,timer,socket,mount,automount,path,snapshot,swap
-        __systemctl $1 list-unit-files -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_startable_units () {
+        # find inactive or failed units, filter out masked and not-found
+        __systemctl $1 list-units --state inactive,failed -- $( __get_all_units ) | \
+                { while read -r a b c d; do [[ $b == "loaded" ]] && echo " $a"; done; }; }
+__get_restartable_units () {
+        # find !masked, filter out masked and not-found
+        __systemctl $1 list-units --state active,inactive,failed -- $( __get_all_units ) | \
+                { while read -r a b c d; do [[ $b == "loaded" ]] && echo " $a"; done; }; }
 __get_failed_units   () { __systemctl $1 list-units       \
         | { while read -r a b c d; do [[ $c == "failed"   ]] && echo " $a"; done; }; }
 __get_enabled_units  () { __systemctl $1 list-unit-files  \
@@ -180,10 +184,7 @@ _systemctl () {
 
         elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
                 comps=$( __filter_units_by_property $mode CanStart yes \
-                      $( __get_all_units $mode \
-                        | while read -r line; do \
-                                [[ "$line" =~ @\.|\.(device|snapshot|socket|timer)$ ]] || echo " $line"; \
-                        done ))
+                      $( __get_restartable_units $mode))
                 compopt -o filenames
 
         elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in
index e681ec6..ca4b899 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -138,8 +138,11 @@ _filter_units_by_property() {
   done
 }
 
+_systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do echo -E - " $a"; done; } }
+
 _systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units          | { while read -r a b; do echo -E - " $a"; done; }) )}
-_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all    | { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo -E - " $a"; done; }) )}
+_systemctl_startable_units(){_sys_startable_units=($(__systemctl list-units --state inactive,failed -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
+_systemctl_restartable_units(){_sys_restartable_units=($(__systemctl list-units --state inactive,failed,active -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
 _systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units --failed | { while read -r a b; do echo -E - " $a"; done; }) )}
 _systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files     | { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; }) )}
 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files     | { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; }) )}
@@ -181,8 +184,9 @@ done
 # Completion functions for STARTABLE_UNITS
 (( $+functions[_systemctl_start] )) || _systemctl_start()
 {
-  _systemctl_inactive_units
-  compadd "$@" -a - _sys_inactive_units
+   _systemctl_startable_units
+   compadd "$@" - $( _filter_units_by_property CanStart yes \
+      ${_sys_startable_units[*]} )
 }
 
 # Completion functions for STOPPABLE_UNITS
@@ -217,11 +221,9 @@ done
 for fun in restart reload-or-restart ; do
   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
   {
-    _systemctl_all_units
+    _systemctl_restartable_units
     compadd "$@" - $( _filter_units_by_property CanStart yes \
-      ${_sys_all_units[*]} | while read -r line; do \
-      [[ "$line" =~ \.device$ ]] || echo -E - " $line"; \
-      done )
+      ${_sys_restartable_units[*]} )
   }
 done
 

commit 1f8af042d99cf40543dad0ec049cf7aa2911feba
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sun Oct 12 22:27:20 2014 -0400

    journal-remote: fix mem leak on error

diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index c97cfe6..eb092ce 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -311,6 +311,8 @@ static int get_source_for_fd(RemoteServer *s,
         Writer *writer;
         int r;
 
+        /* This takes ownership of name, but only on success. */
+
         assert(fd >= 0);
         assert(source);
 
@@ -360,6 +362,8 @@ static int add_source(RemoteServer *s, int fd, char* name, bool own_name) {
         RemoteSource *source;
         int r;
 
+        /* This takes ownership of name, even on failure, if own_name is true. */
+
         assert(s);
         assert(fd >= 0);
         assert(name);
@@ -374,6 +378,7 @@ static int add_source(RemoteServer *s, int fd, char* name, bool own_name) {
         if (r < 0) {
                 log_error("Failed to create source for fd:%d (%s): %s",
                           fd, name, strerror(-r));
+                free(name);
                 return r;
         }
 
@@ -867,8 +872,6 @@ static int remoteserver_init(RemoteServer *s,
                         log_info("Received a connection socket (fd:%d) from %s", fd, hostname);
 
                         r = add_source(s, fd, hostname, true);
-                        if (r < 0)
-                                free(hostname);
                 } else {
                         log_error("Unknown socket passed on fd:%d", fd);
 
@@ -1098,7 +1101,7 @@ static int dispatch_raw_connection_event(sd_event_source *event,
                                          uint32_t revents,
                                          void *userdata) {
         RemoteServer *s = userdata;
-        int fd2, r;
+        int fd2;
         SocketAddress addr = {
                 .size = sizeof(union sockaddr_union),
                 .type = SOCK_STREAM,
@@ -1109,10 +1112,7 @@ static int dispatch_raw_connection_event(sd_event_source *event,
         if (fd2 < 0)
                 return fd2;
 
-        r = add_source(s, fd2, hostname, true);
-        if (r < 0)
-                free(hostname);
-        return r;
+        return add_source(s, fd2, hostname, true);
 }
 
 /**********************************************************************



More information about the systemd-commits mailing list