Commit graph

1644 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek ccc717fa5c test-compress*: silence warning about unused definitions when w/o both xz and lz4
I think it's nice to mark the test as skipped instead of omitting
it entirely, hence #ifdefs in the code instead of excluding the test
in Makefile.am/meson.build.
2017-04-19 19:27:01 -04:00
Yu Watanabe da4128543f tree-wide: fix wrong indent (#5757)
Fixes wrong indent introduced by the commit 43688c49d1.
2017-04-19 08:48:29 +02:00
Michael Biebl b6a20306fa journal: fix up syslog facility when forwarding native messages (#5667)
Native journal messages (_TRANSPORT=journal) typically don't have a
syslog facility attached to it. As a result when forwarding the messages
to syslog they ended up with facility 0 (LOG_KERN).
Apply syslog_fixup_facility() so we use LOG_USER instead.

Fixes: #5640
2017-03-30 11:56:25 +02:00
Tobias Stoeckmann 6f94e420e8 journal: prevent integer overflow while validating header (#5569)
It is possible to overflow uint64_t while validating the header of
a journal file. To prevent this, the addition itself is checked to
be within the limits of UINT64_MAX first.

To keep this readable, I have introduced two stack variables which
hold the converted values during validation.
2017-03-13 08:14:42 +01:00
Zbigniew Jędrzejewski-Szmek 4f37cbd911 journalctl: move access_check() to shared/
The only functional change is that log_notice("No journal files were found.")
is not printed any more with --quiet. log_error("No journal files were opened
due to insufficient permissions.") is still printed.

I wasn't quite sure where to put this function, but shared/ seems to be the
right place and none of the existing files seem to fit too well.

v2: rename journal_access_check to journal_access_check_and_warn.
2017-02-28 21:37:35 -05:00
AsciiWolf 13e785f7a0 Fix missing space in comments (#5439) 2017-02-24 18:14:02 +01:00
Namhyung Kim b4e7bdcb53 journal: avoid duplicated call to get cgroup path (#5404)
The cg_pid_get_path_shifted() is called twice during
server_dispatch_message().  We can get rid of the second by passing the
path to dispatch_message_real().
2017-02-23 13:04:57 +01:00
Lucas Werkmeister cc7de2ba32 tree-wide: add man: to manpage references (#5402)
Found with:

    git grep '"[^"]*[a-z0-9]([0-9]\+p\?)' src/ | grep -vF man:
2017-02-20 18:45:35 -05:00
Lucas Werkmeister 1e94df4471 journalctl: add reference to sd-id128(3) to output (#5382)
SD_ID128_MAKE is clearly not a standard C macro, so let’s point the user
to its documentation to let them know which header they need and what
they can then do with MESSAGE_XYZ.
2017-02-18 16:36:25 -05:00
Zbigniew Jędrzejewski-Szmek 2b0445262a tree-wide: add SD_ID128_MAKE_STR, remove LOG_MESSAGE_ID
Embedding sd_id128_t's in constant strings was rather cumbersome. We had
SD_ID128_CONST_STR which returned a const char[], but it had two problems:
- it wasn't possible to statically concatanate this array with a normal string
- gcc wasn't really able to optimize this, and generated code to perform the
  "conversion" at runtime.
Because of this, even our own code in coredumpctl wasn't using
SD_ID128_CONST_STR.

Add a new macro to generate a constant string: SD_ID128_MAKE_STR.
It is not as elegant as SD_ID128_CONST_STR, because it requires a repetition
of the numbers, but in practice it is more convenient to use, and allows gcc
to generate smarter code:

$ size .libs/systemd{,-logind,-journald}{.old,}
   text	   data	    bss	    dec	    hex	filename
1265204	 149564	   4808	1419576	 15a938	.libs/systemd.old
1260268	 149564	   4808	1414640	 1595f0	.libs/systemd
 246805	  13852	    209	 260866	  3fb02	.libs/systemd-logind.old
 240973	  13852	    209	 255034	  3e43a	.libs/systemd-logind
 146839	   4984	     34	 151857	  25131	.libs/systemd-journald.old
 146391	   4984	     34	 151409	  24f71	.libs/systemd-journald

It is also much easier to check if a certain binary uses a certain MESSAGE_ID:

$ strings .libs/systemd.old|grep MESSAGE_ID
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x

$ strings .libs/systemd|grep MESSAGE_ID
MESSAGE_ID=c7a787079b354eaaa9e77b371893cd27
MESSAGE_ID=b07a249cd024414a82dd00cd181378ff
MESSAGE_ID=641257651c1b4ec9a8624d7a40a9e1e7
MESSAGE_ID=de5b426a63be47a7b6ac3eaac82e2f6f
MESSAGE_ID=d34d037fff1847e6ae669a370e694725
MESSAGE_ID=7d4958e842da4a758f6c1cdc7b36dcc5
MESSAGE_ID=1dee0369c7fc4736b7099b38ecb46ee7
MESSAGE_ID=39f53479d3a045ac8e11786248231fbf
MESSAGE_ID=be02cf6855d2428ba40df7e9d022f03d
MESSAGE_ID=7b05ebc668384222baa8881179cfda54
MESSAGE_ID=9d1aaa27d60140bd96365438aad20286
2017-02-15 00:45:12 -05:00
Zbigniew Jędrzejewski-Szmek b18453eda6 Move export format parsing from src/journal-remote/ to src/basic/
No functional change.
2017-02-14 23:56:48 -05:00
Zbigniew Jędrzejewski-Szmek 1075122f42 journalctl: replace string_erase with memset('x')
The compiler should not be able to optimize out the memset, because optarg is global
memory. In this case, not making the argument an empty string is nicer, so just use
an open-coded version of string_erase from before the explicit_bzero change.
2017-02-05 21:07:55 -05:00
Lennart Poettering 486b3d08db Merge pull request #5204 from keszybz/masked-warning-cleanup
Cleanup of error code mismatch for masked units
2017-02-02 11:47:30 +01:00
Zbigniew Jędrzejewski-Szmek b288cdeb2d Consistently use ERFKILL for masked units
76ec966f0e changed the code from ESHUTDOWN to ERFKILL, but missed one
spot in bus-common-errors.c. Fix that.

The code in transaction.c was checking for ERFKILL, but I'm not sure if this
mismatch had any effect, i.e. if there were any code paths in which the wrong
code actually made difference.

Also add comments when ESHUTDOWN is used in the journal code, so it's easy to
distinguish those cases when grepping. Standarize on the same capitalization.

(There's also a bunch of uses in sd-bus.c, but that's clearly different.)
2017-02-01 19:47:23 -05:00
Lennart Poettering ef2f4f911b Merge pull request #5151 from keszybz/journal-flags
More information about unsupported journal file flags
2017-02-02 01:01:45 +01:00
Zbigniew Jędrzejewski-Szmek 869a3458cb Merge pull request #5191 from keszybz/tweaks 2017-02-01 10:27:32 -05:00
Zbigniew Jędrzejewski-Szmek a6c5909665 Revert "Trivial typo fixes and code refactorings (#5191)"
Let's do a merge to preserve all the commit messages.

This reverts commit 785d345145.
2017-02-01 10:26:50 -05:00
Zbigniew Jędrzejewski-Szmek 785d345145 Trivial typo fixes and code refactorings (#5191)
* logind: trivial simplification

free_and_strdup() handles NULL arg, so make use of that.

* boot: fix two typos

* pid1: rewrite check in ignore_proc() to not check condition twice

It's harmless, but it seems nicer to evaluate a condition just a single time.

* core/execute: reformat exec_context_named_iofds() for legibility

* core/execute.c: check asprintf return value in the usual fashion

This is unlikely to fail, but we cannot rely on asprintf return value
on failure, so let's just be correct here.

CID #1368227.

* core/timer: use (void)

CID #1368234.

* journal-file: check asprintf return value in the usual fashion

This is unlikely to fail, but we cannot rely on asprintf return value
on failure, so let's just be correct here.

CID #1368236.

* shared/cgroup-show: use (void)

CID #1368243.

* cryptsetup: do not return uninitialized value on error

CID #1368416.
2017-02-01 15:04:27 +01:00
Zbigniew Jędrzejewski-Szmek ae50101aab journal/lookup3: silence gcc 7 implicit-fallthrough warning
This file doesn't include any of our headers, so just use the pragma
without defining it in macros.h
2017-01-31 14:04:55 -05:00
Zbigniew Jędrzejewski-Szmek ec251fe7d5 tree-wide: adjust fall through comments so that gcc is happy
gcc 7 adds -Wimplicit-fallthrough=3 to -Wextra. There are a few ways
we could deal with that. After we take into account the need to stay compatible
with older versions of the compiler (and other compilers), I don't think adding
__attribute__((fallthrough)), even as a macro, is worth the trouble. It sticks
out too much, a comment is just as good. But gcc has some very specific
requiremnts how the comment should look. Adjust it the specific form that it
likes. I don't think the extra stuff we had in those comments was adding much
value.

(Note: the documentation seems to be wrong, and seems to describe a different
pattern from the one that is actually used. I guess either the docs or the code
will have to change before gcc 7 is finalized.)
2017-01-31 14:04:55 -05:00
Zbigniew Jędrzejewski-Szmek 7645c77b9b journal-file: check asprintf return value in the usual fashion
This is unlikely to fail, but we cannot rely on asprintf return value
on failure, so let's just be correct here.

CID #1368236.
2017-01-31 11:41:46 -05:00
Zbigniew Jędrzejewski-Szmek 4761fd0ffb journal-file, journalctl: provide better hint about unsupported features
https://bugzilla.redhat.com/show_bug.cgi?id=1416201

$ journalctl -b
Journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ uses an unsupported feature, ignoring file.
Use SYSTEMD_LOG_LEVEL=debug journalctl --file=/var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ to see the details.
-- No entries --

$ journalctl --file=/var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~
Journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~ uses incompatible flag lz4-compressed disabled at compilation time.
Failed to open journal file /var/log/journal/ad18f69b80264b52bb3b766240742383/system@0005467d92e23784-a6571c8b69d09124.journal~: Protocol not supported
mmap cache statistics: 0 hit, 1 miss
Failed to open files: Protocol not supported
2017-01-24 19:19:33 -05:00
Zbigniew Jędrzejewski-Szmek 4214009f8a journal-file: factor out helper function
In preparation for later changes.
2017-01-24 19:00:23 -05:00
Zbigniew Jędrzejewski-Szmek e50412ef19 journalctl: fix memleak
This is harmless, it would only happen if --verify-key is used multiple times.
But let's fix it for correctness.

CID ##1368415.
2017-01-15 12:39:15 -05:00
Lucas Werkmeister 6bae9b2abb journalctl: expunge verification key from argv (#5081)
After parsing the --verify-key argument, overwrite it with null bytes.
This minimizes (but does not completely eliminate) the time frame within
which another process on the system can extract the verification key
from the journalctl command line.
2017-01-14 23:03:00 -05:00
Zbigniew Jędrzejewski-Szmek 6b3d378331 Merge pull request #4879 from poettering/systemd 2017-01-14 21:29:27 -05:00
Mike Gilbert c9f7b4d356 build-sys: add check for gperf lookup function signature (#5055)
gperf-3.1 generates lookup functions that take a size_t length
parameter instead of unsigned int. Test for this at configure time.

Fixes: https://github.com/systemd/systemd/issues/5039
2017-01-10 08:39:05 +01:00
Marcin Bachry 574b77efad journalctl: add remote log dir to search path when --merge is passed (#4970)
The journalctl man page says: "-m, --merge Show entries interleaved from all
available journals, including remote ones.", but current version of journalctl
doesn't live up to this promise. This patch simply adds
"/var/log/journal/remote" to search path if --merge flag is used.

Should fix issue #3618
2016-12-24 00:42:13 +01:00
Lennart Poettering f78273c8da journald: don't flush to /var/log/journal before we get asked to
This changes journald to not write to /var/log/journal until it received
SIGUSR1 for the first time, thus having been requested to flush the runtime
journal to disk.

This makes the journal work nicer with systems which have the root file system
writable early, but still need to rearrange /var before journald should start
writing and creating files to it, for example because ACLs need to be applied
first, or because /var is to be mounted from another file system, NFS or tmpfs
(as is the case for systemd.volatile=state).

Before this change we required setupts with /var split out to mount the root
disk read-only early on, and ship an /etc/fstab that remounted it writable only
after having placed /var at the right place. But even that was racy for various
preparations as journald might end up accessing the file system before it was
entirely set up, as soon as it was writable.

With this change we make scheduling when to start writing to /var/log/journal
explicit. This means persistent mode now requires
systemd-journal-flush.service in the mix to work, as otherwise journald would
never write to the directory.

See: #1397
2016-12-21 19:09:29 +01:00
Lennart Poettering 1d84ad9445 util-lib: various improvements to kernel command line parsing
This improves kernel command line parsing in a number of ways:

a) An kernel option "foo_bar=xyz" is now considered equivalent to
   "foo-bar-xyz", i.e. when comparing kernel command line option names "-" and
   "_" are now considered equivalent (this only applies to the option names
   though, not the option values!). Most of our kernel options used "-" as word
   separator in kernel command line options so far, but some used "_". With
   this change, which was a source of confusion for users (well, at least of
   one user: myself, I just couldn't remember that it's systemd.debug-shell,
   not systemd.debug_shell). Considering both as equivalent is inspired how
   modern kernel module loading normalizes all kernel module names to use
   underscores now too.

b) All options previously using a dash for separating words in kernel command
   line options now use an underscore instead, in all documentation and in
   code. Since a) has been implemented this should not create any compatibility
   problems, but normalizes our documentation and our code.

c) All kernel command line options which take booleans (or are boolean-like)
   have been reworked so that "foobar" (without argument) is now equivalent to
   "foobar=1" (but not "foobar=0"), thus normalizing the handling of our
   boolean arguments. Specifically this means systemd.debug-shell and
   systemd_debug_shell=1 are now entirely equivalent.

d) All kernel command line options which take an argument, and where no
   argument is specified will now result in a log message. e.g. passing just
   "systemd.unit" will no result in a complain that it needs an argument. This
   is implemented in the proc_cmdline_missing_value() function.

e) There's now a call proc_cmdline_get_bool() similar to proc_cmdline_get_key()
   that parses booleans (following the logic explained in c).

f) The proc_cmdline_parse() call's boolean argument has been replaced by a new
   flags argument that takes a common set of bits with proc_cmdline_get_key().

g) All kernel command line APIs now begin with the same "proc_cmdline_" prefix.

h) There are now tests for much of this. Yay!
2016-12-21 19:09:08 +01:00
Zbigniew Jędrzejewski-Szmek 777fe71fdf test-compress: fix warning about LZ4_compress_limitedOutput
691b90d465 fixed one spot, but missed the other one.
2016-12-17 18:27:01 -05:00
Lennart Poettering 493097eecc journalctl: improve wording in an errors message
Fixes: #4660
2016-12-14 18:29:30 +01:00
Zbigniew Jędrzejewski-Szmek 691b90d465 journal: fix warning about LZ4_compress_limitedOutput 2016-12-10 13:52:49 -05:00
Franck Bui 3099caf2b5 journal: make sure to initially populate the space info cache (#4807)
Make sure to populate the cache in cache_space_refresh() at least once
otherwise it's possible that the system boots fast enough (and the journal
flush service is finished) before the invalidate cache timeout (30 us) has
expired.

Fixes: #4790
2016-12-02 18:40:10 +01:00
Lennart Poettering c4f4fce79e fs-util: add flags parameter to chase_symlinks()
Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to
chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of
chase_symlinks_prefix().
2016-12-01 00:25:51 +01:00
Lennart Poettering e187369587 tree-wide: stop using canonicalize_file_name(), use chase_symlinks() instead
Let's use chase_symlinks() everywhere, and stop using GNU
canonicalize_file_name() everywhere. For most cases this should not change
behaviour, however increase exposure of our function to get better tested. Most
importantly in a few cases (most notably nspawn) it can take the correct root
directory into account when chasing symlinks.
2016-12-01 00:25:51 +01:00
Waldemar Brodkorb 9bab3b65b0 fix journald startup problem when code is compiled with -DNDEBUG (#4735)
Similar to this patch from here:
http://systemd-devel.freedesktop.narkive.com/AvfCbi6c/patch-0-3-using-assert-se-on-actions-with-side-effects-on-test-cases

If the code is compiled with -DNDEBUG which is the default for
some embedded buildsystems, systemd-journald does not startup
and silently fails.
2016-11-25 11:24:58 +01:00
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Lennart Poettering 493fd52f1a Merge pull request #4510 from keszybz/tree-wide-cleanups
Tree wide cleanups
2016-11-03 13:59:20 -06:00
Zbigniew Jędrzejewski-Szmek 3e2161153c test-compression: allow the file to compress to be specified
I'm seeing strange decompression errors with lz4, which
might be content-dependent. Extend test-compression to allow
testing specific content.

(Edit: PEBKAC: lzcat and lz4cat are not the same beast.
Nevertheless, the test might still be useful in the future.)
2016-10-31 13:23:16 -04:00
Lennart Poettering 229ba9fd57 Merge pull request #4459 from keszybz/commandline-parsing
Commandline parsing simplification and udev fix
2016-10-24 17:20:37 +02:00
Zbigniew Jędrzejewski-Szmek 605405c6cc tree-wide: drop NULL sentinel from strjoin
This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/systemd -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libsystemd/sd-bus -I ./src/libsystemd/sd-event -I ./src/libsystemd/sd-login -I ./src/libsystemd/sd-netlink -I ./src/libsystemd/sd-network -I ./src/libsystemd/sd-hwdb -I ./src/libsystemd/sd-device -I ./src/libsystemd/sd-id128 -I ./src/libsystemd-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.
2016-10-23 11:43:27 -04:00
Zbigniew Jędrzejewski-Szmek d7f69e16f1 tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
This stripping is contolled by a new boolean parameter. When the parameter
is true, it means that the caller does not care about the distinction between
initrd and real root, and wants to act on both rd-dot-prefixed and unprefixed
parameters in the initramfs, and only on the unprefixed parameters in real
root. If the parameter is false, behaviour is the same as before.

Changes by caller:
log.c (systemd.log_*):      changed to accept rd-dot-prefix params
pid1:                       no change, custom logic
cryptsetup-generator:       no change, still accepts rd-dot-prefix params
debug-generator:            no change, does not accept rd-dot-prefix params
fsck:                       changed to accept rd-dot-prefix params
fstab-generator:            no change, custom logic
gpt-auto-generator:         no change, custom logic
hibernate-resume-generator: no change, does not accept rd-dot-prefix params
journald:                   changed to accept rd-dot-prefix params
modules-load:               no change, still accepts rd-dot-prefix params
quote-check:                no change, does not accept rd-dot-prefix params
udevd:                      no change, still accepts rd-dot-prefix params

I added support for "rd." params in the three cases where I think it's
useful: logging, fsck options, journald forwarding options.
2016-10-22 16:08:55 -04:00
Zbigniew Jędrzejewski-Szmek 5707ecf300 journald: convert journald to use parse_proc_cmdline
This makes journald use the common option parsing functionality.
One behavioural change is implemented:
"systemd.journald.forward_to_syslog" is now equivalent to
"systemd.journald.forward_to_syslog=1".
I think it's nicer to use this way.
2016-10-22 14:38:10 -04:00
Thomas Hindoe Paaboel Andersen b5331acc96 journal: remove unused variable 2016-10-22 16:00:11 +02:00
Umut Tezduyar Lindskog 863a5610c7 journald: systemd.journald.max_level_* kernel command line options (#4427)
The log forward levels can be configured through kernel command line.
2016-10-21 19:40:55 -04:00
Lennart Poettering 8ae2c6300f journald,core: add short comments we we keep reopening /dev/console all the time
Just to make sure the next one reading this isn't surprised that the fd isn't
kept open. SAK and stuff...

Fix suggested:

https://github.com/systemd/systemd/pull/4366#issuecomment-253659162
2016-10-20 13:12:53 +02:00
Franck Bui 57f443a6d9 journal: rename determine_space_for() into cache_space_refresh()
Now that determine_space_for() only deals with storage space (cached) values,
rename it so it reflects the fact that only the cached storage space values are
updated.
2016-10-19 09:53:07 +02:00
Franck Bui 3a19f2150d journal: introduce patch_min_use() helper
Updating min_use is rather an unusual operation that is limited when we first
open the journal files, therefore extracts it from determine_space_for() and
create a function of its own and call this new function when needed.

determine_space_for() is now dealing with storage space (cached) values only.

There should be no functional changes.
2016-10-19 09:53:07 +02:00
Franck Bui a0edc477bd journal: introduce cache_space_invalidate()
Introduce a dedicated helper in order to reset the storage space cache.
2016-10-19 09:53:07 +02:00
Franck Bui 23aba34349 journal: cache used vfs stats as well
The set of storage space values we cache are calculated according to a couple
of filesystem statistics (free blocks, block size).

This patch caches the vfs stats we're interested in so these values are
available later and coherent with the rest of the space cached values.
2016-10-19 09:53:07 +02:00
Franck Bui 18e758bf25 journal: don't emit space usage message when opening the journal (#4190)
This patch makes system_journal_open() stop emitting the space usage
message. The caller is now free to emit this message when appropriate.

When restarting the journal, we can now emit the message *after*
flushing the journal (if required) so that all flushed log entries are
written in the persistent journal *before* the status message.

This is required since the status message is always younger than the
flushed entries.

Fixes #4190.
2016-10-19 09:53:07 +02:00
Franck Bui cba5629e87 journal: introduce server_space_usage_message()
This commit simply extracts from determine_space_for() the code which emits the
storage usage message and put it into a function of its own so it can be reused
by others paths later.

No functional changes.
2016-10-19 09:53:07 +02:00
Franck Bui 266a470005 journal: introduce JournalStorage and JournalStorageSpace structures
This structure keeps track of specificities for a given journal type
(persistent or volatile) such as metrics, name, etc...

The cached space values are now moved in this structure so that each
journal has its own set of cached values.

Previously only one set existed and we didn't know if the cached
values were for the runtime journal or the persistent one.

When doing:

   determine_space_for(s, runtime_metrics, ...);
   determine_space_for(s, system_metrics, ...);

the second call returned the cached values for the runtime metrics.
2016-10-19 09:53:07 +02:00
Franck Bui e0ed6db9cd journal: introduce determine_path_usage()
This commit simply extracts from determine_space_for() the code which
determines the FS usage where the passed path lives (statvfs(3)) and put it
into a function of its own so it can be reused by others paths later.

No functional changes.
2016-10-19 09:53:07 +02:00
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Zbigniew Jędrzejewski-Szmek c1a9199ec4 Merge pull request #4362 from poettering/journalbootlistfix 2016-10-13 07:45:09 -04:00
Lennart Poettering 3cc44bf91b journalctl: say in which directory we vacuum stuff
Fixes: #4060
2016-10-12 20:25:20 +02:00
Lennart Poettering 8da830bca9 journalctl: don't claim the journal was stored on disk
Let's just say that the journal takes up space in the file system, not on disk,
as tmpfs is definitely a file system, but not a disk.

Fixes: #4059
2016-10-12 20:25:20 +02:00
Lennart Poettering ae739cc1ed journal: refuse opening journal files from the future for writing
Never permit that we write to journal files that have newer timestamps than our
local wallclock has. If we'd accept that, then the entries in the file might
end up not being ordered strictly.

Let's refuse this with ETXTBSY, and then immediately rotate to use a new file,
so that each file remains strictly ordered also be wallclock internally.
2016-10-12 20:25:20 +02:00
Lennart Poettering 7c07001711 journald: automatically rotate journal files when the clock jumps backwards
As soon as we notice that the clock jumps backwards, rotate journal files. This
is beneficial, as this makes sure that the entries in journal files remain
strictly ordered internally, and thus the bisection algorithm applied on it is
not confused.

This should help avoiding borked wallclock-based bisection on journal files as
witnessed in #4278.
2016-10-12 20:25:20 +02:00
Lennart Poettering 0f972d66d4 journald: use the event loop dispatch timestamp for journal entries
Let's use the earliest linearized event timestamp for journal entries we have:
the event dispatch timestamp from the event loop, instead of requerying the
timestamp at the time of writing.

This makes the time a bit more accurate, allows us to query the kernel time one
time less per event loop, and also makes sure we always use the same timestamp
for both attempts to write an entry to a journal file.
2016-10-12 20:25:20 +02:00
Lennart Poettering 989793d341 journal: when iterating through entry arrays and we hit an invalid one keep going
When iterating through partially synced journal files we need to be prepared
for hitting with invalid entries (specifically: non-initialized). Instead of
generated an error and giving up, let's simply try to preceed with the next one
that is valid (and debug log about this).

This reworks the logic introduced with caeab8f626
to iteration in both directions, and tries to look for valid entries located
after the invalid one. It also extends the behaviour to both iterating through
the global entry array and per-data object entry arrays.

Fixes: #4088
2016-10-12 20:25:20 +02:00
Lennart Poettering 1c69f0966a journal: add an explicit check for uninitialized objects
Let's make dissecting of borked journal files more expressive: if we encounter
an object whose first 8 bytes are all zeroes, then let's assume the object was
simply never initialized, and say so.

Previously, this would be detected as "overly short object", which is true too
in a away, but it's a lot more helpful printing different debug options for the
case where the size is not initialized at all and where the size is initialized
to some bogus value.

No function behaviour change, only a different log messages for both cases.
2016-10-12 20:25:20 +02:00
Lennart Poettering ded5034e7a journal: also check that our entry arrays are properly ordered
Let's and extra check, reusing check_properly_ordered() also for
journal_file_next_entry_for_data().
2016-10-12 20:25:20 +02:00
Lennart Poettering b6da4ed045 journal: split out check for properly ordered arrays into its own function
This adds a new call check_properly_ordered(), which we can reuse later, and
makes the code a bit more readable.
2016-10-12 20:25:20 +02:00
Lennart Poettering aa598ba5b6 journal: split out array index inc/dec code into a new call bump_array_index()
This allows us to share a bit more code between journal_file_next_entry() and
journal_file_next_entry_for_data().
2016-10-12 20:25:20 +02:00
Lennart Poettering 202fd896e5 journal: when we encounter a broken journal file, add some debug logging
Let's make it easier to figure out when we see an invalid journal file, why we
consider it invalid, and add some minimal debug logging for it.

This log output is normally not seen (after all, this all is library code),
unless debug logging is exlicitly turned on.
2016-10-12 20:25:20 +02:00
hese10 ec02a6c90a Avoid forever loop for journalctl --list-boots command (#4278)
When date is changed in system to future and normal user logs to new journal file, and then date is changed back to present time, the "journalctl --list-boot" command goes to forever loop. This commit tries to fix this problem by checking first the boot id list if the found boot id was already in that list. If it is found, then stopping the boot id find loop.
2016-10-12 18:40:28 +02:00
Lennart Poettering 4b58153dd2 core: add "invocation ID" concept to service manager
This adds a new invocation ID concept to the service manager. The invocation ID
identifies each runtime cycle of a unit uniquely. A new randomized 128bit ID is
generated each time a unit moves from and inactive to an activating or active
state.

The primary usecase for this concept is to connect the runtime data PID 1
maintains about a service with the offline data the journal stores about it.
Previously we'd use the unit name plus start/stop times, which however is
highly racy since the journal will generally process log data after the service
already ended.

The "invocation ID" kinda matches the "boot ID" concept of the Linux kernel,
except that it applies to an individual unit instead of the whole system.

The invocation ID is passed to the activated processes as environment variable.
It is additionally stored as extended attribute on the cgroup of the unit. The
latter is used by journald to automatically retrieve it for each log logged
message and attach it to the log entry. The environment variable is very easily
accessible, even for unprivileged services. OTOH the extended attribute is only
accessible to privileged processes (this is because cgroupfs only supports the
"trusted." xattr namespace, not "user."). The environment variable may be
altered by services, the extended attribute may not be, hence is the better
choice for the journal.

Note that reading the invocation ID off the extended attribute from journald is
racy, similar to the way reading the unit name for a logging process is.

This patch adds APIs to read the invocation ID to sd-id128:
sd_id128_get_invocation() may be used in a similar fashion to
sd_id128_get_boot().

PID1's own logging is updated to always include the invocation ID when it logs
information about a unit.

A new bus call GetUnitByInvocationID() is added that allows retrieving a bus
path to a unit by its invocation ID. The bus path is built using the invocation
ID, thus providing a path for referring to a unit that is valid only for the
current runtime cycleof it.

Outlook for the future: should the kernel eventually allow passing of cgroup
information along AF_UNIX/SOCK_DGRAM messages via a unique cgroup id, then we
can alter the invocation ID to be generated as hash from that rather than
entirely randomly. This way we can derive the invocation race-freely from the
messages.
2016-10-07 20:14:38 +02:00
Lennart Poettering 398a50cdd1 journal: fix format string used for usec_t 2016-10-07 20:14:38 +02:00
Lennart Poettering d473176a74 journal: complete slice info in journal metadata
We are already attaching the system slice information to log messages, now add
theuser slice info too, as well as the object slice info.
2016-10-07 20:14:38 +02:00
Yuki Inoguchi d2665e0866 journald, ratelimit: fix inaccurate message suppression in journal_rate_limit_test() (#4291)
Currently, the ratelimit does not handle the number of suppressed messages accurately.
Even though the number of messages reaches the limit, it still allows to add one extra messages to journal.

This patch fixes the problem.
2016-10-06 11:44:51 +02:00
Vito Caputo 95cbb83c20 journal: add stdout_stream_scan() comment (#4102)
When s->length is zero this function doesn't do anything, note that in a
comment.
2016-09-28 07:35:48 +02:00
HATAYAMA Daisuke eeb084806b journald,ratelimit: fix wrong calculation of burst_modulate() (#4218)
This patch fixes wrong calculation of burst_modulate(), which now calculates
the values smaller than really expected ones if available disk space is
strictly more than 1MB.

In particular, if available disk space is strictly more than 1MB and strictly
less than 16MB, the resulted value becomes smaller than its original one.

>>> (math.log2(1*1024**2)-16) / 4
1.0
>>> (math.log2(16*1024**2)-16) / 4
2.0
>>> (math.log2(256*1024**2)-16) / 4
3.0
→ This matches the comment in the function.
2016-09-26 11:36:20 -04:00
Franck Bui 33685a5a3a journal: fix HMAC calculation when appending a data object
Since commit 5996c7c295 (v190 !), the
calculation of the HMAC is broken because the hash for a data object
including a field is done in the wrong order: the field object is
hashed before the data object is.

However during verification, the hash is done in the opposite order as
objects are scanned sequentially.
2016-09-23 14:59:51 +02:00
Franck Bui 43cd879483 journal: warn when we fail to append a tag to a journal
We shouldn't silently fail when appending the tag to a journal file
since FSS protection will simply be disabled in this case.
2016-09-23 14:59:00 +02:00
Felix Zhang dd8352659c journal: fix typo in comment (#4176) 2016-09-18 11:14:50 +02:00
Martin Pitt 6ac288a990 Merge pull request #4123 from keszybz/network-file-dropins
Network file dropins
2016-09-17 10:00:19 +02:00
Zbigniew Jędrzejewski-Szmek 43688c49d1 tree-wide: rename config_parse_many to …_nulstr
In preparation for adding a version which takes a strv.
2016-09-16 10:32:03 -04:00
hi117 9ea78383e8 Updated formatting for printing the key for FSS (#4165)
The key used to be jammed next to the local file path. Based on the format string on line 1675, I determined that the order of arguments was written incorrectly, and updated the function based on that assumption.

Before:
```
Please write down the following secret verification key. It should be stored
at a safe location and should not be saved locally on disk.

        /var/log/journal/9b47c1a5b339412887a197b7654673a7/fss8f66d6-f0a998-f782d0-1fe522/18fdb8-35a4e900

The sealing key is automatically changed every 15min.
```

After:
```
Please write down the following secret verification key. It should be stored
at a safe location and should not be saved locally on disk.

        d53ed4-cc43d6-284e10-8f0324/18fdb8-35a4e900

The sealing key is automatically changed every 15min.
```
2016-09-16 10:14:55 -04:00
Martin Pitt 2d88def959 Merge pull request #4133 from keszybz/strerror-removal
Strerror removal and other janitorial cleanups
2016-09-14 11:17:58 +02:00
Zbigniew Jędrzejewski-Szmek 9eec7d12ed tests: get rid of strerror 2016-09-13 20:10:57 -04:00
Zbigniew Jędrzejewski-Szmek 581fc868be journal-verify: get rid of strerror 2016-09-13 20:10:56 -04:00
Topi Miettinen 646853bdd8 fileio: simplify mkostemp_safe() (#4090)
According to its manual page, flags given to mkostemp(3) shouldn't include
O_RDWR, O_CREAT or O_EXCL flags as these are always included. Beyond
those, the only flag that all callers (except a few tests where it
probably doesn't matter) use is O_CLOEXEC, so set that unconditionally.
2016-09-13 08:20:38 +02:00
Vito Caputo 6431c7e216 journal: add/use flushed_flag_is_set() helper (#4041)
Minor cleanup suggested by Lennart.
2016-08-26 17:51:13 +02:00
Vito Caputo 929eeb5498 journal: implicitly flush to var on recovery (#4028)
When the system journal becomes re-opened post-flush with the runtime
journal open, it implies we've recovered from something like an ENOSPC
situation where the system journal rotate had failed, leaving the system
journal closed, causing the runtime journal to be opened post-flush.

For the duration of the unavailable system journal, we log to the
runtime journal.  But when the system journal gets opened (space made
available, for example), we need to close the runtime journal before new
journal writes will go to the system journal.  Calling
server_flush_to_var() after opening the system journal with a runtime
journal present, post-flush, achieves this while preserving the runtime
journal's contents in the system journal.

The combination of the present flushed flag file and the runtime journal
being open is a state where we should be logging to the system journal,
so it's appropriate to resume doing so once we've successfully opened
the system journal.
2016-08-25 17:37:57 +02:00
Zbigniew Jędrzejewski-Szmek 61755fdae0 journald: do not create split journals for dynamic users
Dynamic users should be treated like system users, and their logs
should end up in the main system journal.
2016-08-18 23:34:40 -04:00
Lennart Poettering 622a0f628c Merge pull request #3946 from keszybz/open-journal-root
Make journalctl more flexible
2016-08-17 20:28:45 +02:00
Vito Caputo 105bdb46b4 journal: ensure open journals from find_journal() (#3973)
If journals get into a closed state like when rotate fails due to
ENOSPC, when space is made available it currently goes unnoticed leaving
the journals in a closed state indefinitely.

By calling system_journal_open() on entry to find_journal() we ensure
the journal has been opened/created if possible.

Also moved system_journal_open() up to after open_journal(), before
find_journal().

Fixes https://github.com/systemd/systemd/issues/3968
2016-08-17 14:51:07 +02:00
Zbigniew Jędrzejewski-Szmek 0a1750934f journalctl: allow --root argument for journal watching
It is useful to look at a (possibly inactive) container or other os tree
with --root=/path/to/container. This is similar to specifying
--directory=/path/to/container/var/log/journal --directory=/path/to/container/run/systemd/journal
(if using --directory multiple times was allowed), but doesn't require
as much typing.
2016-08-12 00:38:03 -04:00
Zbigniew Jędrzejewski-Szmek 16fefe9080 sd-journal: fix sd_journal_open_directory with SD_JOURNAL_OS_ROOT
The directory argument that is given to sd_j_o_d was ignored when
SD_JOURNAL_OS_ROOT was given, and directories relative to the root of the host
file system were used. With that flag, sd_j_o_d should do the same as
sd_j_open_container: use the path as "prefix", i.e. the directory relative to
which everything happens.

Instead of touching sd_j_o_d, journal_new is fixed to do what sd_j_o_c
was doing, and treat the specified path as prefix when SD_JOURNAL_OS_ROOT is
specified.
2016-08-12 00:38:03 -04:00
Zbigniew Jędrzejewski-Szmek 10752e829b sd-journal: allow SYSTEM and CURRENT_USER flags with sd_j_open_directory[_fd]
There is no reason not to. This makes journalctl -D ... --system work,
useful for example when viewing files from a deactivated container.
2016-08-12 00:38:03 -04:00
Zbigniew Jędrzejewski-Szmek 1aaa68f535 sd-journal: split out flags into separate defines for legibility
… in preparation for future changes.
2016-08-12 00:38:03 -04:00
Evgeny Vereshchagin e73529f9dd sd-journal: watch logs below container's /{var,run}/log/journal (instead of the /) (#3934)
Fixes #3927.
2016-08-09 08:49:32 -04:00
Cristian Rodríguez 7dbe0b72c5 buildsys,journal: allow -fsanitize=address without VALGRIND defined
Fixed (master) versions of libtool pass -fsanitize=address correctly
into CFLAGS and LDFLAGS allowing ASAN to be used without any special
configure tricks..however ASAN triggers in lookup3.c for the same
reasons valgrind does. take the alternative codepath if
__SANITIZE_ADDRESS__ is defined as well.
2016-08-06 02:14:51 +00:00
Lennart Poettering 992e8f224b util-lib: rework /tmp and /var/tmp handling code
Beef up the existing var_tmp() call, rename it to var_tmp_dir() and add a
matching tmp_dir() call (the former looks for the place for /var/tmp, the
latter for /tmp).

Both calls check $TMPDIR, $TEMP, $TMP, following the algorithm Python3 uses.
All dirs are validated before use. secure_getenv() is used in order to limite
exposure in suid binaries.

This also ports a couple of users over to these new APIs.

The var_tmp() return parameter is changed from an allocated buffer the caller
will own to a const string either pointing into environ[], or into a static
const buffer. Given that environ[] is mostly considered constant (and this is
exposed in the very well-known getenv() call), this should be OK behaviour and
allows us to avoid memory allocations in most cases.

Note that $TMPDIR and friends override both /var/tmp and /tmp usage if set.
2016-08-04 16:27:07 +02:00
Zbigniew Jędrzejewski-Szmek 584c6e7050 journalctl,systemctl: add "short-full", "short-unix" mode to --help 2016-08-04 09:03:31 -04:00
Zbigniew Jędrzejewski-Szmek cce9c80af3 gitignore: libsystemd-journal.pc is no more (#3863)
…since 4de282cf93.
2016-08-02 16:04:39 +02:00
Zbigniew Jędrzejewski-Szmek 76153ad45f journald: deprecate SplitMode=login (#3805)
In this mode, messages from processes which are not part of the session
land in the main journal file, and only output of processes which are
properly part of the session land in the user's journal. This is
confusing, in particular because systemd-coredump runs outside of the
login session.

"Deprecate" SplitMode=login by removing it from documentation, to
discourage people from using it.
2016-07-26 08:19:33 +02:00
Lennart Poettering 3bbaff3e08 tree-wide: use sd_id128_is_null() instead of sd_id128_equal where appropriate
It's a bit easier to read because shorter. Also, most likely a tiny bit faster.
2016-07-22 12:38:08 +02:00
Lennart Poettering 0d23bc57da sd-journal: suppress empty lines
Let's make sure our logging APIs is in sync with how stdout/stderr logging
works.
2016-07-19 17:51:20 +02:00
Lennart Poettering c24f1f9df1 sd-journal: when formatting log messages, implicitly strip trailing whitespace
When converting log messages from human readable text into binary records to
send off to journald in sd_journal_print(), strip trailing whitespace in the
log message. This way, handling of logs made via syslog(), stdout/stderr and
sd_journal_print() are treated the same way: trailing (but not leading)
whitespace is automatically removed, in particular \n and \r. Note that in case
of syslog() and stdout/stderr based logging the stripping takes place
server-side though, while for the native protocol based transport this takes
place client-side. This is because in the former cases conversion from
free-form human-readable strings into structured, binary log records takes
place on the server-side while for journal-native logging it happens on the
client side, and after conversion into binary records we probably shouldn't
alter the data anymore.

See: #3416
2016-07-19 14:21:49 +02:00
Zbigniew Jędrzejewski-Szmek 2ed968802c tree-wide: get rid of selinux_context_t (#3732)
9eb9c93275
deprecated selinux_context_t. Replace with a simple char* everywhere.

Alternative fix for #3719.
2016-07-15 18:44:02 +02:00
Torstein Husebø 61233823aa treewide: fix typos and remove accidental repetition of words 2016-07-11 16:18:43 +02:00
ottopotto 34a8f0811c journalctl: Make temporary files directory configurable (#3574)
journalctl: Use env variable TMPDIR to save temporary files
2016-06-30 07:59:06 -07:00
Zbigniew Jędrzejewski-Szmek 592855c318 journalct: allow --boot=0 to DTRT with --file/--directory
--boot=0 magically meant "this boot", but when used with --file/--directory it
should simply refer to the last boot found in the specified journal. This way,
--boot and --list-boots are consistent.

Fixes #3603.
2016-06-28 16:19:59 -04:00
Zbigniew Jędrzejewski-Szmek 07ff6b0823 journalctl: use simpler variable names in get_boots()
Those are just local variables and ref_boot_offset is especially
obnoxious.
2016-06-28 16:14:04 -04:00
Zbigniew Jędrzejewski-Szmek 8453f06257 journalct: do no allow --this-boot to take arguments
Before --this-boot was deprecated in a331b5e6d4, it did not take
any arguments.
2016-06-28 16:14:04 -04:00
Zbigniew Jędrzejewski-Szmek f3bd7561c5 journalctl: allow --file/--directory with --boot or --list-boots
It works mostly fine, and can be quite useful to examine data from another
system.

OTOH, a single boot id doesn't make sense with --merge, so mixing with --merge
is still not allowed.
2016-06-28 16:14:04 -04:00
Lennart Poettering 3f0083a264 tree-wide: some work-arounds for gcc false positives regarding uninitialized variables 2016-06-21 14:15:23 +02:00
Lennart Poettering 7565bb98a4 tree-wide: check colors_enabled() before outputting ANSI color strings 2016-05-30 18:23:08 +02:00
Lennart Poettering 54f8c958f1 tree-wide: use ansi_highlight() instead of ANSI_HIGHLIGHT where appropriate
Let's make sure SYSTEMD_COLORS is honour by more tools
2016-05-30 18:22:16 +02:00
Lennart Poettering 23be5709e1 journald: stack allocation cannot fail
No need to check whether alloca() failed...
2016-05-05 22:26:09 +02:00
Lennart Poettering fc2fffe770 tree-wide: introduce new SOCKADDR_UN_LEN() macro, and use it everywhere
The macro determines the right length of a AF_UNIX "struct sockaddr_un" to pass to
connect() or bind(). It automatically figures out if the socket refers to an
abstract namespace socket, or a socket in the file system, and properly handles
the full length of the path field.

This macro is not only safer, but also simpler to use, than the usual
offsetof() + strlen() logic.
2016-05-05 22:24:36 +02:00
Torstein Husebø f8e2f4d6a0 treewide: fix typos (#3187) 2016-05-04 11:26:17 +02:00
Lennart Poettering a67d68b848 tree-wide: fix invocations of chattr_path()
chattr_path() takes two bitmasks, and no booleans. Fix the various invocations
to do this properly.
2016-05-02 11:15:30 +02:00
Lennart Poettering f0367da7d1 core: rename StartLimitInterval= to StartLimitIntervalSec=
We generally follow the rule that for time settings we suffix the setting name
with "Sec" to indicate the default unit if none is specified. The only
exception was the rate limiting interval settings. Fix this, and keep the old
names for compatibility.

Do the same for journald's RateLimitInterval= setting
2016-04-29 16:27:48 +02:00
Lennart Poettering 1fcefd8815 journal-file: when rotating a journal file, fsync directory too
As suggested by:

https://github.com/systemd/systemd/pull/3126#discussion_r61125474
2016-04-29 12:24:09 +02:00
Lennart Poettering a0fe2a2d20 journal: when creating a new journal file, fsync() the directory it is created in too
Fixes: #2831
2016-04-29 12:23:34 +02:00
Nalin Dahyabhai daf535a382 Correctly parse OBJECT_PID in journald messages (#3129)
The parse_pid() function doesn't succeed if we don't zero-terminate after the
last digit in the buffer.
2016-04-27 10:32:05 +02:00
Vito Caputo 8eb851711f journal: set STATE_ARCHIVED as part of offlining (#2740)
The only code path which makes a journal durable is via
journal_file_set_offline().

When we perform a rotate the journal's header->state is being set to
STATE_ARCHIVED prior to journal_file_set_offline() being called.

In journal_file_set_offline(), we short-circuit the entire offline when
f->header->state != STATE_ONLINE.

This all results in none of the journal_file_set_offline() fsync() calls
being reached when rotate archives a journal, so archived journals are
never explicitly made durable.

What we do now is instead of setting the f->header->state to
STATE_ARCHIVED directly in journal_file_rotate() prior to
journal_file_close(), we set an archive flag in f->archive for the
journal_file_set_offline() machinery to honor by committing
STATE_ARCHIVED instead of STATE_OFFLINE when set.

Prior to this, rotated journals were never getting fsync() explicitly
performed on them, since journal_file_set_offline() short-circuited.
Obviously this is undesirable, and depends entirely on the underlying
filesystem as to how much durability was achieved when simply closing
the file.

Note that this problem existed prior to the recent asynchronous fsync
changes, but those changes do facilitate our performing this durable
offline on rotate without blocking, regardless of the underlying
filesystem sync-on-close semantics.
2016-04-27 08:29:43 +02:00
Lennart Poettering bee6a29198 journal-file: make seeking in corrupted files work
Previously, when we used a bisection table for seeking through a corrupted
file, and the end of the bisection table was corrupted we'd most likely fail
the entire seek operation. Improve the situation: if we encounter invalid
entries in a bisection table, linearly go backwards until we find a working
entry again.
2016-04-26 12:00:49 +02:00
Lennart Poettering caeab8f626 journal-file: when iterating through a partly corruped journal file, treat error like EOF
When we linearly iterate through a corrupted journal file, and we encounter a
read error, don't consider this fatal, but merely as EOF condition (and log
about it).
2016-04-26 12:00:49 +02:00
Lennart Poettering bd30fdf213 journal-file: always generate the same error when encountering corrupted files
Let's make sure EBADMSG is the one error we throw when we encounter corrupted
data, so that we can neatly test for it.
2016-04-26 12:00:03 +02:00
Lennart Poettering 50809d7a9c sd-journal: detect earlier if we try to read an object from an invalid offset
Specifically, detect early if we try to read from offset 0, i.e. are using
uninitialized offset data.
2016-04-26 12:00:02 +02:00
Zbigniew Jędrzejewski-Szmek 47005cf1cf Merge pull request #3109 from poettering/journal-by-fd
rework "journalctl -M"
2016-04-25 15:57:36 -04:00
Zbigniew Jędrzejewski-Szmek 61837e19c6 Merge pull request #3114 from poettering/journalctl-b
Fix endless loops in journalctl --list-boots (closes #617).
2016-04-25 15:56:17 -04:00
Vito Caputo b8f99e27e1 journal: fix already offline check and thread leak (#2810)
Early in journal_file_set_offline() f->header->state is tested to see if
it's != STATE_ONLINE, and since there's no need to do anything if the
journal isn't online, the function simply returned here.

Since moving part of the offlining process to a separate thread, there
are two problems here:

1. We can't simply check f->header->state, because if there is an
offline thread active it may modify f->header->state.

2. Even if the journal is deemed offline, the thread responsible may
still need joining, so a bare return may leak the thread's resources
like its stack.

To address #1, the helper journal_file_is_offlining() is called prior to
accessing f->header->state.

If journal_file_is_offlining() returns true, f->header->state isn't even
checked, because an offlining journal is obviously online, and we'll
just continue with the normal set offline code path.

If journal_file_is_offlining() returns false, then it's safe to check
f->header->state, because the offline_state is beyond the point of
modifying f->header->state, and there's a memory barrier in the helper.

If we find f->header->state is != STATE_ONLINE, then we call the
idempotent journal_file_set_offline_thread_join() on the way out of the
function, to join a potential lingering offline thread.
2016-04-25 19:58:16 +02:00
Lennart Poettering 52051dd84c journalctl: turn --unit= in combination with --user into --user-unit=
Let's be nice to users, and let's turn the nonsensical "--unit=… --user" into
"--user-unit=…" which the user more likely meant.

Fixes #1621
2016-04-25 19:29:01 +02:00
Lennart Poettering 2daa9cbdda sd-journal: "soft" deprecate sd_journal_open_container()
Let's document the call as deprecated, since it doesn't cover containers with
directories that aren#t visible to the host properly.
2016-04-25 19:29:01 +02:00
Lennart Poettering d38c62cc76 journalctl: port --machine= switch to use machined's OpenMachineRootDirectory()
This way, the switch becomes compatible with nspawn containers using --image=,
and those which only store journal data in /run (i.e. have persistant logs
off).

Fixes: #49
2016-04-25 19:29:01 +02:00
Lennart Poettering dc00966228 journalctl: don't trust the per-field entry tables when looking for boot IDs
When appending to a journal file, journald will:

a) first, append the actual entry to the end of the journal file
b) second, add an offset reference to it to the global entry array stored at
   the beginning of the file
c) third, add offset references to it to the per-field entry array stored at
   various places of the file

The global entry array, maintained by b) is used when iterating through the
journal without matches applied.

The per-field entry array maintained by c) is used when iterating through the
journal with a match for that specific field applied.

In the wild, there are journal files where a) and b) were completed, but c)
was not before the files were abandoned. This means, that in some cases log
entries are at the end of these files that appear in the global entry array,
but not in the per-field entry array of the _BOOT_ID= field. Now, the
"journalctl --list-boots" command alternatingly uses the global entry array
and the per-field entry array of the _BOOT_ID= field. It seeks to the last
entry of a specific _BOOT_ID=field by having the right match installed, and
then jumps to the next following entry with no match installed anymore, under
the assumption this would bring it to the next boot ID. However, if the
per-field entry wasn't written fully, it might actually turn out that the
global entry array might know one more entry with the same _BOOT_ID, thus
resulting in a indefinite loop around the same _BOOT_ID.

This patch fixes that, by updating the boot search logic to always continue
reading entries until the boot ID actually changed from the previous. Thus, the
per-field entry array is used as quick jump index (i.e. as an optimization),
but not trusted otherwise.  Only the global entry array is trusted.

This replaces PR #1904, which is actually very similar to this one. However,
this one actually reads the boot ID directly from the entry header, and doesn't
try to read it at all until the read pointer is actually really located on the
first item to read.

Fixes: #617

Replaces: #1904
2016-04-25 18:08:42 +02:00
Lennart Poettering 0808b92f02 journalctl: improve output of --header a bit
Show the various timestamps in hexadecimal too. This is useful for matching the
timestamps included in cursor strings (which are encoded in hex, too), with the
references in the journal header.
2016-04-25 18:06:47 +02:00
Lennart Poettering d1bf9dc963 journalctl: simplify discover_next_boot() a bit
Drop the "read_realtime" parameter. Getting the realtime timestamp from an
entry is cheap, as it is a normal header field, hence let's just get this
unconditionally, and simplify our code a bit.
2016-04-25 16:37:09 +02:00
Lennart Poettering d4723fb501 journalctl: simplify get_boots() a bit, by getting rid of one BootId object
Let's store the reference as simple sd_id128_t, since we don't actually need a
BootId for it.
2016-04-25 16:34:55 +02:00
Lennart Poettering c4fbc6b6e4 journalctl: add some explanatory comments to get_boots() 2016-04-25 16:34:55 +02:00
Lennart Poettering d077390cdf sd-journal: add logic to open journal files of a specific OS tree
With this change a new flag SD_JOURNAL_OS_ROOT is introduced. If specified
while opening the journal with the per-directory calls (specifically:
sd_journal_open_directory() and sd_journal_open_directory_fd()) the passed
directory is assumed to be the root directory of an OS tree, and the journal
files are searched for in /var/log/journal, /run/log/journal relative to it.

This is useful to allow usage of sd-journal on file descriptors returned by the
OpenRootDirectory() call of machined.
2016-04-25 15:24:46 +02:00
Lennart Poettering 5d1ce25728 sd-journal: add API for opening journal files or directories by fd
Also, expose this via the "journalctl --file=-" syntax for STDIN. This feature
remains undocumented though, as it is probably not too useful in real-life as
this still requires fds that support mmaping and seeking, i.e. does not work
for pipes, for which reading from STDIN is most commonly used.
2016-04-25 15:24:46 +02:00
Lennart Poettering cb306f5d50 sd-journal: minor simplification 2016-04-25 12:00:03 +02:00
Lennart Poettering 0f7488722d journalctl: improve error message when we have trouble reading journal files
Let's output the actual error code encountered, and let's not claim this was
purely triggered by files, because it can also be triggered by directories.
2016-04-25 12:00:03 +02:00
Lennart Poettering f637726130 sd-journal: properly collect errors from readdir()
Let's also collect errors returned by readdir() into our set of errors, like we
do this for all other errors from journal files.
2016-04-25 12:00:03 +02:00
Lennart Poettering 430fbf8e7f journal: add inotify watches by-fd instead of by-path
This is slightly nicer, since we actually watch the directories we opened and
enumerate. However, primarily this is preparation for adding support for
opening journal files by fd without specifying any path, to be added in a later
commit.
2016-04-25 12:00:03 +02:00
Lennart Poettering 991e274b61 journalctl: add --no-hostname switch
This suppresses output of the hostname for messages from the local system.

Fixes: #2342
2016-04-22 16:16:59 +02:00
Lennart Poettering 03532f0ae0 coredump,basic: generalize O_TMPFILE handling a bit
This moves the O_TMPFILE handling from the coredumping code into common library
code, and generalizes it as open_tmpfile_linkable() + link_tmpfile(). The
existing open_tmpfile() function (which creates an unlinked temporary file that
cannot be linked into the fs) is renamed to open_tmpfile_unlinkable(), to make
the distinction clear. Thus, code may now choose between:

 a) open_tmpfile_linkable() + link_tmpfile()
 b) open_tmpfile_unlinkable()

Depending on whether they want a file that may be linked back into the fs later
on or not.

In a later commit we should probably convert fopen_temporary() to make use of
open_tmpfile_linkable().

Followup for: #3065
2016-04-22 16:16:53 +02:00
Zbigniew Jędrzejewski-Szmek ccddd104fc tree-wide: use mdash instead of a two minuses 2016-04-21 23:00:13 -04:00
Zbigniew Jędrzejewski-Szmek 6e1045e538 journald: rewrite function with switch, fix handling of -ESHUTDOWN
The comments and the log messages are next to one another, so it's easier
to check that the messages match the comments.

The sign was omitted in the check for -ESHUTDOWN, so it was never matched.
2016-04-16 18:40:21 -04:00
Zbigniew Jędrzejewski-Szmek ddea446252 journal: assert gcry_mpi_scan succeeded
It might be nicer to propagate the error to the caller, but that'd
be a bigger refactoring. This shouldn't really fail, so just add
an assert.

CID #1349697.
2016-04-08 21:08:54 -04:00
Zbigniew Jędrzejewski-Szmek 8e170d2909 compress: fix gcc warnings about void* used in arithmetic
src/journal/compress.c: In function ‘compress_blob_lz4’:
src/journal/compress.c:115:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
         r = LZ4_compress_limitedOutput(src, dst + 8, src_size, (int) dst_alloc_size - 8);
                                                 ^
src/journal/compress.c: In function ‘decompress_blob_xz’:
src/journal/compress.c:179:35: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
                 s.next_out = *dst + used;
                                   ^
src/journal/compress.c: In function ‘decompress_blob_lz4’:
src/journal/compress.c:218:37: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
         r = LZ4_decompress_safe(src + 8, out, src_size - 8, size);
                                     ^
src/journal/compress.c: In function ‘decompress_startswith_xz’:
src/journal/compress.c:294:38: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
                 s.next_out = *buffer + *buffer_size - s.avail_out;
                                      ^
src/journal/compress.c:294:53: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
                 s.next_out = *buffer + *buffer_size - s.avail_out;
                                                     ^
src/journal/compress.c: In function ‘decompress_startswith_lz4’:
src/journal/compress.c:327:45: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
         r = LZ4_decompress_safe_partial(src + 8, *buffer, src_size - 8,
                                             ^

LZ4 and XZ functions use char* and unsigned char*, respectively,
so keep void* in our internal APIs and add casts.
2016-04-02 18:58:21 -04:00
Zbigniew Jędrzejewski-Szmek 7c2da2ca88 test-compress-benchmark: fix argument parsing on 32bit
The patch is not minimal, but a function to parse size_t is probably
going to come in handy in other places, so I think it's nicer to define
a proper parsing function than to open-code the cast.
2016-04-02 18:58:21 -04:00
Zbigniew Jędrzejewski-Szmek 15b947fb79 test-compress-benchmark: skip loop iteration if size is 0
Otherwise we would hit an assert in the compression code.
2016-03-04 21:46:47 -05:00
Elias Probst 82e24b0068
Use PRIu64 to print uint64_t in log msgs 2016-02-29 23:00:21 +01:00
Zbigniew Jędrzejewski-Szmek 06fb28b16e Merge pull request #2671 from 0xAX/move-pager-open-to-one-place
tree-wide: merge pager_open_if_enabled() to the pager_open()
2016-02-25 15:29:59 -05:00
Alexander Kuleshov ea4b98e657 tree-wide: merge pager_open_if_enabled() to the pager_open()
Many subsystems define own pager_open_if_enabled() function which
checks '--no-pager' command line argument and open pager depends
on its value. All implementations of pager_open_if_enabled() are
the same. Let's merger this function with pager_open() from the
shared/pager.c and remove pager_open_if_enabled() from all subsytems
to prevent code duplication.
2016-02-26 01:13:23 +06:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Lennart Poettering d971033f6b Merge pull request #2708 from vcaputo/journal-restore-offline-state-on-error
journal: restore offline state on error
2016-02-23 16:55:16 +01:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Vito Caputo ec9ffa2cdd journal: restore offline state on error
If we fail to create the thread, technically we should leave the
offline_state as OFFLINE_JOINED, not OFFLINE_SYNCING.
2016-02-22 20:00:13 -08:00
Vito Caputo b58c888f30 journal: defer journal closes on rotate
When we rotate journals, we must set offline and close the current one,
but don't generally need to wait for this to complete.

Instead, we'll initiate an asynchronous offline via
journal_file_set_offline(oldfile, false), and add the file to a
per-server set of deferred closes to be closed later when they
won't block.

There's one complication however; journal_file_open() via
journal_file_verify_header() assumes that any writable journal in the
online state is the product of an unclean shutdown or other form of
corruption.

Thus there's a need for journal_file_open() to be aware of deferred
closes and synchronize with their completion when opening preexisting
journals for writing.  To facilitate this the deferred closes set is
supplied to the journal_file_open() function where the deferred closes
may be closed synchronously before verifying the header in such
circumstances.
2016-02-19 18:50:20 -08:00
Vito Caputo ac2e41f510 journal: asynchronous journal_file_set_offline()
This adds a wait flag to journal_file_set_offline(), when false the offline is
performed asynchronously in a separate thread.

When wait is true, if an asynchronous offline is already in-progress it is
restarted and waited for.  Otherwise the offline is performed synchronously
without the use of a thread.

journal_file_set_online() cancels or waits for the asynchronous offline to
complete if in-flight, depending on where in the offline process the thread
happens to be.  If the thread is in the fsync() phase, it is cancelled and
waiting is unnecessary.  Otherwise, the thread is joined before proceeding.

A new offline_state member is added to JournalFile which is used via
atomic operations for communicating between the offline thread and the
journal_file_set_{offline,online}() functions.
2016-02-19 18:50:20 -08:00
Vito Caputo 69a3a6fd3d journal: add void cast to journal_file_close() calls 2016-02-19 18:50:16 -08:00
Vito Caputo fb42603752 journal: add void cast to fsync() calls 2016-02-19 16:54:19 -08:00
Zbigniew Jędrzejewski-Szmek 06466a7f03 journal/catalog: fix memory leaks
Various buffers were lost because finish_item() either consumed
the buffer or allocated a new one (if an entry with the same key existed).
The caller would simply forget the buffer in either case.

Also add a check for the case when a valid identifier is followed by
an empty body. We should not allow this.

Also be more consistent in error handling and always print an error
message.
2016-02-18 19:39:09 -05:00
Lennart Poettering 91ba5ac7d0 Merge pull request #2589 from keszybz/resolve-tool-2
Better support of OPENPGPKEY, CAA, TLSA packets and tests
2016-02-13 11:15:41 +01:00
Zbigniew Jędrzejewski-Szmek 91e023d896 Move initialize_libgcrypt to separate file
It's annoying to have the exact same function in three places.
It's stored in src/shared, but it's not added to the library to
avoid the dependency on libgcrypt.
2016-02-11 13:12:40 -05:00
Zbigniew Jędrzejewski-Szmek 75f32f047c Add memcpy_safe
ISO/IEC 9899:1999 §7.21.1/2 says:
Where an argument declared as size_t n specifies the length of the array
for a function, n can have the value zero on a call to that
function. Unless explicitly stated otherwise in the description of a
particular function in this subclause, pointer arguments on such a call
shall still have valid values, as described in 7.1.4.

In base64_append_width memcpy was called as memcpy(x, NULL, 0).  GCC 4.9
started making use of this and assumes This worked fine under -O0, but
does something strange under -O3.

This patch fixes a bug in base64_append_width(), fixes a possible bug in
journal_file_append_entry_internal(), and makes use of the new function
to simplify the code in other places.
2016-02-11 13:07:02 -05:00
Lennart Poettering f50cd2b2f5 build-sys: move coredump logic into subdir of its own 2016-02-10 14:32:27 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Klearchos Chaloulos ecb6105a1b journal: Drop monotonicity check when appending to journal file
Remove the check that triggers rotation of the journal file when the arriving log entry had a monotonic timestamp smaller that the previous log entry. This check causes unnecessary rotations when journal-remote was receiving from multiple senders, therefore monotonicity can not be guaranteed. Also, it does not offer any useful functionality for systemd-journald.
2016-02-09 12:14:54 +02:00
Zbigniew Jędrzejewski-Szmek ef9fde5378 Merge pull request #2546 from torstehu/fix-typo3
treewide: fix typos and spacing
2016-02-07 09:45:13 -05:00
Zbigniew Jędrzejewski-Szmek 4121e255f2 Merge pull request #2536 from vcaputo/journal-misc-cleanups
journal: miscellaneous cleanups
2016-02-07 09:43:32 -05:00
Torstein Husebø 1f133e0d53 treewide: fix typos and spacing 2016-02-07 15:31:04 +01:00
Vito Caputo 31981791c5 journal: add missing space to switch statement 2016-02-06 03:51:14 -08:00
Lennart Poettering 421180379f Merge pull request #2138 from stefwalter/journal-combine
Combine journal catalog entries with the same id
2016-02-06 11:30:05 +01:00
Vito Caputo 089ed40bf4 journal: remove template from open_journal args
None of the callers take advantage of this parameter, it's always NULL,
this is just a private helper function to simplify the call sites so
drop the template parameter altogether.  If a caller emerges later who
needs it, it can be restored.
2016-02-05 21:30:53 -08:00
Stef Walter c059b62fe6 journal: Add test for merging journal entries 2016-02-05 17:07:01 +01:00
Stef Walter 9d85882aa8 journal: Refactor test-catalog importing tests
One function per test. Remove shared state between tests.
2016-02-05 17:07:01 +01:00
Stef Walter dbae138dc1 journal: Combine journal catalog entries with the same id
Instead of discarding duplicate catalog entries, we now combine
them. This allows software or admins to add or override catalog
headers, or add additional text to the catalog message.
2016-02-05 17:06:59 +01:00
Vito Caputo db87967e5b journal: move mmap() ENOMEM loop to function
Introduces mmap_try_harder()
2016-02-05 07:43:46 -08:00
Vito Caputo 90d222c190 journal: add asserts on f->(data|field)_hash_table
Functions dereferencing these members should assert their non-NULL state.
2016-02-05 07:43:46 -08:00
Vito Caputo c88cc6af70 journal: add asserts for f->header
Just some additional asserts in functions dereferencing f->header.
2016-02-05 07:43:46 -08:00
Vito Caputo 6a49149028 journal: move window initialization to window_add 2016-02-05 07:43:42 -08:00
Lennart Poettering 739731cdac journal: fix boolean handling in MMapCache
Let's use bitfields for our booleans, and don't try to apply binary OR or addition on them, because that's weird and we
should instead use logical OR only.
2016-02-03 23:58:53 +01:00
Lennart Poettering a92ff4003f Merge pull request #2519 from msekletar/journalctl-device-log-current-boot-v2
journalctl: add match for the current boot when called with devpath (v2)
2016-02-03 16:26:21 +01:00
Tom Gundersen 5508e4f218 Merge pull request #2453 from poettering/journalctl-f
journalctl --fields logic
2016-02-03 15:36:06 +01:00
Michal Sekletar 485fd9a7b9 journalctl: add match for the current boot when called with devpath 2016-02-03 13:54:24 +01:00
Lennart Poettering c5c41f1e57 Merge pull request #2510 from msekletar/journalctl-dev-sda-v4
journalctl: make "journalctl /dev/sda" work
2016-02-02 19:34:39 +01:00
Michal Sekletar 795ab08f78 journalctl: make "journalctl /dev/sda" work
Currently when journalctl is called with path to block device node we
add following match _KERNEL_DEVICE=b$MAJOR:$MINOR.

That is not sufficient to actually obtain logs about the disk because
dev_printk() kernel helper puts to /dev/kmsg information about the
device in following format, +$SUBSYSTEM:$ADDRESS,
e.g. "+pci:pci:0000:00:14.0".

Now we will walk upward the syspath and add match for every device in
format produced by dev_printk() as well as match for its device node if
it exists.
2016-02-02 16:46:28 +01:00
Lennart Poettering ed71f95662 sd-journal: minor optimization
No need to store the object and offset data if we don't actually need it ever.
2016-02-01 22:42:33 +01:00
Lennart Poettering 69e714f3d8 journalctl: add new --fields switch to dump all currently used field names
Fixes #2176
2016-02-01 22:42:33 +01:00
Lennart Poettering eb86030ec0 sd-journal: add an API to enumerate known field names of the journal
This adds two new calls to get the list of all journal fields names currently in use.

This is the low-level support to implement the feature requested in #2176 in a more optimized way.
2016-02-01 22:42:33 +01:00
Lennart Poettering 2afcd6902b journal-cat: don't allocate memory for the syslog identifier
Fixes: #2490
2016-02-01 22:18:15 +01:00
Jan Synacek c34e939909 journalctl: improve error messages when the specified boot is not found 2016-02-01 11:59:33 +01:00
Jan Synacek 0f1a9a830c journalctl: show friendly info when using -b on runtime journal only
Make it clear that specifing boot when there is actually only one has no
effect. This cosmetic patch improves user experience a bit.
2016-02-01 11:59:33 +01:00
Jan Synacek 39fd5b08a7 sd-journal: introduce has_runtime_files and has_persistent_files
Also introduce sd_journal_has_runtime_files() and
sd_journal_has_persistent_files() to the public API. These functions
can be used to easily find out if the open journal files are runtime
and/or persistent.
2016-02-01 11:59:27 +01:00
Tom Gundersen 9766c16bd0 Merge pull request #2440 from poettering/journal-fix
journald: minor fixes
2016-01-26 18:16:48 +01:00
Lennart Poettering 4850d39ab7 journald: add a couple of static asserts checking logging constants
Whenever we include a log level or facility in a journal string field, make sure the compiler checks for us that that's
actually the right thing to do.
2016-01-26 14:43:24 +01:00
Lennart Poettering d6f4302b66 journald: fix LOG_AUTH facility in audit code
Fixes: #2304
2016-01-26 14:42:04 +01:00
Lennart Poettering 1d35b2d6e2 Merge pull request #2424 from keszybz/journald-disk-usage
Journald disk usage
2016-01-26 14:20:45 +01:00
Lennart Poettering e167d7fd8d journald: minor fixes
This primarily contains some minor coding style fixups for 7a24f3bf2f and earlier changes. Specifically:

* Don't log at log levels above LOG_DEBUG from "library" code like journal-file.c

* Don't negate errno values before passing them to log_debug_errno(), as the call can handle this fine anyway

* Cast some calls we knowingly ignore the return values of to (void)

* Don't clobber function call-by-ref return values on failure

* Don't mix function calls and variable declarations in one line

There's also one more relevant change: when failing to enqueue a journal change fs event, we'll run it immediately.
2016-01-26 14:13:30 +01:00