generator: modernize generator_open_unit_file()

This commit is contained in:
Lennart Poettering
2022-10-17 08:06:55 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 06648fa991
commit e8ede6f57e
+16 -14
View File
@@ -24,36 +24,38 @@
#include "util.h"
int generator_open_unit_file(
const char *dest,
const char *dir,
const char *source,
const char *name,
FILE **file) {
const char *fn,
FILE **ret) {
_cleanup_free_ char *unit = NULL;
_cleanup_free_ char *p = NULL;
FILE *f;
int r;
unit = path_join(dest, name);
if (!unit)
assert(dir);
assert(fn);
assert(ret);
p = path_join(dir, fn);
if (!p)
return log_oom();
r = fopen_unlocked(unit, "wxe", &f);
r = fopen_unlocked(p, "wxe", &f);
if (r < 0) {
if (source && r == -EEXIST)
return log_error_errno(r,
"Failed to create unit file %s, as it already exists. Duplicate entry in %s?",
unit, source);
else
return log_error_errno(r,
"Failed to create unit file %s: %m",
unit);
"Failed to create unit file '%s', as it already exists. Duplicate entry in '%s'?",
p, source);
return log_error_errno(r, "Failed to create unit file '%s': %m", p);
}
fprintf(f,
"# Automatically generated by %s\n\n",
program_invocation_short_name);
*file = f;
*ret = f;
return 0;
}