summaryrefslogtreecommitdiffstats
path: root/src/sysv-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-08-22 11:38:58 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2022-08-22 20:15:29 +0200
commit8e7e4a730ba40bbc46c9d1e84207fd35781ca05a (patch)
treed3afeaddba38bf96f3df5a08fa7f40aba7a8d2eb /src/sysv-generator
parentMerge pull request #24392 from poettering/chase-symlinks-more-stuff (diff)
downloadsystemd-8e7e4a730ba40bbc46c9d1e84207fd35781ca05a.tar.xz
systemd-8e7e4a730ba40bbc46c9d1e84207fd35781ca05a.zip
tree-wide: use path_join() instead of prefix_roota() in various cases
prefix_roota() is something we should stop using. It is bad for three reasons: 1. As it names suggests it's supposed to be used when working relative to some root directory, but given it doesn't follow symlinks (and instead just stupidly joins paths) it is not a good choice for that. 2. More often than not it is currently used with inputs under control of the user, and that is icky given it typically allocates memory on the stack. 3. It's a redundant interface, where chase_symlinks() and path_join() already exist as better, safer interfaces. Hence, let's start moving things from prefix_roota() to path_join() for the cases where that's appropriate.
Diffstat (limited to 'src/sysv-generator')
-rw-r--r--src/sysv-generator/sysv-generator.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index 14ae873dc0..3c5df6c3ec 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -80,16 +80,16 @@ static void free_sysvstub_hashmapp(Hashmap **h) {
}
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;
@@ -100,9 +100,8 @@ static int add_alias(const char *service, const char *alias) {
}
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);
@@ -114,7 +113,9 @@ static int generate_unit_file(SysvStub *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,