summaryrefslogtreecommitdiff
path: root/src/libnm-systemd-shared
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-04-06 08:19:58 +0200
committerThomas Haller <thaller@redhat.com>2021-04-06 19:48:51 +0200
commit2a88de2280c9c5dcbb35fed02f766cd3f6911303 (patch)
treef722a4039a5b997e85cadcfffacb4bbb300fe6b9 /src/libnm-systemd-shared
parent68913466af49c738d7e226f55db15be70b22dbe6 (diff)
parentbae86ece1eca90673a9aa1cd15715444307262ff (diff)
downloadNetworkManager-2a88de2280c9c5dcbb35fed02f766cd3f6911303.tar.gz
systemd: merge branch systemd into master
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/808
Diffstat (limited to 'src/libnm-systemd-shared')
-rw-r--r--src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h4
-rw-r--r--src/libnm-systemd-shared/src/basic/env-util.c13
-rw-r--r--src/libnm-systemd-shared/src/basic/fileio.c37
-rw-r--r--src/libnm-systemd-shared/src/basic/ordered-set.c21
-rw-r--r--src/libnm-systemd-shared/src/basic/ordered-set.h12
-rw-r--r--src/libnm-systemd-shared/src/basic/parse-util.c2
-rw-r--r--src/libnm-systemd-shared/src/basic/path-util.c6
-rw-r--r--src/libnm-systemd-shared/src/basic/path-util.h2
-rw-r--r--src/libnm-systemd-shared/src/basic/socket-util.c2
-rw-r--r--src/libnm-systemd-shared/src/basic/socket-util.h3
10 files changed, 50 insertions, 52 deletions
diff --git a/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h b/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h
index fd8352ab69..e15032eaa2 100644
--- a/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h
+++ b/src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h
@@ -114,6 +114,10 @@ _nm_gettid(void)
#define HAVE_RT_SIGQUEUEINFO 0
#endif
+ #ifndef ALTIFNAMSIZ
+ #define ALTIFNAMSIZ 128
+ #endif
+
#define HAVE_LINUX_TIME_TYPES_H 0
#ifndef __COMPAR_FN_T
diff --git a/src/libnm-systemd-shared/src/basic/env-util.c b/src/libnm-systemd-shared/src/basic/env-util.c
index 7a66eed223..a13aaac5d7 100644
--- a/src/libnm-systemd-shared/src/basic/env-util.c
+++ b/src/libnm-systemd-shared/src/basic/env-util.c
@@ -518,10 +518,10 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
ALTERNATE_VALUE,
} state = WORD;
- const char *e, *word = format, *test_value;
+ const char *e, *word = format, *test_value = NULL; /* test_value is initialized to appease gcc */
char *k;
_cleanup_free_ char *r = NULL;
- size_t i, len;
+ size_t i, len = 0; /* len is initialized to appease gcc */
int nest = 0;
assert(format);
@@ -584,13 +584,12 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
word = e+1;
state = WORD;
} else if (*e == ':') {
- if (!(flags & REPLACE_ENV_ALLOW_EXTENDED))
+ if (flags & REPLACE_ENV_ALLOW_EXTENDED) {
+ len = e - word - 2;
+ state = TEST;
+ } else
/* Treat this as unsupported syntax, i.e. do no replacement */
state = WORD;
- else {
- len = e-word-2;
- state = TEST;
- }
}
break;
diff --git a/src/libnm-systemd-shared/src/basic/fileio.c b/src/libnm-systemd-shared/src/basic/fileio.c
index b3c5def57d..27ec9b96c8 100644
--- a/src/libnm-systemd-shared/src/basic/fileio.c
+++ b/src/libnm-systemd-shared/src/basic/fileio.c
@@ -124,7 +124,7 @@ int write_string_stream_ts(
const struct timespec *ts) {
bool needs_nl;
- int r, fd;
+ int r, fd = -1;
assert(f);
assert(line);
@@ -143,8 +143,8 @@ int write_string_stream_ts(
needs_nl = !(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n");
if (needs_nl && (flags & WRITE_STRING_FILE_DISABLE_BUFFER)) {
- /* If STDIO buffering was disabled, then let's append the newline character to the string itself, so
- * that the write goes out in one go, instead of two */
+ /* If STDIO buffering was disabled, then let's append the newline character to the string
+ * itself, so that the write goes out in one go, instead of two */
line = strjoina(line, "\n");
needs_nl = false;
@@ -167,6 +167,7 @@ int write_string_stream_ts(
if (ts) {
const struct timespec twice[2] = {*ts, *ts};
+ assert(fd >= 0);
if (futimens(fd, twice) < 0)
return -errno;
}
@@ -389,20 +390,10 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
if (fd < 0)
return -errno;
- /* Start size for files in /proc/ which usually report a file size of 0. (Files in /sys/ report a
- * file size of 4K, which is probably OK for sizing our initial buffer, and sysfs attributes can't be
- * larger anyway.)
- *
- * It's one less than 4k, so that the malloc() below allocates exactly 4k. */
- size = 4095;
-
/* Limit the number of attempts to read the number of bytes returned by fstat(). */
n_retries = 3;
for (;;) {
- if (n_retries <= 0)
- return -EIO;
-
if (fstat(fd, &st) < 0)
return -errno;
@@ -413,24 +404,20 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
assert_cc(READ_FULL_BYTES_MAX < SSIZE_MAX);
if (st.st_size > 0) {
if (st.st_size > READ_FULL_BYTES_MAX)
- return -E2BIG;
+ return -EFBIG;
size = st.st_size;
n_retries--;
} else {
- /* Double the buffer size */
- if (size >= READ_FULL_BYTES_MAX)
- return -E2BIG;
- if (size > READ_FULL_BYTES_MAX / 2 - 1)
- size = READ_FULL_BYTES_MAX; /* clamp to max */
- else
- size = size * 2 + 1; /* Stay always one less than page size, so we malloc evenly */
+ size = READ_FULL_BYTES_MAX;
+ n_retries = 0;
}
buf = malloc(size + 1);
if (!buf)
return -ENOMEM;
- size = malloc_usable_size(buf) - 1; /* Use a bigger allocation if we got it anyway */
+ /* Use a bigger allocation if we got it anyway, but not more than the limit. */
+ size = MIN(malloc_usable_size(buf) - 1, READ_FULL_BYTES_MAX);
for (;;) {
ssize_t k;
@@ -457,6 +444,9 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
* processing, let's try again either with a bigger guessed size or the new
* file size. */
+ if (n_retries <= 0)
+ return st.st_size > 0 ? -EIO : -EFBIG;
+
if (lseek(fd, 0, SEEK_SET) < 0)
return -errno;
@@ -470,8 +460,7 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
p = realloc(buf, n + 1);
if (!p)
return -ENOMEM;
-
- buf = TAKE_PTR(p);
+ buf = p;
}
if (ret_size)
diff --git a/src/libnm-systemd-shared/src/basic/ordered-set.c b/src/libnm-systemd-shared/src/basic/ordered-set.c
index db979864f5..62a36b5dc7 100644
--- a/src/libnm-systemd-shared/src/basic/ordered-set.c
+++ b/src/libnm-systemd-shared/src/basic/ordered-set.c
@@ -37,30 +37,33 @@ int ordered_set_consume(OrderedSet *s, void *p) {
return r;
}
-int ordered_set_put_strdup(OrderedSet *s, const char *p) {
+int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS) {
char *c;
int r;
assert(s);
assert(p);
+ r = _ordered_set_ensure_allocated(s, &string_hash_ops_free HASHMAP_DEBUG_PASS_ARGS);
+ if (r < 0)
+ return r;
+
+ if (ordered_set_contains(*s, p))
+ return 0;
+
c = strdup(p);
if (!c)
return -ENOMEM;
- r = ordered_set_consume(s, c);
- if (r == -EEXIST)
- return 0;
-
- return r;
+ return ordered_set_consume(*s, c);
}
-int ordered_set_put_strdupv(OrderedSet *s, char **l) {
+int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS) {
int n = 0, r;
char **i;
STRV_FOREACH(i, l) {
- r = ordered_set_put_strdup(s, *i);
+ r = _ordered_set_put_strdup(s, *i HASHMAP_DEBUG_PASS_ARGS);
if (r < 0)
return r;
@@ -70,7 +73,7 @@ int ordered_set_put_strdupv(OrderedSet *s, char **l) {
return n;
}
-int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l) {
+int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l) {
int n = 0, r;
char *p;
diff --git a/src/libnm-systemd-shared/src/basic/ordered-set.h b/src/libnm-systemd-shared/src/basic/ordered-set.h
index baf8202088..a377f20b1f 100644
--- a/src/libnm-systemd-shared/src/basic/ordered-set.h
+++ b/src/libnm-systemd-shared/src/basic/ordered-set.h
@@ -26,6 +26,10 @@ static inline OrderedSet* ordered_set_free_free(OrderedSet *s) {
return (OrderedSet*) ordered_hashmap_free_free((OrderedHashmap*) s);
}
+static inline int ordered_set_contains(OrderedSet *s, const void *p) {
+ return ordered_hashmap_contains((OrderedHashmap*) s, p);
+}
+
static inline int ordered_set_put(OrderedSet *s, void *p) {
return ordered_hashmap_put((OrderedHashmap*) s, p, p);
}
@@ -59,9 +63,11 @@ static inline char** ordered_set_get_strv(OrderedSet *s) {
}
int ordered_set_consume(OrderedSet *s, void *p);
-int ordered_set_put_strdup(OrderedSet *s, const char *p);
-int ordered_set_put_strdupv(OrderedSet *s, char **l);
-int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l);
+int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS);
+#define ordered_set_put_strdup(s, p) _ordered_set_put_strdup(s, p HASHMAP_DEBUG_SRC_ARGS)
+int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS);
+#define ordered_set_put_strdupv(s, l) _ordered_set_put_strdupv(s, l HASHMAP_DEBUG_SRC_ARGS)
+int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l);
void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
#define _ORDERED_SET_FOREACH(e, s, i) \
diff --git a/src/libnm-systemd-shared/src/basic/parse-util.c b/src/libnm-systemd-shared/src/basic/parse-util.c
index 76ae8e31d7..13758108fb 100644
--- a/src/libnm-systemd-shared/src/basic/parse-util.c
+++ b/src/libnm-systemd-shared/src/basic/parse-util.c
@@ -93,6 +93,7 @@ int parse_mode(const char *s, mode_t *ret) {
*ret = m;
return 0;
}
+#endif /* NM_IGNORED */
int parse_ifindex(const char *s) {
int ifi, r;
@@ -108,6 +109,7 @@ int parse_ifindex(const char *s) {
return ifi;
}
+#if 0 /* NM_IGNORED */
int parse_mtu(int family, const char *s, uint32_t *ret) {
uint64_t u;
size_t m;
diff --git a/src/libnm-systemd-shared/src/basic/path-util.c b/src/libnm-systemd-shared/src/basic/path-util.c
index cf1607a56c..a867e65a26 100644
--- a/src/libnm-systemd-shared/src/basic/path-util.c
+++ b/src/libnm-systemd-shared/src/basic/path-util.c
@@ -1203,10 +1203,4 @@ bool prefixed_path_strv_contains(char **l, const char *path) {
return false;
}
-
-bool credential_name_valid(const char *s) {
- /* We want that credential names are both valid in filenames (since that's our primary way to pass
- * them around) and as fdnames (which is how we might want to pass them around eventually) */
- return filename_is_valid(s) && fdname_is_valid(s);
-}
#endif /* NM_IGNORED */
diff --git a/src/libnm-systemd-shared/src/basic/path-util.h b/src/libnm-systemd-shared/src/basic/path-util.h
index e679e8a73d..48f0c873db 100644
--- a/src/libnm-systemd-shared/src/basic/path-util.h
+++ b/src/libnm-systemd-shared/src/basic/path-util.h
@@ -185,5 +185,3 @@ static inline const char *empty_to_root(const char *path) {
bool path_strv_contains(char **l, const char *path);
bool prefixed_path_strv_contains(char **l, const char *path);
-
-bool credential_name_valid(const char *s);
diff --git a/src/libnm-systemd-shared/src/basic/socket-util.c b/src/libnm-systemd-shared/src/basic/socket-util.c
index 0aef1617f9..da36c2806c 100644
--- a/src/libnm-systemd-shared/src/basic/socket-util.c
+++ b/src/libnm-systemd-shared/src/basic/socket-util.c
@@ -752,6 +752,7 @@ static const char* const ip_tos_table[] = {
};
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ip_tos, int, 0xff);
+#endif /* NM_IGNORED */
bool ifname_valid_full(const char *p, IfnameValidFlags flags) {
bool numeric = true;
@@ -809,6 +810,7 @@ bool ifname_valid_full(const char *p, IfnameValidFlags flags) {
return true;
}
+#if 0 /* NM_IGNORED */
bool address_label_valid(const char *p) {
if (isempty(p))
diff --git a/src/libnm-systemd-shared/src/basic/socket-util.h b/src/libnm-systemd-shared/src/basic/socket-util.h
index 51c03a1578..a8a915beeb 100644
--- a/src/libnm-systemd-shared/src/basic/socket-util.h
+++ b/src/libnm-systemd-shared/src/basic/socket-util.h
@@ -14,6 +14,7 @@
#include <sys/types.h>
#include <sys/un.h>
+#include "errno-util.h"
#include "macro.h"
#include "missing_network.h"
#include "missing_socket.h"
@@ -266,7 +267,7 @@ static inline int getsockopt_int(int fd, int level, int optname, int *ret) {
socklen_t sl = sizeof(v);
if (getsockopt(fd, level, optname, &v, &sl) < 0)
- return -errno;
+ return negative_errno();
if (sl != sizeof(v))
return -EIO;