1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-22 22:03:43 +03:00

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-11-30 21:39:12 +01:00
parent a12a00c857
commit 0a2152f005
5 changed files with 26 additions and 23 deletions

View File

@ -9,7 +9,6 @@
#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@ -25,7 +24,6 @@
#include "missing.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
@ -1219,25 +1217,6 @@ int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space)
return fputs(s, f);
}
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;
}
int read_nul_string(FILE *f, char **ret) {
_cleanup_free_ char *x = NULL;
size_t allocated = 0, n = 0;

View File

@ -71,8 +71,6 @@ int read_timestamp_file(const char *fn, usec_t *ret);
int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space);
int open_serialization_fd(const char *ident);
int read_nul_string(FILE *f, char **ret);
int read_line(FILE *f, size_t limit, char **ret);

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;
}

View File

@ -21,3 +21,5 @@ static inline int serialize_bool(FILE *f, const char *key, bool b) {
int deserialize_usec(const char *value, usec_t *timestamp);
int deserialize_dual_timestamp(const char *value, dual_timestamp *t);
int deserialize_environment(const char *value, char ***environment);
int open_serialization_fd(const char *ident);

View File

@ -10,6 +10,7 @@
#include "path-util.h"
#include "process-util.h"
#include "random-util.h"
#include "serialize.h"
#include "string-util.h"
#include "tests.h"
#include "tmpfile-util.h"