static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revents, void *userdata) { _cleanup_close_ int fd = -1; Server *s = userdata; int r; assert(s); if (revents != EPOLLIN) { log_error("Got invalid event from epoll for stdout server fd: %"PRIx32, revents); return -EIO; } fd = accept4(s->stdout_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC); if (fd < 0) { if (errno == EAGAIN) return 0; return log_error_errno(errno, "Failed to accept stdout connection: %m"); } if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) { log_warning("Too many stdout streams, refusing connection."); return 0; } r = stdout_stream_install(s, fd, NULL); if (r < 0) return r; fd = -1; return 0; }
static int stdout_stream_restore(Server *s, const char *fname, int fd) { StdoutStream *stream; int r; assert(s); assert(fname); assert(fd >= 0); if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) { log_warning("Too many stdout streams, refusing restoring of stream."); return -ENOBUFS; } r = stdout_stream_install(s, fd, &stream); if (r < 0) return r; stream->state = STDOUT_STREAM_RUNNING; stream->fdstore = true; /* Ignore all parsing errors */ (void) stdout_stream_load(stream, fname); return 0; }
static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revents, void *userdata) { _cleanup_close_ int fd = -1; Server *s = userdata; int r; assert(s); if (revents != EPOLLIN) { log_error("Got invalid event from epoll for stdout server fd: %"PRIx32, revents); return -EIO; } fd = accept4(s->stdout_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC); if (fd < 0) { if (errno == EAGAIN) return 0; return log_error_errno(errno, "Failed to accept stdout connection: %m"); } if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) { struct ucred u; r = getpeercred(fd, &u); /* By closing fd here we make sure that the client won't wait too long for journald to * gather all the data it adds to the error message to find out that the connection has * just been refused. */ fd = safe_close(fd); server_driver_message(s, r < 0 ? 0 : u.pid, NULL, LOG_MESSAGE("Too many stdout streams, refusing connection."), NULL); return 0; } r = stdout_stream_install(s, fd, NULL); if (r < 0) return r; fd = -1; return 0; }
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { Server s; StdoutStream *stream; int v; if (size == 0 || size > 65536) return 0; if (!getenv("SYSTEMD_LOG_LEVEL")) log_set_max_level(LOG_CRIT); assert_se(socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0, stream_fds) >= 0); dummy_server_init(&s, NULL, 0); assert_se(stdout_stream_install(&s, stream_fds[0], &stream) >= 0); assert_se(write(stream_fds[1], data, size) == (ssize_t) size); while (ioctl(stream_fds[0], SIOCINQ, &v) == 0 && v) sd_event_run(s.event, (uint64_t) -1); if (s.n_stdout_streams) stdout_stream_destroy(stream); server_done(&s); stream_fds[1] = safe_close(stream_fds[1]); return 0; }