From: Lennart Poettering Date: Fri, 3 Feb 2017 15:30:00 +0000 (+0100) Subject: core: use a memfd for serialization X-Git-Tag: v234~553^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d53333d4b106423d4c281ad15aefe00e17a57893;p=platform%2Fupstream%2Fsystemd.git 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 --- diff --git a/src/core/manager.c b/src/core/manager.c index b22f85f..e4da945 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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) {