Also convert these to use take_fdopen().
}
int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
- int fd;
+ _cleanup_close_ int fd = -1;
FILE *f;
fd = mkostemp_safe(pattern);
if (fd < 0)
return fd;
- f = fdopen(fd, mode);
- if (!f) {
- safe_close(fd);
+ f = take_fdopen(&fd, mode);
+ if (!f)
return -errno;
- }
*ret_f = f;
return 0;
char machine_string[SD_ID128_STRING_MAX];
_cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_fclose_ FILE *f = NULL;
+ _cleanup_close_ int fd = -1;
const char *p;
- int r, fd;
+ int r;
p = prefix_roota(esp_path, "/loader/loader.conf");
if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
if (fd < 0)
return log_error_errno(fd, "Failed to open \"%s\" for writing: %m", p);
- f = fdopen(fd, "w");
- if (!f) {
- safe_close(fd);
+ f = take_fdopen(&fd, "w");
+ if (!f)
return log_oom();
- }
fprintf(f, "#timeout 3\n"
"#console-mode keep\n"
}
int manager_open_serialization(Manager *m, FILE **_f) {
- int fd;
+ _cleanup_close_ int fd = -1;
FILE *f;
assert(_f);
if (fd < 0)
return fd;
- f = fdopen(fd, "w+");
- if (!f) {
- safe_close(fd);
+ f = take_fdopen(&fd, "w+");
+ if (!f)
return -errno;
- }
*_f = f;
return 0;
FOREACH_DIRENT(dent, proc_fd_dir, return -errno) {
_cleanup_fclose_ FILE *fdinfo = NULL;
_cleanup_free_ char *fdname = NULL;
- int fd;
+ _cleanup_close_ int fd = -1;
r = readlinkat_malloc(dirfd(proc_fd_dir), dent->d_name, &fdname);
if (r < 0)
if (fd < 0)
continue;
- fdinfo = fdopen(fd, "r");
- if (!fdinfo) {
- safe_close(fd);
+ fdinfo = take_fdopen(&fd, "r");
+ if (!fdinfo)
continue;
- }
for (;;) {
_cleanup_free_ char *line = NULL;
if (m->tmp)
rewind(m->tmp);
else {
- int fd;
+ _cleanup_close_ int fd = -1;
fd = open_tmpfile_unlinkable("/tmp", O_RDWR|O_CLOEXEC);
if (fd < 0)
return fd;
- m->tmp = fdopen(fd, "w+");
- if (!m->tmp) {
- safe_close(fd);
+ m->tmp = take_fdopen(&fd, "w+");
+ if (!m->tmp)
return -errno;
- }
}
return 0;