tree-wide: use -EBADF more

This commit is contained in:
Yu Watanabe 2022-12-20 11:09:08 +09:00
parent 19ee48a6c2
commit 5bb1d7fbab
41 changed files with 65 additions and 65 deletions

View file

@ -103,5 +103,5 @@ int asynchronous_close(int fd) {
assert_se(close_nointr(fd) != -EBADF);
}
return -1;
return -EBADF;
}

View file

@ -206,7 +206,7 @@ int chase_symlinks_at(
for (todo = buffer;;) {
_cleanup_free_ char *first = NULL;
_cleanup_close_ int child = -1;
_cleanup_close_ int child = -EBADF;
struct stat st;
const char *e;

View file

@ -246,7 +246,7 @@ static int close_all_fds_frugal(const int except[], size_t n_except) {
"Refusing to loop over %d potential fds.",
max_fd);
for (int fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -1) {
for (int fd = 3; fd >= 0; fd = fd < max_fd ? fd + 1 : -EBADF) {
int q;
if (fd_in_set(fd, except, n_except))

View file

@ -22,8 +22,8 @@ int safe_close(int fd);
void safe_close_pair(int p[static 2]);
static inline int safe_close_above_stdio(int fd) {
if (fd < 3) /* Don't close stdin/stdout/stderr, but still invalidate the fd by returning -1 */
return -1;
if (fd < 3) /* Don't close stdin/stdout/stderr, but still invalidate the fd by returning -EBADF. */
return -EBADF;
return safe_close(fd);
}
@ -87,7 +87,7 @@ int fd_move_above_stdio(int fd);
int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd);
static inline int make_null_stdio(void) {
return rearrange_stdio(-1, -1, -1);
return rearrange_stdio(-EBADF, -EBADF, -EBADF);
}
/* Like TAKE_PTR() but for file descriptors, resetting them to -1 */

View file

@ -767,7 +767,7 @@ int read_full_file_full(
r = xfopenat(dir_fd, filename, "re", 0, &f);
if (r < 0) {
_cleanup_close_ int sk = -1;
_cleanup_close_ int sk = -EBADF;
/* ENXIO is what Linux returns if we open a node that is an AF_UNIX socket */
if (r != -ENXIO)

View file

@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
size_t l;
int r;
r = rearrange_stdio(-1, -1, -1);
r = make_null_stdio();
if (r < 0) {
log_error_errno(r, "Failed to connect stdin/stdout/stderr with /dev/null: %m");
return EXIT_FAILURE;

View file

@ -127,7 +127,7 @@ static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret)
if (r < 0)
return r;
storage_socket[0] = storage_socket[1] = -1;
storage_socket[0] = storage_socket[1] = -EBADF;
if (ret) {
d->n_ref++;
@ -382,7 +382,7 @@ static int dynamic_user_realize(
uid_t *ret_uid, gid_t *ret_gid,
bool is_user) {
_cleanup_(unlockfp) int storage_socket0_lock = -1;
_cleanup_(unlockfp) int storage_socket0_lock = -EBADF;
_cleanup_close_ int uid_lock_fd = -EBADF;
_cleanup_close_ int etc_passwd_lock_fd = -EBADF;
uid_t num = UID_INVALID; /* a uid if is_user, and a gid otherwise */
@ -524,7 +524,7 @@ static int dynamic_user_realize(
}
int dynamic_user_current(DynamicUser *d, uid_t *ret) {
_cleanup_(unlockfp) int storage_socket0_lock = -1;
_cleanup_(unlockfp) int storage_socket0_lock = -EBADF;
_cleanup_close_ int lock_fd = -EBADF;
uid_t uid;
int r;
@ -567,7 +567,7 @@ static DynamicUser* dynamic_user_unref(DynamicUser *d) {
}
static int dynamic_user_close(DynamicUser *d) {
_cleanup_(unlockfp) int storage_socket0_lock = -1;
_cleanup_(unlockfp) int storage_socket0_lock = -EBADF;
_cleanup_close_ int lock_fd = -EBADF;
uid_t uid;
int r;

View file

@ -2832,7 +2832,7 @@ int setup_tmp_dirs(const char *id, char **tmp_dir, char **var_tmp_dir) {
}
int setup_shareable_ns(const int ns_storage_socket[static 2], unsigned long nsflag) {
_cleanup_close_ int ns = -1;
_cleanup_close_ int ns = -EBADF;
int r, q;
const char *ns_name, *ns_path;
@ -2900,7 +2900,7 @@ fail:
}
int open_shareable_ns_path(const int ns_storage_socket[static 2], const char *path, unsigned long nsflag) {
_cleanup_close_ int ns = -1;
_cleanup_close_ int ns = -EBADF;
int q, r;
assert(ns_storage_socket);

View file

@ -1293,7 +1293,7 @@ static int process_kernel(int argc, char* argv[]) {
/* When we're invoked by the kernel, stdout/stderr are closed which is dangerous because the fds
* could get reallocated. To avoid hard to debug issues, let's instead bind stdout/stderr to
* /dev/null. */
r = rearrange_stdio(STDIN_FILENO, -1, -1);
r = rearrange_stdio(STDIN_FILENO, -EBADF, -EBADF);
if (r < 0)
return log_error_errno(r, "Failed to connect stdout/stderr to /dev/null: %m");

View file

@ -881,7 +881,7 @@ static int write_root_shadow(const char *shadow_path, const char *hashed_passwor
}
static int process_root_account(void) {
_cleanup_close_ int lock = -1;
_cleanup_close_ int lock = -EBADF;
_cleanup_(erase_and_freep) char *_hashed_password = NULL;
const char *password, *hashed_password;
const char *etc_passwd, *etc_shadow;

View file

@ -64,7 +64,7 @@ int import_fork_tar_x(const char *path, pid_t *ret) {
pipefd[1] = safe_close(pipefd[1]);
r = rearrange_stdio(TAKE_FD(pipefd[0]), -1, STDERR_FILENO);
r = rearrange_stdio(TAKE_FD(pipefd[0]), -EBADF, STDERR_FILENO);
if (r < 0) {
log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
_exit(EXIT_FAILURE);
@ -130,7 +130,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
pipefd[0] = safe_close(pipefd[0]);
r = rearrange_stdio(-1, TAKE_FD(pipefd[1]), STDERR_FILENO);
r = rearrange_stdio(-EBADF, TAKE_FD(pipefd[1]), STDERR_FILENO);
if (r < 0) {
log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
_exit(EXIT_FAILURE);

View file

@ -395,7 +395,7 @@ static int verify_gpg(
return log_error_errno(errno, "Failed to create pipe for gpg: %m");
if (signature_size > 0) {
_cleanup_close_ int sig_file = -1;
_cleanup_close_ int sig_file = -EBADF;
sig_file = mkostemp(sig_file_path, O_RDWR);
if (sig_file < 0)
@ -440,7 +440,7 @@ static int verify_gpg(
gpg_pipe[1] = safe_close(gpg_pipe[1]);
r = rearrange_stdio(TAKE_FD(gpg_pipe[0]), -1, STDERR_FILENO);
r = rearrange_stdio(TAKE_FD(gpg_pipe[0]), -EBADF, STDERR_FILENO);
if (r < 0) {
log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
_exit(EXIT_FAILURE);

View file

@ -311,7 +311,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
}
static int run(int argc, char *argv[]) {
_cleanup_(server_done) Server server = { .epoll_fd = -1 };
_cleanup_(server_done) Server server = { .epoll_fd = -EBADF };
_unused_ _cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
int r, n;

View file

@ -73,7 +73,7 @@ int arp_network_bind_raw_socket(int ifindex, const struct in_addr *a, const stru
.ll.sll_halen = ETH_ALEN,
.ll.sll_addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(ifindex > 0);

View file

@ -98,7 +98,7 @@ static int _bind_raw_socket(
.len = ELEMENTSOF(filter),
.filter = filter
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
s = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
@ -178,7 +178,7 @@ int dhcp_network_bind_udp_socket(int ifindex, be32_t address, uint16_t port, int
.in.sin_port = htobe16(port),
.in.sin_addr.s_addr = address,
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);

View file

@ -23,7 +23,7 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) {
.in6.sin6_port = htobe16(DHCP6_PORT_CLIENT),
.in6.sin6_scope_id = ifindex,
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(ifindex > 0);

View file

@ -31,7 +31,7 @@
static int icmp6_bind_router_message(const struct icmp6_filter *filter,
const struct ipv6_mreq *mreq) {
int ifindex = mreq->ipv6mr_interface;
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(filter);

View file

@ -213,7 +213,7 @@ int main(int argc, char *argv[]) {
Type type = TYPE_LEGACY;
int i, pair[2] = PIPE_EBADF;
_cleanup_free_ char *address = NULL, *server_name = NULL;
_cleanup_close_ int bus_ref = -1;
_cleanup_close_ int bus_ref = -EBADF;
const char *unique;
cpu_set_t cpuset;
size_t result;

View file

@ -130,7 +130,7 @@ int device_monitor_get_fd(sd_device_monitor *m) {
int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group, int fd) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL;
_cleanup_close_ int sock = -1;
_cleanup_close_ int sock = -EBADF;
int r;
assert(group >= 0 && group < _MONITOR_NETLINK_GROUP_MAX);
@ -184,7 +184,7 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
}
if (DEBUG_LOGGING) {
_cleanup_close_ int netns = -1;
_cleanup_close_ int netns = -EBADF;
/* So here's the thing: only AF_NETLINK sockets from the main network namespace will get
* hardware events. Let's check if ours is from there, and if not generate a debug message,

View file

@ -2072,7 +2072,7 @@ static int event_add_inotify_fd_internal(
sd_event_inotify_handler_t callback,
void *userdata) {
_cleanup_close_ int donated_fd = donate ? fd : -1;
_cleanup_close_ int donated_fd = donate ? fd : -EBADF;
_cleanup_(source_freep) sd_event_source *s = NULL;
struct inotify_data *inotify_data = NULL;
struct inode_data *inode_data = NULL;

View file

@ -436,7 +436,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
int bus_machine_method_open_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ char *pty_name = NULL;
_cleanup_close_ int master = -1;
_cleanup_close_ int master = -EBADF;
Machine *m = ASSERT_PTR(userdata);
int r;
@ -525,7 +525,7 @@ int bus_machine_method_open_login(sd_bus_message *message, void *userdata, sd_bu
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ char *pty_name = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *allocated_bus = NULL;
_cleanup_close_ int master = -1;
_cleanup_close_ int master = -EBADF;
sd_bus *container_bus = NULL;
Machine *m = ASSERT_PTR(userdata);
const char *p, *getty;
@ -588,7 +588,7 @@ int bus_machine_method_open_shell(sd_bus_message *message, void *userdata, sd_bu
_cleanup_free_ char *pty_name = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *allocated_bus = NULL;
sd_bus *container_bus = NULL;
_cleanup_close_ int master = -1, slave = -1;
_cleanup_close_ int master = -EBADF, slave = -EBADF;
_cleanup_strv_free_ char **env = NULL, **args_wire = NULL, **args = NULL;
Machine *m = ASSERT_PTR(userdata);
const char *p, *unit, *user, *path, *description, *utmp_id;

View file

@ -39,7 +39,7 @@ static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
pipe_fds[0] = safe_close(pipe_fds[0]);
if (rearrange_stdio(-1, TAKE_FD(pipe_fds[1]), -1) < 0)
if (rearrange_stdio(-EBADF, TAKE_FD(pipe_fds[1]), -EBADF) < 0)
_exit(EXIT_FAILURE);
(void) close_all_fds(NULL, 0);

View file

@ -2376,7 +2376,7 @@ static int setup_pts(const char *dest) {
}
static int setup_stdio_as_dev_console(void) {
_cleanup_close_ int terminal = -1;
_cleanup_close_ int terminal = -EBADF;
int r;
/* We open the TTY in O_NOCTTY mode, so that we do not become controller yet. We'll do that later
@ -3348,7 +3348,7 @@ static int inner_child(
}
if (arg_console_mode != CONSOLE_PIPE) {
_cleanup_close_ int master = -1;
_cleanup_close_ int master = -EBADF;
_cleanup_free_ char *console = NULL;
/* Allocate a pty and make it available as /dev/console. */
@ -4742,12 +4742,12 @@ static int run_container(
};
_cleanup_(release_lock_file) LockFile uid_shift_lock = LOCK_FILE_INIT;
_cleanup_close_ int etc_passwd_lock = -1;
_cleanup_close_ int etc_passwd_lock = -EBADF;
_cleanup_close_pair_ int
fd_inner_socket_pair[2] = PIPE_EBADF,
fd_outer_socket_pair[2] = PIPE_EBADF;
_cleanup_close_ int notify_socket = -1, mntns_fd = -EBADF, fd_kmsg_fifo = -EBADF;
_cleanup_close_ int notify_socket = -EBADF, mntns_fd = -EBADF, fd_kmsg_fifo = -EBADF;
_cleanup_(barrier_destroy) Barrier barrier = BARRIER_NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *notify_event_source = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
@ -5413,7 +5413,7 @@ static int cant_be_in_netns(void) {
static int run(int argc, char *argv[]) {
bool secondary = false, remove_directory = false, remove_image = false,
veth_created = false, remove_tmprootdir = false;
_cleanup_close_ int master = -1;
_cleanup_close_ int master = -EBADF;
_cleanup_fdset_free_ FDSet *fds = NULL;
int r, n_fd_passed, ret = EXIT_SUCCESS;
char veth_name[IFNAMSIZ] = "";

View file

@ -141,7 +141,7 @@ int manager_llmnr_ipv4_udp_fd(Manager *m) {
.in.sin_family = AF_INET,
.in.sin_port = htobe16(LLMNR_PORT),
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(m);
@ -211,7 +211,7 @@ int manager_llmnr_ipv6_udp_fd(Manager *m) {
.in6.sin6_family = AF_INET6,
.in6.sin6_port = htobe16(LLMNR_PORT),
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(m);
@ -344,7 +344,7 @@ int manager_llmnr_ipv4_tcp_fd(Manager *m) {
.in.sin_family = AF_INET,
.in.sin_port = htobe16(LLMNR_PORT),
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(m);
@ -410,7 +410,7 @@ int manager_llmnr_ipv6_tcp_fd(Manager *m) {
.in6.sin6_family = AF_INET6,
.in6.sin6_port = htobe16(LLMNR_PORT),
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(m);

View file

@ -466,7 +466,7 @@ int manager_mdns_ipv4_fd(Manager *m) {
.in.sin_family = AF_INET,
.in.sin_port = htobe16(MDNS_PORT),
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(m);
@ -541,7 +541,7 @@ int manager_mdns_ipv6_fd(Manager *m) {
.in6.sin6_family = AF_INET6,
.in6.sin6_port = htobe16(MDNS_PORT),
};
_cleanup_close_ int s = -1;
_cleanup_close_ int s = -EBADF;
int r;
assert(m);

View file

@ -267,7 +267,7 @@ static void context_save_and_clear(Context *c) {
}
static int run(int argc, char *argv[]) {
_cleanup_(context_save_and_clear) Context c = { .rfkill_fd = -1 };
_cleanup_(context_save_and_clear) Context c = { .rfkill_fd = -EBADF };
bool ready = false;
int r, n;

View file

@ -1107,7 +1107,7 @@ static int start_transient_service(
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
_cleanup_free_ char *service = NULL, *pty_path = NULL;
_cleanup_close_ int master = -1;
_cleanup_close_ int master = -EBADF;
int r;
assert(bus);

View file

@ -526,7 +526,7 @@ static int hardlink_context_setup(
const char *to,
CopyFlags copy_flags) {
_cleanup_close_ int dt_copy = -1;
_cleanup_close_ int dt_copy = -EBADF;
int r;
assert(c);

View file

@ -683,7 +683,7 @@ int loop_device_make_by_path_memory(
}
static LoopDevice* loop_device_free(LoopDevice *d) {
_cleanup_close_ int control = -1;
_cleanup_close_ int control = -EBADF;
int r;
if (!d)

View file

@ -282,7 +282,7 @@ static int download_manifest(
pfd[0] = safe_close(pfd[0]);
r = rearrange_stdio(-1, pfd[1], STDERR_FILENO);
r = rearrange_stdio(-EBADF, pfd[1], STDERR_FILENO);
if (r < 0) {
log_error_errno(r, "Failed to rearrange stdin/stdout: %m");
_exit(EXIT_FAILURE);

View file

@ -251,7 +251,7 @@ static int load_group_database(void) {
static int make_backup(const char *target, const char *x) {
_cleanup_(unlink_and_freep) char *dst_tmp = NULL;
_cleanup_fclose_ FILE *dst = NULL;
_cleanup_close_ int src = -1;
_cleanup_close_ int src = -EBADF;
const char *backup;
struct stat st;
int r;
@ -2093,7 +2093,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
_cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL;
#endif
_cleanup_close_ int lock = -1;
_cleanup_close_ int lock = -EBADF;
Item *i;
int r;

View file

@ -170,7 +170,7 @@ _unused_ static void test_compress_stream(int flag,
decompress_stream_t decompress,
const char *srcfile) {
_cleanup_close_ int src = -1, dst = -1, dst2 = -1;
_cleanup_close_ int src = -EBADF, dst = -EBADF, dst2 = -EBADF;
_cleanup_(unlink_tempfilep) char
pattern[] = "/tmp/systemd-test.compressed.XXXXXX",
pattern2[] = "/tmp/systemd-test.compressed.XXXXXX";

View file

@ -78,7 +78,7 @@ TEST(copy_tree_replace_file) {
TEST(copy_tree_replace_dirs) {
_cleanup_(rm_rf_physical_and_freep) char *srcp = NULL, *dstp = NULL;
_cleanup_close_ int src = -1, dst = -1;
_cleanup_close_ int src = -EBADF, dst = -EBADF;
/* Create the random source/destination directories */
assert_se((src = mkdtemp_open(NULL, 0, &srcp)) >= 0);

View file

@ -576,7 +576,7 @@ static int find_libraries(const char *exec, char ***ret) {
r = safe_fork("(spawn-ldd)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG, &pid);
assert_se(r >= 0);
if (r == 0) {
if (rearrange_stdio(-1, TAKE_FD(outpipe[1]), TAKE_FD(errpipe[1])) < 0)
if (rearrange_stdio(-EBADF, TAKE_FD(outpipe[1]), TAKE_FD(errpipe[1])) < 0)
_exit(EXIT_FAILURE);
(void) close_all_fds(NULL, 0);

View file

@ -133,7 +133,7 @@ TEST(rearrange_stdio) {
safe_close(STDERR_FILENO); /* Let's close an fd < 2, to make it more interesting */
assert_se(rearrange_stdio(-1, -1, -1) >= 0);
assert_se(rearrange_stdio(-EBADF, -EBADF, -EBADF) >= 0);
assert_se(fd_get_path(STDIN_FILENO, &path) >= 0);
assert_se(path_equal(path, "/dev/null"));
@ -170,7 +170,7 @@ TEST(rearrange_stdio) {
assert_se(read(0, buffer, sizeof(buffer)) == 6);
assert_se(memcmp(buffer, "foobar", 6) == 0);
assert_se(rearrange_stdio(-1, 1, 2) >= 0);
assert_se(rearrange_stdio(-EBADF, 1, 2) >= 0);
assert_se(write(1, "a", 1) < 0 && errno == ENOSPC);
assert_se(write(2, "y", 1) == 1);
assert_se(read(3, buffer, sizeof(buffer)) == 1);

View file

@ -877,7 +877,7 @@ TEST(read_nul_string) {
TEST(read_full_file_socket) {
_cleanup_(rm_rf_physical_and_freep) char *z = NULL;
_cleanup_close_ int listener = -1;
_cleanup_close_ int listener = -EBADF;
_cleanup_free_ char *data = NULL, *clientname = NULL;
union sockaddr_union sa;
const char *j, *jj;

View file

@ -66,7 +66,7 @@ TEST(read_one_char) {
TEST(getttyname_malloc) {
_cleanup_free_ char *ttyname = NULL;
_cleanup_close_ int master = -1;
_cleanup_close_ int master = -EBADF;
assert_se((master = posix_openpt(O_RDWR|O_NOCTTY)) >= 0);
assert_se(getttyname_malloc(master, &ttyname) >= 0);

View file

@ -1113,7 +1113,7 @@ int manager_new(Manager **ret) {
.connection_retry_usec = DEFAULT_CONNECTION_RETRY_USEC,
.server_socket = -1,
.server_socket = -EBADF,
.ratelimit = (const RateLimit) {
RATELIMIT_INTERVAL_USEC,

View file

@ -338,7 +338,7 @@ static int process_and_watch_password_files(bool watch) {
};
_unused_ _cleanup_close_ int tty_block_fd = -EBADF;
_cleanup_close_ int notify = -1, signal_fd = -EBADF;
_cleanup_close_ int notify = -EBADF, signal_fd = -EBADF;
struct pollfd pollfd[_FD_MAX];
sigset_t mask;
int r;

View file

@ -46,7 +46,7 @@ struct UdevCtrl {
};
int udev_ctrl_new_from_fd(UdevCtrl **ret, int fd) {
_cleanup_close_ int sock = -1;
_cleanup_close_ int sock = -EBADF;
UdevCtrl *uctrl;
assert(ret);
@ -64,7 +64,7 @@ int udev_ctrl_new_from_fd(UdevCtrl **ret, int fd) {
*uctrl = (UdevCtrl) {
.n_ref = 1,
.sock = fd >= 0 ? fd : TAKE_FD(sock),
.sock_connect = -1,
.sock_connect = -EBADF,
.bound = fd >= 0,
};
@ -217,7 +217,7 @@ static int udev_ctrl_connection_event_handler(sd_event_source *s, int fd, uint32
static int udev_ctrl_event_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
UdevCtrl *uctrl = ASSERT_PTR(userdata);
_cleanup_close_ int sock = -1;
_cleanup_close_ int sock = -EBADF;
struct ucred ucred;
int r;

View file

@ -815,7 +815,7 @@ int udev_event_spawn(
return log_device_error_errno(event->dev, r,
"Failed to fork() to execute command '%s': %m", cmd);
if (r == 0) {
if (rearrange_stdio(-1, TAKE_FD(outpipe[WRITE_END]), TAKE_FD(errpipe[WRITE_END])) < 0)
if (rearrange_stdio(-EBADF, TAKE_FD(outpipe[WRITE_END]), TAKE_FD(errpipe[WRITE_END])) < 0)
_exit(EXIT_FAILURE);
(void) close_all_fds(NULL, 0);