summaryrefslogtreecommitdiffstats
path: root/src/gpt-auto-generator/gpt-auto-generator.c
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/gpt-auto-generator/gpt-auto-generator.c
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/gpt-auto-generator/gpt-auto-generator.c')
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index fa56a8322d..a95f384ecb 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -415,9 +415,9 @@ static int add_automount(
const char *description,
usec_t timeout) {
- _cleanup_free_ char *unit = NULL;
+ _cleanup_free_ char *unit = NULL, *p = NULL;
_cleanup_fclose_ FILE *f = NULL;
- const char *opt = "noauto", *p;
+ const char *opt = "noauto";
int r;
assert(id);
@@ -443,7 +443,10 @@ static int add_automount(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
- p = prefix_roota(arg_dest, unit);
+ p = path_join(arg_dest, unit);
+ if (!p)
+ return log_oom();
+
f = fopen(p, "wxe");
if (!f)
return log_error_errno(errno, "Failed to create unit file %s: %m", unit);