]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/cgls/cgls.c
strv: make iterator in STRV_FOREACH() declaread in the loop
[thirdparty/systemd.git] / src / cgls / cgls.c
index e2c746f7e7d922a4d0b3ba2604fe6b8b3d91fc4d..6af95204e3ddd5f58dcb0dd04bb51c8e51c89fbc 100644 (file)
@@ -191,8 +191,8 @@ static int run(int argc, char *argv[]) {
         if (r <= 0)
                 return r;
 
-        r = pager_open(arg_pager_flags);
-        if (r > 0 && arg_full < 0)
+        pager_open(arg_pager_flags);
+        if (arg_full < 0 && pager_have())
                 arg_full = true;
 
         if (arg_full > 0)
@@ -201,14 +201,17 @@ static int run(int argc, char *argv[]) {
         if (arg_names) {
                 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
                 _cleanup_free_ char *root = NULL;
-                char **name;
 
                 STRV_FOREACH(name, arg_names) {
                         int q;
 
                         if (arg_show_unit != SHOW_UNIT_NONE) {
                                 /* Command line arguments are unit names */
-                                _cleanup_free_ char *cgroup = NULL;
+                                _cleanup_free_ char *cgroup = NULL, *unit_name = NULL;
+
+                                r = unit_name_mangle(*name, UNIT_NAME_MANGLE_WARN, &unit_name);
+                                if (r < 0)
+                                        return log_error_errno(r, "Failed to mangle unit name: %m");
 
                                 if (!bus) {
                                         /* Connect to the bus only if necessary */
@@ -216,19 +219,19 @@ static int run(int argc, char *argv[]) {
                                                                           arg_show_unit == SHOW_UNIT_USER,
                                                                           &bus);
                                         if (r < 0)
-                                                return bus_log_connect_error(r);
+                                                return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
                                 }
 
-                                q = show_cgroup_get_unit_path_and_warn(bus, *name, &cgroup);
+                                q = show_cgroup_get_unit_path_and_warn(bus, unit_name, &cgroup);
                                 if (q < 0)
                                         goto failed;
 
                                 if (isempty(cgroup)) {
-                                        q = log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Unit %s not found.", *name);
+                                        q = log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Unit %s not found.", unit_name);
                                         goto failed;
                                 }
 
-                                printf("Unit %s (%s):\n", *name, cgroup);
+                                printf("Unit %s (%s):\n", unit_name, cgroup);
                                 fflush(stdout);
 
                                 q = show_cgroup_by_path(cgroup, NULL, 0, arg_output_flags);