util-lib: move open_serialization_fd() to serialize.c

It definitely fits better there.

No code changes, just some rearranging.
This commit is contained in:
Lennart Poettering
2018-12-02 13:22:29 +01:00
parent a12a00c857
commit 0a2152f005
5 changed files with 26 additions and 23 deletions
+23
View File
@@ -1,12 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <sys/mman.h>
#include "alloc-util.h"
#include "env-util.h"
#include "escape.h"
#include "fileio.h"
#include "parse-util.h"
#include "process-util.h"
#include "serialize.h"
#include "strv.h"
#include "tmpfile-util.h"
int serialize_item(FILE *f, const char *key, const char *value) {
assert(f);
@@ -188,3 +192,22 @@ int deserialize_environment(const char *value, char ***list) {
unescaped = NULL; /* now part of 'list' */
return 0;
}
int open_serialization_fd(const char *ident) {
int fd;
fd = memfd_create(ident, MFD_CLOEXEC);
if (fd < 0) {
const char *path;
path = getpid_cached() == 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;
}