summaryrefslogtreecommitdiffstats
path: root/src/nspawn
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-06-19 15:20:13 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-06-21 01:42:55 +0200
commitc6134d3e2f1d1d17b32b6e06556cd0c5429bc78a (patch)
tree14163e4dffb3f2b12dc3fe84e9d676d3521f53cd /src/nspawn
parentnspawn: don't hard fail when setting capabilities (diff)
downloadsystemd-c6134d3e2f1d1d17b32b6e06556cd0c5429bc78a.tar.xz
systemd-c6134d3e2f1d1d17b32b6e06556cd0c5429bc78a.zip
path-util: get rid of prefix_root()
prefix_root() is equivalent to path_join() in almost all ways, hence let's remove it. There are subtle differences though: prefix_root() will try shorten multiple "/" before and after the prefix. path_join() doesn't do that. This means prefix_root() might return a string shorter than both its inputs combined, while path_join() never does that. I like the path_join() semantics better, hence I think dropping prefix_root() is totally OK. In the end the strings generated by both functon should always be identical in terms of path_equal() if not streq(). This leaves prefix_roota() in place. Ideally we'd have path_joina(), but I don't think we can reasonably implement that as a macro. or maybe we can? (if so, sounds like something for a later PR) Also add in a few missing OOM checks
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn-cgroup.c6
-rw-r--r--src/nspawn/nspawn-mount.c16
-rw-r--r--src/nspawn/nspawn.c8
3 files changed, 18 insertions, 12 deletions
diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c
index f84bb39796..0462b46413 100644
--- a/src/nspawn/nspawn-cgroup.c
+++ b/src/nspawn/nspawn-cgroup.c
@@ -370,7 +370,7 @@ static int mount_legacy_cgns_supported(
if (streq(controller, tok))
break;
- target = prefix_root("/sys/fs/cgroup/", tok);
+ target = path_join("/sys/fs/cgroup/", tok);
if (!target)
return log_oom();
@@ -451,7 +451,7 @@ static int mount_legacy_cgns_unsupported(
if (!controller)
break;
- origin = prefix_root("/sys/fs/cgroup/", controller);
+ origin = path_join("/sys/fs/cgroup/", controller);
if (!origin)
return log_oom();
@@ -468,7 +468,7 @@ static int mount_legacy_cgns_unsupported(
else {
_cleanup_free_ char *target = NULL;
- target = prefix_root(dest, origin);
+ target = path_join(dest, origin);
if (!target)
return log_oom();
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c
index 5a1bce4abc..e0740a6cc4 100644
--- a/src/nspawn/nspawn-mount.c
+++ b/src/nspawn/nspawn-mount.c
@@ -97,7 +97,7 @@ static char *resolve_source_path(const char *dest, const char *source) {
return NULL;
if (source[0] == '+')
- return prefix_root(dest, source + 1);
+ return path_join(dest, source + 1);
return strdup(source);
}
@@ -433,11 +433,11 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
FOREACH_STRING(x, "block", "bus", "class", "dev", "devices", "kernel") {
_cleanup_free_ char *from = NULL, *to = NULL;
- from = prefix_root(full, x);
+ from = path_join(full, x);
if (!from)
return log_oom();
- to = prefix_root(top, x);
+ to = path_join(top, x);
if (!to)
return log_oom();
@@ -1190,7 +1190,9 @@ int setup_pivot_root(const char *directory, const char *pivot_root_new, const ch
* Requires all file systems at directory and below to be mounted
* MS_PRIVATE or MS_SLAVE so they can be moved.
*/
- directory_pivot_root_new = prefix_root(directory, pivot_root_new);
+ directory_pivot_root_new = path_join(directory, pivot_root_new);
+ if (!directory_pivot_root_new)
+ return log_oom();
/* Remount directory_pivot_root_new to make it movable. */
r = mount_verbose(LOG_ERR, directory_pivot_root_new, directory_pivot_root_new, NULL, MS_BIND, NULL);
@@ -1204,7 +1206,11 @@ int setup_pivot_root(const char *directory, const char *pivot_root_new, const ch
}
remove_pivot_tmp = true;
- pivot_tmp_pivot_root_old = prefix_root(pivot_tmp, pivot_root_old);
+ pivot_tmp_pivot_root_old = path_join(pivot_tmp, pivot_root_old);
+ if (!pivot_tmp_pivot_root_old) {
+ r = log_oom();
+ goto done;
+ }
r = mount_verbose(LOG_ERR, directory_pivot_root_new, pivot_tmp, NULL, MS_MOVE, NULL);
if (r < 0)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 1c0187ae5c..e7f8cf389f 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1895,11 +1895,11 @@ static int copy_devnodes(const char *dest) {
_cleanup_free_ char *from = NULL, *to = NULL;
struct stat st;
- from = strappend("/dev/", d);
+ from = path_join("/dev/", d);
if (!from)
return log_oom();
- to = prefix_root(dest, from);
+ to = path_join(dest, from);
if (!to)
return log_oom();
@@ -1945,7 +1945,7 @@ static int copy_devnodes(const char *dest) {
if (asprintf(&sl, "%s/%u:%u", dn, major(st.st_rdev), minor(st.st_rdev)) < 0)
return log_oom();
- prefixed = prefix_root(dest, sl);
+ prefixed = path_join(dest, sl);
if (!prefixed)
return log_oom();
@@ -1972,7 +1972,7 @@ static int make_extra_nodes(const char *dest) {
_cleanup_free_ char *path = NULL;
DeviceNode *n = arg_extra_nodes + i;
- path = prefix_root(dest, n->path);
+ path = path_join(dest, n->path);
if (!path)
return log_oom();