X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal-remote%2Fjournal-upload.c;h=87d6ff7c06e10e9325f00838069b243c59648744;hb=cb6518345fcc057ca6ed3d037253bb4eeab4d94e;hp=7a7aee81708ed26f29f9e70e6381b45086d2e4da;hpb=4015ac5c321f34784f73bd91ae9d7855ed663e5e;p=elogind.git diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 7a7aee817..87d6ff7c0 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -37,6 +37,7 @@ #define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem" #define CERT_FILE CERTIFICATE_ROOT "/certs/journal-upload.pem" #define TRUST_FILE CERTIFICATE_ROOT "/ca/trusted.pem" +#define DEFAULT_PORT 19532 static const char* arg_url; @@ -191,7 +192,7 @@ int start_upload(Uploader *u, easy_setopt(curl, CURLOPT_POST, 1L, LOG_ERR, return -EXFULL); - easy_setopt(curl, CURLOPT_ERRORBUFFER, &u->error, + easy_setopt(curl, CURLOPT_ERRORBUFFER, u->error, LOG_ERR, return -EXFULL); /* set where to write to */ @@ -220,8 +221,6 @@ int start_upload(Uploader *u, LOG_WARNING, ); if (arg_key || startswith(u->url, "https://")) { - assert(arg_cert); - easy_setopt(curl, CURLOPT_SSLKEY, arg_key ?: PRIV_KEY_FILE, LOG_ERR, return -EXFULL); easy_setopt(curl, CURLOPT_SSLCERT, arg_cert ?: CERT_FILE, @@ -324,7 +323,7 @@ static int dispatch_fd_input(sd_event_source *event, } static int open_file_for_upload(Uploader *u, const char *filename) { - int fd, r; + int fd, r = 0; if (streq(filename, "-")) fd = STDIN_FILENO; @@ -394,6 +393,7 @@ static int setup_signals(Uploader *u) { static int setup_uploader(Uploader *u, const char *url, const char *state_file) { int r; + const char *host, *proto = ""; assert(u); assert(url); @@ -401,10 +401,24 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file) memzero(u, sizeof(Uploader)); u->input = -1; - if (!startswith(url, "http://") && !startswith(url, "https://")) - url = strappenda("https://", url); + if (!(host = startswith(url, "http://")) && !(host = startswith(url, "https://"))) { + host = url; + proto = "https://"; + } + + if (strchr(host, ':')) + u->url = strjoin(proto, url, "/upload", NULL); + else { + char *t; + size_t x; + + t = strdupa(url); + x = strlen(t); + while (x > 0 && t[x - 1] == '/') + t[x - 1] = '\0'; - u->url = strappend(url, "/upload"); + u->url = strjoin(proto, t, ":" STRINGIFY(DEFAULT_PORT), "/upload", NULL); + } if (!u->url) return log_oom(); @@ -507,10 +521,14 @@ static void help(void) { "Upload journal events to a remote server.\n\n" " -h --help Show this help\n" " --version Show package version\n" - " -u --url=URL Upload to this address\n" - " --key=FILENAME Specify key in PEM format\n" - " --cert=FILENAME Specify certificate in PEM format\n" - " --trust=FILENAME Specify CA certificate in PEM format\n" + " -u --url=URL Upload to this address (default port " + STRINGIFY(DEFAULT_PORT) ")\n" + " --key=FILENAME Specify key in PEM format (default:\n" + " \"" PRIV_KEY_FILE "\")\n" + " --cert=FILENAME Specify certificate in PEM format (default:\n" + " \"" CERT_FILE "\")\n" + " --trust=FILENAME|all Specify CA certificate or disable checking (default:\n" + " \"" TRUST_FILE "\")\n" " --system Use the system journal\n" " --user Use the user journal for the current user\n" " -m --merge Use all available journals\n" @@ -818,7 +836,10 @@ int main(int argc, char **argv) { } cleanup: - sd_notify(false, "STATUS=Shutting down..."); + sd_notify(false, + "STOPPING=1\n" + "STATUS=Shutting down..."); + destroy_uploader(&u); finish: