1
0
mirror of https://github.com/systemd/systemd synced 2026-04-09 08:34:50 +02:00

Compare commits

..

6 Commits

Author SHA1 Message Date
Yu Watanabe
f5caacec1c
Merge pull request #21533 from yuwata/network-trivial-follow-ups
network: trivial follow-ups
2021-11-27 06:42:19 +09:00
Yu Watanabe
e76d491c87
Merge pull request #21530 from keszybz/strv-cleanup
Modernize style and drop strv_free_free
2021-11-27 06:41:56 +09:00
Zbigniew Jędrzejewski-Szmek
1ba193d73e basic/strv: drop strv_free_free
I think the function name is confusing: we generally say "free_free" when
both keys and values are freed in a hash map, but here the type is an
array of strvs, so the name should be something like strv_array_free.

The function is unused since 143fadf369a18449464956206226761e49be1928 (2018),
let's just drop it.
2021-11-26 14:58:44 +01:00
Zbigniew Jędrzejewski-Szmek
14337c374a basic/strv: inline variables and modernize style a bit 2021-11-26 14:52:03 +01:00
Yu Watanabe
36edc2c956 network: update comment
Addresses https://github.com/systemd/systemd/pull/21517#discussion_r757096584.
2021-11-26 21:05:52 +09:00
Yu Watanabe
4bd2c4e8e0 netif-util: update log message
Follow-up for 37593b7c488f7b957936500158f200af16534c6b.
2021-11-26 21:05:52 +09:00
5 changed files with 57 additions and 93 deletions

View File

@ -70,12 +70,10 @@ char *strv_find_startswith(char * const *l, const char *name) {
} }
char** strv_free(char **l) { char** strv_free(char **l) {
char **k;
if (!l) if (!l)
return NULL; return NULL;
for (k = l; *k; k++) for (char **k = l; *k; k++)
free(*k); free(*k);
return mfree(l); return mfree(l);
@ -174,7 +172,7 @@ char **strv_new_internal(const char *x, ...) {
int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) { int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) {
char * const *s, **t; char * const *s, **t;
size_t p, q, i = 0, j; size_t p, q, i = 0;
assert(a); assert(a);
@ -195,7 +193,6 @@ int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) {
*a = t; *a = t;
STRV_FOREACH(s, b) { STRV_FOREACH(s, b) {
if (filter_duplicates && strv_contains(t, *s)) if (filter_duplicates && strv_contains(t, *s))
continue; continue;
@ -212,7 +209,7 @@ int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) {
return (int) i; return (int) i;
rollback: rollback:
for (j = 0; j < i; j++) for (size_t j = 0; j < i; j++)
free(t[p + j]); free(t[p + j]);
t[p] = NULL; t[p] = NULL;
@ -285,7 +282,6 @@ int strv_split_full(char ***t, const char *s, const char *separators, ExtractFla
return -ENOMEM; return -ENOMEM;
l[n++] = TAKE_PTR(word); l[n++] = TAKE_PTR(word);
l[n] = NULL; l[n] = NULL;
} }
@ -477,7 +473,7 @@ int strv_push_pair(char ***l, char *a, char *b) {
int strv_insert(char ***l, size_t position, char *value) { int strv_insert(char ***l, size_t position, char *value) {
char **c; char **c;
size_t n, m, i; size_t n, m;
if (!value) if (!value)
return 0; return 0;
@ -494,18 +490,14 @@ int strv_insert(char ***l, size_t position, char *value) {
if (!c) if (!c)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < position; i++) for (size_t i = 0; i < position; i++)
c[i] = (*l)[i]; c[i] = (*l)[i];
c[position] = value; c[position] = value;
for (i = position; i < n; i++) for (size_t i = position; i < n; i++)
c[i+1] = (*l)[i]; c[i+1] = (*l)[i];
c[n+1] = NULL; c[n+1] = NULL;
free(*l); return free_and_replace(*l, c);
*l = c;
return 0;
} }
int strv_consume(char ***l, char *value) { int strv_consume(char ***l, char *value) {
@ -657,7 +649,6 @@ char **strv_parse_nulstr(const char *s, size_t l) {
* empty strings in s. * empty strings in s.
*/ */
const char *p;
size_t c = 0, i = 0; size_t c = 0, i = 0;
char **v; char **v;
@ -666,7 +657,7 @@ char **strv_parse_nulstr(const char *s, size_t l) {
if (l <= 0) if (l <= 0)
return new0(char*, 1); return new0(char*, 1);
for (p = s; p < s + l; p++) for (const char *p = s; p < s + l; p++)
if (*p == 0) if (*p == 0)
c++; c++;
@ -677,8 +668,7 @@ char **strv_parse_nulstr(const char *s, size_t l) {
if (!v) if (!v)
return NULL; return NULL;
p = s; for (const char *p = s; p < s + l; ) {
while (p < s + l) {
const char *e; const char *e;
e = memchr(p, 0, s + l - p); e = memchr(p, 0, s + l - p);
@ -827,13 +817,13 @@ int strv_extendf(char ***l, const char *format, ...) {
} }
char** strv_reverse(char **l) { char** strv_reverse(char **l) {
size_t n, i; size_t n;
n = strv_length(l); n = strv_length(l);
if (n <= 1) if (n <= 1)
return l; return l;
for (i = 0; i < n / 2; i++) for (size_t i = 0; i < n / 2; i++)
SWAP_TWO(l[i], l[n-1-i]); SWAP_TWO(l[i], l[n-1-i]);
return l; return l;
@ -870,18 +860,6 @@ bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t *
return false; return false;
} }
char ***strv_free_free(char ***l) {
char ***i;
if (!l)
return NULL;
for (i = l; *i; i++)
strv_free(*i);
return mfree(l);
}
char** strv_skip(char **l, size_t n) { char** strv_skip(char **l, size_t n) {
while (n > 0) { while (n > 0) {
@ -895,7 +873,7 @@ char **strv_skip(char **l, size_t n) {
} }
int strv_extend_n(char ***l, const char *value, size_t n) { int strv_extend_n(char ***l, const char *value, size_t n) {
size_t i, j, k; size_t i, k;
char **nl; char **nl;
assert(l); assert(l);
@ -922,15 +900,15 @@ int strv_extend_n(char ***l, const char *value, size_t n) {
if (!nl[i]) if (!nl[i])
goto rollback; goto rollback;
} }
nl[i] = NULL; nl[i] = NULL;
return 0; return 0;
rollback: rollback:
for (j = k; j < i; j++) for (size_t j = k; j < i; j++)
free(nl[j]); free(nl[j]);
nl[k] = NULL; nl[k] = NULL;
return -ENOMEM; return -ENOMEM;
} }

View File

@ -228,9 +228,6 @@ static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, i
strv_fnmatch_full(patterns, s, flags, NULL); strv_fnmatch_full(patterns, s, flags, NULL);
} }
char ***strv_free_free(char ***l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char***, strv_free_free);
char** strv_skip(char **l, size_t n); char** strv_skip(char **l, size_t n);
int strv_extend_n(char ***l, const char *value, size_t n); int strv_extend_n(char ***l, const char *value, size_t n);

View File

@ -543,9 +543,9 @@ static bool link_is_ready_to_call_set_link(Request *req) {
break; break;
case SET_LINK_MAC: case SET_LINK_MAC:
if (req->netlink_handler == link_set_mac_handler) { if (req->netlink_handler == link_set_mac_handler) {
/* This is the second trial to set hardware address. On the first attempt /* This is the second attempt to set hardware address. On the first attempt
* req->netlink_handler points to link_set_mac_allow_retry_handler(). * req->netlink_handler points to link_set_mac_allow_retry_handler().
* The first trial failed as the interface was up. */ * The first attempt failed as the interface was up. */
r = link_down(link); r = link_down(link);
if (r < 0) { if (r < 0) {
link_enter_failed(link); link_enter_failed(link);

View File

@ -148,14 +148,14 @@ int net_verify_hardware_address(
if (ether_addr_is_multicast(&new_hw_addr->ether)) { if (ether_addr_is_multicast(&new_hw_addr->ether)) {
if (warn_invalid) if (warn_invalid)
log_link_warning(&link, "Specified MAC address has multicast bit set, clearing the bit."); log_link_warning(&link, "Specified MAC address has the multicast bit set, clearing the bit.");
new_hw_addr->bytes[0] &= 0xfe; new_hw_addr->bytes[0] &= 0xfe;
} }
if (!ether_addr_is_local(&new_hw_addr->ether)) { if (!ether_addr_is_local(&new_hw_addr->ether)) {
if (warn_invalid) if (warn_invalid)
log_link_warning(&link, "Specified MAC address has not local assignment bit set, setting the bit."); log_link_warning(&link, "Specified MAC address does not have the local assignment bit set, setting the bit.");
new_hw_addr->bytes[0] |= 0x02; new_hw_addr->bytes[0] |= 0x02;
} }

View File

@ -917,17 +917,6 @@ TEST(strv_make_nulstr) {
test_strv_make_nulstr_one(STRV_MAKE("foo", "bar", "quuux")); test_strv_make_nulstr_one(STRV_MAKE("foo", "bar", "quuux"));
} }
TEST(strv_free_free) {
char ***t;
assert_se(t = new(char**, 3));
assert_se(t[0] = strv_new("a", "b"));
assert_se(t[1] = strv_new("c", "d", "e"));
t[2] = NULL;
t = strv_free_free(t);
}
TEST(foreach_string) { TEST(foreach_string) {
const char * const t[] = { const char * const t[] = {
"foo", "foo",