Merge pull request #10970 from yuwata/from-name-return-negative-errno
util: make *_from_name() returns negative errno on error
This commit is contained in:
commit
50ae773f85
|
@ -1388,6 +1388,8 @@ includes = include_directories('src/basic',
|
|||
|
||||
add_project_arguments('-include', 'config.h', language : 'c')
|
||||
|
||||
generate_gperfs = find_program('tools/generate-gperfs.py')
|
||||
|
||||
subdir('po')
|
||||
subdir('catalog')
|
||||
subdir('src/systemd')
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -179,8 +179,6 @@ basic_sources = files('''
|
|||
|
||||
missing_h = files('missing.h')
|
||||
|
||||
generate_gperfs = find_program('generate-gperfs.py')
|
||||
|
||||
generate_af_list = find_program('generate-af-list.sh')
|
||||
af_list_txt = custom_target(
|
||||
'af-list.txt',
|
||||
|
@ -209,19 +207,11 @@ errno_list_txt = custom_target(
|
|||
command : [generate_errno_list, cpp],
|
||||
capture : true)
|
||||
|
||||
generate_socket_protocol_list = find_program('generate-socket-protocol-list.sh')
|
||||
socket_protocol_list_txt = custom_target(
|
||||
'socket-protocol-list.txt',
|
||||
output : 'socket-protocol-list.txt',
|
||||
command : [generate_socket_protocol_list, cpp],
|
||||
capture : true)
|
||||
|
||||
generated_gperf_headers = []
|
||||
foreach item : [['af', af_list_txt, 'af', ''],
|
||||
['arphrd', arphrd_list_txt, 'arphrd', 'ARPHRD_'],
|
||||
['cap', cap_list_txt, 'capability', ''],
|
||||
['errno', errno_list_txt, 'errno', ''],
|
||||
['socket-protocol', socket_protocol_list_txt, 'socket_protocol', 'IPPROTO_']]
|
||||
['errno', errno_list_txt, 'errno', '']]
|
||||
|
||||
fname = '@0@-from-name.gperf'.format(item[0])
|
||||
gperf_file = custom_target(
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,6 +186,45 @@ if conf.get('HAVE_KMOD') == 1
|
|||
shared_sources += files('module-util.c')
|
||||
endif
|
||||
|
||||
generate_socket_protocol_list = find_program('generate-socket-protocol-list.sh')
|
||||
socket_protocol_list_txt = custom_target(
|
||||
'socket-protocol-list.txt',
|
||||
output : 'socket-protocol-list.txt',
|
||||
command : [generate_socket_protocol_list, cpp],
|
||||
capture : true)
|
||||
|
||||
fname = 'socket-protocol-from-name.gperf'
|
||||
gperf_file = custom_target(
|
||||
fname,
|
||||
input : socket_protocol_list_txt,
|
||||
output : fname,
|
||||
command : [generate_gperfs, 'socket_protocol', 'IPPROTO_', '@INPUT@'],
|
||||
capture : true)
|
||||
|
||||
fname = 'socket-protocol-from-name.h'
|
||||
target1 = custom_target(
|
||||
fname,
|
||||
input : gperf_file,
|
||||
output : fname,
|
||||
command : [gperf,
|
||||
'-L', 'ANSI-C', '-t', '--ignore-case',
|
||||
'-N', 'lookup_socket_protocol',
|
||||
'-H', 'hash_socket_protocol_name',
|
||||
'-p', '-C',
|
||||
'@INPUT@'],
|
||||
capture : true)
|
||||
|
||||
fname = 'socket-protocol-to-name.h'
|
||||
awkscript = 'socket-protocol-to-name.awk'
|
||||
target2 = custom_target(
|
||||
fname,
|
||||
input : [awkscript, socket_protocol_list_txt],
|
||||
output : fname,
|
||||
command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
|
||||
capture : true)
|
||||
|
||||
shared_sources += [target1, target2]
|
||||
|
||||
libshared_name = 'systemd-shared-@0@'.format(meson.project_version())
|
||||
|
||||
libshared_deps = [threads,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue