1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

core: use a memfd for serialization

If we can, use a memfd for serializing state during a daemon reload or
reexec. Fall back to a file in /run/systemd or /tmp only if memfds are
not available.

See: #5016
This commit is contained in:
Lennart Poettering 2017-02-03 16:30:00 +01:00
parent ae57dad3f9
commit d53333d4b1

View File

@ -2436,18 +2436,22 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
}
int manager_open_serialization(Manager *m, FILE **_f) {
const char *path;
int fd = -1;
FILE *f;
assert(_f);
path = MANAGER_IS_SYSTEM(m) ? "/run/systemd" : "/tmp";
fd = open_tmpfile_unlinkable(path, O_RDWR|O_CLOEXEC);
if (fd < 0)
return -errno;
fd = memfd_create("systemd-serialization", MFD_CLOEXEC);
if (fd < 0) {
const char *path;
log_debug("Serializing state to %s", path);
path = MANAGER_IS_SYSTEM(m) ? "/run/systemd" : "/tmp";
fd = open_tmpfile_unlinkable(path, O_RDWR|O_CLOEXEC);
if (fd < 0)
return -errno;
log_debug("Serializing state to %s.", path);
} else
log_debug("Serializing state to memfd.");
f = fdopen(fd, "w+");
if (!f) {