From 84a6c2ba93cccf8896b47328f2156e66c26f701e Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 19 Jun 2023 17:12:37 +0200 Subject: journal-remote: minor cleanups --- src/journal-remote/journal-remote.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/journal-remote') diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 08b3e53ef2..93f2dff591 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -49,6 +49,9 @@ static int open_output(RemoteServer *s, Writer *w, const char* host) { const char *filename; int r; + assert(s); + assert(w); + switch (s->split_mode) { case JOURNAL_WRITE_SPLIT_NONE: filename = s->output; @@ -118,6 +121,9 @@ int journal_remote_get_writer(RemoteServer *s, const char *host, Writer **writer const void *key; int r; + assert(s); + assert(writer); + switch (s->split_mode) { case JOURNAL_WRITE_SPLIT_NONE: key = "one and only"; @@ -186,6 +192,7 @@ static int get_source_for_fd(RemoteServer *s, /* This takes ownership of name, but only on success. */ + assert(s); assert(fd >= 0); assert(source); @@ -289,10 +296,11 @@ int journal_remote_add_source(RemoteServer *s, int fd, char* name, bool own_name } int journal_remote_add_raw_socket(RemoteServer *s, int fd) { - int r; _unused_ _cleanup_close_ int fd_ = fd; char name[STRLEN("raw-socket-") + DECIMAL_STR_MAX(int) + 1]; + int r; + assert(s); assert(fd >= 0); r = sd_event_add_io(s->events, &s->listen_event, @@ -307,7 +315,7 @@ int journal_remote_add_raw_socket(RemoteServer *s, int fd) { if (r < 0) return r; - fd_ = -EBADF; + TAKE_FD(fd_); s->active++; return 0; } @@ -355,6 +363,9 @@ int journal_remote_server_init( void journal_remote_server_destroy(RemoteServer *s) { size_t i; + if (!s) + return; + #if HAVE_MICROHTTPD hashmap_free_with_destructor(s->daemons, MHDDaemonWrapper_free); #endif @@ -394,6 +405,7 @@ int journal_remote_handle_raw_source( * 0 if data is currently exhausted, negative on error. */ + assert(s); assert(fd >= 0 && fd < (ssize_t) MALLOC_ELEMENTSOF(s->sources)); source = s->sources[fd]; assert(source->importer.fd == fd); @@ -429,9 +441,11 @@ int journal_remote_handle_raw_source( static int dispatch_raw_source_until_block(sd_event_source *event, void *userdata) { - RemoteSource *source = userdata; + RemoteSource *source = ASSERT_PTR(userdata); int r; + assert(event); + /* Make sure event stays around even if source is destroyed */ sd_event_source_ref(event); @@ -454,7 +468,7 @@ static int dispatch_raw_source_event(sd_event_source *event, int fd, uint32_t revents, void *userdata) { - RemoteSource *source = userdata; + RemoteSource *source = ASSERT_PTR(userdata); int r; assert(source->event); @@ -476,7 +490,7 @@ static int dispatch_raw_source_event(sd_event_source *event, static int dispatch_blocking_source_event(sd_event_source *event, void *userdata) { - RemoteSource *source = userdata; + RemoteSource *source = ASSERT_PTR(userdata); return journal_remote_handle_raw_source(event, source->importer.fd, EPOLLIN, journal_remote_server_global); } @@ -490,6 +504,9 @@ static int accept_connection( _cleanup_close_ int fd2 = -EBADF; int r; + assert(addr); + assert(hostname); + log_debug("Accepting new %s connection on fd:%d", type, fd); fd2 = accept4(fd, &addr->sockaddr.sa, &addr->size, SOCK_NONBLOCK|SOCK_CLOEXEC); if (fd2 < 0) { @@ -535,7 +552,7 @@ static int dispatch_raw_connection_event( uint32_t revents, void *userdata) { - RemoteServer *s = userdata; + RemoteServer *s = ASSERT_PTR(userdata); int fd2; SocketAddress addr = { .size = sizeof(union sockaddr_union), -- cgit v1.2.3