summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-13 03:30:42 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-13 04:06:43 +0100
commit7b77ed8cf36e8eca6017791626044b61ae2d68e7 (patch)
treeb9315db260bbd82cfbc4ae7cd736d9d8df65f626 /src
parentc5ef10429a7768e3453f29e8c85cb560ce382649 (diff)
event: be more conservative when returning errors from event handler callbacks
We really should return errors from event handlers if we have a continous problem and don't know any other solution.
Diffstat (limited to 'src')
-rw-r--r--src/core/manager.c2
-rw-r--r--src/journal/journald-stream.c8
-rw-r--r--src/login/logind-button.c26
-rw-r--r--src/login/logind.c38
-rw-r--r--src/network/networkd-manager.c11
-rw-r--r--src/socket-proxy/socket-proxyd.c17
6 files changed, 42 insertions, 60 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index ad4c6e8ed9..a2f3570bb6 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1631,7 +1631,7 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
}
if (sigchld)
- return manager_dispatch_sigchld(m);
+ manager_dispatch_sigchld(m);
return 0;
}
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index 8958c7f3de..aba9054b27 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -293,7 +293,6 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
if ((revents|EPOLLIN|EPOLLHUP) != (EPOLLIN|EPOLLHUP)) {
log_error("Got invalid event from epoll for stdout stream: %"PRIx32, revents);
- r = -EIO;
goto terminate;
}
@@ -304,12 +303,11 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
return 0;
log_warning("Failed to read from stream: %m");
- r = -errno;
goto terminate;
}
if (l == 0) {
- r = stdout_stream_scan(s, true);
+ stdout_stream_scan(s, true);
goto terminate;
}
@@ -391,7 +389,6 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
len = sizeof(stream->ucred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &stream->ucred, &len) < 0) {
log_error("Failed to determine peer credentials: %m");
- r = -errno;
goto fail;
}
@@ -404,7 +401,6 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
if (shutdown(fd, SHUT_WR) < 0) {
log_error("Failed to shutdown writing side of socket: %m");
- r = -errno;
goto fail;
}
@@ -428,7 +424,7 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
fail:
stdout_stream_free(stream);
- return r;
+ return 0;
}
int server_open_stdout_socket(Server *s) {
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 3dd0829486..e29f2c4c5f 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -141,7 +141,9 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
"MESSAGE=Power key pressed.",
MESSAGE_ID(SD_MESSAGE_POWER_KEY),
NULL);
- return button_handle(b, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true);
+
+ button_handle(b, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true);
+ break;
/* The kernel is a bit confused here:
@@ -154,41 +156,41 @@ static int button_dispatch(sd_event_source *s, int fd, uint32_t revents, void *u
"MESSAGE=Suspend key pressed.",
MESSAGE_ID(SD_MESSAGE_SUSPEND_KEY),
NULL);
- return button_handle(b, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true);
+
+ button_handle(b, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true);
+ break;
case KEY_SUSPEND:
log_struct(LOG_INFO,
"MESSAGE=Hibernate key pressed.",
MESSAGE_ID(SD_MESSAGE_HIBERNATE_KEY),
NULL);
- return button_handle(b, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true);
+
+ button_handle(b, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true);
+ break;
}
} else if (ev.type == EV_SW && ev.value > 0) {
- switch (ev.code) {
-
- case SW_LID:
+ if (ev.code == SW_LID) {
log_struct(LOG_INFO,
"MESSAGE=Lid closed.",
MESSAGE_ID(SD_MESSAGE_LID_CLOSED),
NULL);
- b->lid_close_queued = true;
- return button_handle(b, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, true);
+ b->lid_close_queued = true;
+ button_handle(b, INHIBIT_HANDLE_LID_SWITCH, b->manager->handle_lid_switch, b->manager->lid_switch_ignore_inhibited, true);
}
} else if (ev.type == EV_SW && ev.value == 0) {
- switch (ev.code) {
-
- case SW_LID:
+ if (ev.code == SW_LID) {
log_struct(LOG_INFO,
"MESSAGE=Lid opened.",
MESSAGE_ID(SD_MESSAGE_LID_OPENED),
NULL);
+
b->lid_close_queued = false;
- break;
}
}
diff --git a/src/login/logind.c b/src/login/logind.c
index 222608743e..b7c8f71a52 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -34,6 +34,7 @@
#include "bus-util.h"
#include "bus-error.h"
#include "logind.h"
+#include "udev-util.h"
Manager *manager_new(void) {
Manager *m;
@@ -490,9 +491,8 @@ static int manager_enumerate_inhibitors(Manager *m) {
}
static int manager_dispatch_seat_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ _cleanup_udev_device_unref_ struct udev_device *d = NULL;
Manager *m = userdata;
- struct udev_device *d;
- int r;
assert(m);
@@ -500,16 +500,13 @@ static int manager_dispatch_seat_udev(sd_event_source *s, int fd, uint32_t reven
if (!d)
return -ENOMEM;
- r = manager_process_seat_device(m, d);
- udev_device_unref(d);
-
- return r;
+ manager_process_seat_device(m, d);
+ return 0;
}
static int manager_dispatch_device_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ _cleanup_udev_device_unref_ struct udev_device *d = NULL;
Manager *m = userdata;
- struct udev_device *d;
- int r;
assert(m);
@@ -517,16 +514,13 @@ static int manager_dispatch_device_udev(sd_event_source *s, int fd, uint32_t rev
if (!d)
return -ENOMEM;
- r = manager_process_seat_device(m, d);
- udev_device_unref(d);
-
- return r;
+ manager_process_seat_device(m, d);
+ return 0;
}
static int manager_dispatch_vcsa_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ _cleanup_udev_device_unref_ struct udev_device *d = NULL;
Manager *m = userdata;
- struct udev_device *d;
- int r = 0;
const char *name;
assert(m);
@@ -541,17 +535,14 @@ static int manager_dispatch_vcsa_udev(sd_event_source *s, int fd, uint32_t reven
* VTs, to make sure our auto VTs never go away. */
if (name && startswith(name, "vcsa") && streq_ptr(udev_device_get_action(d), "remove"))
- r = seat_preallocate_vts(m->seat0);
+ seat_preallocate_vts(m->seat0);
- udev_device_unref(d);
-
- return r;
+ return 0;
}
static int manager_dispatch_button_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ _cleanup_udev_device_unref_ struct udev_device *d = NULL;
Manager *m = userdata;
- struct udev_device *d;
- int r;
assert(m);
@@ -559,10 +550,8 @@ static int manager_dispatch_button_udev(sd_event_source *s, int fd, uint32_t rev
if (!d)
return -ENOMEM;
- r = manager_process_button_device(m, d);
- udev_device_unref(d);
-
- return r;
+ manager_process_button_device(m, d);
+ return 0;
}
static int manager_dispatch_console(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
@@ -573,7 +562,6 @@ static int manager_dispatch_console(sd_event_source *s, int fd, uint32_t revents
assert(m->console_active_fd == fd);
seat_read_active_vt(m->seat0);
-
return 0;
}
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index d59b9139a3..1b5837e42c 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -22,6 +22,7 @@
#include "path-util.h"
#include "networkd.h"
#include "libudev-private.h"
+#include "udev-util.h"
int manager_new(Manager **ret) {
_cleanup_manager_free_ Manager *m = NULL;
@@ -204,19 +205,13 @@ finish:
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
Manager *m = userdata;
struct udev_monitor *monitor = m->udev_monitor;
- struct udev_device *device;
- int r;
+ _cleanup_udev_device_unref_ struct udev_device *device = NULL;
device = udev_monitor_receive_device(monitor);
if (!device)
return -ENOMEM;
- r = manager_process_link(m, device);
- if (r < 0)
- return r;
-
- udev_device_unref(device);
-
+ manager_process_link(m, device);
return 0;
}
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index c6f56be60a..b066633b1d 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -462,6 +462,7 @@ fail:
}
static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ _cleanup_free_ char *peer = NULL;
Context *context = userdata;
int nfd = -1, r;
@@ -471,24 +472,24 @@ static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdat
assert(context);
nfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
- if (nfd >= 0) {
- _cleanup_free_ char *peer = NULL;
-
+ if (nfd < 0) {
+ if (errno != -EAGAIN)
+ log_warning("Failed to accept() socket: %m");
+ } else {
getpeername_pretty(nfd, &peer);
log_debug("New connection from %s", strna(peer));
r = add_connection_socket(context, sd_event_source_get_event(s), nfd);
if (r < 0) {
+ log_error("Failed to accept connection, ignoring: %s", strerror(-r));
close_nointr_nofail(fd);
- return r;
}
-
- } else if (errno != -EAGAIN)
- log_warning("Failed to accept() socket: %m");
+ }
r = sd_event_source_set_enabled(s, SD_EVENT_ONESHOT);
if (r < 0) {
- log_error("Error %d while re-enabling listener with ONESHOT: %s", r, strerror(-r));
+ log_error("Error while re-enabling listener with ONESHOT: %s", strerror(-r));
+ sd_event_exit(sd_event_source_get_event(s), r);
return r;
}