summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-05-11 01:47:33 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-05-11 01:47:33 +0900
commit945403e6edbe6bf98015aabb38b281aa89334d0a (patch)
tree83f64d3cb247b4e5070ca673b4fdf30e7a275843
parent54138a8de1ef098caf9a2847b4c5ee970d1727f3 (diff)
downloadsystemd-945403e6edbe6bf98015aabb38b281aa89334d0a.tar.gz
path-util: introduce empty_to_root() and use it many places
-rw-r--r--src/basic/path-util.h3
-rw-r--r--src/cgls/cgls.c2
-rw-r--r--src/cgtop/cgtop.c10
-rw-r--r--src/core/dbus-unit.c2
-rw-r--r--src/libsystemd/sd-bus/bus-socket.c2
-rw-r--r--src/test/test-unit-name.c4
-rw-r--r--src/tmpfiles/tmpfiles.c2
7 files changed, 12 insertions, 13 deletions
diff --git a/src/basic/path-util.h b/src/basic/path-util.h
index fd3143d9ac..134e1ebc98 100644
--- a/src/basic/path-util.h
+++ b/src/basic/path-util.h
@@ -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;
+}
diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c
index 61e0a67b83..7c7ea18b61 100644
--- a/src/cgls/cgls.c
+++ b/src/cgls/cgls.c
@@ -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);
}
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index de7ecf54cd..401c08600a 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -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);
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index f93893c62f..9a61f6ce11 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -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);
}
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 54feddf9e5..04839bada4 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -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;
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 300a1c5a82..b46925be80 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -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)));
}
}
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index bc66299142..5190d7eb76 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -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