}
int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
+ _cleanup_free_ char *joined = NULL;
CGroupMask delegated_mask;
const char *p;
void *pidp;
if (isempty(suffix_path))
p = u->cgroup_path;
- else
- p = prefix_roota(u->cgroup_path, suffix_path);
+ else {
+ joined = path_join(u->cgroup_path, suffix_path);
+ if (!joined)
+ return -ENOMEM;
+
+ p = joined;
+ }
delegated_mask = unit_get_delegate_mask(u);
static int should_skip_path(const char *prefix, const char *suffix) {
#if HAVE_SPLIT_USR
- _cleanup_free_ char *target = NULL;
- const char *dirname, *p;
+ _cleanup_free_ char *target = NULL, *dirname = NULL;
+ const char *p;
- dirname = prefix_roota(prefix, suffix);
+ dirname = path_join(prefix, suffix);
+ if (!dirname)
+ return -ENOMEM;
if (chase_symlinks(dirname, NULL, 0, &target, NULL) < 0)
return false;
const char *description,
usec_t timeout) {
- _cleanup_free_ char *unit = NULL;
+ _cleanup_free_ char *unit = NULL, *p = NULL;
_cleanup_fclose_ FILE *f = NULL;
- const char *opt = "noauto", *p;
+ const char *opt = "noauto";
int r;
assert(id);
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
- p = prefix_roota(arg_dest, unit);
+ p = path_join(arg_dest, unit);
+ if (!p)
+ return log_oom();
+
f = fopen(p, "wxe");
if (!f)
return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
/* We cache all sysattr lookups. If an attribute does not exist, it is stored
* with a NULL value in the cache, otherwise the returned string is stored */
_public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **ret_value) {
- _cleanup_free_ char *value = NULL;
- const char *path, *syspath;
+ _cleanup_free_ char *value = NULL, *path = NULL;
+ const char *syspath;
struct stat statbuf;
int r;
if (r < 0)
return r;
- path = prefix_roota(syspath, sysattr);
+ path = path_join(syspath, sysattr);
+ if (!path)
+ return -ENOMEM;
+
if (lstat(path, &statbuf) < 0) {
int k;
}
_public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *_value) {
- _cleanup_free_ char *value = NULL;
- const char *syspath, *path;
+ _cleanup_free_ char *value = NULL, *path = NULL;
+ const char *syspath;
size_t len;
int r;
if (r < 0)
return r;
- path = prefix_roota(syspath, sysattr);
+ path = path_join(syspath, sysattr);
+ if (!path)
+ return -ENOMEM;
len = strlen(_value);
const char *prefix,
const char *filename) {
- const char *path;
+ _cleanup_free_ char *path = NULL;
assert(j);
assert(prefix);
if (!file_type_wanted(j->flags, filename))
return 0;
- path = prefix_roota(prefix, filename);
+ path = path_join(prefix, filename);
+ if (!path)
+ return -ENOMEM;
+
return add_any_file(j, -1, path);
}
-static void remove_file_by_name(
+static int remove_file_by_name(
sd_journal *j,
const char *prefix,
const char *filename) {
- const char *path;
+ _cleanup_free_ char *path = NULL;
JournalFile *f;
assert(j);
assert(prefix);
assert(filename);
- path = prefix_roota(prefix, filename);
+ path = path_join(prefix, filename);
+ if (!path)
+ return -ENOMEM;
+
f = ordered_hashmap_get(j->files, path);
if (!f)
- return;
+ return 0;
remove_file_real(j, f);
+ return 1;
}
static void remove_file_real(sd_journal *j, JournalFile *f) {
if (e->mask & (IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB))
(void) add_file_by_name(j, d->path, e->name);
else if (e->mask & (IN_DELETE|IN_MOVED_FROM|IN_UNMOUNT))
- remove_file_by_name(j, d->path, e->name);
+ (void) remove_file_by_name(j, d->path, e->name);
} else if (!d->is_root && e->len == 0) {
const char *path,
const char *source) {
+ _cleanup_free_ char *path_buf = NULL, *source_buf = NULL;
+
assert(path);
assert(!changes == !n_changes);
return 0;
if (prefix) {
- path = prefix_roota(prefix, path);
+ path_buf = path_join(prefix, path);
+ if (!path_buf)
+ return -ENOMEM;
+
+ path = path_buf;
+
+ if (source) {
+ source_buf = path_join(prefix, source);
+ if (!source_buf)
+ return -ENOMEM;
- if (source)
- source = prefix_roota(prefix, source);
+ source = source_buf;
+ }
}
return portable_changes_add(changes, n_changes, type_or_errno, path, source);
_cleanup_(unlink_and_freep) char *chroot_dropin = NULL, *profile_dropin = NULL;
_cleanup_(rmdir_and_freep) char *dropin_dir = NULL;
- const char *where, *path;
+ _cleanup_free_ char *path = NULL;
+ const char *where;
int r;
assert(paths);
} else
(void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, where, NULL);
- path = prefix_roota(where, m->name);
+ path = path_join(where, m->name);
+ if (!path)
+ return -ENOMEM;
+
dropin_dir = strjoin(path, ".d");
if (!dropin_dir)
return -ENOMEM;
const char *name,
FILE **file) {
- const char *unit;
+ _cleanup_free_ char *unit = NULL;
FILE *f;
int r;
- unit = prefix_roota(dest, name);
+ unit = path_join(dest, name);
+ if (!unit)
+ return log_oom();
r = fopen_unlocked(unit, "wxe", &f);
if (r < 0) {
const char *what) {
_cleanup_free_ char *node = NULL, *unit = NULL, *escaped = NULL, *where_unit = NULL;
+ _cleanup_free_ char *unit_file = NULL;
_cleanup_fclose_ FILE *f = NULL;
- const char *unit_file;
int r;
node = fstab_node_to_udev_node(what);
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
node);
- unit_file = prefix_roota(dir, unit);
+ unit_file = path_join(dir, unit);
+ if (!unit_file)
+ return log_oom();
+
log_debug("Creating %s", unit_file);
escaped = cescape(node);
const char *where,
const char *type) {
- _cleanup_free_ char *node = NULL, *unit = NULL, *escaped = NULL, *where_unit = NULL;
+ _cleanup_free_ char *node = NULL, *unit = NULL, *unit_file = NULL, *escaped = NULL, *where_unit = NULL;
_cleanup_fclose_ FILE *f = NULL;
- const char *unit_file;
int r;
node = fstab_node_to_udev_node(what);
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
node);
- unit_file = prefix_roota(dir, unit);
+ unit_file = path_join(dir, unit);
+ if (!unit_file)
+ return log_oom();
+
log_debug("Creating %s", unit_file);
escaped = cescape(node);
const char *where,
const char *target) {
- _cleanup_free_ char *unit = NULL, *escaped = NULL, *where_unit = NULL;
+ _cleanup_free_ char *unit = NULL, *escaped = NULL, *where_unit = NULL, *unit_file = NULL;
_cleanup_fclose_ FILE *f = NULL;
- const char *unit_file;
int r;
assert(dir);
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
where);
- unit_file = prefix_roota(dir, unit);
+ unit_file = path_join(dir, unit);
+ if (!unit_file)
+ return log_oom();
+
log_debug("Creating %s", unit_file);
f = fopen(unit_file, "wxe");
}
static int add_alias(const char *service, const char *alias) {
- const char *link;
- int r;
+ _cleanup_free_ char *link = NULL;
assert(service);
assert(alias);
- link = prefix_roota(arg_dest, alias);
+ link = path_join(arg_dest, alias);
+ if (!link)
+ return -ENOMEM;
- r = symlink(service, link);
- if (r < 0) {
+ if (symlink(service, link) < 0) {
if (errno == EEXIST)
return 0;
}
static int generate_unit_file(SysvStub *s) {
- _cleanup_free_ char *path_escaped = NULL;
+ _cleanup_free_ char *path_escaped = NULL, *unit = NULL;
_cleanup_fclose_ FILE *f = NULL;
- const char *unit;
int r;
assert(s);
if (!path_escaped)
return log_oom();
- unit = prefix_roota(arg_dest, s->name);
+ unit = path_join(arg_dest, s->name);
+ if (!unit)
+ return log_oom();
/* We might already have a symlink with the same name from a Provides:,
* or from backup files like /etc/init.d/foo.bak. Real scripts always win,