[systemd-devel] [PATCH 4/4] systemctl: unit_find_paths(): unify error handling in two code pathes

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Jan 5 08:11:15 PST 2015


"two code paths".

1/4 and 4/4 are fine, but I think it's better to have them applied
adjacent to the remaing two, so I leave them for now too.

Zbyszek

On Fri, Dec 19, 2014 at 05:08:10PM +0300, Ivan Shapovalov wrote:
> ---
>  src/systemctl/systemctl.c | 63 ++++++++++++++++++++++++++---------------------
>  1 file changed, 35 insertions(+), 28 deletions(-)
> 
> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
> index 20c367c..2a4e2a2 100644
> --- a/src/systemctl/systemctl.c
> +++ b/src/systemctl/systemctl.c
> @@ -2309,6 +2309,9 @@ static int unit_find_paths(sd_bus *bus,
>                             LookupPaths *lp,
>                             char **fragment_path,
>                             char ***dropin_paths) {
> +
> +        _cleanup_free_ char *path = NULL;
> +        _cleanup_strv_free_ char **dropins = NULL;
>          int r;
>  
>          /**
> @@ -2327,8 +2330,6 @@ static int unit_find_paths(sd_bus *bus,
>                  _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
>                  _cleanup_bus_message_unref_ sd_bus_message *unit_load_error = NULL;
>                  _cleanup_free_ char *unit = NULL;
> -                _cleanup_free_ char *path = NULL;
> -                _cleanup_strv_free_ char **dropins = NULL;
>                  _cleanup_strv_free_ char **load_error = NULL;
>                  char *unit_load_error_name, *unit_load_error_message;
>  
> @@ -2375,28 +2376,17 @@ static int unit_find_paths(sd_bus *bus,
>                  if (r < 0)
>                          return log_error_errno(r, "Failed to get FragmentPath: %s", bus_error_message(&error, r));
>  
> -                r = sd_bus_get_property_strv(
> -                                bus,
> -                                "org.freedesktop.systemd1",
> -                                unit,
> -                                "org.freedesktop.systemd1.Unit",
> -                                "DropInPaths",
> -                                &error,
> -                                &dropins);
> -                if (r < 0)
> -                        return log_error_errno(r, "Failed to get DropInPaths: %s", bus_error_message(&error, r));
> -
> -                r = 0;
> -                if (!isempty(path)) {
> -                        *fragment_path = path;
> -                        path = NULL;
> -                        r = 1;
> -                }
> -
> -                if (dropin_paths && !strv_isempty(dropins)) {
> -                        *dropin_paths = dropins;
> -                        dropins = NULL;
> -                        r = 1;
> +                if (dropin_paths) {
> +                        r = sd_bus_get_property_strv(
> +                                        bus,
> +                                        "org.freedesktop.systemd1",
> +                                        unit,
> +                                        "org.freedesktop.systemd1.Unit",
> +                                        "DropInPaths",
> +                                        &error,
> +                                        &dropins);
> +                        if (r < 0)
> +                                return log_error_errno(r, "Failed to get DropInPaths: %s", bus_error_message(&error, r));
>                  }
>          } else {
>                  _cleanup_set_free_ Set *names;
> @@ -2409,7 +2399,7 @@ static int unit_find_paths(sd_bus *bus,
>                  if (r < 0)
>                          return r;
>  
> -                r = unit_file_find_path(lp, unit_name, fragment_path);
> +                r = unit_file_find_path(lp, unit_name, &path);
>                  if (r < 0)
>                          return r;
>  
> @@ -2421,14 +2411,31 @@ static int unit_find_paths(sd_bus *bus,
>                                  return log_oom();
>  
>                          if (!streq(template, unit_name)) {
> -                                r = unit_file_find_path(lp, template, fragment_path);
> +                                r = unit_file_find_path(lp, template, &path);
>                                  if (r < 0)
>                                          return r;
>                          }
>                  }
>  
> -                if (dropin_paths)
> -                        r = unit_file_find_dropin_paths(lp->unit_path, NULL, names, dropin_paths);
> +                if (dropin_paths) {
> +                        r = unit_file_find_dropin_paths(lp->unit_path, NULL, names, &dropins);
> +                        if (r < 0)
> +                                return r;
> +                }
> +        }
> +
> +        r = 0;
> +
> +        if (!isempty(path)) {
> +                *fragment_path = path;
> +                path = NULL;
> +                r = 1;
> +        }
> +
> +        if (dropin_paths && !strv_isempty(dropins)) {
> +                *dropin_paths = dropins;
> +                dropins = NULL;
> +                r = 1;
>          }
>  
>          if (r == 0) {
> -- 
> 2.2.0
> 
> _______________________________________________
> 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