diff options
Diffstat (limited to 'src/journal')
50 files changed, 624 insertions, 402 deletions
diff --git a/src/journal/.gitignore b/src/journal/.gitignore index d6a79460cd..04d5852547 100644 --- a/src/journal/.gitignore +++ b/src/journal/.gitignore @@ -1,2 +1,4 @@ /journald-gperf.c /libsystemd-journal.pc +/audit_type-list.txt +/audit_type-*-name.* diff --git a/src/journal/audit-type.c b/src/journal/audit-type.c new file mode 100644 index 0000000000..4888c7d05d --- /dev/null +++ b/src/journal/audit-type.c @@ -0,0 +1,32 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2015 Zbigniew Jędrzejewski-Szmek + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <stdio.h> +#include <linux/audit.h> +#ifdef HAVE_AUDIT +# include <libaudit.h> +#endif + +#include "audit-type.h" +#include "macro.h" +#include "missing.h" + +#include "audit_type-to-name.h" diff --git a/src/journal/audit-type.h b/src/journal/audit-type.h new file mode 100644 index 0000000000..fa5284e027 --- /dev/null +++ b/src/journal/audit-type.h @@ -0,0 +1,39 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2015 Zbigniew Jędrzejewski-Szmek + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include "macro.h" + +const char *audit_type_to_string(int type); +int audit_type_from_string(const char *s); + +/* This is inspired by DNS TYPEnnn formatting */ +#define audit_type_name_alloca(type) \ + ({ \ + const char *_s_; \ + _s_ = audit_type_to_string(type); \ + if (!_s_) { \ + _s_ = alloca(strlen("AUDIT") + DECIMAL_STR_MAX(int)); \ + sprintf((char*) _s_, "AUDIT%04i", type); \ + } \ + _s_; \ + }) diff --git a/src/journal/cat.c b/src/journal/cat.c index 79706b692d..2e236f0004 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -21,7 +21,6 @@ #include <stdio.h> #include <getopt.h> -#include <assert.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> diff --git a/src/journal/catalog.c b/src/journal/catalog.c index f170232841..0801e13599 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -34,7 +34,6 @@ #include "hashmap.h" #include "strv.h" #include "strbuf.h" -#include "strxcpyx.h" #include "conf-files.h" #include "mkdir.h" #include "catalog.h" @@ -559,7 +558,7 @@ static const char *find_id(void *p, sd_id128_t id) { int catalog_get(const char* database, sd_id128_t id, char **_text) { _cleanup_close_ int fd = -1; void *p = NULL; - struct stat st; + struct stat st = {}; char *text = NULL; int r; const char *s; diff --git a/src/journal/compress.c b/src/journal/compress.c index 6923753f89..383f6a6e96 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -19,7 +19,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <assert.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -590,14 +589,12 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) { return log_oom(); for (;;) { - ssize_t n, m; + ssize_t m; int r; - n = read(fdf, &header, sizeof(header)); - if (n < 0) - return -errno; - if (n != sizeof(header)) - return errno ? -errno : -EIO; + r = loop_read_exact(fdf, &header, sizeof(header), false); + if (r < 0) + return r; m = le32toh(header); if (m == 0) @@ -619,12 +616,9 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) { if (!GREEDY_REALLOC(buf, buf_size, m)) return log_oom(); - errno = 0; - n = loop_read(fdf, buf, m, false); - if (n < 0) - return n; - if (n != m) - return errno ? -errno : -EIO; + r = loop_read_exact(fdf, buf, m, false); + if (r < 0) + return r; r = LZ4_decompress_safe_continue(&lz4_data, buf, out, m, 4*LZ4_BUFSIZE); if (r <= 0) @@ -637,9 +631,9 @@ int decompress_stream_lz4(int fdf, int fdt, off_t max_bytes) { return -EFBIG; } - n = loop_write(fdt, out, r, false); - if (n < 0) - return n; + r = loop_write(fdt, out, r, false); + if (r < 0) + return r; } log_debug("LZ4 decompression finished (%zu -> %zu bytes, %.1f%%)", diff --git a/src/journal/compress.h b/src/journal/compress.h index 136dda6d39..6294f16faa 100644 --- a/src/journal/compress.h +++ b/src/journal/compress.h @@ -21,8 +21,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <inttypes.h> -#include <stdbool.h> #include <unistd.h> #include "journal-def.h" diff --git a/src/journal/coredump-vacuum.c b/src/journal/coredump-vacuum.c index 9b73795e5b..c0347ef569 100644 --- a/src/journal/coredump-vacuum.c +++ b/src/journal/coredump-vacuum.c @@ -103,8 +103,7 @@ static bool vacuum_necessary(int fd, off_t sum, off_t keep_free, off_t max_use) if (max_use < DEFAULT_MAX_USE_LOWER) max_use = DEFAULT_MAX_USE_LOWER; - } - else + } else max_use = DEFAULT_MAX_USE_LOWER; } else max_use = PAGE_ALIGN(max_use); @@ -135,7 +134,7 @@ int coredump_vacuum(int exclude_fd, off_t keep_free, off_t max_use) { struct stat exclude_st; int r; - if (keep_free <= 0 && max_use <= 0) + if (keep_free == 0 && max_use == 0) return 0; if (exclude_fd >= 0) { diff --git a/src/journal/coredump.c b/src/journal/coredump.c index f7ba0191e1..1c747aa2b4 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -23,7 +23,6 @@ #include <unistd.h> #include <stdio.h> #include <sys/prctl.h> -#include <sys/types.h> #include <sys/xattr.h> #ifdef HAVE_ELFUTILS @@ -44,12 +43,12 @@ #include "conf-parser.h" #include "copy.h" #include "stacktrace.h" -#include "path-util.h" #include "compress.h" #include "acl-util.h" #include "capability.h" #include "journald-native.h" #include "coredump-vacuum.h" +#include "process-util.h" /* The maximum size up to which we process coredumps */ #define PROCESS_SIZE_MAX ((off_t) (2LLU*1024LLU*1024LLU*1024LLU)) @@ -244,7 +243,7 @@ static int maybe_remove_external_coredump(const char *filename, off_t size) { static int make_filename(const char *info[_INFO_LEN], char **ret) { _cleanup_free_ char *c = NULL, *u = NULL, *p = NULL, *t = NULL; - sd_id128_t boot; + sd_id128_t boot = {}; int r; assert(info); @@ -843,7 +842,7 @@ log: /* Optionally store the entire coredump in the journal */ if (IN_SET(arg_storage, COREDUMP_STORAGE_JOURNAL, COREDUMP_STORAGE_BOTH) && coredump_size <= (off_t) arg_journal_size_max) { - size_t sz; + size_t sz = 0; /* Store the coredump itself in the journal */ diff --git a/src/journal/coredump.conf b/src/journal/coredump.conf index 0fe9fe801a..c2f0643e03 100644 --- a/src/journal/coredump.conf +++ b/src/journal/coredump.conf @@ -5,10 +5,11 @@ # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # -# You can override the directives in this file by creating files in -# /etc/systemd/coredump.conf.d/*.conf. +# Entries in this file show the compile time defaults. +# You can change settings by editing this file. +# Defaults can be restored by simply deleting this file. # -# See coredump.conf(5) for details +# See coredump.conf(5) for details. [Coredump] #Storage=external diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index afb39ad035..381bf72776 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -35,9 +35,11 @@ #include "pager.h" #include "macro.h" #include "journal-internal.h" -#include "copy.h" #include "compress.h" #include "sigbus.h" +#include "process-util.h" +#include "terminal-util.h" +#include "signal-util.h" static enum { ACTION_NONE, @@ -650,7 +652,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { } #else log_error("Cannot decompress file. Compiled without compression support."); - r = -ENOTSUP; + r = -EOPNOTSUPP; goto error; #endif } else { diff --git a/src/journal/fsprg.c b/src/journal/fsprg.c index 5c8d6d6feb..a9f564c249 100644 --- a/src/journal/fsprg.c +++ b/src/journal/fsprg.c @@ -30,7 +30,6 @@ #include <gcrypt.h> #include <string.h> -#include <assert.h> #include "fsprg.h" diff --git a/src/journal/journal-authenticate.c b/src/journal/journal-authenticate.c index b3e2601c4e..cdc80e2d26 100644 --- a/src/journal/journal-authenticate.c +++ b/src/journal/journal-authenticate.c @@ -106,7 +106,7 @@ static int journal_file_get_epoch(JournalFile *f, uint64_t realtime, uint64_t *e if (f->fss_start_usec == 0 || f->fss_interval_usec == 0) - return -ENOTSUP; + return -EOPNOTSUPP; if (realtime < f->fss_start_usec) return -ESTALE; @@ -446,7 +446,7 @@ int journal_file_hmac_setup(JournalFile *f) { e = gcry_md_open(&f->hmac, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC); if (e != 0) - return -ENOTSUP; + return -EOPNOTSUPP; return 0; } diff --git a/src/journal/journal-authenticate.h b/src/journal/journal-authenticate.h index 565fe8432c..118bb1367b 100644 --- a/src/journal/journal-authenticate.h +++ b/src/journal/journal-authenticate.h @@ -22,7 +22,6 @@ ***/ #include <stdbool.h> -#include <inttypes.h> #include "journal-file.h" diff --git a/src/journal/journal-def.h b/src/journal/journal-def.h index ab089cb966..39c9dd0dbf 100644 --- a/src/journal/journal-def.h +++ b/src/journal/journal-def.h @@ -220,7 +220,7 @@ struct Header { le64_t n_tags; le64_t n_entry_arrays; - /* Size: 224 */ + /* Size: 240 */ } _packed_; #define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' }) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 2845e05ce0..be6a5522fa 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -34,7 +34,7 @@ #include "journal-authenticate.h" #include "lookup3.h" #include "compress.h" -#include "fsprg.h" +#include "random-util.h" #define DEFAULT_DATA_HASH_TABLE_SIZE (2047ULL*sizeof(HashItem)) #define DEFAULT_FIELD_HASH_TABLE_SIZE (333ULL*sizeof(HashItem)) @@ -150,7 +150,7 @@ void journal_file_close(JournalFile *f) { * reenable all the good bits COW usually provides * (such as data checksumming). */ - (void) chattr_fd(f->fd, false, FS_NOCOW_FL); + (void) chattr_fd(f->fd, 0, FS_NOCOW_FL); (void) btrfs_defrag_fd(f->fd); } @@ -888,7 +888,7 @@ int journal_file_find_data_object_with_hash( if (o->object.flags & OBJECT_COMPRESSION_MASK) { #if defined(HAVE_XZ) || defined(HAVE_LZ4) uint64_t l; - size_t rsize; + size_t rsize = 0; l = le64toh(o->object.size); if (l <= offsetof(Object, data.payload)) @@ -1053,7 +1053,7 @@ static int journal_file_append_data( #if defined(HAVE_XZ) || defined(HAVE_LZ4) if (f->compress_xz && size >= COMPRESSION_SIZE_THRESHOLD) { - size_t rsize; + size_t rsize = 0; compression = compress_blob(data, size, o->data.payload, &rsize); @@ -2014,8 +2014,7 @@ void journal_file_reset_location(JournalFile *f) { f->current_xor_hash = 0; } -void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset) { - f->last_direction = direction; +void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) { f->location_type = LOCATION_SEEK; f->current_offset = offset; f->current_seqnum = le64toh(o->entry.seqnum); @@ -2523,6 +2522,41 @@ void journal_file_print_header(JournalFile *f) { printf("Disk usage: %s\n", format_bytes(bytes, sizeof(bytes), (off_t) st.st_blocks * 512ULL)); } +static int journal_file_warn_btrfs(JournalFile *f) { + unsigned attrs; + int r; + + assert(f); + + /* Before we write anything, check if the COW logic is turned + * off on btrfs. Given our write pattern that is quite + * unfriendly to COW file systems this should greatly improve + * performance on COW file systems, such as btrfs, at the + * expense of data integrity features (which shouldn't be too + * bad, given that we do our own checksumming). */ + + r = btrfs_is_filesystem(f->fd); + if (r < 0) + return log_warning_errno(r, "Failed to determine if journal is on btrfs: %m"); + if (!r) + return 0; + + r = read_attr_fd(f->fd, &attrs); + if (r < 0) + return log_warning_errno(r, "Failed to read file attributes: %m"); + + if (attrs & FS_NOCOW_FL) { + log_debug("Detected btrfs file system with copy-on-write disabled, all is good."); + return 0; + } + + log_notice("Creating journal file %s on a btrfs file system, and copy-on-write is enabled. " + "This is likely to slow down journal access substantially, please consider turning " + "off the copy-on-write file attribute on the journal directory, using chattr +C.", f->path); + + return 1; +} + int journal_file_open( const char *fname, int flags, @@ -2603,16 +2637,7 @@ int journal_file_open( if (f->last_stat.st_size == 0 && f->writable) { - /* Before we write anything, turn off COW logic. Given - * our write pattern that is quite unfriendly to COW - * file systems this should greatly improve - * performance on COW file systems, such as btrfs, at - * the expense of data integrity features (which - * shouldn't be too bad, given that we do our own - * checksumming). */ - r = chattr_fd(f->fd, true, FS_NOCOW_FL); - if (r < 0) - log_warning_errno(errno, "Failed to set file attributes: %m"); + (void) journal_file_warn_btrfs(f); /* Let's attach the creation time to the journal file, * so that the vacuuming code knows the age of this @@ -2653,10 +2678,8 @@ int journal_file_open( } r = mmap_cache_get(f->mmap, f->fd, f->prot, CONTEXT_HEADER, true, 0, PAGE_ALIGN(sizeof(Header)), &f->last_stat, &h); - if (r < 0) { - r = -errno; + if (r < 0) goto fail; - } f->header = h; @@ -2797,14 +2820,15 @@ int journal_file_open_reliably( r = journal_file_open(fname, flags, mode, compress, seal, metrics, mmap_cache, template, ret); - if (r != -EBADMSG && /* corrupted */ - r != -ENODATA && /* truncated */ - r != -EHOSTDOWN && /* other machine */ - r != -EPROTONOSUPPORT && /* incompatible feature */ - r != -EBUSY && /* unclean shutdown */ - r != -ESHUTDOWN && /* already archived */ - r != -EIO && /* IO error, including SIGBUS on mmap */ - r != -EIDRM /* File has been deleted */) + if (!IN_SET(r, + -EBADMSG, /* corrupted */ + -ENODATA, /* truncated */ + -EHOSTDOWN, /* other machine */ + -EPROTONOSUPPORT, /* incompatible feature */ + -EBUSY, /* unclean shutdown */ + -ESHUTDOWN, /* already archived */ + -EIO, /* IO error, including SIGBUS on mmap */ + -EIDRM /* File has been deleted */)) return r; if ((flags & O_ACCMODE) == O_RDONLY) @@ -2819,9 +2843,9 @@ int journal_file_open_reliably( /* The file is corrupted. Rotate it away and try it again (but only once) */ l = strlen(fname); - if (asprintf(&p, "%.*s@%016llx-%016" PRIx64 ".journal~", + if (asprintf(&p, "%.*s@%016"PRIx64 "-%016"PRIx64 ".journal~", (int) l - 8, fname, - (unsigned long long) now(CLOCK_REALTIME), + now(CLOCK_REALTIME), random_u64()) < 0) return -ENOMEM; @@ -2889,7 +2913,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6 if (o->object.flags & OBJECT_COMPRESSION_MASK) { #if defined(HAVE_XZ) || defined(HAVE_LZ4) - size_t rsize; + size_t rsize = 0; r = decompress_blob(o->object.flags & OBJECT_COMPRESSION_MASK, o->data.payload, l, &from->compress_buffer, &from->compress_buffer_size, &rsize, 0); diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index 2526e14d65..403c8f760c 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -199,7 +199,7 @@ int journal_file_find_field_object(JournalFile *f, const void *field, uint64_t s int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, uint64_t size, uint64_t hash, Object **ret, uint64_t *offset); void journal_file_reset_location(JournalFile *f); -void journal_file_save_location(JournalFile *f, direction_t direction, Object *o, uint64_t offset); +void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset); int journal_file_compare_locations(JournalFile *af, JournalFile *bf); int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret, uint64_t *offset); diff --git a/src/journal/journal-qrcode.h b/src/journal/journal-qrcode.h index c527e65553..3ff6a3ad4a 100644 --- a/src/journal/journal-qrcode.h +++ b/src/journal/journal-qrcode.h @@ -21,8 +21,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <inttypes.h> -#include <sys/types.h> #include <stdio.h> #include "systemd/sd-id128.h" diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c index 832c327b31..81a577ea27 100644 --- a/src/journal/journal-vacuum.c +++ b/src/journal/journal-vacuum.c @@ -19,12 +19,9 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <sys/types.h> #include <fcntl.h> #include <sys/stat.h> -#include <sys/statvfs.h> #include <unistd.h> -#include <sys/xattr.h> #include "journal-def.h" #include "journal-file.h" @@ -76,7 +73,7 @@ static void patch_realtime( unsigned long long *realtime) { _cleanup_free_ const char *path = NULL; - usec_t x, crtime; + usec_t x, crtime = 0; /* The timestamp was determined by the file name, but let's * see if the file might actually be older than the file name diff --git a/src/journal/journal-vacuum.h b/src/journal/journal-vacuum.h index a7fb6f0f0d..c45cc31d0e 100644 --- a/src/journal/journal-vacuum.h +++ b/src/journal/journal-vacuum.h @@ -21,6 +21,5 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <inttypes.h> int journal_directory_vacuum(const char *directory, uint64_t max_use, usec_t max_retention_usec, usec_t *oldest_usec, bool vacuum); diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index b03335ef31..ce734d8df7 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -32,7 +32,7 @@ #include "journal-verify.h" #include "lookup3.h" #include "compress.h" -#include "fsprg.h" +#include "terminal-util.h" static void draw_progress(uint64_t p, usec_t *last_usec) { unsigned n, i, j, k; @@ -818,7 +818,7 @@ int journal_file_verify( return r; } #else - return -ENOTSUP; + return -EOPNOTSUPP; #endif } else if (f->seal) return -ENOKEY; @@ -846,7 +846,7 @@ int journal_file_verify( if (le32toh(f->header->compatible_flags) & ~HEADER_COMPATIBLE_SUPPORTED) { log_error("Cannot verify file with unknown extensions."); - r = -ENOTSUP; + r = -EOPNOTSUPP; goto fail; } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 55c7786331..76ec0827e7 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -28,18 +28,15 @@ #include <stdio.h> #include <unistd.h> #include <stdlib.h> -#include <time.h> #include <getopt.h> #include <signal.h> #include <poll.h> #include <sys/stat.h> -#include <sys/ioctl.h> #include <sys/inotify.h> #include <linux/fs.h> #include "sd-journal.h" #include "sd-bus.h" - #include "log.h" #include "logs-show.h" #include "util.h" @@ -54,7 +51,6 @@ #include "journal-internal.h" #include "journal-def.h" #include "journal-verify.h" -#include "journal-authenticate.h" #include "journal-qrcode.h" #include "journal-vacuum.h" #include "fsprg.h" @@ -63,6 +59,8 @@ #include "mkdir.h" #include "bus-util.h" #include "bus-error.h" +#include "terminal-util.h" +#include "hostname-util.h" #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE) @@ -127,11 +125,12 @@ static enum { ACTION_VACUUM, } arg_action = ACTION_SHOW; -typedef struct boot_id_t { +typedef struct BootId { sd_id128_t id; uint64_t first; uint64_t last; -} boot_id_t; + LIST_FIELDS(struct BootId, boot_list); +} BootId; static void pager_open_if_enabled(void) { @@ -452,7 +451,7 @@ static int parse_argv(int argc, char *argv[]) { arg_boot = true; if (optarg) { - r = parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset); + r = parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset); if (r < 0) { log_error("Failed to parse boot descriptor '%s'", optarg); return -EINVAL; @@ -579,7 +578,7 @@ static int parse_argv(int argc, char *argv[]) { case ARG_INTERVAL: case ARG_FORCE: log_error("Forward-secure sealing not available."); - return -ENOTSUP; + return -EOPNOTSUPP; #endif case 'p': { @@ -735,6 +734,11 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; } + if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && (arg_file || arg_directory || arg_merge)) { + log_error("Using --boot or --list-boots with --file, --directory or --merge is not supported."); + return -EINVAL; + } + return 1; } @@ -791,7 +795,7 @@ static int add_matches(sd_journal *j, char **args) { p = canonicalize_file_name(*i); path = p ? p : *i; - if (stat(path, &st) < 0) + if (lstat(path, &st) < 0) return log_error_errno(errno, "Couldn't stat file: %m"); if (S_ISREG(st.st_mode) && (0111 & st.st_mode)) { @@ -814,17 +818,11 @@ static int add_matches(sd_journal *j, char **args) { } } else t = strappend("_EXE=", path); - } else if (S_ISCHR(st.st_mode)) { - if (asprintf(&t, "_KERNEL_DEVICE=c%u:%u", - major(st.st_rdev), - minor(st.st_rdev)) < 0) - return -ENOMEM; - } else if (S_ISBLK(st.st_mode)) { - if (asprintf(&t, "_KERNEL_DEVICE=b%u:%u", - major(st.st_rdev), - minor(st.st_rdev)) < 0) - return -ENOMEM; - } else { + } else if (S_ISCHR(st.st_mode)) + (void) asprintf(&t, "_KERNEL_DEVICE=c%u:%u", major(st.st_rdev), minor(st.st_rdev)); + else if (S_ISBLK(st.st_mode)) + (void) asprintf(&t, "_KERNEL_DEVICE=b%u:%u", major(st.st_rdev), minor(st.st_rdev)); + else { log_error("File is neither a device node, nor regular file, nor executable: %s", *i); return -EINVAL; } @@ -854,111 +852,217 @@ static int add_matches(sd_journal *j, char **args) { return 0; } -static int boot_id_cmp(const void *a, const void *b) { - uint64_t _a, _b; - - _a = ((const boot_id_t *)a)->first; - _b = ((const boot_id_t *)b)->first; +static void boot_id_free_all(BootId *l) { - return _a < _b ? -1 : (_a > _b ? 1 : 0); + while (l) { + BootId *i = l; + LIST_REMOVE(boot_list, l, i); + free(i); + } } -static int get_boots(sd_journal *j, - boot_id_t **boots, - unsigned int *count, - boot_id_t *query_ref_boot) { +static int discover_next_boot( + sd_journal *j, + BootId **boot, + bool advance_older, + bool read_realtime) { + int r; - const void *data; - size_t length, allocated = 0; + char match[9+32+1] = "_BOOT_ID="; + _cleanup_free_ BootId *next_boot = NULL; assert(j); - assert(boots); - assert(count); + assert(boot); + + /* We expect the journal to be on the last position of a boot + * (in relation to the direction we are going), so that the next + * invocation of sd_journal_next/previous will be from a different + * boot. We then collect any information we desire and then jump + * to the last location of the new boot by using a _BOOT_ID match + * coming from the other journal direction. */ + + /* Make sure we aren't restricted by any _BOOT_ID matches, so that + * we can actually advance to a *different* boot. */ + sd_journal_flush_matches(j); - r = sd_journal_query_unique(j, "_BOOT_ID"); + if (advance_older) + r = sd_journal_previous(j); + else + r = sd_journal_next(j); if (r < 0) return r; + else if (r == 0) + return 0; /* End of journal, yay. */ - *count = 0; - SD_JOURNAL_FOREACH_UNIQUE(j, data, length) { - boot_id_t *id; + next_boot = new0(BootId, 1); + if (!next_boot) + return -ENOMEM; - assert(startswith(data, "_BOOT_ID=")); + r = sd_journal_get_monotonic_usec(j, NULL, &next_boot->id); + if (r < 0) + return r; - if (!GREEDY_REALLOC(*boots, allocated, *count + 1)) - return log_oom(); + if (read_realtime) { + r = sd_journal_get_realtime_usec(j, &next_boot->first); + if (r < 0) + return r; + } + + /* Now seek to the last occurrence of this boot ID. */ + sd_id128_to_string(next_boot->id, match + 9); + r = sd_journal_add_match(j, match, sizeof(match) - 1); + if (r < 0) + return r; + + if (advance_older) + r = sd_journal_seek_head(j); + else + r = sd_journal_seek_tail(j); + if (r < 0) + return r; - id = *boots + *count; + if (advance_older) + r = sd_journal_next(j); + else + r = sd_journal_previous(j); + if (r < 0) + return r; + else if (r == 0) + return -ENODATA; /* This shouldn't happen. We just came from this very boot ID. */ - r = sd_id128_from_string(((const char *)data) + strlen("_BOOT_ID="), &id->id); + if (read_realtime) { + r = sd_journal_get_realtime_usec(j, &next_boot->last); if (r < 0) - continue; + return r; + } - r = sd_journal_add_match(j, data, length); + *boot = next_boot; + next_boot = NULL; + + return 0; +} + +static int get_boots( + sd_journal *j, + BootId **boots, + BootId *query_ref_boot, + int ref_boot_offset) { + + bool skip_once; + int r, count = 0; + BootId *head = NULL, *tail = NULL; + const bool advance_older = query_ref_boot && ref_boot_offset <= 0; + + assert(j); + + /* Adjust for the asymmetry that offset 0 is + * the last (and current) boot, while 1 is considered the + * (chronological) first boot in the journal. */ + skip_once = query_ref_boot && sd_id128_is_null(query_ref_boot->id) && ref_boot_offset < 0; + + /* Advance to the earliest/latest occurrence of our reference + * boot ID (taking our lookup direction into account), so that + * discover_next_boot() can do its job. + * If no reference is given, the journal head/tail will do, + * they're "virtual" boots after all. */ + if (query_ref_boot && !sd_id128_is_null(query_ref_boot->id)) { + char match[9+32+1] = "_BOOT_ID="; + + sd_journal_flush_matches(j); + + sd_id128_to_string(query_ref_boot->id, match + 9); + r = sd_journal_add_match(j, match, sizeof(match) - 1); if (r < 0) return r; - r = sd_journal_seek_head(j); + if (advance_older) + r = sd_journal_seek_head(j); + else + r = sd_journal_seek_tail(j); if (r < 0) return r; - r = sd_journal_next(j); + if (advance_older) + r = sd_journal_next(j); + else + r = sd_journal_previous(j); if (r < 0) return r; else if (r == 0) - goto flush; - - r = sd_journal_get_realtime_usec(j, &id->first); + goto finish; + else if (ref_boot_offset == 0) { + count = 1; + goto finish; + } + } else { + if (advance_older) + r = sd_journal_seek_tail(j); + else + r = sd_journal_seek_head(j); if (r < 0) return r; - if (query_ref_boot) { - id->last = 0; - if (sd_id128_equal(id->id, query_ref_boot->id)) - *query_ref_boot = *id; - } else { - r = sd_journal_seek_tail(j); - if (r < 0) - return r; + /* No sd_journal_next/previous here. */ + } - r = sd_journal_previous(j); - if (r < 0) - return r; - else if (r == 0) - goto flush; + for (;;) { + _cleanup_free_ BootId *current = NULL; - r = sd_journal_get_realtime_usec(j, &id->last); - if (r < 0) - return r; + r = discover_next_boot(j, ¤t, advance_older, !query_ref_boot); + if (r < 0) { + boot_id_free_all(head); + return r; } - (*count)++; - flush: - sd_journal_flush_matches(j); + if (!current) + break; + + if (query_ref_boot) { + if (!skip_once) + ref_boot_offset += advance_older ? 1 : -1; + skip_once = false; + + if (ref_boot_offset == 0) { + count = 1; + query_ref_boot->id = current->id; + break; + } + } else { + LIST_INSERT_AFTER(boot_list, head, tail, current); + tail = current; + current = NULL; + count++; + } } - qsort_safe(*boots, *count, sizeof(boot_id_t), boot_id_cmp); - return 0; +finish: + if (boots) + *boots = head; + + sd_journal_flush_matches(j); + + return count; } static int list_boots(sd_journal *j) { - int r, w, i; - unsigned int count; - boot_id_t *id; - _cleanup_free_ boot_id_t *all_ids = NULL; + int w, i, count; + BootId *id, *all_ids; assert(j); - r = get_boots(j, &all_ids, &count, NULL); - if (r < 0) - return r; + count = get_boots(j, &all_ids, NULL, 0); + if (count < 0) + return log_error_errno(count, "Failed to determine boots: %m"); + if (count == 0) + return count; pager_open_if_enabled(); /* numbers are one less, but we need an extra char for the sign */ w = DECIMAL_STR_WIDTH(count - 1) + 1; - for (id = all_ids, i = 0; id < all_ids + count; id++, i++) { + i = 0; + LIST_FOREACH(boot_list, id, all_ids) { char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX]; printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n", @@ -966,40 +1070,10 @@ static int list_boots(sd_journal *j) { SD_ID128_FORMAT_VAL(id->id), format_timestamp_maybe_utc(a, sizeof(a), id->first), format_timestamp_maybe_utc(b, sizeof(b), id->last)); + i++; } - return 0; -} - -static int get_boot_id_by_offset(sd_journal *j, sd_id128_t *boot_id, int offset) { - int r; - unsigned int count; - boot_id_t ref_boot_id = {}, *id; - _cleanup_free_ boot_id_t *all_ids = NULL; - - assert(j); - assert(boot_id); - - ref_boot_id.id = *boot_id; - r = get_boots(j, &all_ids, &count, &ref_boot_id); - if (r < 0) - return r; - - if (sd_id128_equal(*boot_id, SD_ID128_NULL)) { - if (offset > (int) count || offset <= -(int)count) - return -EADDRNOTAVAIL; - - *boot_id = all_ids[(offset <= 0)*count + offset - 1].id; - } else { - id = bsearch(&ref_boot_id, all_ids, count, sizeof(boot_id_t), boot_id_cmp); - - if (!id || - offset <= 0 ? (id - all_ids) + offset < 0 : - (id - all_ids) + offset >= (int) count) - return -EADDRNOTAVAIL; - - *boot_id = (id + offset)->id; - } + boot_id_free_all(all_ids); return 0; } @@ -1007,6 +1081,7 @@ static int get_boot_id_by_offset(sd_journal *j, sd_id128_t *boot_id, int offset) static int add_boot(sd_journal *j) { char match[9+32+1] = "_BOOT_ID="; int r; + BootId ref_boot_id = {}; assert(j); @@ -1016,17 +1091,22 @@ static int add_boot(sd_journal *j) { if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL)) return add_match_this_boot(j, arg_machine); - r = get_boot_id_by_offset(j, &arg_boot_id, arg_boot_offset); - if (r < 0) { - if (sd_id128_equal(arg_boot_id, SD_ID128_NULL)) - log_error_errno(r, "Failed to look up boot %+i: %m", arg_boot_offset); + ref_boot_id.id = arg_boot_id; + r = get_boots(j, NULL, &ref_boot_id, arg_boot_offset); + assert(r <= 1); + if (r <= 0) { + const char *reason = (r == 0) ? "No such boot ID in journal" : strerror(-r); + + if (sd_id128_is_null(arg_boot_id)) + log_error("Failed to look up boot %+i: %s", arg_boot_offset, reason); else log_error("Failed to look up boot ID "SD_ID128_FORMAT_STR"%+i: %s", - SD_ID128_FORMAT_VAL(arg_boot_id), arg_boot_offset, strerror(-r)); - return r; + SD_ID128_FORMAT_VAL(arg_boot_id), arg_boot_offset, reason); + + return r == 0 ? -ENODATA : r; } - sd_id128_to_string(arg_boot_id, match + 9); + sd_id128_to_string(ref_boot_id.id, match + 9); r = sd_journal_add_match(j, match, sizeof(match) - 1); if (r < 0) @@ -1034,7 +1114,7 @@ static int add_boot(sd_journal *j) { r = sd_journal_add_conjunction(j); if (r < 0) - return r; + return log_error_errno(r, "Failed to add conjunction: %m"); return 0; } @@ -1052,22 +1132,24 @@ static int add_dmesg(sd_journal *j) { r = sd_journal_add_conjunction(j); if (r < 0) - return r; + return log_error_errno(r, "Failed to add conjunction: %m"); return 0; } -static int get_possible_units(sd_journal *j, - const char *fields, - char **patterns, - Set **units) { +static int get_possible_units( + sd_journal *j, + const char *fields, + char **patterns, + Set **units) { + _cleanup_set_free_free_ Set *found; const char *field; int r; found = set_new(&string_hash_ops); if (!found) - return log_oom(); + return -ENOMEM; NULSTR_FOREACH(field, fields) { const void *data; @@ -1090,7 +1172,7 @@ static int get_possible_units(sd_journal *j, u = strndup((char*) data + prefix, size - prefix); if (!u) - return log_oom(); + return -ENOMEM; STRV_FOREACH(pattern, patterns) if (fnmatch(*pattern, u, FNM_NOESCAPE) == 0) { @@ -1137,9 +1219,9 @@ static int add_units(sd_journal *j) { STRV_FOREACH(i, arg_system_units) { _cleanup_free_ char *u = NULL; - u = unit_name_mangle(*i, MANGLE_GLOB); - if (!u) - return log_oom(); + r = unit_name_mangle(*i, UNIT_NAME_GLOB, &u); + if (r < 0) + return r; if (string_is_glob(u)) { r = strv_push(&patterns, u); @@ -1183,9 +1265,9 @@ static int add_units(sd_journal *j) { STRV_FOREACH(i, arg_user_units) { _cleanup_free_ char *u = NULL; - u = unit_name_mangle(*i, MANGLE_GLOB); - if (!u) - return log_oom(); + r = unit_name_mangle(*i, UNIT_NAME_GLOB, &u); + if (r < 0) + return r; if (string_is_glob(u)) { r = strv_push(&patterns, u); @@ -1254,7 +1336,7 @@ static int add_priorities(sd_journal *j) { r = sd_journal_add_conjunction(j); if (r < 0) - return r; + return log_error_errno(r, "Failed to add conjunction: %m"); return 0; } @@ -1289,7 +1371,6 @@ static int setup_keys(void) { #ifdef HAVE_GCRYPT size_t mpk_size, seed_size, state_size, i; uint8_t *mpk, *seed, *state; - ssize_t l; int fd = -1, r; sd_id128_t machine, boot; char *p = NULL, *k = NULL; @@ -1319,19 +1400,16 @@ static int setup_keys(void) { SD_ID128_FORMAT_VAL(machine)) < 0) return log_oom(); - if (access(p, F_OK) >= 0) { - if (arg_force) { - r = unlink(p); - if (r < 0) { - log_error_errno(errno, "unlink(\"%s\") failed: %m", p); - r = -errno; - goto finish; - } - } else { - log_error("Sealing key file %s exists already. (--force to recreate)", p); - r = -EEXIST; + if (arg_force) { + r = unlink(p); + if (r < 0 && errno != ENOENT) { + r = log_error_errno(errno, "unlink(\"%s\") failed: %m", p); goto finish; } + } else if (access(p, F_OK) >= 0) { + log_error("Sealing key file %s exists already. Use --force to recreate.", p); + r = -EEXIST; + goto finish; } if (asprintf(&k, "/var/log/journal/" SD_ID128_FORMAT_STR "/fss.tmp.XXXXXX", @@ -1357,10 +1435,9 @@ static int setup_keys(void) { } log_info("Generating seed..."); - l = loop_read(fd, seed, seed_size, true); - if (l < 0 || (size_t) l != seed_size) { - log_error_errno(EIO, "Failed to read random seed: %m"); - r = -EIO; + r = loop_read_exact(fd, seed, seed_size, true); + if (r < 0) { + log_error_errno(r, "Failed to read random seed: %m"); goto finish; } @@ -1385,7 +1462,7 @@ static int setup_keys(void) { /* Enable secure remove, exclusion from dump, synchronous * writing and in-place updating */ - r = chattr_fd(fd, true, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL); + r = chattr_fd(fd, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL, FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL); if (r < 0) log_warning_errno(errno, "Failed to set file attributes: %m"); @@ -1480,7 +1557,7 @@ finish: return r; #else log_error("Forward-secure sealing not available."); - return -ENOTSUP; + return -EOPNOTSUPP; #endif } @@ -1495,7 +1572,7 @@ static int verify(sd_journal *j) { ORDERED_HASHMAP_FOREACH(f, j->files, i) { int k; - usec_t first, validated, last; + usec_t first = 0, validated = 0, last = 0; #ifdef HAVE_GCRYPT if (!arg_verify_key && JOURNAL_HEADER_SEALED(f->header)) @@ -1531,54 +1608,76 @@ static int verify(sd_journal *j) { return r; } -#ifdef HAVE_ACL static int access_check_var_log_journal(sd_journal *j) { +#ifdef HAVE_ACL _cleanup_strv_free_ char **g = NULL; - bool have_access; + const char* dir; +#endif int r; assert(j); - have_access = in_group("systemd-journal") > 0; + if (arg_quiet) + return 0; - if (!have_access) { - /* Let's enumerate all groups from the default ACL of - * the directory, which generally should allow access - * to most journal files too */ - r = search_acl_groups(&g, "/var/log/journal/", &have_access); - if (r < 0) - return r; - } + /* If we are root, we should have access, don't warn. */ + if (getuid() == 0) + return 0; - if (!have_access) { + /* If we are in the 'systemd-journal' group, we should have + * access too. */ + r = in_group("systemd-journal"); + if (r < 0) + return log_error_errno(r, "Failed to check if we are in the 'systemd-journal' group: %m"); + if (r > 0) + return 0; - if (strv_isempty(g)) - log_notice("Hint: You are currently not seeing messages from other users and the system.\n" - " Users in the 'systemd-journal' group can see all messages. Pass -q to\n" - " turn off this notice."); - else { - _cleanup_free_ char *s = NULL; +#ifdef HAVE_ACL + if (laccess("/run/log/journal", F_OK) >= 0) + dir = "/run/log/journal"; + else + dir = "/var/log/journal"; - r = strv_extend(&g, "systemd-journal"); - if (r < 0) - return log_oom(); + /* If we are in any of the groups listed in the journal ACLs, + * then all is good, too. Let's enumerate all groups from the + * default ACL of the directory, which generally should allow + * access to most journal files too. */ + r = acl_search_groups(dir, &g); + if (r < 0) + return log_error_errno(r, "Failed to search journal ACL: %m"); + if (r > 0) + return 0; - strv_sort(g); - strv_uniq(g); + /* Print a pretty list, if there were ACLs set. */ + if (!strv_isempty(g)) { + _cleanup_free_ char *s = NULL; - s = strv_join(g, "', '"); - if (!s) - return log_oom(); + /* Thre are groups in the ACL, let's list them */ + r = strv_extend(&g, "systemd-journal"); + if (r < 0) + return log_oom(); - log_notice("Hint: You are currently not seeing messages from other users and the system.\n" - " Users in the groups '%s' can see all messages.\n" - " Pass -q to turn off this notice.", s); - } + strv_sort(g); + strv_uniq(g); + + s = strv_join(g, "', '"); + if (!s) + return log_oom(); + + log_notice("Hint: You are currently not seeing messages from other users and the system.\n" + " Users in groups '%s' can see all messages.\n" + " Pass -q to turn off this notice.", s); + return 1; } +#endif - return 0; + /* If no ACLs were found, print a short version of the message. */ + log_notice("Hint: You are currently not seeing messages from other users and the system.\n" + " Users in the 'systemd-journal' group can see all messages. Pass -q to\n" + " turn off this notice."); + + return 1; } -#endif static int access_check(sd_journal *j) { Iterator it; @@ -1590,40 +1689,15 @@ static int access_check(sd_journal *j) { if (set_isempty(j->errors)) { if (ordered_hashmap_isempty(j->files)) log_notice("No journal files were found."); + return 0; } if (set_contains(j->errors, INT_TO_PTR(-EACCES))) { -#ifdef HAVE_ACL - /* If /var/log/journal doesn't even exist, - * unprivileged users have no access at all */ - if (access("/var/log/journal", F_OK) < 0 && - geteuid() != 0 && - in_group("systemd-journal") <= 0) { - log_error("Unprivileged users cannot access messages, unless persistent log storage is\n" - "enabled. Users in the 'systemd-journal' group may always access messages."); - return -EACCES; - } - - /* If /var/log/journal exists, try to pring a nice - notice if the user lacks access to it */ - if (!arg_quiet && geteuid() != 0) { - r = access_check_var_log_journal(j); - if (r < 0) - return r; - } -#else - if (geteuid() != 0 && in_group("systemd-journal") <= 0) { - log_error("Unprivileged users cannot access messages. Users in the 'systemd-journal' group\n" - "group may access messages."); - return -EACCES; - } -#endif + (void) access_check_var_log_journal(j); - if (ordered_hashmap_isempty(j->files)) { - log_error("No journal files were opened due to insufficient permissions."); - r = -EACCES; - } + if (ordered_hashmap_isempty(j->files)) + r = log_error_errno(EACCES, "No journal files were opened due to insufficient permissions."); } SET_FOREACH(code, j->errors, it) { @@ -1632,8 +1706,12 @@ static int access_check(sd_journal *j) { err = -PTR_TO_INT(code); assert(err > 0); - if (err != EACCES) - log_warning_errno(err, "Error was encountered while opening journal files: %m"); + if (err == EACCES) + continue; + + log_warning_errno(err, "Error was encountered while opening journal files: %m"); + if (r == 0) + r = -err; } return r; @@ -1780,12 +1858,12 @@ int main(int argc, char *argv[]) { if (r < 0) { log_error_errno(r, "Failed to open %s: %m", arg_directory ? arg_directory : arg_file ? "files" : "journal"); - return EXIT_FAILURE; + goto finish; } r = access_check(j); if (r < 0) - return EXIT_FAILURE; + goto finish; if (arg_action == ACTION_VERIFY) { r = verify(j); @@ -1794,7 +1872,8 @@ int main(int argc, char *argv[]) { if (arg_action == ACTION_PRINT_HEADER) { journal_print_header(j); - return EXIT_SUCCESS; + r = 0; + goto finish; } if (arg_action == ACTION_DISK_USAGE) { @@ -1803,11 +1882,11 @@ int main(int argc, char *argv[]) { r = sd_journal_get_usage(j, &bytes); if (r < 0) - return EXIT_FAILURE; + goto finish; printf("Archived and active journals take up %s on disk.\n", format_bytes(sbytes, sizeof(sbytes), bytes)); - return EXIT_SUCCESS; + goto finish; } if (arg_action == ACTION_VACUUM) { @@ -1827,7 +1906,7 @@ int main(int argc, char *argv[]) { } } - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + goto finish; } if (arg_action == ACTION_LIST_BOOTS) { @@ -1839,43 +1918,39 @@ int main(int argc, char *argv[]) { * It may need to seek the journal to find parent boot IDs. */ r = add_boot(j); if (r < 0) - return EXIT_FAILURE; + goto finish; r = add_dmesg(j); if (r < 0) - return EXIT_FAILURE; + goto finish; r = add_units(j); - strv_free(arg_system_units); - strv_free(arg_user_units); - if (r < 0) { log_error_errno(r, "Failed to add filter for units: %m"); - return EXIT_FAILURE; + goto finish; } r = add_syslog_identifier(j); if (r < 0) { log_error_errno(r, "Failed to add filter for syslog identifiers: %m"); - return EXIT_FAILURE; + goto finish; } r = add_priorities(j); - if (r < 0) { - log_error_errno(r, "Failed to add filter for priorities: %m"); - return EXIT_FAILURE; - } + if (r < 0) + goto finish; r = add_matches(j, argv + optind); - if (r < 0) { - log_error_errno(r, "Failed to add filters: %m"); - return EXIT_FAILURE; - } + if (r < 0) + goto finish; if (_unlikely_(log_get_max_level() >= LOG_DEBUG)) { _cleanup_free_ char *filter; filter = journal_make_match_string(j); + if (!filter) + return log_oom(); + log_debug("Journal filter: %s", filter); } @@ -1885,14 +1960,14 @@ int main(int argc, char *argv[]) { r = sd_journal_set_data_threshold(j, 0); if (r < 0) { - log_error("Failed to unset data size threshold"); - return EXIT_FAILURE; + log_error_errno(r, "Failed to unset data size threshold: %m"); + goto finish; } r = sd_journal_query_unique(j, arg_field); if (r < 0) { log_error_errno(r, "Failed to query unique data objects: %m"); - return EXIT_FAILURE; + goto finish; } SD_JOURNAL_FOREACH_UNIQUE(j, data, size) { @@ -1910,22 +1985,26 @@ int main(int argc, char *argv[]) { n_shown ++; } - return EXIT_SUCCESS; + r = 0; + goto finish; } /* Opening the fd now means the first sd_journal_wait() will actually wait */ if (arg_follow) { r = sd_journal_get_fd(j); - if (r < 0) - return EXIT_FAILURE; + if (r < 0) { + log_error_errno(r, "Failed to get journal fd: %m"); + goto finish; + } } if (arg_cursor || arg_after_cursor) { r = sd_journal_seek_cursor(j, arg_cursor ?: arg_after_cursor); if (r < 0) { log_error_errno(r, "Failed to seek to cursor: %m"); - return EXIT_FAILURE; + goto finish; } + if (!arg_reverse) r = sd_journal_next_skip(j, 1 + !!arg_after_cursor); else @@ -1943,7 +2022,7 @@ int main(int argc, char *argv[]) { r = sd_journal_seek_realtime_usec(j, arg_since); if (r < 0) { log_error_errno(r, "Failed to seek to date: %m"); - return EXIT_FAILURE; + goto finish; } r = sd_journal_next(j); @@ -1951,7 +2030,7 @@ int main(int argc, char *argv[]) { r = sd_journal_seek_realtime_usec(j, arg_until); if (r < 0) { log_error_errno(r, "Failed to seek to date: %m"); - return EXIT_FAILURE; + goto finish; } r = sd_journal_previous(j); @@ -1959,7 +2038,7 @@ int main(int argc, char *argv[]) { r = sd_journal_seek_tail(j); if (r < 0) { log_error_errno(r, "Failed to seek to tail: %m"); - return EXIT_FAILURE; + goto finish; } r = sd_journal_previous_skip(j, arg_lines); @@ -1968,7 +2047,7 @@ int main(int argc, char *argv[]) { r = sd_journal_seek_tail(j); if (r < 0) { log_error_errno(r, "Failed to seek to tail: %m"); - return EXIT_FAILURE; + goto finish; } r = sd_journal_previous(j); @@ -1977,7 +2056,7 @@ int main(int argc, char *argv[]) { r = sd_journal_seek_head(j); if (r < 0) { log_error_errno(r, "Failed to seek to head: %m"); - return EXIT_FAILURE; + goto finish; } r = sd_journal_next(j); @@ -1985,7 +2064,7 @@ int main(int argc, char *argv[]) { if (r < 0) { log_error_errno(r, "Failed to iterate through journal: %m"); - return EXIT_FAILURE; + goto finish; } if (!arg_follow) @@ -2113,5 +2192,9 @@ finish: strv_free(arg_file); + strv_free(arg_syslog_identifier); + strv_free(arg_system_units); + strv_free(arg_user_units); + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index c2f1545cc9..83c3332abf 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -21,6 +21,7 @@ #include "missing.h" #include "journald-audit.h" +#include "audit-type.h" typedef struct MapField { const char *audit_field; @@ -336,7 +337,7 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s size_t n_iov_allocated = 0; unsigned n_iov = 0, k; uint64_t seconds, msec, id; - const char *p; + const char *p, *type_name; unsigned z; char id_field[sizeof("_AUDIT_ID=") + DECIMAL_STR_MAX(uint64_t)], type_field[sizeof("_AUDIT_TYPE=") + DECIMAL_STR_MAX(int)], @@ -373,7 +374,7 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s if (isempty(p)) return; - n_iov_allocated = N_IOVEC_META_FIELDS + 5; + n_iov_allocated = N_IOVEC_META_FIELDS + 7; iov = new(struct iovec, n_iov_allocated); if (!iov) { log_oom(); @@ -392,8 +393,13 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s sprintf(id_field, "_AUDIT_ID=%" PRIu64, id); IOVEC_SET_STRING(iov[n_iov++], id_field); - m = alloca(strlen("MESSAGE=<audit-") + DECIMAL_STR_MAX(int) + strlen("> ") + strlen(p) + 1); - sprintf(m, "MESSAGE=<audit-%i> %s", type, p); + assert_cc(32 == LOG_AUTH); + IOVEC_SET_STRING(iov[n_iov++], "SYSLOG_FACILITY=32"); + IOVEC_SET_STRING(iov[n_iov++], "SYSLOG_IDENTIFIER=audit"); + + type_name = audit_type_name_alloca(type); + + m = strjoina("MESSAGE=", type_name, " ", p); IOVEC_SET_STRING(iov[n_iov++], m); z = n_iov; @@ -528,9 +534,14 @@ int server_open_audit(Server *s) { return 0; } - r = bind(s->audit_fd, &sa.sa, sizeof(sa.nl)); - if (r < 0) - return log_error_errno(errno, "Failed to join audit multicast group: %m"); + if (bind(s->audit_fd, &sa.sa, sizeof(sa.nl)) < 0) { + log_warning_errno(errno, + "Failed to join audit multicast group. " + "The kernel is probably too old or multicast reading is not supported. " + "Ignoring: %m"); + s->audit_fd = safe_close(s->audit_fd); + return 0; + } } else fd_nonblock(s->audit_fd, 1); diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 5363aaa4ff..307bdc3949 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -21,12 +21,14 @@ #include <time.h> #include <fcntl.h> -#include <unistd.h> #include <sys/socket.h> #include "fileio.h" #include "journald-server.h" #include "journald-console.h" +#include "formats-util.h" +#include "process-util.h" +#include "terminal-util.h" static bool prefix_timestamp(void) { diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index c4216c4043..e5be7f7766 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -31,6 +31,8 @@ #include "journald-server.h" #include "journald-kmsg.h" #include "journald-syslog.h" +#include "formats-util.h" +#include "process-util.h" void server_forward_kmsg( Server *s, @@ -201,8 +203,7 @@ static void dev_kmsg_record(Server *s, const char *p, size_t l) { *e = 0; - m = cunescape_length_with_prefix(k, e - k, "_KERNEL_"); - if (!m) + if (cunescape_length_with_prefix(k, e - k, "_KERNEL_", UNESCAPE_RELAX, &m) < 0) break; if (startswith(m, "_KERNEL_DEVICE=")) @@ -299,8 +300,7 @@ static void dev_kmsg_record(Server *s, const char *p, size_t l) { } } - message = cunescape_length_with_prefix(p, pl, "MESSAGE="); - if (message) + if (cunescape_length_with_prefix(p, pl, "MESSAGE=", UNESCAPE_RELAX, &message) >= 0) IOVEC_SET_STRING(iovec[n++], message); server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, NULL, NULL, 0, NULL, priority, 0); diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index 851625de04..da3faef93e 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -433,7 +433,7 @@ int server_open_native_socket(Server*s) { if (r < 0) return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path); - chmod(sa.un.sun_path, 0666); + (void) chmod(sa.un.sun_path, 0666); } else fd_nonblock(s->native_fd, 1); diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c index 6d779d2966..6f83035a4e 100644 --- a/src/journal/journald-rate-limit.c +++ b/src/journal/journald-rate-limit.c @@ -26,6 +26,7 @@ #include "list.h" #include "util.h" #include "hashmap.h" +#include "random-util.h" #define POOLS_MAX 5 #define BUCKETS_MAX 127 diff --git a/src/journal/journald-rate-limit.h b/src/journal/journald-rate-limit.h index 648ab22786..466239d3c6 100644 --- a/src/journal/journald-rate-limit.h +++ b/src/journal/journald-rate-limit.h @@ -21,7 +21,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "macro.h" #include "util.h" typedef struct JournalRateLimit JournalRateLimit; diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 7ee8174ea2..3353024f4e 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -24,23 +24,30 @@ #include <linux/sockios.h> #include <sys/statvfs.h> #include <sys/mman.h> -#include <sys/timerfd.h> + +#ifdef HAVE_SELINUX +#include <selinux/selinux.h> +#endif #include <libudev.h> #include "sd-journal.h" #include "sd-messages.h" #include "sd-daemon.h" -#include "fileio.h" #include "mkdir.h" +#include "rm-rf.h" #include "hashmap.h" #include "journal-file.h" #include "socket-util.h" #include "cgroup-util.h" -#include "list.h" #include "missing.h" #include "conf-parser.h" #include "selinux-util.h" +#include "acl-util.h" +#include "formats-util.h" +#include "process-util.h" +#include "hostname-util.h" +#include "signal-util.h" #include "journal-internal.h" #include "journal-vacuum.h" #include "journal-authenticate.h" @@ -48,15 +55,9 @@ #include "journald-kmsg.h" #include "journald-syslog.h" #include "journald-stream.h" -#include "journald-console.h" #include "journald-native.h" #include "journald-audit.h" #include "journald-server.h" -#include "acl-util.h" - -#ifdef HAVE_SELINUX -#include <selinux/selinux.h> -#endif #define USER_JOURNALS_MAX 1024 @@ -1092,7 +1093,7 @@ finish: s->runtime_journal = NULL; if (r >= 0) - rm_rf("/run/log/journal", false, true, false); + (void) rm_rf("/run/log/journal", REMOVE_ROOT); sd_journal_close(j); diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index c96877c508..559d100131 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -21,16 +21,12 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <inttypes.h> #include <stdbool.h> -#include <sys/epoll.h> #include <sys/types.h> -#include <sys/socket.h> #include "sd-event.h" #include "journal-file.h" #include "hashmap.h" -#include "util.h" #include "audit.h" #include "journald-rate-limit.h" #include "list.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 942a857803..b572147a56 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -19,7 +19,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <fcntl.h> #include <unistd.h> #include <stddef.h> @@ -721,7 +720,7 @@ int server_open_stdout_socket(Server *s, FDSet *fds) { if (r < 0) return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path); - chmod(sa.un.sun_path, 0666); + (void) chmod(sa.un.sun_path, 0666); if (listen(s->stdout_fd, SOMAXCONN) < 0) return log_error_errno(errno, "listen(%s) failed: %m", sa.un.sun_path); diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 7d545ca31d..90b7530946 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -31,6 +31,8 @@ #include "journald-kmsg.h" #include "journald-console.h" #include "journald-wall.h" +#include "formats-util.h" +#include "process-util.h" /* Warn once every 30s if we missed syslog message */ #define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC) @@ -396,7 +398,7 @@ int server_open_syslog_socket(Server *s) { if (r < 0) return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path); - chmod(sa.un.sun_path, 0666); + (void) chmod(sa.un.sun_path, 0666); } else fd_nonblock(s->syslog_fd, 1); diff --git a/src/journal/journald-wall.c b/src/journal/journald-wall.c index e3201674d4..7863766ae7 100644 --- a/src/journal/journald-wall.c +++ b/src/journal/journald-wall.c @@ -22,6 +22,8 @@ #include "utmp-wtmp.h" #include "journald-server.h" #include "journald-wall.h" +#include "formats-util.h" +#include "process-util.h" void server_forward_wall( Server *s, @@ -63,7 +65,7 @@ void server_forward_wall( } else l = message; - r = utmp_wall(l, "systemd-journald", NULL); + r = utmp_wall(l, "systemd-journald", NULL, NULL, NULL); if (r < 0) log_debug_errno(r, "Failed to send wall message: %m"); } diff --git a/src/journal/journald.c b/src/journal/journald.c index 80f4634f67..b2624c6d28 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -19,12 +19,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <sys/epoll.h> -#include <sys/socket.h> -#include <errno.h> #include <unistd.h> -#include "systemd/sd-journal.h" #include "systemd/sd-messages.h" #include "systemd/sd-daemon.h" @@ -34,6 +30,7 @@ #include "journald-syslog.h" #include "sigbus.h" +#include "formats-util.h" int main(int argc, char *argv[]) { Server server; diff --git a/src/journal/journald.conf b/src/journal/journald.conf index 29bdf8f183..47eefe91c1 100644 --- a/src/journal/journald.conf +++ b/src/journal/journald.conf @@ -5,10 +5,11 @@ # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # -# You can override the directives in this file by creating files in -# /etc/systemd/journald.conf.d/*.conf. +# Entries in this file show the compile time defaults. +# You can change settings by editing this file. +# Defaults can be restored by simply deleting this file. # -# See journald.conf(5) for details +# See journald.conf(5) for details. [Journal] #Storage=auto diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index ab21cdc288..22f75540b8 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -22,7 +22,6 @@ #include <errno.h> #include <stdlib.h> #include <sys/mman.h> -#include <string.h> #include "hashmap.h" #include "list.h" diff --git a/src/journal/mmap-cache.h b/src/journal/mmap-cache.h index a85c2b6063..37ea7b4a9c 100644 --- a/src/journal/mmap-cache.h +++ b/src/journal/mmap-cache.h @@ -21,7 +21,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <inttypes.h> #include <stdbool.h> #include <sys/stat.h> diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 94891cdf35..9f0f71aa81 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -42,6 +42,7 @@ #include "catalog.h" #include "replace-var.h" #include "fileio.h" +#include "formats-util.h" #define JOURNAL_FILES_MAX 7168 @@ -723,13 +724,17 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc assert(j); assert(f); - if (f->last_direction == direction && f->current_offset > 0) { - /* If we hit EOF before, recheck if any new entries arrived. */ - n_entries = le64toh(f->header->n_entries); - if (f->location_type == LOCATION_TAIL && n_entries == f->last_n_entries) - return 0; - f->last_n_entries = n_entries; + n_entries = le64toh(f->header->n_entries); + + /* If we hit EOF before, we don't need to look into this file again + * unless direction changed or new entries appeared. */ + if (f->last_direction == direction && f->location_type == LOCATION_TAIL && + n_entries == f->last_n_entries) + return 0; + + f->last_n_entries = n_entries; + if (f->last_direction == direction && f->current_offset > 0) { /* LOCATION_SEEK here means we did the work in a previous * iteration and the current location already points to a * candidate entry. */ @@ -738,14 +743,16 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc if (r <= 0) return r; - journal_file_save_location(f, direction, c, cp); + journal_file_save_location(f, c, cp); } } else { + f->last_direction = direction; + r = find_location_with_matches(j, f, direction, &c, &cp); if (r <= 0) return r; - journal_file_save_location(f, direction, c, cp); + journal_file_save_location(f, c, cp); } /* OK, we found the spot, now let's advance until an entry @@ -773,7 +780,7 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc if (r <= 0) return r; - journal_file_save_location(f, direction, c, cp); + journal_file_save_location(f, c, cp); } } @@ -1242,7 +1249,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) { r = add_any_file(j, path); if (r == -ENOENT) return 0; - return 0; + return r; } static int remove_file(sd_journal *j, const char *prefix, const char *filename) { diff --git a/src/journal/stacktrace.c b/src/journal/stacktrace.c index 6b9d2729f5..706c08eac7 100644 --- a/src/journal/stacktrace.c +++ b/src/journal/stacktrace.c @@ -25,6 +25,7 @@ #include "util.h" #include "macro.h" #include "stacktrace.h" +#include "formats-util.h" #define FRAMES_MAX 64 #define THREADS_MAX 64 diff --git a/src/journal/test-audit-type.c b/src/journal/test-audit-type.c new file mode 100644 index 0000000000..7946cf3c41 --- /dev/null +++ b/src/journal/test-audit-type.c @@ -0,0 +1,44 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2015 Zbigniew Jędrzejewski-Szmek + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <stdio.h> +#include <linux/audit.h> + +#include "audit-type.h" + +static void print_audit_label(int i) { + const char *name; + + name = audit_type_name_alloca(i); + /* This is a separate function only because of alloca */ + printf("%i → %s → %s\n", i, audit_type_to_string(i), name); +} + +static void test_audit_type(void) { + int i; + + for (i = 0; i <= AUDIT_KERNEL; i++) + print_audit_label(i); +} + +int main(int argc, char **argv) { + test_audit_type(); +} diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index c605ee0e70..dbfdea609d 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -21,7 +21,6 @@ ***/ #include <locale.h> -#include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c index ae41c0c4c7..41a566d714 100644 --- a/src/journal/test-compress.c +++ b/src/journal/test-compress.c @@ -20,6 +20,7 @@ #include "compress.h" #include "util.h" #include "macro.h" +#include "random-util.h" #ifdef HAVE_XZ # define XZ_OK 0 diff --git a/src/journal/test-journal-enum.c b/src/journal/test-journal-enum.c index 980244e016..cde2025ae9 100644 --- a/src/journal/test-journal-enum.c +++ b/src/journal/test-journal-enum.c @@ -24,7 +24,6 @@ #include "log.h" #include "sd-journal.h" #include "macro.h" -#include "util.h" #include "journal-internal.h" int main(int argc, char *argv[]) { diff --git a/src/journal/test-journal-flush.c b/src/journal/test-journal-flush.c index 914ca0b4d1..2d4f531e9b 100644 --- a/src/journal/test-journal-flush.c +++ b/src/journal/test-journal-flush.c @@ -27,8 +27,8 @@ #include "journal-internal.h" int main(int argc, char *argv[]) { - - char dn[] = "/var/tmp/test-journal-flush.XXXXXX", *fn; + _cleanup_free_ char *fn = NULL; + char dn[] = "/var/tmp/test-journal-flush.XXXXXX"; JournalFile *new_journal = NULL; sd_journal *j = NULL; unsigned n = 0; diff --git a/src/journal/test-journal-init.c b/src/journal/test-journal-init.c index 11fb150fe8..e6599f366d 100644 --- a/src/journal/test-journal-init.c +++ b/src/journal/test-journal-init.c @@ -23,6 +23,7 @@ #include "log.h" #include "util.h" +#include "rm-rf.h" int main(int argc, char *argv[]) { sd_journal *j; @@ -58,7 +59,7 @@ int main(int argc, char *argv[]) { assert_se(j == NULL); } - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); return 0; } diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index 3c706018e9..c2fc123e42 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -23,13 +23,12 @@ #include <unistd.h> #include <fcntl.h> -#include "systemd/sd-journal.h" - +#include "sd-journal.h" #include "journal-file.h" -#include "journal-internal.h" #include "journal-vacuum.h" #include "util.h" #include "log.h" +#include "rm-rf.h" /* This program tests skipping around in a multi-file journal. */ @@ -191,7 +190,7 @@ static void test_skip(void (*setup)(void)) { else { journal_directory_vacuum(".", 3000000, 0, NULL, true); - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); } puts("------------------------------------------------------------"); @@ -276,7 +275,7 @@ static void test_sequence_numbers(void) { else { journal_directory_vacuum(".", 3000000, 0, NULL, true); - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); } } diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index 3996e778e6..e1146c692d 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -22,13 +22,13 @@ #include <unistd.h> #include <fcntl.h> -#include "systemd/sd-journal.h" - -#include "journal-file.h" -#include "journal-internal.h" +#include "sd-journal.h" #include "util.h" #include "log.h" #include "macro.h" +#include "rm-rf.h" +#include "journal-file.h" +#include "journal-internal.h" #define N_ENTRIES 200 @@ -42,7 +42,7 @@ static void verify_contents(sd_journal *j, unsigned skip) { const void *d; char *k, *c; size_t l; - unsigned u; + unsigned u = 0; assert_se(sd_journal_get_cursor(j, &k) >= 0); printf("cursor: %s\n", k); @@ -180,7 +180,7 @@ int main(int argc, char *argv[]) { SD_JOURNAL_FOREACH_UNIQUE(j, data, l) printf("%.*s\n", (int) l, (const char*) data); - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); return 0; } diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index 9da120c0bb..d24502d9a8 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -25,9 +25,10 @@ #include "util.h" #include "log.h" +#include "rm-rf.h" #include "journal-file.h" #include "journal-verify.h" -#include "journal-authenticate.h" +#include "terminal-util.h" #define N_ENTRIES 6000 #define RANDOM_RANGE 77 @@ -145,7 +146,7 @@ int main(int argc, char *argv[]) { log_info("Exiting..."); - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); return 0; } diff --git a/src/journal/test-journal.c b/src/journal/test-journal.c index 230d26596a..caaab258c9 100644 --- a/src/journal/test-journal.c +++ b/src/journal/test-journal.c @@ -22,9 +22,8 @@ #include <fcntl.h> #include <unistd.h> -#include "systemd/sd-journal.h" - #include "log.h" +#include "rm-rf.h" #include "journal-file.h" #include "journal-authenticate.h" #include "journal-vacuum.h" @@ -119,7 +118,7 @@ static void test_non_empty(void) { else { journal_directory_vacuum(".", 3000000, 0, NULL, true); - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); } puts("------------------------------------------------------------"); @@ -158,7 +157,7 @@ static void test_empty(void) { else { journal_directory_vacuum(".", 3000000, 0, NULL, true); - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); + assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); } journal_file_close(f1); diff --git a/src/journal/test-mmap-cache.c b/src/journal/test-mmap-cache.c index 3fcd77475d..3258b22702 100644 --- a/src/journal/test-mmap-cache.c +++ b/src/journal/test-mmap-cache.c @@ -24,7 +24,6 @@ #include <unistd.h> #include <fcntl.h> -#include "log.h" #include "macro.h" #include "util.h" #include "mmap-cache.h" |