diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-07-30 13:08:52 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-09 09:34:54 +0200 |
commit | dd630d3cac6d72e2f4661273d2b28c95c545881c (patch) | |
tree | 3fa0523f3f7f62321d21b0d1b7e81905a06f4d5b /src/libsystemd/sd-login/sd-login.c | |
parent | Rewrite sd_machine_get_ifindices() to avoid FOREACH_WORD() (diff) | |
download | systemd-dd630d3cac6d72e2f4661273d2b28c95c545881c.tar.xz systemd-dd630d3cac6d72e2f4661273d2b28c95c545881c.zip |
Let sd_machine_get_ifindices() omit the output param too
Nowadays we do that almost everywhere, let's also do it here.
Diffstat (limited to '')
-rw-r--r-- | src/libsystemd/sd-login/sd-login.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 3828fa58e4..601a27ab57 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -900,7 +900,6 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ret_ifindices) int r; assert_return(machine_name_is_valid(machine), -EINVAL); - assert_return(ret_ifindices, -EINVAL); p = strjoina("/run/systemd/machines/", machine); r = parse_env_file(NULL, p, "NETIF", &netif_line); @@ -918,9 +917,12 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ret_ifindices) return -ENOMEM; size_t n = 0; - int *ifindices = new(int, strv_length(tt)); - if (!ifindices) - return -ENOMEM; + int *ifindices; + if (ret_ifindices) { + ifindices = new(int, strv_length(tt)); + if (!ifindices) + return -ENOMEM; + } for (size_t i = 0; tt[i]; i++) { int ind; @@ -930,10 +932,13 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ret_ifindices) /* Return -EUCLEAN to distinguish from -EINVAL for invalid args */ return ind == -EINVAL ? -EUCLEAN : ind; - ifindices[n++] = ind; + if (ret_ifindices) + ifindices[n] = ind; + n++; } - *ret_ifindices = ifindices; + if (ret_ifindices) + *ret_ifindices = ifindices; return n; } |