From: Lennart Poettering Date: Thu, 4 Jan 2024 17:37:38 +0000 (+0100) Subject: generator: optionally return resulting unit file path in generator_open_unit_file_full() X-Git-Tag: v256-rc1~1185^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7ceb76b63c20bb21c422ec297e09e562e10e2219;p=thirdparty%2Fsystemd.git generator: optionally return resulting unit file path in generator_open_unit_file_full() This is useful if we want to make symlinks to it later. --- diff --git a/src/network/generator/main.c b/src/network/generator/main.c index 540b6df4fc5..4a3ccd6a992 100644 --- a/src/network/generator/main.c +++ b/src/network/generator/main.c @@ -28,7 +28,13 @@ static int network_save(Network *network, const char *dest_dir) { assert(network); - r = generator_open_unit_file_full(dest_dir, NULL, NULL, &f, &temp_path); + r = generator_open_unit_file_full( + dest_dir, + /* source= */ NULL, + /* name= */ NULL, + &f, + /* ret_final_path= */ NULL, + &temp_path); if (r < 0) return r; @@ -56,7 +62,13 @@ static int netdev_save(NetDev *netdev, const char *dest_dir) { assert(netdev); - r = generator_open_unit_file_full(dest_dir, NULL, NULL, &f, &temp_path); + r = generator_open_unit_file_full( + dest_dir, + /* source= */ NULL, + /* name= */ NULL, + &f, + /* ret_final_path= */ NULL, + &temp_path); if (r < 0) return r; @@ -81,7 +93,13 @@ static int link_save(Link *link, const char *dest_dir) { assert(link); - r = generator_open_unit_file_full(dest_dir, NULL, NULL, &f, &temp_path); + r = generator_open_unit_file_full( + dest_dir, + /* source= */ NULL, + /* name= */ NULL, + &f, + /* ret_final_path= */ NULL, + &temp_path); if (r < 0) return r; diff --git a/src/shared/generator.c b/src/shared/generator.c index fe58021f000..d183eb9654f 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -29,6 +29,7 @@ int generator_open_unit_file_full( const char *source, const char *fn, FILE **ret_file, + char **ret_final_path, char **ret_temp_path) { _cleanup_free_ char *p = NULL; @@ -72,6 +73,10 @@ int generator_open_unit_file_full( program_invocation_short_name); *ret_file = f; + + if (ret_final_path) + *ret_final_path = TAKE_PTR(p); + return 0; } diff --git a/src/shared/generator.h b/src/shared/generator.h index d97d6edc676..c17feafacc2 100644 --- a/src/shared/generator.h +++ b/src/shared/generator.h @@ -6,10 +6,10 @@ #include "macro.h" #include "main-func.h" -int generator_open_unit_file_full(const char *dest, const char *source, const char *name, FILE **ret_file, char **ret_temp_path); +int generator_open_unit_file_full(const char *dest, const char *source, const char *name, FILE **ret_file, char **ret_final_path, char **ret_temp_path); static inline int generator_open_unit_file(const char *dest, const char *source, const char *name, FILE **ret_file) { - return generator_open_unit_file_full(dest, source, name, ret_file, NULL); + return generator_open_unit_file_full(dest, source, name, ret_file, NULL, NULL); } int generator_add_symlink_full(const char *dir, const char *dst, const char *dep_type, const char *src, const char *instance);