core/manager: split out creation of serialization fd out to a helper
There is a slight change in behaviour: the user manager for root will create a temporary file in /run/systemd, not /tmp. I don't think this matters, but simplifies implementation.
This commit is contained in:
@@ -1342,6 +1342,25 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
int open_serialization_fd(const char *ident) {
|
||||
int fd = -1;
|
||||
|
||||
fd = memfd_create(ident, MFD_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
const char *path;
|
||||
|
||||
path = getpid() == 1 ? "/run/systemd" : "/tmp";
|
||||
fd = open_tmpfile_unlinkable(path, O_RDWR|O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
log_debug("Serializing %s to %s.", ident, path);
|
||||
} else
|
||||
log_debug("Serializing %s to memfd.", ident);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int link_tmpfile(int fd, const char *path, const char *target) {
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
@@ -84,6 +84,7 @@ int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space)
|
||||
|
||||
int open_tmpfile_unlinkable(const char *directory, int flags);
|
||||
int open_tmpfile_linkable(const char *target, int flags, char **ret_path);
|
||||
int open_serialization_fd(const char *ident);
|
||||
|
||||
int link_tmpfile(int fd, const char *path, const char *target);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user