if (!t)
return -ENOMEM;
- *fs = path_simplify(t, false);
+ *fs = path_simplify(t);
return 0;
}
if (r < 0)
return r;
- path_simplify(*fs, false);
+ path_simplify(*fs);
return 0;
}
if (!path)
return -ENOMEM;
- path_simplify(path, false);
+ path_simplify(path);
}
} else {
!path_is_absolute(path))
return -EINVAL;
- path_simplify(path, false);
+ path_simplify(path);
}
} else {
if (!t)
return -ENOMEM;
- *result = path_simplify(t, false);
+ *result = path_simplify(t);
return 0;
}
f = fopen(p, mode);
if (f) {
if (ret_path)
- *ret_path = path_simplify(TAKE_PTR(p), true);
+ *ret_path = path_simplify(TAKE_PTR(p));
*ret = f;
return 0;
if (!p)
return -ENOMEM;
- *ret_path = path_simplify(p, true);
+ *ret_path = path_simplify(p);
}
*ret = TAKE_PTR(f);
if (!p)
return -ENOMEM;
- *ret_path = path_simplify(p, true);
+ *ret_path = path_simplify(p);
}
*ret = TAKE_PTR(f);
* anyway. Moreover at the end of this function after processing everything we'll always turn
* the empty string back to "/". */
delete_trailing_chars(root, "/");
- path_simplify(root, true);
+ path_simplify(root);
if (flags & CHASE_PREFIX_ROOT) {
/* We don't support relative paths in combination with a root directory */
if (!result)
return -ENOMEM;
- path_simplify(result, true);
+ path_simplify(result);
if (!path_is_valid(result))
return -EINVAL;
strcpy(p, t);
- path_simplify(result, true);
+ path_simplify(result);
if (!path_is_valid(result))
return -EINVAL;
if (r < 0)
return r;
- path_simplify(t, false);
+ path_simplify(t);
free_and_replace(*s, t);
}
return strv_uniq(l);
}
-char *path_simplify(char *path, bool kill_dots) {
+char *path_simplify(char *path) {
char *f, *t;
bool slash = false, ignore_slash = false, absolute;
absolute = path_is_absolute(path);
f = path;
- if (kill_dots && *f == '.' && IN_SET(f[1], 0, '/')) {
+ if (*f == '.' && IN_SET(f[1], 0, '/')) {
ignore_slash = true;
f++;
}
}
if (slash) {
- if (kill_dots && *f == '.' && IN_SET(f[1], 0, '/'))
+ if (*f == '.' && IN_SET(f[1], 0, '/'))
continue;
slash = false;
lvalue, fatal ? "" : ", ignoring", path);
}
- path_simplify(path, true);
+ path_simplify(path);
if (!path_is_valid(path))
return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
/* Found it! */
if (ret_filename)
- *ret_filename = path_simplify(TAKE_PTR(element), false);
+ *ret_filename = path_simplify(TAKE_PTR(element));
if (ret_fd)
*ret_fd = TAKE_FD(fd);
if (!a)
return -ENOMEM;
- path_simplify(a, true);
+ path_simplify(a);
if (!path_is_valid(a))
return -EINVAL;
#define path_extend(x, ...) path_extend_internal(x, __VA_ARGS__, POINTER_MAX)
#define path_join(...) path_extend_internal(NULL, __VA_ARGS__, POINTER_MAX)
-char* path_simplify(char *path, bool kill_dots);
+char* path_simplify(char *path);
enum {
PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */
* directory. Excludes the specified directory itself */
#define PATH_FOREACH_PREFIX(prefix, path) \
for (char *_slash = ({ \
- path_simplify(strcpy(prefix, path), false); \
+ path_simplify(strcpy(prefix, path)); \
streq(prefix, "/") ? NULL : strrchr(prefix, '/'); \
}); \
_slash && ((*_slash = 0), true); \
/* Same as PATH_FOREACH_PREFIX but also includes the specified path itself */
#define PATH_FOREACH_PREFIX_MORE(prefix, path) \
for (char *_slash = ({ \
- path_simplify(strcpy(prefix, path), false); \
+ path_simplify(strcpy(prefix, path)); \
if (streq(prefix, "/")) \
prefix[0] = 0; \
strrchr(prefix, 0); \
n = strpbrk(n + 1, "/.");
} while (n);
- path_simplify(s, true);
+ path_simplify(s);
/* Kill the leading slash, but keep the first character of the string in the same place. */
if (*s == '/' && *(s+1))
if (!path_extend(&d, nf))
return -ENOMEM;
- *ret = path_simplify(TAKE_PTR(d), false);
+ *ret = path_simplify(TAKE_PTR(d));
} else
*ret = TAKE_PTR(nf);
if (!path_extend(&d, nf))
return -ENOMEM;
- *ret = path_simplify(TAKE_PTR(d), false);
+ *ret = path_simplify(TAKE_PTR(d));
} else
*ret = TAKE_PTR(nf);
*x = 0;
- *ret = path_simplify(t, false);
+ *ret = path_simplify(t);
return 0;
}
if (!p)
return -ENOMEM;
- path_simplify(p, false);
+ path_simplify(p);
if (empty_or_root(p))
s = strdup("-");
if (!h)
return -ENOMEM;
- *_h = path_simplify(h, true);
+ *_h = path_simplify(h);
return 0;
}
if (!h)
return -ENOMEM;
- *_h = path_simplify(h, true);
+ *_h = path_simplify(h);
return 0;
}
if (!s)
return -ENOMEM;
- *_s = path_simplify(s, true);
+ *_s = path_simplify(s);
return 0;
}
if (!s)
return -ENOMEM;
- *_s = path_simplify(s, true);
+ *_s = path_simplify(s);
return 0;
}
if (!j)
return log_oom();
- path_simplify(j, false);
+ path_simplify(j);
path = j;
} else
path = root;
if (!p)
return -ENOMEM;
- path_simplify(p, false);
+ path_simplify(p);
r = refresh_one(controller, p, a, b, iteration, depth + 1, &child);
if (r < 0)
if (r < 0)
return r;
- path_simplify(a->where, false);
+ path_simplify(a->where);
return 1;
}
return -EINVAL;
pp = strjoina("/", pp, suffix_path);
- path_simplify(pp, false);
+ path_simplify(pp);
r = sd_bus_call_method(u->manager->system_bus,
"org.freedesktop.systemd1",
} else
c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0;
- path_simplify(c->path, false);
+ path_simplify(c->path);
exec_command_append_list(exec_command, c);
}
if (!path_is_absolute(i + offset))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid %s", name);
- path_simplify(i + offset, false);
+ path_simplify(i + offset);
}
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
if (!k)
return -ENOMEM;
- path_simplify(k, false);
+ path_simplify(k);
s = new0(PathSpec, 1);
if (!s)
if (!n)
return -ENOMEM;
- path_simplify(n, true);
+ path_simplify(n);
if (!path_is_normalized(n))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "PIDFile= path '%s' is not valid", n);
if (!p->path)
return log_oom();
- path_simplify(p->path, false);
+ path_simplify(p->path);
} else if (streq(t, "Netlink")) {
r = socket_address_parse_netlink(&p->address, a);
return r;
STRV_FOREACH(p, l) {
- path_simplify(*p, true);
+ path_simplify(*p);
if (!path_is_absolute(*p))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path specified in %s is not absolute: %s", name, *p);
if (!x)
return -ENOMEM;
- path_simplify(x + 5, true);
+ path_simplify(x + 5);
our_env[n_env++] = x;
}
if (!x)
return -ENOMEM;
- path_simplify(x + 6, true);
+ path_simplify(x + 6);
our_env[n_env++] = x;
}
n[nlen] = NULL;
}
- path_simplify(path, false);
+ path_simplify(path);
while (!isempty(p)) {
_cleanup_free_ char *word = NULL, *resolved = NULL;
assert(path);
strcpy(p, path);
- path_simplify(p, false);
+ path_simplify(p);
return hashmap_get(m->units_requiring_mounts_for, streq(p, "/") ? "" : p);
}
return r;
}
- path_simplify(m->where, false);
+ path_simplify(m->where);
if (!u->description) {
r = unit_set_description(u, m->where);
return -ENOMEM;
}
- path_simplify(ps->path, false);
+ path_simplify(ps->path);
/* PATH_CHANGED would not be enough. There are daemons (sendmail) that
* keep their PID file open all the time. */
goto fail;
}
- path_simplify(ep, false);
+ path_simplify(ep);
r = usbffs_address_create(ep);
if (r < 0)
return -ENOMEM;
}
- path_simplify(s->what, false);
+ path_simplify(s->what);
if (!UNIT(s)->description) {
r = unit_set_description(UNIT(s), s->what);
if (!p)
return -ENOMEM;
- path = path_simplify(p, true);
+ path = path_simplify(p);
if (!path_is_normalized(path))
return -EPERM;
int i;
for (i = optind; i < argc; i++) {
- path_simplify(argv[i], false);
+ path_simplify(argv[i]);
k = process_suffix_chop(argv[i]);
if (k < 0)
return log_oom();
if (is_path(where)) {
- path_simplify(where, false);
+ path_simplify(where);
/* Follow symlinks here; see 5261ba901845c084de5a8fd06500ed09bfb0bd80 which makes sense for
* mount units, but causes problems since it historically worked to have symlinks in e.g.
return -ENOMEM;
free_and_replace(syspath, new_syspath);
- path_simplify(syspath, false);
+ path_simplify(syspath);
}
if (path_startswith(syspath, "/sys/devices/")) {
if (!arg_mount_what)
return log_oom();
- path_simplify(arg_mount_what, false);
+ path_simplify(arg_mount_what);
if (!path_is_absolute(arg_mount_what))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
if (!arg_mount_where)
return log_oom();
- path_simplify(arg_mount_where, false);
+ path_simplify(arg_mount_where);
if (!path_is_absolute(arg_mount_where))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
if (!p)
return log_oom();
- path_simplify(p, false);
+ path_simplify(p);
r = stop_mounts(bus, p);
if (r < 0)
if (!p)
return -ENOMEM;
- path_simplify(p, false);
+ path_simplify(p);
if (source) {
s = strdup(source);
if (!s)
return -ENOMEM;
- path_simplify(s, false);
+ path_simplify(s);
}
c[(*n_changes)++] = (PortableChange) {
if (!i->path)
return -ENOMEM;
- path_simplify(i->path, false);
+ path_simplify(i->path);
*ret = TAKE_PTR(i);
if (!p)
return -ENOMEM;
- path_simplify(p, false);
+ path_simplify(p);
if (source) {
s = strdup(source);
if (!s)
return -ENOMEM;
- path_simplify(s, false);
+ path_simplify(s);
}
c[(*n_changes)++] = (UnitFileChange) {
if (!n)
return -ENOMEM;
- path_simplify(n, false);
+ path_simplify(n);
r = set_consume(*remove_symlinks_to, n);
if (r == -EEXIST)
p = path_make_absolute(de->d_name, path);
if (!p)
return -ENOMEM;
- path_simplify(p, false);
+ path_simplify(p);
q = chase_symlinks(p, NULL, CHASE_NONEXISTENT, &dest, NULL);
if (q == -ENOENT)
if (r == 0) /* EOF */
break;
- path_simplify(line, true);
+ path_simplify(line);
if (!path_is_normalized(line)) {
log_warning("Path to relabel is not normalized, ignoring: %s", line);
if (r < 0)
return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
- path_simplify(p, false);
+ path_simplify(p);
if (suppress_root && empty_or_root(p))
p = mfree(p);
if (resolved_id) {
if (path_is_absolute(resolved_id)) {
i->uid_path = TAKE_PTR(resolved_id);
- path_simplify(i->uid_path, false);
+ path_simplify(i->uid_path);
} else {
_cleanup_free_ char *uid = NULL, *gid = NULL;
if (split_pair(resolved_id, ":", &uid, &gid) == 0) {
if (resolved_id) {
if (path_is_absolute(resolved_id)) {
i->gid_path = TAKE_PTR(resolved_id);
- path_simplify(i->gid_path, false);
+ path_simplify(i->gid_path);
} else {
r = parse_gid(resolved_id, &i->gid);
if (r < 0)
log_info("DEFAULT_USER_PATH=%s", DEFAULT_USER_PATH);
}
-static void test_path_simplify(const char *in, const char *out, const char *out_dot) {
+static void test_path_simplify(const char *in, const char *out) {
char *p;
log_info("/* %s */", __func__);
p = strdupa(in);
- assert_se(streq(path_simplify(p, false), out));
-
- p = strdupa(in);
- assert_se(streq(path_simplify(p, true), out_dot));
+ assert_se(streq(path_simplify(p), out));
}
static void test_path(void) {
assert_se(streq(basename("/aa///file..."), "file..."));
assert_se(streq(basename("file.../"), ""));
- test_path_simplify("aaa/bbb////ccc", "aaa/bbb/ccc", "aaa/bbb/ccc");
- test_path_simplify("//aaa/.////ccc", "/aaa/./ccc", "/aaa/ccc");
- test_path_simplify("///", "/", "/");
- test_path_simplify("///.//", "/.", "/");
- test_path_simplify("///.//.///", "/./.", "/");
- test_path_simplify("////.././///../.", "/.././../.", "/../..");
- test_path_simplify(".", ".", ".");
- test_path_simplify("./", ".", ".");
- test_path_simplify(".///.//./.", "./././.", ".");
- test_path_simplify(".///.//././/", "./././.", ".");
+ test_path_simplify("aaa/bbb////ccc", "aaa/bbb/ccc");
+ test_path_simplify("//aaa/.////ccc", "/aaa/ccc");
+ test_path_simplify("///", "/");
+ test_path_simplify("///.//", "/");
+ test_path_simplify("///.//.///", "/");
+ test_path_simplify("////.././///../.", "/../..");
+ test_path_simplify(".", ".");
+ test_path_simplify("./", ".");
+ test_path_simplify(".///.//./.", ".");
+ test_path_simplify(".///.//././/", ".");
test_path_simplify("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.",
- "/./aaa/././.bbb/../c./d.dd/..eeee/.",
"/aaa/.bbb/../c./d.dd/..eeee");
test_path_simplify("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
- "/./aaa/././.bbb/../c./d.dd/..eeee/..",
"/aaa/.bbb/../c./d.dd/..eeee/..");
test_path_simplify(".//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
- "././aaa/././.bbb/../c./d.dd/..eeee/..",
"aaa/.bbb/../c./d.dd/..eeee/..");
test_path_simplify("..//./aaa///.//./.bbb/..///c.//d.dd///..eeee/..",
- ".././aaa/././.bbb/../c./d.dd/..eeee/..",
"../aaa/.bbb/../c./d.dd/..eeee/..");
assert_se(PATH_IN_SET("/bin", "/", "/bin", "/foo"));
test_tempfn_random_one("foo", "bar", ".#barfoo", 0);
test_tempfn_random_one("/tmp/foo", NULL, "/tmp/.#foo", 0);
test_tempfn_random_one("/tmp/foo", "bar", "/tmp/.#barfoo", 0);
- test_tempfn_random_one("./foo", NULL, "./.#foo", 0);
- test_tempfn_random_one("./foo", "bar", "./.#barfoo", 0);
+ test_tempfn_random_one("./foo", NULL, ".#foo", 0);
+ test_tempfn_random_one("./foo", "bar", ".#barfoo", 0);
test_tempfn_random_one("../foo", NULL, "../.#foo", 0);
test_tempfn_random_one("../foo", "bar", "../.#barfoo", 0);
test_tempfn_random_one("foo/", "bar", ".#barfoo", 0);
test_tempfn_random_one("/tmp/foo/", NULL, "/tmp/.#foo", 0);
test_tempfn_random_one("/tmp/foo/", "bar", "/tmp/.#barfoo", 0);
- test_tempfn_random_one("./foo/", NULL, "./.#foo", 0);
- test_tempfn_random_one("./foo/", "bar", "./.#barfoo", 0);
+ test_tempfn_random_one("./foo/", NULL, ".#foo", 0);
+ test_tempfn_random_one("./foo/", "bar", ".#barfoo", 0);
test_tempfn_random_one("../foo/", NULL, "../.#foo", 0);
test_tempfn_random_one("../foo/", "bar", "../.#barfoo", 0);
}
test_tempfn_xxxxxx_one("foo", "bar", ".#barfoo", 0);
test_tempfn_xxxxxx_one("/tmp/foo", NULL, "/tmp/.#foo", 0);
test_tempfn_xxxxxx_one("/tmp/foo", "bar", "/tmp/.#barfoo", 0);
- test_tempfn_xxxxxx_one("./foo", NULL, "./.#foo", 0);
- test_tempfn_xxxxxx_one("./foo", "bar", "./.#barfoo", 0);
+ test_tempfn_xxxxxx_one("./foo", NULL, ".#foo", 0);
+ test_tempfn_xxxxxx_one("./foo", "bar", ".#barfoo", 0);
test_tempfn_xxxxxx_one("../foo", NULL, "../.#foo", 0);
test_tempfn_xxxxxx_one("../foo", "bar", "../.#barfoo", 0);
test_tempfn_xxxxxx_one("foo/", "bar", ".#barfoo", 0);
test_tempfn_xxxxxx_one("/tmp/foo/", NULL, "/tmp/.#foo", 0);
test_tempfn_xxxxxx_one("/tmp/foo/", "bar", "/tmp/.#barfoo", 0);
- test_tempfn_xxxxxx_one("./foo/", NULL, "./.#foo", 0);
- test_tempfn_xxxxxx_one("./foo/", "bar", "./.#barfoo", 0);
+ test_tempfn_xxxxxx_one("./foo/", NULL, ".#foo", 0);
+ test_tempfn_xxxxxx_one("./foo/", "bar", ".#barfoo", 0);
test_tempfn_xxxxxx_one("../foo/", NULL, "../.#foo", 0);
test_tempfn_xxxxxx_one("../foo/", "bar", "../.#barfoo", 0);
}
test_unit_name_from_path_one("/", ".mount", "-.mount", 0);
test_unit_name_from_path_one("///", ".mount", "-.mount", 0);
test_unit_name_from_path_one("/foo/../bar", ".mount", NULL, -EINVAL);
- test_unit_name_from_path_one("/foo/./bar", ".mount", NULL, -EINVAL);
+ test_unit_name_from_path_one("/foo/./bar", ".mount", "foo-bar.mount", 0);
test_unit_name_from_path_one("/waldoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ".mount", NULL, -EINVAL);
}
if (!s)
return log_oom();
- path_simplify(s, false);
+ path_simplify(s);
r = set_consume(sockets, s);
if (r == -EEXIST)
free_and_replace(i.argument, p);
}
- path_simplify(i.argument, false);
+ path_simplify(i.argument);
break;
case CREATE_CHAR_DEVICE:
"Path '%s' not absolute.", i.path);
}
- path_simplify(i.path, false);
+ path_simplify(i.path);
if (!should_include_path(i.path))
return 0;
test_event_spawn_cat(false);
assert_se(path_make_absolute_cwd(argv[0], &self) >= 0);
- path_simplify(self, true);
+ path_simplify(self);
test_event_spawn_self(self, "test1", true);
test_event_spawn_self(self, "test1", false);