diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 13:07:42 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 15:00:57 +0100 |
commit | 254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch) | |
tree | 067102a36abe6bf597c26a42d79018a1060c9007 /src/libsystemd/sd-event | |
parent | cbff793ffb280d9d11e5d7b1dc3964276491bee8 (diff) | |
download | systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.gz |
tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.
Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state
Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.
In some places, initialization is dropped if unnecessary.
Diffstat (limited to 'src/libsystemd/sd-event')
-rw-r--r-- | src/libsystemd/sd-event/event-util.c | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-event/sd-event.c | 24 | ||||
-rw-r--r-- | src/libsystemd/sd-event/test-event.c | 5 |
3 files changed, 15 insertions, 16 deletions
diff --git a/src/libsystemd/sd-event/event-util.c b/src/libsystemd/sd-event/event-util.c index a36eba9029..9863b07653 100644 --- a/src/libsystemd/sd-event/event-util.c +++ b/src/libsystemd/sd-event/event-util.c @@ -111,7 +111,7 @@ int event_reset_time_relative( int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata) { _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(e); diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index c936fcb3b6..b9df1c86c3 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -378,22 +378,22 @@ _public_ int sd_event_new(sd_event** ret) { *e = (sd_event) { .n_ref = 1, - .epoll_fd = -1, - .watchdog_fd = -1, + .epoll_fd = -EBADF, + .watchdog_fd = -EBADF, .realtime.wakeup = WAKEUP_CLOCK_DATA, - .realtime.fd = -1, + .realtime.fd = -EBADF, .realtime.next = USEC_INFINITY, .boottime.wakeup = WAKEUP_CLOCK_DATA, - .boottime.fd = -1, + .boottime.fd = -EBADF, .boottime.next = USEC_INFINITY, .monotonic.wakeup = WAKEUP_CLOCK_DATA, - .monotonic.fd = -1, + .monotonic.fd = -EBADF, .monotonic.next = USEC_INFINITY, .realtime_alarm.wakeup = WAKEUP_CLOCK_DATA, - .realtime_alarm.fd = -1, + .realtime_alarm.fd = -EBADF, .realtime_alarm.next = USEC_INFINITY, .boottime_alarm.wakeup = WAKEUP_CLOCK_DATA, - .boottime_alarm.fd = -1, + .boottime_alarm.fd = -EBADF, .boottime_alarm.next = USEC_INFINITY, .perturb = USEC_INFINITY, .original_pid = getpid_cached(), @@ -643,7 +643,7 @@ static int event_make_signal_data( *d = (struct signal_data) { .wakeup = WAKEUP_SIGNAL_DATA, - .fd = -1, + .fd = -EBADF, .priority = priority, }; @@ -1180,7 +1180,7 @@ static int event_setup_timer_fd( if (_likely_(d->fd >= 0)) return 0; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = timerfd_create(clock, TFD_NONBLOCK|TFD_CLOEXEC); if (fd < 0) @@ -1516,7 +1516,7 @@ _public_ int sd_event_add_child( } else s->child.pidfd_owned = true; /* If we allocate the pidfd we own it by default */ } else - s->child.pidfd = -1; + s->child.pidfd = -EBADF; if (EVENT_SOURCE_WATCH_PIDFD(s)) { /* We have a pidfd and we only want to watch for exit */ @@ -1779,7 +1779,7 @@ static int event_make_inotify_data( int64_t priority, struct inotify_data **ret) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct inotify_data *d; int r; @@ -1976,7 +1976,7 @@ static int event_make_inode_data( .dev = dev, .ino = ino, .wd = -1, - .fd = -1, + .fd = -EBADF, .inotify_data = inotify_data, }; diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index 9ec988d76e..8d0cb5861b 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -225,8 +225,7 @@ static void test_basic_one(bool with_pidfd) { got_a = false, got_b = false, got_c = false, got_d = 0; - /* Add a oneshot handler, trigger it, reenable it, and trigger - * it again. */ + /* Add a oneshot handler, trigger it, reenable it, and trigger it again. */ assert_se(sd_event_add_io(e, &w, d[0], EPOLLIN, io_handler, INT_TO_PTR('d')) >= 0); assert_se(sd_event_source_set_enabled(w, SD_EVENT_ONESHOT) >= 0); assert_se(write(d[1], &ch, 1) >= 0); @@ -742,7 +741,7 @@ TEST(inotify_self_destroy) { _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL; _cleanup_(sd_event_unrefp) sd_event *e = NULL; char path[] = "/tmp/inotifyXXXXXX"; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; /* Tests that destroying an inotify event source from its own handler is safe */ |