diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-12-21 16:51:48 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-12-23 17:35:21 +0100 |
commit | 1d8a8a7dee82cea3b110d2d3a3a67350b385748e (patch) | |
tree | cc9e5ece19cf3330e5b30a27c561fb569437a818 /src/sysv-generator/sysv-generator.c | |
parent | shared: port various shared helpers basename() → path_extract_filename() (diff) | |
download | systemd-1d8a8a7dee82cea3b110d2d3a3a67350b385748e.tar.xz systemd-1d8a8a7dee82cea3b110d2d3a3a67350b385748e.zip |
sysv-generator: port basename() → path_extract_filename()
Diffstat (limited to '')
-rw-r--r-- | src/sysv-generator/sysv-generator.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 9b465e8c84..7c290a8b0d 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -244,21 +244,22 @@ static int sysv_translate_facility(SysvStub *s, unsigned line, const char *name, "time", SPECIAL_TIME_SYNC_TARGET, }; - const char *filename; - char *filename_no_sh, *e, *m; + _cleanup_free_ char *filename = NULL; const char *n; - unsigned i; + char *e, *m; int r; assert(name); assert(s); assert(ret); - filename = basename(s->path); + r = path_extract_filename(s->path, &filename); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from path '%s': %m", s->path); n = *name == '$' ? name + 1 : name; - for (i = 0; i < ELEMENTSOF(table); i += 2) { + for (size_t i = 0; i < ELEMENTSOF(table); i += 2) { if (!streq(table[i], n)) continue; @@ -288,12 +289,9 @@ static int sysv_translate_facility(SysvStub *s, unsigned line, const char *name, } /* Strip ".sh" suffix from file name for comparison */ - filename_no_sh = strdupa_safe(filename); - e = endswith(filename_no_sh, ".sh"); - if (e) { + e = endswith(filename, ".sh"); + if (e) *e = '\0'; - filename = filename_no_sh; - } /* Names equaling the file name of the services are redundant */ if (streq_ptr(n, filename)) { |