1
0
mirror of https://github.com/systemd/systemd synced 2026-04-08 16:14: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 **k;
if (!l)
return NULL;
for (k = l; *k; k++)
for (char **k = l; *k; k++)
free(*k);
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) {
char * const *s, **t;
size_t p, q, i = 0, j;
size_t p, q, i = 0;
assert(a);
@ -195,7 +193,6 @@ int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) {
*a = t;
STRV_FOREACH(s, b) {
if (filter_duplicates && strv_contains(t, *s))
continue;
@ -212,7 +209,7 @@ int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates) {
return (int) i;
rollback:
for (j = 0; j < i; j++)
for (size_t j = 0; j < i; j++)
free(t[p + j]);
t[p] = NULL;
@ -285,7 +282,6 @@ int strv_split_full(char ***t, const char *s, const char *separators, ExtractFla
return -ENOMEM;
l[n++] = TAKE_PTR(word);
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) {
char **c;
size_t n, m, i;
size_t n, m;
if (!value)
return 0;
@ -494,18 +490,14 @@ int strv_insert(char ***l, size_t position, char *value) {
if (!c)
return -ENOMEM;
for (i = 0; i < position; i++)
for (size_t i = 0; i < position; i++)
c[i] = (*l)[i];
c[position] = value;
for (i = position; i < n; i++)
for (size_t i = position; i < n; i++)
c[i+1] = (*l)[i];
c[n+1] = NULL;
free(*l);
*l = c;
return 0;
return free_and_replace(*l, c);
}
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.
*/
const char *p;
size_t c = 0, i = 0;
char **v;
@ -666,7 +657,7 @@ char **strv_parse_nulstr(const char *s, size_t l) {
if (l <= 0)
return new0(char*, 1);
for (p = s; p < s + l; p++)
for (const char *p = s; p < s + l; p++)
if (*p == 0)
c++;
@ -677,8 +668,7 @@ char **strv_parse_nulstr(const char *s, size_t l) {
if (!v)
return NULL;
p = s;
while (p < s + l) {
for (const char *p = s; p < s + l; ) {
const char *e;
e = memchr(p, 0, s + l - p);
@ -827,13 +817,13 @@ int strv_extendf(char ***l, const char *format, ...) {
}
char** strv_reverse(char **l) {
size_t n, i;
size_t n;
n = strv_length(l);
if (n <= 1)
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]);
return l;
@ -870,18 +860,6 @@ bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t *
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) {
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) {
size_t i, j, k;
size_t i, k;
char **nl;
assert(l);
@ -922,15 +900,15 @@ int strv_extend_n(char ***l, const char *value, size_t n) {
if (!nl[i])
goto rollback;
}
nl[i] = NULL;
return 0;
rollback:
for (j = k; j < i; j++)
for (size_t j = k; j < i; j++)
free(nl[j]);
nl[k] = NULL;
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);
}
char ***strv_free_free(char ***l);
DEFINE_TRIVIAL_CLEANUP_FUNC(char***, strv_free_free);
char** strv_skip(char **l, 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;
case SET_LINK_MAC:
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().
* The first trial failed as the interface was up. */
* The first attempt failed as the interface was up. */
r = link_down(link);
if (r < 0) {
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 (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;
}
if (!ether_addr_is_local(&new_hw_addr->ether)) {
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;
}

View File

@ -917,17 +917,6 @@ TEST(strv_make_nulstr) {
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) {
const char * const t[] = {
"foo",