return 0;
}
-static int extract_subvolume_name(const char *path, const char **subvolume) {
- const char *fn;
+static int extract_subvolume_name(const char *path, char **ret) {
+ _cleanup_free_ char *fn = NULL;
int r;
assert(path);
- assert(subvolume);
+ assert(ret);
- fn = basename(path);
+ r = path_extract_filename(path, &fn);
+ if (r < 0)
+ return r;
r = validate_subvolume_name(fn);
if (r < 0)
return r;
- *subvolume = fn;
+ *ret = TAKE_PTR(fn);
return 0;
}
}
int btrfs_subvol_make(const char *path) {
+ _cleanup_free_ char *subvolume = NULL;
_cleanup_close_ int fd = -EBADF;
- const char *subvolume;
int r;
assert(path);
}
int btrfs_subvol_remove(const char *path, BtrfsRemoveFlags flags) {
+ _cleanup_free_ char *subvolume = NULL;
_cleanup_close_ int fd = -EBADF;
- const char *subvolume;
int r;
assert(path);
copy_progress_bytes_t progress_bytes,
void *userdata) {
+ _cleanup_free_ char *subvolume = NULL;
_cleanup_close_ int new_fd = -EBADF;
- const char *subvolume;
int r;
assert(old_fd >= 0);
#include "hashmap.h"
#include "macro.h"
#include "missing_syscall.h"
+#include "path-util.h"
#include "process-util.h"
#include "rlimit-util.h"
#include "serialize.h"
return log_oom();
if (callbacks) {
- fd = open_serialization_fd(basename(*path));
+ _cleanup_free_ char *bn = NULL;
+
+ r = path_extract_filename(*path, &bn);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract filename from path '%s': %m", *path);
+
+ fd = open_serialization_fd(bn);
if (fd < 0)
return log_error_errno(fd, "Failed to open serialization file: %m");
}
ExecDirFlags flags) {
char **dirs = (char**) directories;
+ _cleanup_free_ char *name = NULL;
_cleanup_close_ int fd = -EBADF;
- char *name;
int r;
pid_t executor_pid;
assert(!strv_isempty(dirs));
- name = basename(dirs[0]);
- assert(!isempty(name));
+ r = path_extract_filename(dirs[0], &name);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract file name from '%s': %m", dirs[0]);
if (callbacks) {
assert(callback_args);
}
int generator_add_symlink(const char *dir, const char *dst, const char *dep_type, const char *src) {
+ _cleanup_free_ char *bn = NULL;
+ const char *from, *to;
+ int r;
+
/* Adds a symlink from <dst>.<dep_type>/ to <src> (if src is absolute)
* or ../<src> (otherwise). */
- const char *from, *to;
+ r = path_extract_filename(src, &bn);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract filename from '%s': %m", src);
from = path_is_absolute(src) ? src : strjoina("../", src);
- to = strjoina(dir, "/", dst, ".", dep_type, "/", basename(src));
+ to = strjoina(dir, "/", dst, ".", dep_type, "/", bn);
(void) mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0)
}
int make_lock_file_for(const char *p, int operation, LockFile *ret) {
- const char *fn;
- char *t;
+ _cleanup_free_ char *fn = NULL, *dn = NULL, *t = NULL;
+ int r;
assert(p);
assert(ret);
- fn = basename(p);
- if (!filename_is_valid(fn))
- return -EINVAL;
+ r = path_extract_filename(p, &fn);
+ if (r < 0)
+ return r;
+
+ r = path_extract_directory(p, &dn);
+ if (r < 0)
+ return r;
- t = newa(char, strlen(p) + 2 + 4 + 1);
- stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), fn), ".lck");
+ t = strjoin(dn, "/.#", fn, ".lck");
+ if (!t)
+ return -ENOMEM;
return make_lock_file(t, operation, ret);
}
if (r < 0)
goto finish;
if (r == 0) {
- const char *mount_inside;
+ _cleanup_free_ char *mount_outside_fn = NULL, *mount_inside = NULL;
errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]);
}
/* Fifth, move the mount to the right place inside */
- mount_inside = strjoina(incoming_path, basename(mount_outside));
- r = mount_nofollow_verbose(LOG_ERR, mount_inside, dest, NULL, MS_MOVE, NULL);
+ r = path_extract_filename(mount_outside, &mount_outside_fn);
+ if (r < 0) {
+ log_debug_errno(r, "Failed to extract filename from propagation file or directory '%s': %m", mount_outside);
+ goto child_fail;
+ }
+
+ mount_inside = path_join(incoming_path, mount_outside_fn);
+ if (!mount_inside) {
+ r = log_oom_debug();
+ goto child_fail;
+ }
+
+ r = mount_nofollow_verbose(LOG_DEBUG, mount_inside, dest, NULL, MS_MOVE, NULL);
if (r < 0)
goto child_fail;