Return -EINVAL from _from_string() functions

We'd return -1 (-EPERM), even though we have a general rule to use real errno
values. The particular case that caught my attention was:

$ sudo udevadm control -l asdf
Failed to parse log priority 'asdf': Operation not permitted

... but "git grep 'r =.*_from_string' src/" return 110 hits. Confusingly, some
of the _from_string functions already return a proper errno value, so not all
of those are broken, but probably quite a few.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-02-10 14:46:59 +01:00
parent 2d93c20e5f
commit 751db3b4cd
5 changed files with 20 additions and 18 deletions
+8 -6
View File
@@ -29,7 +29,7 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope) \
scope type name##_from_string(const char *s) { \
if (!s) \
return -1; \
return -EINVAL; \
int b = parse_boolean(s); \
if (b == 0) \
return (type) 0; \
@@ -60,14 +60,16 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
unsigned u = 0; \
type i; \
if (!s) \
return (type) -1; \
return -EINVAL; \
i = (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
if (i >= 0) \
return i; \
if (safe_atou(s, &u) >= 0 && u <= max) \
return (type) u; \
return (type) -1; \
} \
if (safe_atou(s, &u) < 0) \
return -EINVAL; \
if (u > max) \
return -EINVAL; \
return (type) u; \
}
#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \