]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-util: introduce empty_to_root() and use it many places
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 May 2018 16:47:33 +0000 (01:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 May 2018 16:47:33 +0000 (01:47 +0900)
src/basic/path-util.h
src/cgls/cgls.c
src/cgtop/cgtop.c
src/core/dbus-unit.c
src/libsystemd/sd-bus/bus-socket.c
src/test/test-unit-name.c
src/tmpfiles/tmpfiles.c

index fd3143d9acce8d5ac08fba9989cdb37b56d50277..134e1ebc98f1f8c2835b3ae04075f01cc060f0a7 100644 (file)
@@ -164,3 +164,6 @@ static inline const char *skip_dev_prefix(const char *p) {
 }
 
 bool empty_or_root(const char *root);
+static inline const char *empty_to_root(const char *path) {
+        return isempty(path) ? "/" : path;
+}
index 61e0a67b83c5e0060cc9914029fdb463d5a45bb6..7c7ea18b6159c13bb8b10606bbe08a9ca953da53 100644 (file)
@@ -149,7 +149,7 @@ static void show_cg_info(const char *controller, const char *path) {
         if (cg_all_unified() == 0 && controller && !streq(controller, SYSTEMD_CGROUP_CONTROLLER))
                 printf("Controller %s; ", controller);
 
-        printf("Control group %s:\n", isempty(path) ? "/" : path);
+        printf("Control group %s:\n", empty_to_root(path));
         fflush(stdout);
 }
 
index de7ecf54cda902df4f4369996601aec5bcf77324..401c08600ae121e7ffd558a3e1b4d0bf818c65ea 100644 (file)
@@ -529,10 +529,6 @@ static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration)
         return 0;
 }
 
-static const char *empty_to_slash(const char *p) {
-        return isempty(p) ? "/" : p;
-}
-
 static int group_compare(const void*a, const void *b) {
         const Group *x = *(Group**)a, *y = *(Group**)b;
 
@@ -542,9 +538,9 @@ static int group_compare(const void*a, const void *b) {
                  * recursive summing is off, since that is actually
                  * not accumulative for all children. */
 
-                if (path_startswith(empty_to_slash(y->path), empty_to_slash(x->path)))
+                if (path_startswith(empty_to_root(y->path), empty_to_root(x->path)))
                         return -1;
-                if (path_startswith(empty_to_slash(x->path), empty_to_slash(y->path)))
+                if (path_startswith(empty_to_root(x->path), empty_to_root(y->path)))
                         return 1;
         }
 
@@ -693,7 +689,7 @@ static void display(Hashmap *a) {
 
                 g = array[j];
 
-                path = empty_to_slash(g->path);
+                path = empty_to_root(g->path);
                 ellipsized = ellipsize(path, path_columns, 33);
                 printf("%-*s", path_columns, ellipsized ?: path);
 
index f93893c62f2f0a293b0e8f61884ad259be6e2e47..9a61f6ce11f6208bdfb133b93e8a61534f0e2c14 100644 (file)
@@ -931,7 +931,7 @@ static int property_get_cgroup(
          * other cases we report as-is. */
 
         if (u->cgroup_path)
-                t = isempty(u->cgroup_path) ? "/" : u->cgroup_path;
+                t = empty_to_root(u->cgroup_path);
 
         return sd_bus_message_append(reply, "s", t);
 }
index 54feddf9e542ee8d66af850ad754288299b582ab..04839bada415d544db18f6b290dc8453f0424007 100644 (file)
@@ -777,7 +777,7 @@ static int bus_socket_inotify_setup(sd_bus *b) {
                         if (IN_SET(errno, ENOENT, ELOOP))
                                 break; /* This component doesn't exist yet, or the path contains a cyclic symlink right now */
 
-                        r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", isempty(prefix) ? "/" : prefix);
+                        r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", empty_to_root(prefix));
                         goto fail;
                 } else
                         new_watches[n++] = wd;
index 300a1c5a82ea7ce5447c3937f44e1d164339beaa..b46925be806b51f90d44b697c63b289fc9bb24a1 100644 (file)
@@ -96,7 +96,7 @@ static void test_unit_name_from_path_one(const char *path, const char *suffix, c
                 _cleanup_free_ char *k = NULL;
                 assert_se(unit_name_to_path(t, &k) == 0);
                 puts(strna(k));
-                assert_se(path_equal(k, isempty(path) ? "/" : path));
+                assert_se(path_equal(k, empty_to_root(path)));
         }
 }
 
@@ -124,7 +124,7 @@ static void test_unit_name_from_path_instance_one(const char *pattern, const cha
 
                 assert_se(unit_name_to_instance(t, &k) > 0);
                 assert_se(unit_name_path_unescape(k, &v) == 0);
-                assert_se(path_equal(v, isempty(path) ? "/" : path));
+                assert_se(path_equal(v, empty_to_root(path)));
         }
 }
 
index bc662991425bc6d9215c9baa67a4b94616e17e51..5190d7eb76d3a740291e5bb3be8ca05dd06f2c61 100644 (file)
@@ -1502,7 +1502,7 @@ static int create_item(Item *i) {
 
                 if (IN_SET(i->type, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)) {
 
-                        if (btrfs_is_subvol(isempty(arg_root) ? "/" : arg_root) <= 0)
+                        if (btrfs_is_subvol(empty_to_root(arg_root)) <= 0)
 
                                 /* Don't create a subvolume unless the
                                  * root directory is one, too. We do