journalctl.c revision 99271804172f6ac51be9556b2bdf37d6a7e952bc
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan/***
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan This file is part of systemd.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan Copyright 2011 Lennart Poettering
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan systemd is free software; you can redistribute it and/or modify it
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan under the terms of the GNU Lesser General Public License as published by
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan the Free Software Foundation; either version 2.1 of the License, or
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan (at your option) any later version.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan systemd is distributed in the hope that it will be useful, but
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan WITHOUT ANY WARRANTY; without even the implied warranty of
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan Lesser General Public License for more details.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan You should have received a copy of the GNU Lesser General Public License
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan along with systemd; If not, see <http://www.gnu.org/licenses/>.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan***/
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <locale.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <fcntl.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <errno.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <stddef.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <string.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <stdio.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <unistd.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <stdlib.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <time.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <getopt.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <signal.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <sys/stat.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <sys/ioctl.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <linux/fs.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_ACL
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <sys/acl.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "acl-util.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include <systemd/sd-journal.h>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "log.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "logs-show.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "util.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "path-util.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "build.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "pager.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "logs-show.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "strv.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "journal-internal.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "journal-def.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "journal-verify.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "journal-authenticate.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "journal-qrcode.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "fsprg.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "unit-name.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#include "catalog.h"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic OutputMode arg_output = OUTPUT_SHORT;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_pager_end = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_follow = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_full = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_all = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_no_pager = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int arg_lines = -1;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_no_tail = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_quiet = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_merge = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_this_boot = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_dmesg = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic const char *arg_cursor = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic const char *arg_directory = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int arg_priorities = 0xFF;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic const char *arg_verify_key = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_GCRYPT
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic usec_t arg_interval = DEFAULT_FSS_INTERVAL_USEC;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic usec_t arg_since, arg_until;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_since_set = false, arg_until_set = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic char **arg_system_units = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic char **arg_user_units = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic const char *arg_field = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_catalog = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic bool arg_reverse = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic const char *arg_root = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic enum {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_SHOW,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_NEW_ID128,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_PRINT_HEADER,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_SETUP_KEYS,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_VERIFY,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_DISK_USAGE,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_LIST_CATALOG,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_DUMP_CATALOG,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ACTION_UPDATE_CATALOG
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan} arg_action = ACTION_SHOW;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int help(void) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("%s [OPTIONS...] [MATCHES...]\n\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "Query the journal.\n\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "Flags:\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --since=DATE Start showing entries newer or of the specified date\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --until=DATE Stop showing entries older or of the specified date\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -c --cursor=CURSOR Start showing entries from specified cursor\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -b --this-boot Show data only from current boot\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -k --dmesg Show kmsg log from current boot\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -u --unit=UNIT Show data only from the specified unit\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --user-unit=UNIT Show data only from the specified user session unit\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -p --priority=RANGE Show only messages within the specified priority range\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -e --pager-end Immediately jump to end of the journal in the pager\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -f --follow Follow journal\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -n --lines[=INTEGER] Number of journal entries to show\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --no-tail Show all lines, even in follow mode\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -r --reverse Show the newest entries first\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -o --output=STRING Change journal output mode (short, short-monotonic,\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " verbose, export, json, json-pretty, json-sse, cat)\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -x --catalog Add message explanations where available\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --full Do not ellipsize fields\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -a --all Show all fields, including long and unprintable\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -q --quiet Don't show privilege warning\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --no-pager Do not pipe output into a pager\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -m --merge Show entries from all available journals\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -D --directory=PATH Show journal files from directory\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --root=ROOT Operate on catalog files underneath the root ROOT\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_GCRYPT
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --interval=TIME Time interval for changing the FSS sealing key\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --verify-key=KEY Specify FSS verification key\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "\nCommands:\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -h --help Show this help\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --version Show package version\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --new-id128 Generate a new 128 Bit ID\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --header Show journal header information\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --disk-usage Show total disk usage\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " -F --field=FIELD List all values a certain field takes\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --list-catalog Show message IDs of all entries in the message catalog\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --dump-catalog Show entries in the message catalog\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --update-catalog Update the message catalog database\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_GCRYPT
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --setup-keys Generate new FSS key pair\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " --verify Verify journal file consistency\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan , program_invocation_short_name);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int parse_argv(int argc, char *argv[]) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan enum {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_VERSION = 0x100,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_NO_PAGER,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_NO_TAIL,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_NEW_ID128,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_ROOT,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_HEADER,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_FULL,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_SETUP_KEYS,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_INTERVAL,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_VERIFY,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_VERIFY_KEY,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_DISK_USAGE,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_SINCE,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_UNTIL,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_USER_UNIT,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_LIST_CATALOG,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_DUMP_CATALOG,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ARG_UPDATE_CATALOG
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan };
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan static const struct option options[] = {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "help", no_argument, NULL, 'h' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "version" , no_argument, NULL, ARG_VERSION },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "no-pager", no_argument, NULL, ARG_NO_PAGER },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "pager-end", no_argument, NULL, 'e' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "follow", no_argument, NULL, 'f' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "output", required_argument, NULL, 'o' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "all", no_argument, NULL, 'a' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "full", no_argument, NULL, ARG_FULL },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "lines", optional_argument, NULL, 'n' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "no-tail", no_argument, NULL, ARG_NO_TAIL },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "new-id128", no_argument, NULL, ARG_NEW_ID128 },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "quiet", no_argument, NULL, 'q' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "merge", no_argument, NULL, 'm' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "this-boot", no_argument, NULL, 'b' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "dmesg", no_argument, NULL, 'k' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "directory", required_argument, NULL, 'D' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "root", required_argument, NULL, ARG_ROOT },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "header", no_argument, NULL, ARG_HEADER },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "priority", required_argument, NULL, 'p' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "setup-keys", no_argument, NULL, ARG_SETUP_KEYS },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "interval", required_argument, NULL, ARG_INTERVAL },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "verify", no_argument, NULL, ARG_VERIFY },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "verify-key", required_argument, NULL, ARG_VERIFY_KEY },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "disk-usage", no_argument, NULL, ARG_DISK_USAGE },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "cursor", required_argument, NULL, 'c' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "since", required_argument, NULL, ARG_SINCE },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "until", required_argument, NULL, ARG_UNTIL },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "unit", required_argument, NULL, 'u' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "user-unit", required_argument, NULL, ARG_USER_UNIT },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "field", required_argument, NULL, 'F' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "catalog", no_argument, NULL, 'x' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "list-catalog", no_argument, NULL, ARG_LIST_CATALOG },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "dump-catalog", no_argument, NULL, ARG_DUMP_CATALOG },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "update-catalog",no_argument, NULL, ARG_UPDATE_CATALOG },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { "reverse", no_argument, NULL, 'r' },
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan { NULL, 0, NULL, 0 }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan };
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int c, r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(argc >= 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(argv);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan while ((c = getopt_long(argc, argv, "hefo:an::qmbkD:p:c:u:F:xr", options, NULL)) >= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan switch (c) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'h':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan help();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_VERSION:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan puts(PACKAGE_STRING);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan puts(SYSTEMD_FEATURES);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_NO_PAGER:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_no_pager = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'e':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_pager_end = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_lines < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_lines = 1000;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'f':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_follow = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'o':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_output = output_mode_from_string(optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_output < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Unknown output format '%s'.", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_output == OUTPUT_EXPORT ||
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_output == OUTPUT_JSON ||
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_output == OUTPUT_JSON_PRETTY ||
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_output == OUTPUT_JSON_SSE ||
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_output == OUTPUT_CAT)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_quiet = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_FULL:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_full = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'a':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_all = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'n':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (optarg) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = safe_atoi(optarg, &arg_lines);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0 || arg_lines < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to parse lines '%s'", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int n;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* Hmm, no argument? Maybe the next
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * word on the command line is
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * supposed to be the argument? Let's
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * see if there is one, and is
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * parsable as a positive
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * integer... */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (optind < argc &&
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan safe_atoi(argv[optind], &n) >= 0 &&
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan n >= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_lines = n;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan optind++;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_lines = 10;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_NO_TAIL:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_no_tail = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_NEW_ID128:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_NEW_ID128;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'q':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_quiet = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'm':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_merge = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'b':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_this_boot = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'k':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_this_boot = arg_dmesg = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'D':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_directory = optarg;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_ROOT:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_root = optarg;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'c':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_cursor = optarg;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_HEADER:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_PRINT_HEADER;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_VERIFY:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_VERIFY;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_DISK_USAGE:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_DISK_USAGE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_GCRYPT
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_SETUP_KEYS:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_SETUP_KEYS;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_VERIFY_KEY:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_VERIFY;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_verify_key = optarg;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_merge = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_INTERVAL:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = parse_sec(optarg, &arg_interval);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0 || arg_interval <= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to parse sealing key change interval: %s", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_SETUP_KEYS:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_VERIFY_KEY:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_INTERVAL:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Forward-secure sealing not available.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -ENOTSUP;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'p': {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan const char *dots;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan dots = strstr(optarg, "..");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (dots) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char *a;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int from, to, i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* a range */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan a = strndup(optarg, dots - optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!a)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan from = log_level_from_string(a);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan to = log_level_from_string(dots + 2);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan free(a);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (from < 0 || to < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to parse log level range %s", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_priorities = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (from < to) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (i = from; i <= to; i++)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_priorities |= 1 << i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (i = to; i <= from; i++)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_priorities |= 1 << i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int p, i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan p = log_level_from_string(optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (p < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Unknown log level %s", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_priorities = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (i = 0; i <= p; i++)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_priorities |= 1 << i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_SINCE:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = parse_timestamp(optarg, &arg_since);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to parse timestamp: %s", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_since_set = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_UNTIL:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = parse_timestamp(optarg, &arg_until);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to parse timestamp: %s", optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_until_set = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'u':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = strv_extend(&arg_system_units, optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_USER_UNIT:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = strv_extend(&arg_user_units, optarg);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case '?':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'F':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_field = optarg;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'x':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_catalog = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_LIST_CATALOG:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_LIST_CATALOG;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_DUMP_CATALOG:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_DUMP_CATALOG;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case ARG_UPDATE_CATALOG:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action = ACTION_UPDATE_CATALOG;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan case 'r':
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_reverse = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan default:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Unknown option code %c", c);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_follow && !arg_no_tail && arg_lines < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_lines = 10;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_since_set && arg_until_set && arg_since > arg_until) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("--since= must be before --until=.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_cursor && arg_since_set) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Please specify either --since= or --cursor=, not both.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_follow && arg_reverse) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Please specify either --reverse= or --follow=, not both.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 1;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int generate_new_id128(void) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan sd_id128_t id;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan unsigned i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_id128_randomize(&id);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to generate ID: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("As string:\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_ID128_FORMAT_STR "\n\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "As UUID:\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "As macro:\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "#define MESSAGE_XYZ SD_ID128_MAKE(",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_ID128_FORMAT_VAL(id),
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_ID128_FORMAT_VAL(id));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (i = 0; i < 16; i++)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("%02x%s", id.bytes[i], i != 15 ? "," : "");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fputs(")\n\n", stdout);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("As Python constant:\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ">>> import uuid\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ">>> MESSAGE_XYZ = uuid.UUID('" SD_ID128_FORMAT_STR "')\n",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_ID128_FORMAT_VAL(id));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int add_matches(sd_journal *j, char **args) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char **i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan STRV_FOREACH(i, args) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (streq(*i, "+"))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_disjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else if (path_is_absolute(*i)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan _cleanup_free_ char *p, *t = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan const char *path;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan struct stat st;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan p = canonicalize_file_name(*i);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan path = p ? p : *i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (stat(path, &st) < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Couldn't stat file: %m");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -errno;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (S_ISREG(st.st_mode) && (0111 & st.st_mode))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan t = strappend("_EXE=", path);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else if (S_ISCHR(st.st_mode))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan asprintf(&t, "_KERNEL_DEVICE=c%u:%u", major(st.st_rdev), minor(st.st_rdev));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else if (S_ISBLK(st.st_mode))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan asprintf(&t, "_KERNEL_DEVICE=b%u:%u", major(st.st_rdev), minor(st.st_rdev));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("File is neither a device node, nor regular file, nor executable: %s", *i);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EINVAL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!t)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_match(j, t, 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_match(j, *i, 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to add match '%s': %s", *i, strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int add_this_boot(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char match[9+32+1] = "_BOOT_ID=";
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan sd_id128_t boot_id;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_this_boot)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_id128_get_boot(&boot_id);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to get boot id: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan sd_id128_to_string(boot_id, match + 9);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_match(j, match, strlen(match));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to add match: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_conjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int add_dmesg(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_dmesg)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_match(j, "_TRANSPORT=kernel", strlen("_TRANSPORT=kernel"));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to add match: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_conjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int add_units(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan _cleanup_free_ char *u = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char **i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan STRV_FOREACH(i, arg_system_units) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan u = unit_name_mangle(*i);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!u)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_matches_for_unit(j, u);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_disjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan STRV_FOREACH(i, arg_user_units) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan u = unit_name_mangle(*i);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!u)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_matches_for_user_unit(j, u, getuid());
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_disjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_conjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int add_priorities(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char match[] = "PRIORITY=0";
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int i, r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_priorities == 0xFF)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (i = LOG_EMERG; i <= LOG_DEBUG; i++)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_priorities & (1 << i)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan match[sizeof(match)-2] = '0' + i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_match(j, match, strlen(match));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to add match: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_add_conjunction(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int setup_keys(void) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_GCRYPT
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan size_t mpk_size, seed_size, state_size, i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan uint8_t *mpk, *seed, *state;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ssize_t l;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int fd = -1, r, attr = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan sd_id128_t machine, boot;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char *p = NULL, *k = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan struct FSSHeader h;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan uint64_t n;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_id128_get_machine(&machine);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to get machine ID: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_id128_get_boot(&boot);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to get boot ID: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/fss",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_ID128_FORMAT_VAL(machine)) < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (access(p, F_OK) >= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Sealing key file %s exists already.", p);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -EEXIST;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (asprintf(&k, "/var/log/journal/" SD_ID128_FORMAT_STR "/fss.tmp.XXXXXX",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_ID128_FORMAT_VAL(machine)) < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan mpk_size = FSPRG_mskinbytes(FSPRG_RECOMMENDED_SECPAR);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan mpk = alloca(mpk_size);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan seed_size = FSPRG_RECOMMENDED_SEEDLEN;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan seed = alloca(seed_size);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan state_size = FSPRG_stateinbytes(FSPRG_RECOMMENDED_SECPAR);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan state = alloca(state_size);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (fd < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to open /dev/random: %m");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -errno;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("Generating seed...");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan l = loop_read(fd, seed, seed_size, true);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (l < 0 || (size_t) l != seed_size) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to read random seed: %s", strerror(EIO));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -EIO;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("Generating key pair...");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan FSPRG_GenMK(NULL, mpk, seed, seed_size, FSPRG_RECOMMENDED_SECPAR);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("Generating sealing key...");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan FSPRG_GenState0(state, mpk, seed, seed_size);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(arg_interval > 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan n = now(CLOCK_REALTIME);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan n /= arg_interval;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan close_nointr_nofail(fd);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fd = mkostemp(k, O_WRONLY|O_CLOEXEC|O_NOCTTY);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (fd < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to open %s: %m", k);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -errno;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* Enable secure remove, exclusion from dump, synchronous
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * writing and in-place updating */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (ioctl(fd, FS_IOC_GETFLAGS, &attr) < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_warning("FS_IOC_GETFLAGS failed: %m");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan attr |= FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (ioctl(fd, FS_IOC_SETFLAGS, &attr) < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_warning("FS_IOC_SETFLAGS failed: %m");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan zero(h);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan memcpy(h.signature, "KSHHRHLP", 8);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.machine_id = machine;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.boot_id = boot;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.header_size = htole64(sizeof(h));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.start_usec = htole64(n * arg_interval);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.interval_usec = htole64(arg_interval);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.fsprg_secpar = htole16(FSPRG_RECOMMENDED_SECPAR);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan h.fsprg_state_size = htole64(state_size);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan l = loop_write(fd, &h, sizeof(h), false);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (l < 0 || (size_t) l != sizeof(h)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to write header: %s", strerror(EIO));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -EIO;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan l = loop_write(fd, state, state_size, false);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (l < 0 || (size_t) l != state_size) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to write state: %s", strerror(EIO));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -EIO;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (link(k, p) < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to link file: %m");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -errno;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (on_tty()) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fprintf(stderr,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "The new key pair has been generated. The " ANSI_HIGHLIGHT_ON "secret sealing key" ANSI_HIGHLIGHT_OFF " has been written to\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "the following local file. This key file is automatically updated when the\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "sealing key is advanced. It should not be used on multiple hosts.\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "\t%s\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "Please write down the following " ANSI_HIGHLIGHT_ON "secret verification key" ANSI_HIGHLIGHT_OFF ". It should be stored\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "at a safe location and should not be saved locally on disk.\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "\n\t" ANSI_HIGHLIGHT_RED_ON, p);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fflush(stderr);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (i = 0; i < seed_size; i++) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (i > 0 && i % 3 == 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan putchar('-');
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("%02x", ((uint8_t*) seed)[i]);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("/%llx-%llx\n", (unsigned long long) n, (unsigned long long) arg_interval);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (on_tty()) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char tsb[FORMAT_TIMESPAN_MAX], *hn;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fprintf(stderr,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ANSI_HIGHLIGHT_OFF "\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "The sealing key is automatically changed every %s.\n",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timespan(tsb, sizeof(tsb), arg_interval, 0));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan hn = gethostname_malloc();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (hn) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan hostname_cleanup(hn, false);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_QRENCODE
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* If this is not an UTF-8 system don't print any QR codes */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (is_locale_utf8()) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan fputs("\nTo transfer the verification key to your phone please scan the QR code below:\n\n", stderr);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan print_qr_code(stderr, seed, seed_size, n, arg_interval, hn, machine);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan free(hn);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganfinish:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (fd >= 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan close_nointr_nofail(fd);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (k) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan unlink(k);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan free(k);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan free(p);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Forward-secure sealing not available.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -ENOTSUP;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int verify(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan Iterator i;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan JournalFile *f;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_show_color(true);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan HASHMAP_FOREACH(f, j->files, i) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int k;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan usec_t first, validated, last;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_GCRYPT
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_verify_key && JOURNAL_HEADER_SEALED(f->header))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_notice("Journal file %s has sealing enabled but verification key has not been passed using --verify-key=.", f->path);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan k = journal_file_verify(f, arg_verify_key, &first, &validated, &last, true);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (k == -EINVAL) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* If the key was invalid give up right-away. */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return k;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else if (k < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_warning("FAIL: %s (%s)", f->path, strerror(-k));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = k;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX], c[FORMAT_TIMESPAN_MAX];
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("PASS: %s", f->path);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (validated > 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("=> Validated from %s to %s, final %s entries not sealed.",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timestamp(a, sizeof(a), first),
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timestamp(b, sizeof(b), validated),
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timespan(c, sizeof(c), last > validated ? last - validated : 0, 0));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else if (last > 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("=> No sealing yet, %s of entries not sealed.",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timespan(c, sizeof(c), last - first, 0));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_info("=> No sealing yet, no entries in file.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_ACL
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int access_check_var_log_journal(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan _cleanup_strv_free_ char **g = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan bool have_access;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan have_access = in_group("systemd-journal") > 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!have_access) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* Let's enumerate all groups from the default ACL of
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * the directory, which generally should allow access
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * to most journal files too */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = search_acl_groups(&g, "/var/log/journal/", &have_access);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!have_access) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (strv_isempty(g))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_notice("Hint: You are currently not seeing messages from other users and the system.\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " Users in the 'systemd-journal' group can see all messages. Pass -q to\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " turn off this notice.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan _cleanup_free_ char *s = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = strv_extend(&g, "systemd-journal");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan strv_sort(g);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan strv_uniq(g);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan s = strv_join(g, "', '");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!s)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_notice("Hint: You are currently not seeing messages from other users and the system.\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " Users in the groups '%s' can see all messages.\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan " Pass -q to turn off this notice.", s);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic int access_check(sd_journal *j) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan Iterator it;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan void *code;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (set_isempty(j->errors)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (hashmap_isempty(j->files))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_notice("No journal files were found.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (set_contains(j->errors, INT_TO_PTR(-EACCES))) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#ifdef HAVE_ACL
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* If /var/log/journal doesn't even exist,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * unprivileged users have no access at all */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (access("/var/log/journal", F_OK) < 0 &&
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan geteuid() != 0 &&
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan in_group("systemd-journal") <= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Unprivileged users cannot access messages, unless persistent log storage is\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "enabled. Users in the 'systemd-journal' group may always access messages.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EACCES;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* If /var/log/journal exists, try to pring a nice
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan notice if the user lacks access to it */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_quiet && geteuid() != 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = access_check_var_log_journal(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (geteuid() != 0 && in_group("systemd-journal") <= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Unprivileged users cannot access messages. Users in the 'systemd-journal' group\n"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan "group may access messages.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return -EACCES;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (hashmap_isempty(j->files)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("No journal files were opened due to insufficient permissions.");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = -EACCES;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SET_FOREACH(code, j->errors, it) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int err;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan err = -PTR_TO_INT(code);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan assert(err > 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (err != EACCES)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_warning("Error was encountered while opening journal files: %s",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan strerror(err));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganint main(int argc, char *argv[]) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int r;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan _cleanup_journal_close_ sd_journal*j = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan bool need_seek = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan sd_id128_t previous_boot_id;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan bool previous_boot_id_valid = false, first_line = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int n_shown = 0;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan setlocale(LC_ALL, "");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_parse_environment();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_open();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = parse_argv(argc, argv);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r <= 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan signal(SIGWINCH, columns_lines_cache_reset);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_NEW_ID128) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = generate_new_id128();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_SETUP_KEYS) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = setup_keys();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_UPDATE_CATALOG ||
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action == ACTION_LIST_CATALOG ||
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_action == ACTION_DUMP_CATALOG) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan const char* database = CATALOG_DATABASE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan _cleanup_free_ char *copy = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_root) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan copy = strjoin(arg_root, "/", CATALOG_DATABASE, NULL);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!copy) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = log_oom();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan path_kill_slashes(copy);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan database = copy;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_UPDATE_CATALOG) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = catalog_update(database, arg_root, catalog_file_dirs);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to list catalog: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan bool oneline = arg_action == ACTION_LIST_CATALOG;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (optind < argc)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = catalog_list_items(stdout, database,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan oneline, argv + optind);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = catalog_list(stdout, database, oneline);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to list catalog: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_directory)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_open_directory(&j, arg_directory, 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_open(&j, arg_merge ? 0 : SD_JOURNAL_LOCAL_ONLY);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to open journal: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = access_check(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_VERIFY) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = verify(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_PRINT_HEADER) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan journal_print_header(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_SUCCESS;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_action == ACTION_DISK_USAGE) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan uint64_t bytes;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char sbytes[FORMAT_BYTES_MAX];
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_get_usage(j, &bytes);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("Journals take up %s on disk.\n",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_bytes(sbytes, sizeof(sbytes), bytes));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_SUCCESS;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_this_boot(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_dmesg(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_units(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan strv_free(arg_system_units);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan strv_free(arg_user_units);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_priorities(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = add_matches(j, argv + optind);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan /* Opening the fd now means the first sd_journal_wait() will actually wait */
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_get_fd(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_field) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan const void *data;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan size_t size;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_set_data_threshold(j, 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to unset data size threshold");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_query_unique(j, arg_field);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to query unique data objects: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan const void *eq;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_lines >= 0 && n_shown >= arg_lines)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan eq = memchr(data, '=', size);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (eq)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("%.*s\n", (int) (size - ((const uint8_t*) eq - (const uint8_t*) data + 1)), (const char*) eq + 1);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("%.*s\n", (int) size, (const char*) data);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan n_shown ++;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_SUCCESS;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_cursor) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_seek_cursor(j, arg_cursor);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to seek to cursor: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_reverse)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_next(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_previous(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else if (arg_since_set && !arg_reverse) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_seek_realtime_usec(j, arg_since);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to seek to date: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_next(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else if (arg_until_set && arg_reverse) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_seek_realtime_usec(j, arg_until);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to seek to date: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_previous(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else if (arg_lines >= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_seek_tail(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to seek to tail: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_previous_skip(j, arg_lines);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else if (arg_reverse) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_seek_tail(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to seek to tail: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_previous(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan } else {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_seek_head(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to seek to head: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_next(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to iterate through journal: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return EXIT_FAILURE;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_no_pager && !arg_follow)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan pager_open(arg_pager_end);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_quiet) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan usec_t start, end;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan char start_buf[FORMAT_TIMESTAMP_MAX], end_buf[FORMAT_TIMESTAMP_MAX];
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_get_cutoff_realtime_usec(j, &start, &end);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to get cutoff: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r > 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_follow)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("-- Logs begin at %s. --\n",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timestamp(start_buf, sizeof(start_buf), start));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf("-- Logs begin at %s, end at %s. --\n",
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timestamp(start_buf, sizeof(start_buf), start),
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan format_timestamp(end_buf, sizeof(end_buf), end));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (;;) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan while (arg_lines < 0 || n_shown < arg_lines || (arg_follow && !first_line)) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan int flags;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (need_seek) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_reverse)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_next(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan else
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_previous(j);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to iterate through journal: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r == 0)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_until_set && !arg_reverse) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan usec_t usec;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_get_realtime_usec(j, &usec);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to determine timestamp: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (usec > arg_until)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (arg_since_set && arg_reverse) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan usec_t usec;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_get_realtime_usec(j, &usec);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Failed to determine timestamp: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (usec < arg_since)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_merge) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan sd_id128_t boot_id;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_get_monotonic_usec(j, NULL, &boot_id);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r >= 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (previous_boot_id_valid &&
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan !sd_id128_equal(boot_id, previous_boot_id))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan printf(ANSI_HIGHLIGHT_ON "-- Reboot --" ANSI_HIGHLIGHT_OFF "\n");
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan previous_boot_id = boot_id;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan previous_boot_id_valid = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan flags =
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_all * OUTPUT_SHOW_ALL |
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan on_tty() * OUTPUT_COLOR |
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan arg_catalog * OUTPUT_CATALOG;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = output_journal(stdout, j, arg_output, 0, flags);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0 || ferror(stdout))
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan need_seek = true;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan n_shown++;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (!arg_follow)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan break;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan r = sd_journal_wait(j, (uint64_t) -1);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan if (r < 0) {
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan log_error("Couldn't wait for journal event: %s", strerror(-r));
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan goto finish;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan first_line = false;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan }
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganfinish:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan pager_close();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan}
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan