mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
fileio: simplify write_env_file()
This commit is contained in:
parent
6294aa76d8
commit
736937e5aa
@ -756,35 +756,31 @@ static void write_env_var(FILE *f, const char *v) {
|
||||
}
|
||||
|
||||
int write_env_file(const char *fname, char **l) {
|
||||
char **i;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
assert(fname);
|
||||
|
||||
r = fopen_temporary(fname, &f, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
fchmod_umask(fileno(f), 0644);
|
||||
|
||||
errno = 0;
|
||||
STRV_FOREACH(i, l)
|
||||
write_env_var(f, *i);
|
||||
|
||||
fflush(f);
|
||||
r = fflush_and_check(f);
|
||||
if (r >= 0) {
|
||||
if (rename(p, fname) >= 0)
|
||||
return 0;
|
||||
|
||||
if (ferror(f))
|
||||
r = errno ? -errno : -EIO;
|
||||
else {
|
||||
if (rename(p, fname) < 0)
|
||||
r = -errno;
|
||||
else
|
||||
r = 0;
|
||||
r = -errno;
|
||||
}
|
||||
|
||||
if (r < 0)
|
||||
unlink(p);
|
||||
|
||||
unlink(p);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user