1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-08 11:27:32 +03:00

core: modernize prepare_reexecute()

This commit is contained in:
Lennart Poettering 2015-09-23 01:11:30 +02:00
parent aa8aeac050
commit 48b9085914

View File

@ -956,8 +956,8 @@ static int version(void) {
} }
static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching_root) { static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching_root) {
FILE *f = NULL; _cleanup_fdset_free_ FDSet *fds = NULL;
FDSet *fds = NULL; _cleanup_fclose_ FILE *f = NULL;
int r; int r;
assert(m); assert(m);
@ -965,56 +965,39 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
assert(_fds); assert(_fds);
r = manager_open_serialization(m, &f); r = manager_open_serialization(m, &f);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to create serialization file: %m"); return log_error_errno(r, "Failed to create serialization file: %m");
goto fail;
}
/* Make sure nothing is really destructed when we shut down */ /* Make sure nothing is really destructed when we shut down */
m->n_reloading ++; m->n_reloading ++;
bus_manager_send_reloading(m, true); bus_manager_send_reloading(m, true);
fds = fdset_new(); fds = fdset_new();
if (!fds) { if (!fds)
r = -ENOMEM; return log_oom();
log_error_errno(r, "Failed to allocate fd set: %m");
goto fail;
}
r = manager_serialize(m, f, fds, switching_root); r = manager_serialize(m, f, fds, switching_root);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to serialize state: %m"); return log_error_errno(r, "Failed to serialize state: %m");
goto fail;
}
if (fseeko(f, 0, SEEK_SET) < 0) { if (fseeko(f, 0, SEEK_SET) == (off_t) -1)
log_error_errno(errno, "Failed to rewind serialization fd: %m"); return log_error_errno(errno, "Failed to rewind serialization fd: %m");
goto fail;
}
r = fd_cloexec(fileno(f), false); r = fd_cloexec(fileno(f), false);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to disable O_CLOEXEC for serialization: %m"); return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization: %m");
goto fail;
}
r = fdset_cloexec(fds, false); r = fdset_cloexec(fds, false);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m"); return log_error_errno(r, "Failed to disable O_CLOEXEC for serialization fds: %m");
goto fail;
}
*_f = f; *_f = f;
*_fds = fds; *_fds = fds;
f = NULL;
fds = NULL;
return 0; return 0;
fail:
fdset_free(fds);
safe_fclose(f);
return r;
} }
static int bump_rlimit_nofile(struct rlimit *saved_rlimit) { static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {