Commit Graph

229 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Lennart Poettering df0ff12775 tree-wide: make use of getpid_cached() wherever we can
This moves pretty much all uses of getpid() over to getpid_raw(). I
didn't specifically check whether the optimization is worth it for each
replacement, but in order to keep things simple and systematic I
switched over everything at once.
2017-07-20 20:27:24 +02:00
Lars Karlitski 0488435496 journal: return 0 from _skip() when it didn't skip
Seeking to the tail and calling `sd_journal_previous_skip(journal, 0)`
was equivalent to calling it with skip == 1 (same for head and next()).
2017-05-11 22:49:20 +02:00
Michal Sekletar f934644424 sd-journal: return SD_JOURNAL_INVALIDATE only if journal files were actually deleted/moved (#5580)
When caller invokes sd_journal_open() we usually open at least one
directory with journal files. add_root_directory() function increments
current_invalidate_counter. After sd_journal_open() returns
current_invalidate_counter != last_invalidate_counter.

After caller waits for journal events (e.g. waits for new messages in
journal) then it usually calls sd_journal_process(). However, on first
call to sd_journal_process(), function determine_change() returns
SD_JOURNAL_INVALIDATE even though no journal files were
deleted/moved. This is because current_invalidate_counter !=
last_invalidate_counter.

After the fix we make sure counters has the same value before we begin
processing inotify events.
2017-04-24 18:33:12 +02: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
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
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 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -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
Torstein Husebø 61233823aa treewide: fix typos and remove accidental repetition of words 2016-07-11 16:18:43 +02:00
Torstein Husebø f8e2f4d6a0 treewide: fix typos (#3187) 2016-05-04 11:26:17 +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 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 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
Elias Probst 82e24b0068
Use `PRIu64` to print `uint64_t` in log msgs 2016-02-29 23:00:21 +01:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08: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 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 69a3a6fd3d journal: add void cast to journal_file_close() calls 2016-02-19 18:50:16 -08: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
Torstein Husebø 1f133e0d53 treewide: fix typos and spacing 2016-02-07 15:31:04 +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 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
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
Zbigniew Jędrzejewski-Szmek 2aaec9b4f6 journal: decompress_startswith can return an error
The return value was used directly in an if, so an error was treated
as success; we need to bail out instead. An error should not happen,
unless we have a compression/decompression mismatch, so output a debug
line.
2015-12-13 14:54:47 -05:00
Lennart Poettering 5768d25949 journalctl: when we fail to open a journal file, print why
When we enumerate journal files and encounter an invalid one, remember
which this, and show it to the user.

Note the possibly slightly surprising logic here: we store only one path
per error code. This means we show all error kinds but not every actual
error we encounter. This has the benefit of not requiring us to keep a
potentially unbounded list of errors with their sources around, but can
still provide a pretty complete overview on the errors we encountered.

Fixes #1669.
2015-11-03 00:02:00 +01:00
Lennart Poettering d617408ecb sd-journal: various clean-ups and modernizations
- Always print a debug log message about files and directories we cannot
  open right when it happens instead of the caller, thus reducing the
  number of places where we need to generate the debug message.

- Always push the errors we encounter immediately into the error set,
  when we run into them, instead of in the caller. Thus, we never forget
  to push them in.

- Use stack instead of heap memory where we can.

- Make remove_file() void, since it cannot fail anyway and always
  returned 0.

- Make local machine check of journal directories explicit in a
  function, to make things more readable.

- Port to all directory listing loops FOREACH_DIRENT_ALL()

- sd-daemon is library code, hence never log at higher log levels than
  LOG_DEBUG.
2015-11-03 00:02:00 +01:00
Susant Sahani 7294bb5be2 sd-journal.c: port to extract_first_word 2015-11-01 03:32:45 +05:30
Lennart Poettering 7760171904 util-lib: move inotify-related definitions to fs-util.[ch] 2015-10-27 14:58:05 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 15a5e95075 util-lib: split out printf() helpers to stdio-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering a09561746f util-lib: introduce dirent-util.[ch] for directory entry calls
Also, move a couple of more path-related functions to path-util.c.
2015-10-27 13:25:56 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 25300b5a1f util: make machine_name_is_valid() a macro and move it to hostname-util.h
As it turns out machine_name_is_valid() does the exact same thing as
hostname_is_valid() these days, as it just invoked that and checked the
name length was < 64. However, hostname_is_valid() checks the length
against HOST_NAME_MAX anyway (which is 64 on Linux), hence any
additional check is redundant.

We hence replace machine_name_is_valid() by a macro that simply maps it
to hostname_is_valid() but sets the allow_trailing_dot parameter to
false. We also move this this call to hostname-util.h, to the same place
as the hostname_is_valid() declaration.
2015-08-24 22:46:45 +02:00
Thomas Hindoe Paaboel Andersen b2b46f91db journal: remove error check that never happens
remove_directory will always return 0 so this can never happen.
Besides that, d->path and d are freed so we would end up with
a null pointer dereference anyway.
2015-08-18 00:11:16 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Zbigniew Jędrzejewski-Szmek 7b300be75e sd-journal: return error when we cannot open a file
Lack of this caused journalctl not to display a hint about missing groups
properly when the user lacks permissions.
2015-03-08 11:11:50 -04:00
Michal Schmidt 950c07d421 journal: make skipping of exhausted journal files effective again
Commit 668c965af "journal: skipping of exhausted journal files is bad if
direction changed" fixed a correctness issue, but it also significantly
limited the cases where the optimization that skips exhausted journal
files could apply.
As a result, some journalctl queries are much slower in v219 than in v218.
(e.g. queries where a "--since" cutoff should have quickly eliminated
older journal files from consideration, but didn't.)

If already in the initial iteration find_location_with_matches() finds
no entry, the journal file's location is not updated. This is fine,
except that:
 - We must update at least f->last_direction. The optimization relies on
   it. Let's separate that from journal_file_save_location() and update
   it immediately after the direction checks.
 - The optimization was conditional on "f->current_offset > 0", but it
   would always be 0 in this scenario. This check is unnecessary for the
   optimization.
2015-02-25 17:32:27 +01:00
Thomas Hindoe Paaboel Andersen 0a6f50c0af include <poll.h> instead of <sys/poll.h>
include-what-you-use automatically does this and it makes finding
unnecessary harder to spot. The only content of poll.h is a include
of sys/poll.h so should be harmless.
2015-02-12 20:47:38 +01:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Zbigniew Jędrzejewski-Szmek 5ffa8c8181 Add a snprinf wrapper which checks that the buffer was big enough
If we scale our buffer to be wide enough for the format string, we
should expect that the calculation was correct.

char_array_0() invocations are removed, since snprintf nul-terminates
the output in any case.

A similar wrapper is used for strftime calls, but only in timedatectl.c.
2015-02-01 17:21:39 -05:00