summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-12-21 16:49:30 +0100
committerLennart Poettering <lennart@poettering.net>2022-12-23 15:04:19 +0100
commit7e763f940273e7566ab23d584b576a91b5f1b93c (patch)
treeeee50c8c3a53013739b7bd4f2393338564d0e0c9 /src/portable
parentb36e39d2eb3605378f67b937b212e7bf0d5a30b3 (diff)
downloadsystemd-7e763f940273e7566ab23d584b576a91b5f1b93c.tar.gz
portable: port basename() → path_extract_filename()
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/portablectl.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c
index ff71535c13..cd9f462bb3 100644
--- a/src/portable/portablectl.c
+++ b/src/portable/portablectl.c
@@ -123,11 +123,14 @@ static int attach_extensions_to_message(sd_bus_message *m, char **extensions) {
}
static int extract_prefix(const char *path, char **ret) {
- _cleanup_free_ char *name = NULL;
- const char *bn, *underscore;
+ _cleanup_free_ char *name = NULL, *bn = NULL;
+ const char *underscore;
size_t m;
+ int r;
- bn = basename(path);
+ r = path_extract_filename(path, &bn);
+ if (r < 0)
+ return r;
underscore = strchr(bn, '_');
if (underscore)
@@ -155,7 +158,6 @@ static int extract_prefix(const char *path, char **ret) {
return -EINVAL;
*ret = TAKE_PTR(name);
-
return 0;
}
@@ -591,7 +593,8 @@ static int maybe_enable_disable(sd_bus *bus, const char *path, bool enable) {
static int maybe_start_stop_restart(sd_bus *bus, const char *path, const char *method, BusWaitForJobs *wait) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- char *name = (char *)basename(path), *job = NULL;
+ _cleanup_free_ char *name = NULL;
+ const char *job = NULL;
int r;
assert(STR_IN_SET(method, "StartUnit", "StopUnit", "RestartUnit"));
@@ -599,6 +602,10 @@ static int maybe_start_stop_restart(sd_bus *bus, const char *path, const char *m
if (!arg_now)
return 0;
+ r = path_extract_filename(path, &name);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract file name from '%s': %m", path);
+
r = bus_call_method(
bus,
bus_systemd_mgr,