X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Ffileio.c;h=94ebcbdc459e4b5fb7c9440d39108390f623a8d2;hb=187b257e8a1e6efba8fd60638e88342acdea2b5f;hp=411c8601b95d36a7f4f424357f8a816f75fd752b;hpb=2ac8af71ede1796f39d261203ddd16f9b6c4e0ca;p=elogind.git diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 411c8601b..94ebcbdc4 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -37,6 +37,7 @@ #include "hexdecoct.h" //#include "log.h" //#include "macro.h" +#include "missing.h" #include "parse-util.h" #include "path-util.h" #include "random-util.h" @@ -585,9 +586,14 @@ fail: return r; } -static int check_utf8ness_and_warn( +static int parse_env_file_push( const char *filename, unsigned line, - const char *key, char *value) { + const char *key, char *value, + void *userdata, + int *n_pushed) { + + const char *k; + va_list aq, *ap = userdata; if (!utf8_is_valid(key)) { _cleanup_free_ char *p = NULL; @@ -605,23 +611,6 @@ static int check_utf8ness_and_warn( return -EINVAL; } - return 0; -} - -static int parse_env_file_push( - const char *filename, unsigned line, - const char *key, char *value, - void *userdata, - int *n_pushed) { - - const char *k; - va_list aq, *ap = userdata; - int r; - - r = check_utf8ness_and_warn(filename, line, key, value); - if (r < 0) - return r; - va_copy(aq, *ap); while ((k = va_arg(aq, const char *))) { @@ -674,9 +663,19 @@ static int load_env_file_push( char *p; int r; - r = check_utf8ness_and_warn(filename, line, key, value); - if (r < 0) - return r; + if (!utf8_is_valid(key)) { + _cleanup_free_ char *t = utf8_escape_invalid(key); + + log_error("%s:%u: invalid UTF-8 for key '%s', ignoring.", strna(filename), line, t); + return -EINVAL; + } + + if (value && !utf8_is_valid(value)) { + _cleanup_free_ char *t = utf8_escape_invalid(value); + + log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", strna(filename), line, key, t); + return -EINVAL; + } p = strjoin(key, "=", strempty(value)); if (!p) @@ -718,9 +717,19 @@ static int load_env_file_push_pairs( char ***m = userdata; int r; - r = check_utf8ness_and_warn(filename, line, key, value); - if (r < 0) - return r; + if (!utf8_is_valid(key)) { + _cleanup_free_ char *t = utf8_escape_invalid(key); + + log_error("%s:%u: invalid UTF-8 for key '%s', ignoring.", strna(filename), line, t); + return -EINVAL; + } + + if (value && !utf8_is_valid(value)) { + _cleanup_free_ char *t = utf8_escape_invalid(value); + + log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", strna(filename), line, key, t); + return -EINVAL; + } r = strv_extend(m, key); if (r < 0) @@ -1338,6 +1347,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);