X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournald-stream.c;h=36fc755260f585f13ea29e9956d4ef06bedc2fa4;hb=0a1b6da82109c3b08b1f966a1625a77cc312135a;hp=b2291a260f32318716a306ba46314ebc8c628dc2;hpb=91bf3b3e124575f6f647bff29766e9d992f55b32;p=elogind.git diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index b2291a260..36fc75526 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; } @@ -334,8 +332,10 @@ void stdout_stream_free(StdoutStream *s) { LIST_REMOVE(stdout_stream, s->server->stdout_streams, s); } - if (s->event_source) + if (s->event_source) { + sd_event_source_set_enabled(s->event_source, SD_EVENT_OFF); s->event_source = sd_event_source_unref(s->event_source); + } if (s->fd >= 0) close_nointr_nofail(s->fd); @@ -354,7 +354,6 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent Server *s = userdata; StdoutStream *stream; int fd, r; - socklen_t len; assert(s); @@ -386,10 +385,9 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent stream->fd = fd; - len = sizeof(stream->ucred); - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &stream->ucred, &len) < 0) { + r = getpeercred(fd, &stream->ucred); + if (r < 0) { log_error("Failed to determine peer credentials: %m"); - r = -errno; goto fail; } @@ -402,11 +400,10 @@ 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; } - r = sd_event_add_io(s->event, fd, EPOLLIN, stdout_stream_process, stream, &stream->event_source); + r = sd_event_add_io(s->event, &stream->event_source, fd, EPOLLIN, stdout_stream_process, stream); if (r < 0) { log_error("Failed to add stream to event loop: %s", strerror(-r)); goto fail; @@ -426,7 +423,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) { @@ -463,7 +460,7 @@ int server_open_stdout_socket(Server *s) { } else fd_nonblock(s->stdout_fd, 1); - r = sd_event_add_io(s->event, s->stdout_fd, EPOLLIN, stdout_stream_new, s, &s->stdout_event_source); + r = sd_event_add_io(s->event, &s->stdout_event_source, s->stdout_fd, EPOLLIN, stdout_stream_new, s); if (r < 0) { log_error("Failed to add stdout server fd to event source: %s", strerror(-r)); return r;