summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/cgroup-util.c18
-rw-r--r--src/basic/conf-files.c2
-rw-r--r--src/basic/fileio.c149
-rw-r--r--src/basic/fs-util.c2
-rw-r--r--src/basic/mount-util.c5
-rw-r--r--src/basic/path-util.c22
-rw-r--r--src/basic/process-util.c6
-rw-r--r--src/basic/string-util.c2
-rw-r--r--src/basic/string-util.h3
-rw-r--r--src/basic/unit-name.c4
-rw-r--r--src/basic/util.c2
11 files changed, 62 insertions, 153 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 44ab535cc..953bb86f6 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -346,7 +346,7 @@ int cg_kill_recursive(
while ((r = cg_read_subgroup(d, &fn)) > 0) {
_cleanup_free_ char *p = NULL;
- p = strjoin(path, "/", fn, NULL);
+ p = strjoin(path, "/", fn);
free(fn);
if (!p)
return -ENOMEM;
@@ -484,7 +484,7 @@ int cg_migrate_recursive(
while ((r = cg_read_subgroup(d, &fn)) > 0) {
_cleanup_free_ char *p = NULL;
- p = strjoin(pfrom, "/", fn, NULL);
+ p = strjoin(pfrom, "/", fn);
free(fn);
if (!p)
return -ENOMEM;
@@ -567,11 +567,11 @@ static int join_path_legacy(const char *controller, const char *path, const char
if (isempty(path) && isempty(suffix))
t = strappend("/sys/fs/cgroup/", dn);
else if (isempty(path))
- t = strjoin("/sys/fs/cgroup/", dn, "/", suffix, NULL);
+ t = strjoin("/sys/fs/cgroup/", dn, "/", suffix);
else if (isempty(suffix))
- t = strjoin("/sys/fs/cgroup/", dn, "/", path, NULL);
+ t = strjoin("/sys/fs/cgroup/", dn, "/", path);
else
- t = strjoin("/sys/fs/cgroup/", dn, "/", path, "/", suffix, NULL);
+ t = strjoin("/sys/fs/cgroup/", dn, "/", path, "/", suffix);
if (!t)
return -ENOMEM;
@@ -591,7 +591,7 @@ static int join_path_unified(const char *path, const char *suffix, char **fs) {
else if (isempty(suffix))
t = strappend("/sys/fs/cgroup/", path);
else
- t = strjoin("/sys/fs/cgroup/", path, "/", suffix, NULL);
+ t = strjoin("/sys/fs/cgroup/", path, "/", suffix);
if (!t)
return -ENOMEM;
@@ -618,7 +618,7 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch
else if (!path)
t = strdup(suffix);
else
- t = strjoin(path, "/", suffix, NULL);
+ t = strjoin(path, "/", suffix);
if (!t)
return -ENOMEM;
@@ -1155,7 +1155,7 @@ int cg_is_empty_recursive(const char *controller, const char *path) {
while ((r = cg_read_subgroup(d, &fn)) > 0) {
_cleanup_free_ char *p = NULL;
- p = strjoin(path, "/", fn, NULL);
+ p = strjoin(path, "/", fn);
free(fn);
if (!p)
return -ENOMEM;
@@ -2481,10 +2481,8 @@ bool cg_is_unified_systemd_controller_wanted(void) {
return wanted;
r = get_proc_cmdline_key("systemd.legacy_systemd_cgroup_controller", NULL);
- if (r > 0) {
if (r > 0)
wanted = false;
- } else {
else {
_cleanup_free_ char *value = NULL;
diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c
index 92fc792d6..950bdf53d 100644
--- a/src/basic/conf-files.c
+++ b/src/basic/conf-files.c
@@ -60,7 +60,7 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
if (!dirent_is_file_with_suffix(de, suffix))
continue;
- p = strjoin(dirpath, "/", de->d_name, NULL);
+ p = strjoin(dirpath, "/", de->d_name);
if (!p)
return -ENOMEM;
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 5b20fbb49..f4915b28a 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -585,9 +585,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 +610,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,19 +662,27 @@ 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, "=", value);
+ p = strjoin(key, "=", strempty(value));
if (!p)
return -ENOMEM;
- r = strv_env_replace(m, p);
- if (r < 0) {
- free(p);
+ r = strv_consume(m, p);
+ if (r < 0)
return r;
- }
if (n_pushed)
(*n_pushed)++;
@@ -720,9 +716,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)
@@ -761,51 +767,6 @@ int load_env_file_pairs(FILE *f, const char *fname, const char *newline, char **
return 0;
}
-static int merge_env_file_push(
- const char *filename, unsigned line,
- const char *key, char *value,
- void *userdata,
- int *n_pushed) {
-
- char ***env = userdata;
- char *expanded_value;
-
- assert(env);
-
- if (!value) {
- log_error("%s:%u: invalid syntax (around \"%s\"), ignoring.", strna(filename), line, key);
- return 0;
- }
-
- if (!env_name_is_valid(key)) {
- log_error("%s:%u: invalid variable name \"%s\", ignoring.", strna(filename), line, key);
- return 0;
- }
-
- expanded_value = replace_env(value, *env,
- REPLACE_ENV_USE_ENVIRONMENT|
- REPLACE_ENV_ALLOW_BRACELESS|
- REPLACE_ENV_ALLOW_EXTENDED);
- if (!expanded_value)
- return -ENOMEM;
-
- free_and_replace(value, expanded_value);
-
- return load_env_file_push(filename, line, key, value, env, n_pushed);
-}
-
-int merge_env_file(
- char ***env,
- FILE *f,
- const char *fname) {
-
- /* NOTE: this function supports braceful and braceless variable expansions,
- * plus "extended" substitutions, unlike other exported parsing functions.
- */
-
- return parse_env_file_internal(f, fname, NEWLINE, merge_env_file_push, env, NULL);
-}
-
static void write_env_var(FILE *f, const char *v) {
const char *p;
@@ -1385,25 +1346,6 @@ 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);
@@ -1472,22 +1414,3 @@ int read_nul_string(FILE *f, char **ret) {
return 0;
}
-
-int mkdtemp_malloc(const char *template, char **ret) {
- char *p;
-
- assert(template);
- assert(ret);
-
- p = strdup(template);
- if (!p)
- return -ENOMEM;
-
- if (!mkdtemp(p)) {
- free(p);
- return -errno;
- }
-
- *ret = p;
- return 0;
-}
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 59787552d..f288848c9 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -747,7 +747,7 @@ int chase_symlinks(const char *path, const char *_root, char **ret) {
/* A relative destination. If so, this is what we'll prefix what's left to do with what
* we just read, and start the loop again, but remain in the current directory. */
- joined = strjoin("/", destination, todo, NULL);
+ joined = strjoin("/", destination, todo);
if (!joined)
return -ENOMEM;
diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c
index e2bdfcd8a..051b14b17 100644
--- a/src/basic/mount-util.c
+++ b/src/basic/mount-util.c
@@ -161,7 +161,7 @@ int fd_is_mount_point(int fd, const char *filename, int flags) {
fallback_fdinfo:
r = fd_fdinfo_mnt_id(fd, filename, flags, &mount_id);
- if (IN_SET(r, -EOPNOTSUPP, -EACCES))
+ if (r == -EOPNOTSUPP)
goto fallback_fstat;
if (r < 0)
return r;
@@ -525,7 +525,6 @@ bool fstype_is_network(const char *fstype) {
"glusterfs\0"
"pvfs2\0" /* OrangeFS */
"ocfs2\0"
- "lustre\0"
;
const char *x;
@@ -644,7 +643,7 @@ static char* mount_flags_to_string(long unsigned flags) {
FLAG(MS_I_VERSION),
FLAG(MS_STRICTATIME),
FLAG(MS_LAZYTIME),
- y, NULL);
+ y);
if (!x)
return NULL;
if (!y)
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index 8cb013e6c..25a956e97 100644
--- a/src/basic/path-util.c
+++ b/src/basic/path-util.c
@@ -82,7 +82,7 @@ char *path_make_absolute(const char *p, const char *prefix) {
if (path_is_absolute(p) || !prefix)
return strdup(p);
- return strjoin(prefix, "/", p, NULL);
+ return strjoin(prefix, "/", p);
}
#endif // 0
@@ -104,7 +104,7 @@ int path_make_absolute_cwd(const char *p, char **ret) {
if (!cwd)
return negative_errno();
- c = strjoin(cwd, "/", p, NULL);
+ c = strjoin(cwd, "/", p);
}
if (!c)
return -ENOMEM;
@@ -356,16 +356,6 @@ char* path_startswith(const char *path, const char *prefix) {
assert(path);
assert(prefix);
- /* Returns a pointer to the start of the first component after the parts matched by
- * the prefix, iff
- * - both paths are absolute or both paths are relative,
- * and
- * - each component in prefix in turn matches a component in path at the same position.
- * An empty string will be returned when the prefix and path are equivalent.
- *
- * Returns NULL otherwise.
- */
-
if ((path[0] == '/') != (prefix[0] == '/'))
return NULL;
@@ -457,13 +447,11 @@ char* path_join(const char *root, const char *path, const char *rest) {
return strjoin(root, endswith(root, "/") ? "" : "/",
path[0] == '/' ? path+1 : path,
rest ? (endswith(path, "/") ? "" : "/") : NULL,
- rest && rest[0] == '/' ? rest+1 : rest,
- NULL);
+ rest && rest[0] == '/' ? rest+1 : rest);
else
return strjoin(path,
rest ? (endswith(path, "/") ? "" : "/") : NULL,
- rest && rest[0] == '/' ? rest+1 : rest,
- NULL);
+ rest && rest[0] == '/' ? rest+1 : rest);
}
int find_binary(const char *name, char **ret) {
@@ -507,7 +495,7 @@ int find_binary(const char *name, char **ret) {
if (!path_is_absolute(element))
continue;
- j = strjoin(element, "/", name, NULL);
+ j = strjoin(element, "/", name);
if (!j)
return -ENOMEM;
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index cd9c0f7e5..359c3a4e4 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -235,14 +235,14 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
return h;
if (max_length == 0)
- r = strjoin("[", t, "]", NULL);
+ r = strjoin("[", t, "]");
else {
size_t l;
l = strlen(t);
if (l + 3 <= max_length)
- r = strjoin("[", t, "]", NULL);
+ r = strjoin("[", t, "]");
else if (max_length <= 6) {
r = new(char, max_length);
@@ -262,7 +262,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
e--;
*e = 0;
- r = strjoin("[", t, "...]", NULL);
+ r = strjoin("[", t, "...]");
}
}
if (!r)
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index ebe146b03..b906b581c 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -218,7 +218,7 @@ char *strappend(const char *s, const char *suffix) {
return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
}
-char *strjoin(const char *x, ...) {
+char *strjoin_real(const char *x, ...) {
va_list ap;
size_t l;
char *r, *p;
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index 66e55cb2c..4b5cb8c70 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -120,7 +120,8 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
char *strappend(const char *s, const char *suffix);
char *strnappend(const char *s, const char *suffix, size_t length);
-char *strjoin(const char *x, ...) _sentinel_;
+char *strjoin_real(const char *x, ...) _sentinel_;
+#define strjoin(a, ...) strjoin_real((a), __VA_ARGS__, NULL)
#define strjoina(a, ...) \
({ \
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index 463301eeb..21fec7316 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -275,7 +275,7 @@ int unit_name_build(const char *prefix, const char *instance, const char *suffix
if (!instance)
s = strappend(prefix, suffix);
else
- s = strjoin(prefix, "@", instance, suffix, NULL);
+ s = strjoin(prefix, "@", instance, suffix);
if (!s)
return -ENOMEM;
@@ -557,7 +557,7 @@ int unit_name_from_path_instance(const char *prefix, const char *path, const cha
if (r < 0)
return r;
- s = strjoin(prefix, "@", p, suffix, NULL);
+ s = strjoin(prefix, "@", p, suffix);
if (!s)
return -ENOMEM;
diff --git a/src/basic/util.c b/src/basic/util.c
index 27c3d4839..c73a7df19 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -131,7 +131,7 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) {
if (r < 0)
return log_oom();
- path = strjoin(*directory, "/", de->d_name, NULL);
+ path = strjoin(*directory, "/", de->d_name);
if (!path)
return log_oom();