1
0
mirror of https://github.com/systemd/systemd synced 2024-07-08 20:15:55 +00:00

parse-util: make parse_fd() return -EBADF

The previous error code -ERANGE is slightly ambiguous, and use more
specific one. This also drops unnecessary error handlings.

Follow-up for 754d8b9c33 and
e652663a04.
This commit is contained in:
Yu Watanabe 2023-05-06 14:11:08 +09:00 committed by Daan De Meyer
parent b3d12ac0da
commit d2132d3d8d
6 changed files with 4 additions and 13 deletions

View File

@ -343,7 +343,7 @@ int parse_fd(const char *t) {
return r;
if (fd < 0)
return -ERANGE;
return -EBADF;
return fd;
}

View File

@ -1003,10 +1003,8 @@ static int parse_argv(int argc, char *argv[]) {
FILE *f;
fd = parse_fd(optarg);
if (fd == -ERANGE)
return log_error_errno(fd, "Invalid serialization fd: %s", optarg);
if (fd < 0)
return log_error_errno(fd, "Failed to parse deserialize option \"%s\": %m", optarg);
return log_error_errno(fd, "Failed to parse serialization fd \"%s\": %m", optarg);
(void) fd_cloexec(fd, true);

View File

@ -216,8 +216,6 @@ static int parse_argv(int argc, char *argv[]) {
int fdnr;
fdnr = parse_fd(optarg);
if (fdnr == -ERANGE)
return log_error_errno(fdnr, "File descriptor can't be negative: %s", optarg);
if (fdnr < 0)
return log_error_errno(fdnr, "Failed to parse file descriptor: %s", optarg);

View File

@ -450,8 +450,6 @@ int bpf_program_deserialize_attachment(const char *v, FDSet *fds, BPFProgram **b
return -EINVAL;
ifd = parse_fd(sfd);
if (ifd == -ERANGE)
return -EBADF;
if (ifd < 0)
return r;

View File

@ -3061,9 +3061,6 @@ int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *f
buf = strndupa_safe(v, n);
fd = parse_fd(buf);
if (fd == -ERANGE)
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"VarlinkServerSocket varlink-server-socket-fd= has an invalid value: %s", buf);
if (fd < 0)
return log_debug_errno(fd, "Unable to parse VarlinkServerSocket varlink-server-socket-fd=%s: %m", buf);
if (!fdset_contains(fds, fd))

View File

@ -869,8 +869,8 @@ TEST(parse_fd) {
assert_se(parse_fd("0") == 0);
assert_se(parse_fd("1") == 1);
assert_se(parse_fd("-1") == -ERANGE);
assert_se(parse_fd("-3") == -ERANGE);
assert_se(parse_fd("-1") == -EBADF);
assert_se(parse_fd("-3") == -EBADF);
assert_se(parse_fd("") == -EINVAL);
assert_se(parse_fd("12.3") == -EINVAL);