]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal-remote/journal-remote.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / journal-remote / journal-remote.c
index 911e2a178bef0fc0b829d8d8774110c7d095e519..27385d9b9438146bc887d412c29e5c097ef4f33c 100644 (file)
 
 #include <errno.h>
 #include <fcntl.h>
+#include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/prctl.h>
 #include <sys/socket.h>
 #include <unistd.h>
-#include <getopt.h>
+
+#ifdef HAVE_GNUTLS
+#include <gnutls/gnutls.h>
+#endif
 
 #include "sd-daemon.h"
-#include "signal-util.h"
+
+#include "conf-parser.h"
+#include "escape.h"
+#include "fileio.h"
 #include "journal-file.h"
+#include "journal-remote-write.h"
 #include "journald-native.h"
-#include "socket-util.h"
-#include "build.h"
 #include "macro.h"
+#include "signal-util.h"
+#include "socket-util.h"
+#include "string-util.h"
 #include "strv.h"
-#include "fileio.h"
-#include "conf-parser.h"
-
-#ifdef HAVE_GNUTLS
-#include <gnutls/gnutls.h>
-#endif
-
 #include "journal-remote.h"
-#include "journal-remote-write.h"
 
 #define REMOTE_JOURNAL_PATH "/var/log/journal/remote"
 
@@ -88,14 +89,17 @@ static int spawn_child(const char* child, char** argv) {
 
         child_pid = fork();
         if (child_pid < 0) {
-                r = -errno;
-                log_error_errno(errno, "Failed to fork: %m");
+                r = log_error_errno(errno, "Failed to fork: %m");
                 safe_close_pair(fd);
                 return r;
         }
 
         /* In the child */
         if (child_pid == 0) {
+
+                (void) reset_all_signal_handlers();
+                (void) reset_signal_mask();
+
                 r = dup2(fd[1], STDOUT_FILENO);
                 if (r < 0) {
                         log_error_errno(errno, "Failed to dup pipe to stdout: %m");
@@ -144,7 +148,7 @@ static int spawn_getter(const char *getter, const char *url) {
         _cleanup_strv_free_ char **words = NULL;
 
         assert(getter);
-        r = strv_split_quoted(&words, getter, 0);
+        r = strv_split_extract(&words, getter, WHITESPACE, EXTRACT_QUOTES);
         if (r < 0)
                 return log_error_errno(r, "Failed to split getter option: %m");
 
@@ -515,7 +519,7 @@ static int process_http_upload(
         } else
                 finished = true;
 
-        while (true) {
+        for (;;) {
                 r = process_source(source, arg_compress, arg_seal);
                 if (r == -EAGAIN)
                         break;
@@ -611,10 +615,9 @@ static int request_handler(
                         return code;
         } else {
                 r = getnameinfo_pretty(fd, &hostname);
-                if (r < 0) {
+                if (r < 0)
                         return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
                                            "Cannot check remote hostname");
-                }
         }
 
         assert(hostname);
@@ -646,9 +649,10 @@ static int setup_microhttpd_server(RemoteServer *s,
         int opts_pos = 3;
         int flags =
                 MHD_USE_DEBUG |
-                MHD_USE_PEDANTIC_CHECKS |
+                MHD_USE_DUAL_STACK |
                 MHD_USE_EPOLL_LINUX_ONLY |
-                MHD_USE_DUAL_STACK;
+                MHD_USE_PEDANTIC_CHECKS |
+                MHD_USE_PIPE_FOR_SHUTDOWN;
 
         const union MHD_DaemonInfo *info;
         int r, epoll_fd;
@@ -784,14 +788,11 @@ static int dispatch_http_event(sd_event_source *event,
  **********************************************************************/
 
 static int setup_signals(RemoteServer *s) {
-        sigset_t mask;
         int r;
 
         assert(s);
 
-        assert_se(sigemptyset(&mask) == 0);
-        sigset_add_many(&mask, SIGINT, SIGTERM, -1);
-        assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
+        assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, -1) >= 0);
 
         r = sd_event_add_signal(s->events, &s->sigterm_event, SIGTERM, NULL, s);
         if (r < 0)
@@ -955,7 +956,7 @@ static int remoteserver_init(RemoteServer *s,
         }
 
         if (s->active == 0) {
-                log_error("Zarro sources specified");
+                log_error("Zero sources specified");
                 return -EINVAL;
         }
 
@@ -1113,6 +1114,7 @@ static int accept_connection(const char* type, int fd,
 
                 r = socknameinfo_pretty(&addr->sockaddr, addr->size, &b);
                 if (r < 0) {
+                        log_error_errno(r, "Resolving hostname failed: %m");
                         close(fd2);
                         return r;
                 }
@@ -1259,9 +1261,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return 0 /* done */;
 
                 case ARG_VERSION:
-                        puts(PACKAGE_STRING);
-                        puts(SYSTEMD_FEATURES);
-                        return 0 /* done */;
+                        return version();
 
                 case ARG_URL:
                         if (arg_url) {