Commit Graph

173 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
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
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
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
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
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 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
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
Zbigniew Jędrzejewski-Szmek 8a03c9ef74 journald: allow additional payload in server_driver_message
The code to format the iovec is shared with log.c. All call sites to
server_driver_message are changed to include the additional "MESSAGE="
part, but the new functionality is not used and change in functionality
is not expected.

iovec is preallocated, so the maximum number of messages is limited.
In server_driver_message N_IOVEC_PAYLOAD_FIELDS is currently set to 1.

New code is not oom safe, it will fail if memory cannot be allocated.
This will be fixed in subsequent commit.
2016-01-23 19:49:00 -05:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Lennart Poettering e22aa3d328 journald: never block when sending messages on NOTIFY_SOCKET socket
Otherwise we might run into deadlocks, when journald blocks on the
notify socket on PID 1, and PID 1 blocks on IPC to dbus-daemon and
dbus-daemon blocks on logging to journald. Break this cycle by making
sure that journald never ever blocks on PID 1.

Note that this change disables support for event loop watchdog support,
as these messages are sent in blocking style by sd-event. That should
not be a big loss though, as people reported frequent problems with the
watchdog hitting journald on excessively slow IO.

Fixes: #1505.
2015-11-01 22:12:29 +01:00
Lennart Poettering 8580d1f73d journal: rework vacuuming logic
Implement a maximum limit on number of journal files to keep around.
Enforcing a limit is useful on this since our performance when viewing
pays a heavy penalty for each journal file to interleve. This setting is
turned on now by default, and set to 100.

Also, actully implement what 348ced9097
promised: use whatever we find on disk at startup as lower bound on how
much disk space we can use. That commit introduced some provisions to
implement this, but actually never did.

This also adds "journalctl --vacuum-files=" to vacuum files on disk by
their number explicitly.
2015-10-02 23:21:59 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Lennart Poettering fa6ac76083 journald: process SIGBUS for the memory maps we set up
Even though we use fallocate() it appears that file systems like btrfs
will trigger SIGBUS on certain low-disk-space situation. We should
handle that, hence catch the signal, add it to a list of invalidated
pages, and replace the page with an empty memory area. After each write
check if SIGBUS was triggered, and consider the write invalid if it was.

This should make journald a lot more robust with file systems where
fallocate() is not reliable, for example all CoW file systems
(btrfs...), where changing written data can fail with disk full errors.

https://bugzilla.redhat.com/show_bug.cgi?id=1045810
2015-01-05 01:40:51 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Lennart Poettering af4ec4309e notify: send STOPPING=1 from our daemons 2014-08-21 17:24:21 +02:00
Zbigniew Jędrzejewski-Szmek 73f860db98 Always prefer our headers to system headers
In practice this shouldn't make much difference, but
sometimes our headers might be newer, and we want to
test them.
2014-07-31 08:56:03 -04:00
Kay Sievers 3a43da2832 time-util: add and use USEC/NSEC_INFINIY 2014-07-29 13:20:20 +02:00
Zbigniew Jędrzejewski-Szmek de0671ee7f Remove unnecessary casts in printfs
No functional change expected :)
2014-05-15 15:29:58 +02:00
Lennart Poettering dfdb269daf journald: remove some dead code 2014-05-06 17:03:28 +02:00
Zbigniew Jędrzejewski-Szmek 2fc74bf433 journald: remove stray reset of error return value 2014-03-17 01:55:47 -04:00
Lennart Poettering 565a9388f2 journal: when we shall go down do so cleanly 2013-12-22 21:12:25 +01:00
Lennart Poettering f9a810beda journald: port to sd-event and enable watchdog support 2013-12-11 20:55:09 +01:00
Kay Sievers 7964dfca1b journald: remove unconditional log_*() use in the main loop
Setting MaxRetentionSec= caused the kernel log to overflow and the
journal daemon to enter an endless loop.

Logging from the journald main loop gets directed to /dev/kmsg,
which wakes up journald again. We skip the import of this message
by checking for our own PID, but this still causes the main loop
to never go to sleep again because we never stopped logging from
there.
2013-03-23 21:09:37 +01:00
Zbigniew Jędrzejewski-Szmek d025f1e4dc build-sys: store journald code in a noinst library
The point is to allow the use of journald functions by other binaries.
Before, journald code was split into multiple files (journald-*.[ch]),
but all those files all required functions from journald.c. And
journald.c has its own main(). Now, it is possible to link against
those functions, e.g. from test binaries.

This constitutes a fix for https://bugzilla.redhat.com/show_bug.cgi?id=872638.

The patch does the following:
1. rename journald.h to journald-server.h and move corresponding code
   to journald-server.c.
2. add journald-server.c and other journald-*.c parts to
   libsystemd-journal-internal.
3. remove journald-syslog.c from test_journal_syslog_SOURCES, since
   it is now contained in libsystemd-journal-internal.
There are no code changes, apart from the removal of a few static's,
to allow function calls between files.
2012-11-14 23:39:53 +01:00
Lennart Poettering fb0951b02e journal: implement time-based rotation/vacuuming
This also enables time-based rotation (but not vacuuming) after 1month,
so that not more one month of journal is lost at a time per vacuuming.
2012-10-16 22:58:07 +02:00
Zbigniew Jędrzejewski-Szmek 1ca6783f5e log: introduce a macro to format message id
The MESSAGE_ID=... stanza will appear in countless number of places.
It is just too long to write it out in full each time.

Incidentally, this also fixes a typo of MESSSAGE is three places.
2012-10-13 14:26:30 +02:00
Lennart Poettering 760c85c0bd journald: rework auto-rotation logic 2012-09-28 15:42:34 +02:00
Lennart Poettering 80d1c5988b journald: close sd_journal context after flushing to /var 2012-09-28 15:41:20 +02:00
Lennart Poettering c2893c4b34 journald: log how big the journal files may grow 2012-09-21 22:50:26 +02:00
Lennart Poettering 7d5e9c0f60 util: define union dirent_storage and make use of it everywhere
Make sure to allocate enough space for readdir_r().

https://bugzilla.redhat.com/show_bug.cgi?id=858754
2012-09-19 22:21:09 +02:00
Lennart Poettering 178cc7700c journald: log when we fail to forward messages to syslog
https://bugzilla.redhat.com/show_bug.cgi?id=847207
2012-09-17 23:59:26 +02:00
Lennart Poettering b58b344afd journald: properly update perms on freshly rotate user journals 2012-09-17 15:53:42 +02:00
Lennart Poettering c17a8454f7 journald: don't do debug logging by default 2012-09-10 13:18:39 +02:00
Lennart Poettering 182b858fc2 journald: make splitting up of journal files per-user configurable 2012-09-07 23:40:00 +02:00
Lennart Poettering 2b43f939a4 journald: avoid logging to kmsg in the normal paths 2012-09-06 00:32:51 -07:00
Lennart Poettering 99add6fd0b journalctl: complain if unprivileged users attempt to access the journal and persistant logging is off 2012-08-22 04:45:17 +02:00
Lennart Poettering d2bd7630d7 journal: the ratelimiter is part of journald 2012-08-22 03:43:45 +02:00
Lennart Poettering 0153028ae3 journald: split off native protocol support into its own .c file 2012-08-22 03:42:23 +02:00
Lennart Poettering 3b7124a8db journald: split console transport stuff into its own file 2012-08-22 03:36:29 +02:00
Lennart Poettering a45b9fca6b journald: move stream protocol into its own .c file 2012-08-22 03:32:41 +02:00
Lennart Poettering 35e2e347d3 journald: splitt of syslog protocol support into its own file 2012-08-22 03:21:03 +02:00
Lennart Poettering ef63833d53 journald: split /dev/kmsg related stuff into its own .c file 2012-08-22 03:09:44 +02:00
Lennart Poettering 671e021c92 journald: write tags also to user journal files 2012-08-22 02:53:51 +02:00
Lennart Poettering bdfb9e7f7c journald: augment journal entries from the kernel with data from udev 2012-08-22 02:49:17 +02:00
Lennart Poettering 24a598f889 journal: properly handle EPIPE from /dev/kmsg 2012-08-21 15:39:34 +02:00
Lennart Poettering 89fef99014 journal: automatically evolve FSS key even when nothing is logged 2012-08-21 01:29:17 +02:00
Lennart Poettering eb53b74f7e journald: add new Seal= configuration option 2012-08-20 22:13:22 +02:00