tree-wide: use parse_fd()
This commit is contained in:
+2
-1
@@ -416,7 +416,8 @@ int close_all_fds(const int except[], size_t n_except) {
|
|||||||
if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN))
|
if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (safe_atoi(de->d_name, &fd) < 0)
|
fd = parse_fd(de->d_name);
|
||||||
|
if (fd < 0)
|
||||||
/* Let's better ignore this, just in case */
|
/* Let's better ignore this, just in case */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -938,7 +938,7 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
|
|||||||
} else if (streq(key, "pipe-fd")) {
|
} else if (streq(key, "pipe-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse pipe-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse pipe-fd value: %s", value);
|
||||||
else {
|
else {
|
||||||
safe_close(a->pipe_fd);
|
safe_close(a->pipe_fd);
|
||||||
|
|||||||
@@ -645,12 +645,12 @@ void dynamic_user_deserialize_one(Manager *m, const char *value, FDSet *fds) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safe_atoi(s0, &fd0) < 0 || !fdset_contains(fds, fd0)) {
|
if ((fd0 = parse_fd(s0)) < 0 || !fdset_contains(fds, fd0)) {
|
||||||
log_debug("Unable to process dynamic user fd specification.");
|
log_debug("Unable to process dynamic user fd specification.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safe_atoi(s1, &fd1) < 0 || !fdset_contains(fds, fd1)) {
|
if ((fd1 = parse_fd(s1)) < 0 || !fdset_contains(fds, fd1)) {
|
||||||
log_debug("Unable to process dynamic user fd specification.");
|
log_debug("Unable to process dynamic user fd specification.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -7338,7 +7338,7 @@ int exec_shared_runtime_deserialize_compat(Unit *u, const char *key, const char
|
|||||||
} else if (streq(key, "netns-socket-0")) {
|
} else if (streq(key, "netns-socket-0")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || !fdset_contains(fds, fd)) {
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd)) {
|
||||||
log_unit_debug(u, "Failed to parse netns socket value: %s", value);
|
log_unit_debug(u, "Failed to parse netns socket value: %s", value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -7349,7 +7349,7 @@ int exec_shared_runtime_deserialize_compat(Unit *u, const char *key, const char
|
|||||||
} else if (streq(key, "netns-socket-1")) {
|
} else if (streq(key, "netns-socket-1")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || !fdset_contains(fds, fd)) {
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd)) {
|
||||||
log_unit_debug(u, "Failed to parse netns socket value: %s", value);
|
log_unit_debug(u, "Failed to parse netns socket value: %s", value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -7422,9 +7422,9 @@ int exec_shared_runtime_deserialize_one(Manager *m, const char *value, FDSet *fd
|
|||||||
n = strcspn(v, " ");
|
n = strcspn(v, " ");
|
||||||
buf = strndupa_safe(v, n);
|
buf = strndupa_safe(v, n);
|
||||||
|
|
||||||
r = safe_atoi(buf, &netns_fdpair[0]);
|
netns_fdpair[0] = parse_fd(buf);
|
||||||
if (r < 0)
|
if (netns_fdpair[0] < 0)
|
||||||
return log_debug_errno(r, "Unable to parse exec-runtime specification netns-socket-0=%s: %m", buf);
|
return log_debug_errno(netns_fdpair[0], "Unable to parse exec-runtime specification netns-socket-0=%s: %m", buf);
|
||||||
if (!fdset_contains(fds, netns_fdpair[0]))
|
if (!fdset_contains(fds, netns_fdpair[0]))
|
||||||
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
||||||
"exec-runtime specification netns-socket-0= refers to unknown fd %d: %m", netns_fdpair[0]);
|
"exec-runtime specification netns-socket-0= refers to unknown fd %d: %m", netns_fdpair[0]);
|
||||||
@@ -7441,9 +7441,9 @@ int exec_shared_runtime_deserialize_one(Manager *m, const char *value, FDSet *fd
|
|||||||
n = strcspn(v, " ");
|
n = strcspn(v, " ");
|
||||||
buf = strndupa_safe(v, n);
|
buf = strndupa_safe(v, n);
|
||||||
|
|
||||||
r = safe_atoi(buf, &netns_fdpair[1]);
|
netns_fdpair[1] = parse_fd(buf);
|
||||||
if (r < 0)
|
if (netns_fdpair[1] < 0)
|
||||||
return log_debug_errno(r, "Unable to parse exec-runtime specification netns-socket-1=%s: %m", buf);
|
return log_debug_errno(netns_fdpair[1], "Unable to parse exec-runtime specification netns-socket-1=%s: %m", buf);
|
||||||
if (!fdset_contains(fds, netns_fdpair[1]))
|
if (!fdset_contains(fds, netns_fdpair[1]))
|
||||||
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
||||||
"exec-runtime specification netns-socket-1= refers to unknown fd %d: %m", netns_fdpair[1]);
|
"exec-runtime specification netns-socket-1= refers to unknown fd %d: %m", netns_fdpair[1]);
|
||||||
@@ -7460,9 +7460,9 @@ int exec_shared_runtime_deserialize_one(Manager *m, const char *value, FDSet *fd
|
|||||||
n = strcspn(v, " ");
|
n = strcspn(v, " ");
|
||||||
buf = strndupa_safe(v, n);
|
buf = strndupa_safe(v, n);
|
||||||
|
|
||||||
r = safe_atoi(buf, &ipcns_fdpair[0]);
|
ipcns_fdpair[0] = parse_fd(buf);
|
||||||
if (r < 0)
|
if (ipcns_fdpair[0] < 0)
|
||||||
return log_debug_errno(r, "Unable to parse exec-runtime specification ipcns-socket-0=%s: %m", buf);
|
return log_debug_errno(ipcns_fdpair[0], "Unable to parse exec-runtime specification ipcns-socket-0=%s: %m", buf);
|
||||||
if (!fdset_contains(fds, ipcns_fdpair[0]))
|
if (!fdset_contains(fds, ipcns_fdpair[0]))
|
||||||
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
||||||
"exec-runtime specification ipcns-socket-0= refers to unknown fd %d: %m", ipcns_fdpair[0]);
|
"exec-runtime specification ipcns-socket-0= refers to unknown fd %d: %m", ipcns_fdpair[0]);
|
||||||
@@ -7479,9 +7479,9 @@ int exec_shared_runtime_deserialize_one(Manager *m, const char *value, FDSet *fd
|
|||||||
n = strcspn(v, " ");
|
n = strcspn(v, " ");
|
||||||
buf = strndupa_safe(v, n);
|
buf = strndupa_safe(v, n);
|
||||||
|
|
||||||
r = safe_atoi(buf, &ipcns_fdpair[1]);
|
ipcns_fdpair[1] = parse_fd(buf);
|
||||||
if (r < 0)
|
if (ipcns_fdpair[1] < 0)
|
||||||
return log_debug_errno(r, "Unable to parse exec-runtime specification ipcns-socket-1=%s: %m", buf);
|
return log_debug_errno(ipcns_fdpair[1], "Unable to parse exec-runtime specification ipcns-socket-1=%s: %m", buf);
|
||||||
if (!fdset_contains(fds, ipcns_fdpair[1]))
|
if (!fdset_contains(fds, ipcns_fdpair[1]))
|
||||||
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
||||||
"exec-runtime specification ipcns-socket-1= refers to unknown fd %d: %m", ipcns_fdpair[1]);
|
"exec-runtime specification ipcns-socket-1= refers to unknown fd %d: %m", ipcns_fdpair[1]);
|
||||||
|
|||||||
+4
-6
@@ -1002,13 +1002,11 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
int fd;
|
int fd;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
r = safe_atoi(optarg, &fd);
|
fd = parse_fd(optarg);
|
||||||
if (r < 0)
|
if (fd == -ERANGE)
|
||||||
return log_error_errno(r, "Failed to parse deserialize option \"%s\": %m", optarg);
|
return log_error_errno(fd, "Invalid deserialize fd: %s", optarg);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
return log_error_errno(fd, "Failed to parse deserialize option \"%s\": %m", optarg);
|
||||||
"Invalid deserialize fd: %d",
|
|
||||||
fd);
|
|
||||||
|
|
||||||
(void) fd_cloexec(fd, true);
|
(void) fd_cloexec(fd, true);
|
||||||
|
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
|
|||||||
} else if ((val = startswith(l, "notify-fd="))) {
|
} else if ((val = startswith(l, "notify-fd="))) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(val, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(val)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_notice("Failed to parse notify fd, ignoring: \"%s\"", val);
|
log_notice("Failed to parse notify fd, ignoring: \"%s\"", val);
|
||||||
else {
|
else {
|
||||||
m->notify_event_source = sd_event_source_disable_unref(m->notify_event_source);
|
m->notify_event_source = sd_event_source_disable_unref(m->notify_event_source);
|
||||||
@@ -492,7 +492,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
|
|||||||
} else if ((val = startswith(l, "cgroups-agent-fd="))) {
|
} else if ((val = startswith(l, "cgroups-agent-fd="))) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(val, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(val)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_notice("Failed to parse cgroups agent fd, ignoring.: %s", val);
|
log_notice("Failed to parse cgroups agent fd, ignoring.: %s", val);
|
||||||
else {
|
else {
|
||||||
m->cgroups_agent_event_source = sd_event_source_disable_unref(m->cgroups_agent_event_source);
|
m->cgroups_agent_event_source = sd_event_source_disable_unref(m->cgroups_agent_event_source);
|
||||||
|
|||||||
+6
-6
@@ -3235,7 +3235,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
} else if (streq(key, "socket-fd")) {
|
} else if (streq(key, "socket-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse socket-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse socket-fd value: %s", value);
|
||||||
else {
|
else {
|
||||||
asynchronous_close(s->socket_fd);
|
asynchronous_close(s->socket_fd);
|
||||||
@@ -3246,7 +3246,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
int fd, do_poll;
|
int fd, do_poll;
|
||||||
|
|
||||||
r = extract_first_word(&value, &fdv, NULL, 0);
|
r = extract_first_word(&value, &fdv, NULL, 0);
|
||||||
if (r <= 0 || safe_atoi(fdv, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd)) {
|
if (r <= 0 || (fd = parse_fd(fdv)) < 0 || !fdset_contains(fds, fd)) {
|
||||||
log_unit_debug(u, "Failed to parse fd-store-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse fd-store-fd value: %s", value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3324,7 +3324,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
} else if (streq(key, "stdin-fd")) {
|
} else if (streq(key, "stdin-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse stdin-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse stdin-fd value: %s", value);
|
||||||
else {
|
else {
|
||||||
asynchronous_close(s->stdin_fd);
|
asynchronous_close(s->stdin_fd);
|
||||||
@@ -3334,7 +3334,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
} else if (streq(key, "stdout-fd")) {
|
} else if (streq(key, "stdout-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse stdout-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse stdout-fd value: %s", value);
|
||||||
else {
|
else {
|
||||||
asynchronous_close(s->stdout_fd);
|
asynchronous_close(s->stdout_fd);
|
||||||
@@ -3344,7 +3344,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
} else if (streq(key, "stderr-fd")) {
|
} else if (streq(key, "stderr-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse stderr-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse stderr-fd value: %s", value);
|
||||||
else {
|
else {
|
||||||
asynchronous_close(s->stderr_fd);
|
asynchronous_close(s->stderr_fd);
|
||||||
@@ -3354,7 +3354,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
} else if (streq(key, "exec-fd")) {
|
} else if (streq(key, "exec-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(value)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse exec-fd value: %s", value);
|
log_unit_debug(u, "Failed to parse exec-fd value: %s", value);
|
||||||
else {
|
else {
|
||||||
s->exec_fd_event_source = sd_event_source_disable_unref(s->exec_fd_event_source);
|
s->exec_fd_event_source = sd_event_source_disable_unref(s->exec_fd_event_source);
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
else if (STR_IN_SET(l, "ipv4-socket-bind-bpf-link-fd", "ipv6-socket-bind-bpf-link-fd")) {
|
else if (STR_IN_SET(l, "ipv4-socket-bind-bpf-link-fd", "ipv6-socket-bind-bpf-link-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(v, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
if ((fd = parse_fd(v)) < 0 || !fdset_contains(fds, fd))
|
||||||
log_unit_debug(u, "Failed to parse %s value: %s, ignoring.", l, v);
|
log_unit_debug(u, "Failed to parse %s value: %s, ignoring.", l, v);
|
||||||
else {
|
else {
|
||||||
if (fdset_remove(fds, fd) < 0) {
|
if (fdset_remove(fds, fd) < 0) {
|
||||||
@@ -423,7 +423,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
} else if (streq(l, "restrict-ifaces-bpf-fd")) {
|
} else if (streq(l, "restrict-ifaces-bpf-fd")) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (safe_atoi(v, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd)) {
|
if ((fd = parse_fd(v)) < 0 || !fdset_contains(fds, fd)) {
|
||||||
log_unit_debug(u, "Failed to parse restrict-ifaces-bpf-fd value: %s", v);
|
log_unit_debug(u, "Failed to parse restrict-ifaces-bpf-fd value: %s", v);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -215,11 +215,11 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
_cleanup_close_ int owned_fd = -EBADF;
|
_cleanup_close_ int owned_fd = -EBADF;
|
||||||
int fdnr;
|
int fdnr;
|
||||||
|
|
||||||
r = safe_atoi(optarg, &fdnr);
|
fdnr = parse_fd(optarg);
|
||||||
if (r < 0)
|
if (fdnr == -ERANGE)
|
||||||
return log_error_errno(r, "Failed to parse file descriptor: %s", optarg);
|
return log_error_errno(fdnr, "File descriptor can't be negative: %s", optarg);
|
||||||
if (fdnr < 0)
|
if (fdnr < 0)
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "File descriptor can't be negative: %i", fdnr);
|
return log_error_errno(fdnr, "Failed to parse file descriptor: %s", optarg);
|
||||||
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
/* Take possession of all passed fds */
|
/* Take possession of all passed fds */
|
||||||
|
|||||||
@@ -449,11 +449,11 @@ int bpf_program_deserialize_attachment(const char *v, FDSet *fds, BPFProgram **b
|
|||||||
if (r == 0)
|
if (r == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
r = safe_atoi(sfd, &ifd);
|
ifd = parse_fd(sfd);
|
||||||
if (r < 0)
|
if (ifd == -ERANGE)
|
||||||
return r;
|
|
||||||
if (ifd < 0)
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
if (ifd < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
/* Extract second word: the attach type */
|
/* Extract second word: the attach type */
|
||||||
r = extract_first_word(&v, &sat, NULL, 0);
|
r = extract_first_word(&v, &sat, NULL, 0);
|
||||||
|
|||||||
@@ -3060,12 +3060,12 @@ int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *f
|
|||||||
n = strcspn(v, " ");
|
n = strcspn(v, " ");
|
||||||
buf = strndupa_safe(v, n);
|
buf = strndupa_safe(v, n);
|
||||||
|
|
||||||
r = safe_atoi(buf, &fd);
|
fd = parse_fd(buf);
|
||||||
if (r < 0)
|
if (fd == -ERANGE)
|
||||||
return log_debug_errno(r, "Unable to parse VarlinkServerSocket varlink-server-socket-fd=%s: %m", buf);
|
|
||||||
if (fd < 0)
|
|
||||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
"VarlinkServerSocket varlink-server-socket-fd= has an invalid value: %d", fd);
|
"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))
|
if (!fdset_contains(fds, fd))
|
||||||
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
|
||||||
"VarlinkServerSocket varlink-server-socket-fd= has unknown fd %d: %m", fd);
|
"VarlinkServerSocket varlink-server-socket-fd= has unknown fd %d: %m", fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user