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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user