]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: make *_from_name() returns negative errno on error 10970/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Nov 2018 08:54:04 +0000 (17:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Nov 2018 11:20:50 +0000 (20:20 +0900)
src/basic/af-list.c
src/basic/arphrd-list.c
src/core/dbus-execute.c
src/core/load-fragment.c
src/nspawn/nspawn-settings.c
src/nspawn/nspawn.c
src/shared/socket-protocol-list.c
src/test/test-af-list.c
src/test/test-arphrd-list.c

index 866a1d43173e44cd820e4da62e56839f4a664fd3..cf03dfc6d3911f90e81d9f18f5a43c967397a2a1 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include <errno.h>
 #include <string.h>
 #include <sys/socket.h>
 
@@ -29,7 +30,7 @@ int af_from_name(const char *name) {
 
         sc = lookup_af(name, strlen(name));
         if (!sc)
-                return AF_UNSPEC;
+                return -EINVAL;
 
         return sc->id;
 }
index a7ae4b8162eae7119fc1f2dc651573b8cffa4029..a6b8fa9d84bfaf731193e98f1cd8b3ff28115ec5 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include <errno.h>
 #include <net/if_arp.h>
 #include <string.h>
 
@@ -29,7 +30,7 @@ int arphrd_from_name(const char *name) {
 
         sc = lookup_arphrd(name, strlen(name));
         if (!sc)
-                return 0;
+                return -EINVAL;
 
         return sc->id;
 }
index 39823c8675afecc95361fcaf4007299b23c84fe9..31f9099b98e872e8a9422df9f20f4f1cf510f378 100644 (file)
@@ -1517,8 +1517,8 @@ int bus_exec_context_set_transient_property(
                                 int af;
 
                                 af = af_from_name(*s);
-                                if (af <= 0)
-                                        return -EINVAL;
+                                if (af < 0)
+                                        return af;
 
                                 if (!invert == c->address_families_whitelist) {
                                         r = set_put(c->address_families, INT_TO_PTR(af));
index ce222e402308d102861a1657d8952accbd156b40..8b36365dd6d0212ef37343399418f78379be671f 100644 (file)
@@ -65,7 +65,7 @@ static int supported_socket_protocol_from_string(const char *s) {
 
         r = socket_protocol_from_name(s);
         if (r < 0)
-                return -EINVAL;
+                return r;
         if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP))
                 return -EPROTONOSUPPORT;
 
@@ -2871,8 +2871,8 @@ int config_parse_address_families(
                 }
 
                 af = af_from_name(word);
-                if (af <= 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0,
+                if (af < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, af,
                                    "Failed to parse address family, ignoring: %s", word);
                         continue;
                 }
index 264ec61ad9db7cf8b0480f2602cbebeb8572cc06..505e8cac4052402eed964be19c3ce6deb43602fa 100644 (file)
@@ -177,7 +177,6 @@ int config_parse_capability(
 
         for (;;) {
                 _cleanup_free_ char *word = NULL;
-                int cap;
 
                 r = extract_first_word(&rvalue, &word, NULL, 0);
                 if (r < 0) {
@@ -187,13 +186,13 @@ int config_parse_capability(
                 if (r == 0)
                         break;
 
-                cap = capability_from_name(word);
-                if (cap < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse capability, ignoring: %s", word);
+                r = capability_from_name(word);
+                if (r < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse capability, ignoring: %s", word);
                         continue;
                 }
 
-                u |= UINT64_C(1) << cap;
+                u |= UINT64_C(1) << r;
         }
 
         if (u == 0)
index c581514b297ddbb108b182393e587eab74e73819..6eddae49d993cf6dec0d5d1528bbec18913006c5 100644 (file)
@@ -774,17 +774,14 @@ static int parse_argv(int argc, char *argv[]) {
                                         else
                                                 minus = (uint64_t) -1;
                                 } else {
-                                        int cap;
-
-                                        cap = capability_from_name(t);
-                                        if (cap < 0)
-                                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                                       "Failed to parse capability %s.", t);
+                                        r = capability_from_name(t);
+                                        if (r < 0)
+                                                return log_error_errno(r, "Failed to parse capability %s.", t);
 
                                         if (c == ARG_CAPABILITY)
-                                                plus |= 1ULL << (uint64_t) cap;
+                                                plus |= 1ULL << r;
                                         else
-                                                minus |= 1ULL << (uint64_t) cap;
+                                                minus |= 1ULL << r;
                                 }
                         }
 
index 8041b84958ec33b209a23d4bd4e06a3a1ca9fd79..797f1e9507bff1af170458e76f1fdb28d753aeee 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include <errno.h>
 #include <netinet/in.h>
 #include <string.h>
 
@@ -29,7 +30,7 @@ int socket_protocol_from_name(const char *name) {
 
         sc = lookup_socket_protocol(name, strlen(name));
         if (!sc)
-                return 0;
+                return -EINVAL;
 
         return sc->id;
 }
index e9fd66b1e65c9e94c858788a2ab09485775e4957..c8ef3295b568556e7869f6bfebffbce318317ac8 100644 (file)
@@ -27,8 +27,8 @@ int main(int argc, const char *argv[]) {
 
         assert_se(af_to_name(af_max()) == NULL);
         assert_se(af_to_name(-1) == NULL);
-        assert_se(af_from_name("huddlduddl") == AF_UNSPEC);
-        assert_se(af_from_name("") == AF_UNSPEC);
+        assert_se(af_from_name("huddlduddl") == -EINVAL);
+        assert_se(af_from_name("") == -EINVAL);
 
         return 0;
 }
index fd4cd626231ad520ee9cca3c1bbbfdbc2fd1f4a6..9803c53f212a5caac8996132ef4073d3f29a8253 100644 (file)
@@ -27,8 +27,8 @@ int main(int argc, const char *argv[]) {
 
         assert_se(arphrd_to_name(arphrd_max()) == NULL);
         assert_se(arphrd_to_name(0) == NULL);
-        assert_se(arphrd_from_name("huddlduddl") == 0);
-        assert_se(arphrd_from_name("") == 0);
+        assert_se(arphrd_from_name("huddlduddl") == -EINVAL);
+        assert_se(arphrd_from_name("") == -EINVAL);
 
         return 0;
 }