From b68f6b0a794f9e6cb6457a0ac55041c4e7b1a5cb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 24 Jan 2016 15:45:47 +0900 Subject: journal-remote: make --url option support arbitrary url Currently, --url option supports the only form like http(s)://some.host:19531. This commit adds support to call systemd-journal-remote as follwos: systemd-journal-remote --url='http://some.host:19531' systemd-journal-remote --url='http://some.host:19531/' systemd-journal-remote --url='http://some.host:19531/entries' systemd-journal-remote --url='http://some.host:19531/entries?boot&follow' The first three example result the same and retrieve all entries. The last example retrieves only current boot entries and wait new events. --- src/journal-remote/journal-remote.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/journal-remote') diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index e7003da9c1..fa0cc99b89 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -900,7 +900,14 @@ static int remoteserver_init(RemoteServer *s, if (arg_url) { const char *url, *hostname; - url = strjoina(arg_url, "/entries"); + 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); if (arg_getter) { log_info("Spawning getter %s...", url); -- cgit v1.2.3-54-g00ecf From d10accb0b1af1950882fd91f19dc7df4b0e11aa6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 24 Jan 2016 15:49:04 +0900 Subject: journal-remote: output file name is determined by the remote hostname When --url option is specified, e.g. --url='http://some.host:19531/entries' retrieved remote journal entries will be stored to /var/log/journal/remote/remote-some.host.journal --- src/journal-remote/journal-remote.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/journal-remote') diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index fa0cc99b89..68237be643 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -898,7 +898,8 @@ static int remoteserver_init(RemoteServer *s, } if (arg_url) { - const char *url, *hostname; + const char *url; + char *hostname, *p; if (!strstr(arg_url, "/entries")) { if (endswith(arg_url, "/")) @@ -924,7 +925,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; } -- cgit v1.2.3-54-g00ecf From 2f1acf6f1321e00c8e48ca8f161c4d7883ffad63 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 24 Jan 2016 15:55:07 +0900 Subject: journal-remote: fix broken --getter option This commit fixes the following broken --getter option: when systemd-journal-remote is called with --getter option, it causes the error meesage "Zero sources specified" and the getter command will not be called. --- src/journal-remote/journal-remote.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/journal-remote') diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 68237be643..04bca11277 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -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,6 +893,17 @@ static int remoteserver_init(RemoteServer *s, fd); } + if (arg_getter) { + log_info("Spawning getter %s...", arg_getter); + fd = spawn_getter(arg_getter); + if (fd < 0) + return fd; + + r = add_source(s, fd, (char*) arg_output, false); + if (r < 0) + return r; + } + if (arg_url) { const char *url; char *hostname, *p; @@ -910,13 +917,8 @@ static int remoteserver_init(RemoteServer *s, else url = strdupa(arg_url); - 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); - } + log_info("Spawning curl %s...", url); + fd = spawn_curl(url); if (fd < 0) return fd; -- cgit v1.2.3-54-g00ecf