X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsocket-proxy%2Fsocket-proxyd.c;h=b066633b1d83663a467d1b810746876c95d31466;hb=cf6a8911738fe2635a5210769d5348b05b166691;hp=8cba8e06798e80eef0e963e7ec8a1644b22b7613;hpb=afc6adb5ec7e73bc13156c43f52fb015cd80cc68;p=elogind.git diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index 8cba8e067..b066633b1 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -287,7 +287,7 @@ static int traffic_cb(sd_event_source *s, int fd, uint32_t revents, void *userda if (c->client_fd == -1 && c->client_to_server_buffer_full <= 0) goto quit; - r = connection_enable_event_sources(c, sd_event_get(s)); + r = connection_enable_event_sources(c, sd_event_source_get_event(s)); if (r < 0) goto quit; @@ -373,7 +373,7 @@ static int connect_cb(sd_event_source *s, int fd, uint32_t revents, void *userda if (r < 0) goto fail; - r = connection_enable_event_sources(c, sd_event_get(s)); + r = connection_enable_event_sources(c, sd_event_source_get_event(s)); if (r < 0) goto fail; @@ -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_get(s), nfd); + 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; } @@ -632,6 +633,8 @@ int main(int argc, char *argv[]) { goto finish; } + sd_event_set_watchdog(event, true); + n = sd_listen_fds(1); if (n < 0) { log_error("Failed to receive sockets from parent.");