journal-upload.c revision dacd6cee76a08331b8c8616c5f30f70ee49aa2f9
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering This file is part of systemd.
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering Copyright 2014 Zbigniew Jędrzejewski-Szmek
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering systemd is free software; you can redistribute it and/or modify it
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering under the terms of the GNU Lesser General Public License as published by
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering (at your option) any later version.
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering systemd is distributed in the hope that it will be useful, but
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering Lesser General Public License for more details.
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering You should have received a copy of the GNU Lesser General Public License
8530dc4467691a893aa2e07319b18a84fec96cadLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include "formats-util.h"
#include "signal-util.h"
#include "journal-upload.h"
static bool arg_after_cursor = false;
static int arg_journal_type = 0;
static bool arg_merge = false;
if (code) { \
cmd; \
void *userp) {
assert(u);
if (!u->answer)
if (!u->state_file)
u->state_file);
u->state_file);
goto fail;
fprintf(f,
u->last_cursor);
r = fflush_and_check(f);
goto fail;
r = -errno;
goto fail;
fail:
if (temp_path)
if (!u->state_file)
NULL);
if (r == -ENOENT)
u->state_file);
void *userdata),
void *data) {
assert(u);
if (!u->header) {
struct curl_slist *h;
return log_oom();
return log_oom();
return log_oom();
u->header = h;
if (!u->easy) {
if (!curl) {
return -ENOSR;
LOG_WARNING, );
LOG_WARNING, );
u->answer = 0;
if (code) {
return -EXFULL;
u->uploading = true;
ssize_t r;
assert(u);
if (u->input < 0)
u->uploading = false;
close_fd_input(u);
return CURL_READFUNC_ABORT;
assert(u);
if (u->input >= 0)
u->timeout = 0;
int fd,
void *userp) {
assert(u);
close_fd_input(u);
return -EINVAL;
if (u->uploading) {
int fd, r = 0;
if (fd < 0)
if (arg_follow) {
void *userdata) {
assert(u);
close_fd_input(u);
assert(u);
assert(u);
size_t x;
x = strlen(t);
if (!u->url)
return log_oom();
r = setup_signals(u);
return load_cursor_state(u);
assert(u);
close_fd_input(u);
long status;
assert(u);
if (code) {
if (u->error[0])
return -EIO;
if (code) {
return -EUCLEAN;
return -EIO;
return -EIO;
return update_cursor_state(u);
static int parse_config(void) {
false, NULL);
static void help(void) {
opterr = 0;
help();
case ARG_VERSION:
if (arg_url) {
return -EINVAL;
case ARG_KEY:
if (arg_key) {
return -EINVAL;
case ARG_CERT:
if (arg_cert) {
return -EINVAL;
case ARG_TRUST:
if (arg_trust) {
return -EINVAL;
case ARG_SYSTEM:
case ARG_USER:
arg_merge = true;
if (arg_machine) {
return -EINVAL;
if (arg_directory) {
return -EINVAL;
case ARG_FILE:
case ARG_CURSOR:
if (arg_cursor) {
return -EINVAL;
case ARG_AFTER_CURSOR:
if (arg_cursor) {
return -EINVAL;
arg_after_cursor = true;
case ARG_FOLLOW:
if (optarg) {
return -EINVAL;
arg_follow = !!r;
arg_follow = true;
case ARG_SAVE_STATE:
return -EINVAL;
return -EINVAL;
if (!arg_url) {
return -EINVAL;
return -EINVAL;
return -EINVAL;
if (arg_directory)
else if (arg_file)
else if (arg_machine)
Uploader u;
bool use_journal;
log_show_color(true);
r = parse_config();
goto finish;
goto finish;
goto cleanup;
r = check_cursor_updating(&u);
goto cleanup;
if (use_journal) {
sd_journal *j;
r = open_journal(&j);
goto finish;
r = open_journal_for_upload(&u, j,
!!arg_follow);
goto finish;
sd_notify(false,
if (r == SD_EVENT_FINISHED)
if (use_journal) {
if (!u.journal)
r = check_journal_input(&u);
goto cleanup;
if (u.uploading) {
r = perform_upload(&u);
sd_notify(false,
destroy_uploader(&u);