]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal-remote/journal-remote.c
journal-remote: fix broken --getter option
[thirdparty/systemd.git] / src / journal-remote / journal-remote.c
index e7003da9c1a4415806cd7774a99f93105ccc2d53..04bca11277aa12e4095bff3a706d769ad7c3edbb 100644 (file)
@@ -150,7 +150,7 @@ static int spawn_curl(const char* url) {
         return r;
 }
 
-static int spawn_getter(const char *getter, const char *url) {
+static int spawn_getter(const char *getter) {
         int r;
         _cleanup_strv_free_ char **words = NULL;
 
@@ -159,10 +159,6 @@ static int spawn_getter(const char *getter, const char *url) {
         if (r < 0)
                 return log_error_errno(r, "Failed to split getter option: %m");
 
-        r = strv_extend(&words, url);
-        if (r < 0)
-                return log_error_errno(r, "Failed to create command line: %m");
-
         r = spawn_child(words[0], words);
         if (r < 0)
                 log_error_errno(r, "Failed to spawn getter %s: %m", getter);
@@ -897,18 +893,32 @@ static int remoteserver_init(RemoteServer *s,
                                                fd);
         }
 
-        if (arg_url) {
-                const char *url, *hostname;
+        if (arg_getter) {
+                log_info("Spawning getter %s...", arg_getter);
+                fd = spawn_getter(arg_getter);
+                if (fd < 0)
+                        return fd;
 
-                url = strjoina(arg_url, "/entries");
+                r = add_source(s, fd, (char*) arg_output, false);
+                if (r < 0)
+                        return r;
+        }
 
-                if (arg_getter) {
-                        log_info("Spawning getter %s...", url);
-                        fd = spawn_getter(arg_getter, url);
-                } else {
-                        log_info("Spawning curl %s...", url);
-                        fd = spawn_curl(url);
+        if (arg_url) {
+                const char *url;
+                char *hostname, *p;
+
+                if (!strstr(arg_url, "/entries")) {
+                        if (endswith(arg_url, "/"))
+                                url = strjoina(arg_url, "entries");
+                        else
+                                url = strjoina(arg_url, "/entries");
                 }
+                else
+                        url = strdupa(arg_url);
+
+                log_info("Spawning curl %s...", url);
+                fd = spawn_curl(url);
                 if (fd < 0)
                         return fd;
 
@@ -917,7 +927,15 @@ static int remoteserver_init(RemoteServer *s,
                         startswith(arg_url, "http://") ?:
                         arg_url;
 
-                r = add_source(s, fd, (char*) hostname, false);
+                hostname = strdupa(hostname);
+                if (!hostname)
+                        return log_oom();
+                if ((p = strchr(hostname, '/')))
+                        *p = '\0';
+                if ((p = strchr(hostname, ':')))
+                        *p = '\0';
+
+                r = add_source(s, fd, hostname, false);
                 if (r < 0)
                         return r;
         }