[systemd-devel] [PATCH] systemctl: print unit package in status

Andrei Borzenkov arvidjaar at gmail.com
Thu Dec 18 01:05:30 PST 2014


On Thu, Dec 18, 2014 at 7:00 AM, Spencer Baugh <sbaugh at catern.com> wrote:
> When printing the status of a unit, open a connection to the session bus
> and query PackageKit for the package that the unit file belongs
> to. Print it if PackageKit knows.

Searching packages database may be quite time consuming. At least make
it optional.

> ---
>  src/systemctl/systemctl.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
> index 4c4648f..ea2772b 100644
> --- a/src/systemctl/systemctl.c
> +++ b/src/systemctl/systemctl.c
> @@ -3381,6 +3381,8 @@ typedef struct UnitStatusInfo {
>          const char *source_path;
>          const char *control_group;
>
> +        const char *package_name;
> +
>          char **dropin_paths;
>
>          const char *load_error;
> @@ -3507,6 +3509,9 @@ static void print_status_info(
>                  printf("   Loaded: %s%s%s\n",
>                         on, strna(i->load_state), off);
>
> +        if (i->package_name)
> +                printf("  Package: %s\n", i->package_name);
> +
>          if (!strv_isempty(i->dropin_paths)) {
>                  _cleanup_free_ char *dir = NULL;
>                  bool last = false;
> @@ -4384,6 +4389,11 @@ static int show_one(
>
>          _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
>          _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
> +
> +        _cleanup_bus_close_unref_ sd_bus *user_bus = NULL;
> +        _cleanup_bus_message_unref_ sd_bus_message *packagekit_reply = NULL;
> +
> +        const char *file_path;
>          UnitStatusInfo info = {};
>          ExecStatusInfo *p;
>          int r;
> @@ -4453,6 +4463,28 @@ static int show_one(
>          if (r < 0)
>                  return bus_log_parse_error(r);
>
> +        file_path = info.source_path ? info.source_path : info.fragment_path;
> +        if (file_path) {
> +                /* we frequently can't get the user bus, nor call PackageKit, so don't complain on error */
> +                sd_bus_default_user(&user_bus);
> +                if (user_bus) {
> +                        sd_bus_call_method(
> +                                user_bus,
> +                                "org.freedesktop.PackageKit",
> +                                "/org/freedesktop/PackageKit",
> +                                "org.freedesktop.PackageKit.Query",
> +                                "SearchFile",
> +                                NULL,
> +                                &packagekit_reply,
> +                                "ss", file_path, "0");
> +                        if (packagekit_reply) {
> +                                r = sd_bus_message_read(packagekit_reply, "bs", NULL, &info.package_name);
> +                                if (r < 0)
> +                                        return bus_log_parse_error(r);
> +                        }
> +                }
> +        }
> +
>          r = 0;
>
>          if (!show_properties) {
> --
> 2.1.3
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list