[systemd-devel] [PATCH] [RFC] Show listen addresses in status output

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sun Mar 31 20:24:04 PDT 2013


On Mon, Apr 01, 2013 at 12:09:50AM +0300, Oleksii Shevchuk wrote:
> ---
>  src/systemctl/systemctl.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
> index 328b91b..0ad5112 100644
> --- a/src/systemctl/systemctl.c
> +++ b/src/systemctl/systemctl.c
> @@ -2254,6 +2254,7 @@ typedef struct UnitStatusInfo {
>          unsigned n_accepted;
>          unsigned n_connections;
>          bool accept;
> +        char **listen;
>  
>          /* Device */
>          const char *sysfs_path;
> @@ -2386,6 +2387,19 @@ static void print_status_info(UnitStatusInfo *i) {
>                  }
>          }
Nitpick:

STRV_FOREACH works fine with NULL strv. What about something like this:

STRV_FOREACH(t, i->listen)
     printf("\t  %6s: %s\n", t == i->listen ? "Listen" : "", *t);

instead of the whole if below?

> +        if (!strv_isempty(i->listen)) {
> +                char **t;
> +                bool first = true;
> +
> +                STRV_FOREACH(t, i->listen) {
> +                        if (first) {
> +                                printf("\t  Listen: %s\n", *t);
> +                                first = false;
> +                        } else
> +                                printf("\t          %s\n", *t);
> +                }
> +        }
> +
>          if (i->accept)
>                  printf("\tAccepted: %u; Connected: %u\n", i->n_accepted, i->n_connections);
>  
> @@ -2757,6 +2771,27 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
>  
>                                  dbus_message_iter_next(&sub);
>                          }
> +
> +                } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING &&
> +                           startswith(name, "Listen")) {
> +                        DBusMessageIter sub;
> +
> +                        dbus_message_iter_recurse(iter, &sub);
> +                        while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING) {
> +                                const char *s;
> +                                char **l;
> +
> +                                dbus_message_iter_get_basic(&sub, &s);
> +
> +                                l = strv_append(i->listen, s);
> +                                if (!l)
> +                                        return -ENOMEM;
s is leaked here.

> +
> +                                strv_free(i->listen);
> +                                i->listen = l;
> +
> +                                dbus_message_iter_next(&sub);
> +                        }
>                  }

Anyway, this patch has to wait for the other one...

Zbyszek


More information about the systemd-devel mailing list