shared: port various shared helpers basename() → path_extract_filename()

This commit is contained in:
Lennart Poettering
2022-12-23 17:35:21 +01:00
parent 7b2ffb593e
commit 03469b770b
5 changed files with 56 additions and 24 deletions
+12 -4
View File
@@ -18,6 +18,7 @@
#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"
@@ -131,7 +132,13 @@ static int do_execute(
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");
}
@@ -199,15 +206,16 @@ int execute_directories(
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);