Commit graph

251 commits

Author SHA1 Message Date
Olivier Brunel 00a1686189 journald: Log error when failed to get machine-id on start
Can help since the journal requires /etc/machine-id to exists in order to start,
and will simply silently exit when it does not.
2013-09-12 18:19:16 +02:00
Zbigniew Jędrzejewski-Szmek 289f910e16 journald: be a bit more verbose when vacuuming
Vacuuming behaviour is a bit confusing, and/or we have some bugs,
so those additional messages should help to find out what's going
on. Also, rotation of journal files shouldn't be happening too
often, so the level of the messages is bumped to info, so that
they'll be logged under normal operation.
2013-09-10 08:27:30 -04:00
Zbigniew Jędrzejewski-Szmek 608c3dc569 journald: remove unused variable 2013-08-06 21:02:47 -04:00
Harald Hoyer 04fefcddb8 journal: handle multiline syslog messages
Since the journal can handle multiple lines just well natively,
and rsyslog can be configured to handle them as well, there is no need
to truncate messages from syslog() after the first newline.

Reproducer:

1. Add following four lines to /etc/rsyslog.conf

   ----------
   $EscapeControlCharactersOnReceive off
   $ActionFileDefaultTemplate RSYSLOG_SysklogdFileFormat
   $SpaceLFOnReceive on
   $DropTrailingLFOnReception off
   ----------

3. Restart rsyslog
  # service rsyslog restart

4. Compile and run the following program

   ----------
   #include <stdio.h>
   #include <syslog.h>

   int main()
   {
    syslog(LOG_INFO, "aaa%caaa", '\n');
    return 0;
   }
   ----------

Actual results:
Below message appears in /var/log/messages.

   ----------
   Sep  7 19:19:39 localhost test2: aaa
   ----------

Expected results:
Below message, which worked prior to systemd-journald
appears in /var/log/messages.

   ----------
   Sep  7 19:19:39 localhost test2: aaa aaa

https://bugzilla.redhat.com/show_bug.cgi?id=855313
2013-08-06 12:58:17 +02:00
Lennart Poettering d07f7b9ef2 journal: immediately sync to disk as soon as we receieve an EMERG/ALERT/CRIT message 2013-07-24 12:34:28 +02:00
Lennart Poettering 19cace379f journald: after the cgroup rework processes may be in both user and system units at the same time 2013-07-19 19:52:30 +02:00
Holger Hans Peter Freyther 2f5df74a5e journal: Leave server_dispatch_message early when Storage is none
When using Storage=none there is no point in collecting all the
information just to throw them away. After this change journald
consumes a lot less CPU time when only forwarding messages.
2013-07-18 19:55:11 +02:00
Shawn Landden 3a83211689 journal: add logging of effective capabilities _CAP_EFFECTIVE
I think this is the most important of the capabilities bitmasks to log.
2013-07-16 04:27:04 +02:00
Lukas Nykryn 433dd10044 journald-server: r should be checked after journal_file_open_reliably 2013-07-12 01:18:16 +02:00
Zbigniew Jędrzejewski-Szmek 670b110c3b journald: fix space limits reporting
Reporting of the free space was bogus, since the remaining space
was compared with the maximum allowed, instead of the current
use being compared with the maximum allowed. Simplify and fix
by reporting limits directly at the point where they are calculated.

Also, assign a UUID to the message.
2013-06-24 21:06:06 -04:00
Lennart Poettering 7f1ad696a2 journald: bump the journal per-unit ratelimit defaults
Too many people kept hitting them, so let's increase the limits a bit.

https://bugzilla.redhat.com/show_bug.cgi?id=965803
2013-06-21 15:57:57 +02:00
Zbigniew Jędrzejewski-Szmek 968f319679 journal: allow callers to specify OBJECT_PID=
When journald encounters a message with OBJECT_PID= set
coming from a priviledged process (UID==0), additional fields
will be added to the message:

OBJECT_UID=,
OBJECT_GID=,
OBJECT_COMM=,
OBJECT_EXE=,
OBJECT_CMDLINE=,
OBJECT_AUDIT_SESSION=,
OBJECT_AUDIT_LOGINUID=,
OBJECT_SYSTEMD_CGROUP=,
OBJECT_SYSTEMD_SESSION=,
OBJECT_SYSTEMD_OWNER_UID=,
OBJECT_SYSTEMD_UNIT= or OBJECT_SYSTEMD_USER_UNIT=.

This is for other logging daemons, like setroubleshoot, to be able to
augment their logs with data about the process.

https://bugzilla.redhat.com/show_bug.cgi?id=951627
2013-06-20 23:03:58 -04:00
Zbigniew Jędrzejewski-Szmek e40ec7aec5 journald: do not calculate free space too early
Since the system journal wasn't open yet, available_space() returned 0.

Before:
systemd-journal[22170]: Allowing system journal files to grow to 4.0G.
systemd-journal[22170]: Journal size currently limited to 0B due to SystemKeepFree.

After:
systemd-journal[22178]: Allowing system journal files to grow to 4.0G.
systemd-journal[22178]: Journal size currently limited to 3.0G due to SystemKeepFree.

Also, when failing to write a message, show how much space was needed:
"Failed to write entry (26 items, 260123456 bytes) despite vacuuming, ignoring: ...".
2013-06-13 23:35:12 -04:00
Zbigniew Jędrzejewski-Szmek cbd671772c journal: letting (interleaved) seqnums go
In the following scenario:
  server creates system.journal
  server creates user-1000.journal
both journals share the same seqnum_id.
Then
  server writes to user-1000.journal first,
  and server writes to system.journal a bit later,
and everything is fine.
The server then terminates (crash, reboot, rsyslog testing,
whatever), and user-1000.journal has entries which end with
a lower seqnum than system.journal. Now
  server is restarted
  server opens user-1000.journal and writes entries to it...
BAM! duplicate seqnums for the same seqnum_id.

Now, we usually don't see that happen, because system.journal
is closed last, and opened first. Since usually at least one
message is written during boot and lands in the system.journal,
the seqnum is initialized from it, and is set to a number higher
than than anything found in user journals. Nevertheless, if
system.journal is corrupted and is rotated, it can happen that
an entry is written to the user journal with a seqnum that is
a duplicate with an entry found in the corrupted system.journal~.
When browsing the journal, journalctl can fall into a loop
where it tries to follow the seqnums, and tries to go the
next location by seqnum, and is transported back in time to
to the older duplicate seqnum. There is not way to find
out the maximum seqnum used in a multiple files, without
actually looking at all of them. But we don't want to do
that because it would be slow, and actually it isn't really
possible, because a file might e.g. be temporarily unaccessible.

Fix the problem by using different seqnum series for user
journals. Using the same seqnum series for rotated journals
is still fine, because we know that nothing will write
to the rotated journal anymore.

Likely related:
https://bugs.freedesktop.org/show_bug.cgi?id=64566
https://bugs.freedesktop.org/show_bug.cgi?id=59856
https://bugs.freedesktop.org/show_bug.cgi?id=64296
https://bugs.archlinux.org/task/35581
https://bugzilla.novell.com/show_bug.cgi?id=817778

Possibly related:
https://bugs.freedesktop.org/show_bug.cgi?id=64293
2013-06-10 10:10:07 -04:00
Zbigniew Jędrzejewski-Szmek ed375bebf4 journalctl: print monotonic timestamp in --header 2013-06-10 10:10:07 -04:00
Daniel Albers fe1abefcd3 journal: take KeepFree into account when reporting maximum size
When reporting the maximum journal size add a hint if it's limited
by KeepFree.
2013-06-01 09:15:11 -04:00
Jan Alexander Steffens (heftig) 23ad4dd884 journald: DO recalculate the ACL mask, but only if it doesn't exist
Since 11ec7ce, journald isn't setting the ACLs properly anymore if
the files had no ACLs to begin with: acl_set_fd fails with EINVAL.

An ACL with ACL_USER or ACL_GROUP entries but no ACL_MASK entry is
invalid, so make sure a mask exists before trying to set the ACL.
2013-05-30 00:43:39 -04:00
Michał Bartoszkiewicz ca26701624 journal: correctly convert usec_t to timespec.
Use timespec_store instead of (incorrectly) doing it inline.
2013-05-15 21:02:46 -04:00
Lennart Poettering 11ec7cede5 journald: don't recalculate the ACL mask
Otherwise we might end up with executable files if some default ACL is
set for the journal directory.
2013-05-07 19:20:26 +02:00
Lennart Poettering 253f59dff9 journald: be more careful when we try to flush the runtime journal to disk and the disk is close to being full
Bump the minimal size of the journal so that we can be sure creating the
journal file will always succeed. Previously the minimum size was
smaller than a empty jounral file...
2013-05-07 01:10:05 +02:00
Lennart Poettering db5c012285 conf-parser: restrict .include usage
Disallow recursive .include, and make it unavailable in anything but
unit files.
2013-04-25 00:05:14 -03:00
Greg Kroah-Hartman e7ff4e7fe9 journal: remove build warning when SELinux is disabled
A small patch to remove a build warnining when SELinux is disabled.
2013-04-25 02:13:56 +02:00
Lennart Poettering ae018d9bc9 cgroup: make sure all our cgroup objects have a suffix and are properly escaped
Session objects will now get the .session suffix, user objects the .user
suffix, nspawn containers the .nspawn suffix.

This also changes the user cgroups to be named after the numeric UID
rather than the username, since this allows us the parse these paths
standalone without requiring access to the cgroup file system.

This also changes the mapping of instanced units to cgroups. Instead of
mapping foo@bar.service to the cgroup path /user/foo@.service/bar we
will now map it to /user/foo@.service/foo@bar.service, in order to
ensure that all our objects are properly suffixed in the tree.
2013-04-22 23:14:12 -03:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek e8e581bf25 Report about syntax errors with metadata
The information about the unit for which files are being parsed
is passed all the way down. This way messages land in the journal
with proper UNIT=... or USER_UNIT=... attribution.

'systemctl status' and 'journalctl -u' not displaying those messages
has been a source of confusion for users, since the journal entry for
a misspelt setting was often logged quite a bit earlier than the
failure to start a unit.

Based-on-a-patch-by: Oleksii Shevchuk <alxchk@gmail.com>
2013-04-17 00:09:16 -04:00
Lennart Poettering 7027ff61a3 nspawn: introduce the new /machine/ tree in the cgroup tree and move containers there
Containers will now carry a label (normally derived from the root
directory name, but configurable by the user), and the container's root
cgroup is /machine/<label>. This label is called "machine name", and can
cover both containers and VMs (as soon as libvirt also makes use of
/machine/).

libsystemd-login can be used to query the machine name from a process.

This patch also includes numerous clean-ups for the cgroup code.
2013-04-16 04:41:21 +02:00
Mirco Tischler d378991747 journal: fix broken tags _SOURCE_REALTIME_TIMESTAMP and _MACHINE_ID 2013-04-12 19:26:49 -04:00
Lennart Poettering 7120511888 journald: no need to free audit vars 2013-04-08 15:48:31 +02:00
Lennart Poettering adb435bb70 journald: drop two more memory allocations 2013-04-08 15:48:31 +02:00
Lennart Poettering a569398925 journald: get rid of one more memory allocation 2013-04-08 15:48:31 +02:00
Holger Hans Peter Freyther c2457105d7 journald: Do not dynamically allocate _UID/_GID/_PID strings
Avoid the dynamic allocation for the _UID, _GID, and _PID strings.
The maximum size of the string can be determined at compile time.

The code has only been compile tested.
2013-04-08 15:35:03 +02:00
Holger Hans Peter Freyther 0a20e3c107 journald: Do not always record _AUDIT_SESSION and _AUDIT_LOGINUID
When systemd was compiled without audit support, do not collect the
audit session and loginuid in the journal. This is saving a couple of
syscalls and memory allocations per log message.
2013-04-08 15:30:04 +02:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Oleksii Shevchuk 26687bf8a9 journal: Add sync timer to journal server
Add option to force journal sync with fsync. Default timeout is 5min.
Interval configured via SyncIntervalSec option at journal.conf. Synced
journal files will be marked as OFFLINE.

Manual sync can be performed via sending SIGUSR1.
2013-03-25 17:51:06 +01:00
Zbigniew Jędrzejewski-Szmek 763c7aa288 journal,shared: add _cleanup_journal_close_ 2013-03-18 19:49:30 -04:00
Kay Sievers 83d7d83bcc journal: pass the *pid* to sd_pid_get_owner_uid() 2013-03-16 16:10:22 +01:00
Lennart Poettering a24c64f03f journald: introduce new "systemd-journal" group and make it own the journal files
Previously all journal files were owned by "adm". In order to allow
specific users to read the journal files without granting it access to
the full "adm" powers, introduce a new specific group for this.

"systemd-journal" has to be created by the packaging scripts manually at
installation time. It's a good idea to assign a static UID/GID to this
group, since /var/log/journal might be shared across machines via NFS.

This commit also grants read access to the journal files by default to
members of the "wheel" and "adm" groups via file system ACLs, since
these "almost-root" groups should be able to see what's going on on the
system. These ACLs are created by "make install". Packagers probably
need to duplicate this logic in their postinst scripts.

This also adds documentation how to grant access to the journal to
additional users or groups via fs ACLs.
2013-03-05 18:59:03 +01:00
Lennart Poettering fc7b7e2e74 journald: stpcpy() + mempcpy() are awesome 2013-03-05 15:02:38 +01:00
Lennart Poettering 82499507b3 journald: drop splitting-by-audit entirely
Thinking about it we should probably not hide bugs by falling back to
audit when we have our own session information anyway.
2013-03-05 14:36:59 +01:00
Lennart Poettering 40adcda869 journald: be a bit more careful when spitting up journals by user id 2013-03-05 14:27:34 +01:00
Lennart Poettering 8a0889dfda journald: check session owner UID rather then audit ID when splitting up journal files
We should always go by our own cgroup hierarchy before using foreign
schemes such as audit, so let's do that for the split out logic too.
2013-03-05 14:23:27 +01:00
Kay Sievers da4993920c journal: split journal uid only when audit uid data is valid 2013-03-04 15:19:10 +01:00
Zbigniew Jędrzejewski-Szmek d288f79fb4 journald: do not barf when setting RateLimitInterval=0
Assertion 'interval > 0 || burst == 0' failed at src/journal/journald-rate-limit.c:78, function journal_rate_limit_new(). Aborting.
2013-03-03 09:11:28 -05:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00
Colin Walters 759c945a43 journal: Don't use loginuid if it's not valid
Code above this attempted to load loginuid, if this failed for
whatever reason, we'd still end up using that value (0) in place of
realuid.  Fix this by setting a bool when we know the loginuid is
valid.

This fixes journal messages showing up in per-user journals in
gnome-ostree (not configured with loginuid, but I'll shortly fix
that).
2013-02-13 01:02:25 +01:00
Mirco Tischler ef1673d169 journal: log _SYSTEMD_USER_UNIT for user session units 2013-01-18 11:14:00 -05:00
Lukas Nykryn 9bdbc2e2ec systemctl,loginctl,cgls: do not ellipsize cgroup members when --full is specified
New file output.h with output flags and modes.

--full parameter also for cgls and loginctl.

Include 'all' parameter in flags (show_cgroup_by_path, show_cgroup,
show_cgroup_and_extra, show_cgroup_and_extra_by_spec).

get_process_cmdline with max_length == 0 will not ellipsize output.

Replace LINE_MAX with 0 in some calls of get_process_cmdline.

[zj: Default to --full when under pager for clgs.
     Drop '-f' since it wasn't documented and didn't actually work.
     Reindent a bit.
]
2013-01-16 12:11:47 -05:00
Zbigniew Jędrzejewski-Szmek db91ea32aa journald: use automatic cleanup 2013-01-10 15:19:15 -05:00
Lennart Poettering 93b73b064c journal: by default do not decompress dat objects larger than 64K
This introduces a new data threshold setting for sd_journal objects
which controls the maximum size of objects to decompress. This is
relieves the library from having to decompress full data objects even
if a client program is only interested in the initial part of them.

This speeds up "systemd-coredumpctl" drastically when invoked without
parameters.
2012-11-21 00:28:00 +01:00
Lennart Poettering 7d73c1343b journald: fix bad memory access
https://bugzilla.redhat.com/show_bug.cgi?id=875653
2012-11-20 00:21:44 +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