Commit graph

103 commits

Author SHA1 Message Date
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
Harald Hoyer aea275c431 rename CMP_F_TYPE to F_TYPE_CMP 2013-04-18 08:06:55 +02:00
Harald Hoyer fc6e6d245e Add ugly CMP_F_TYPE() macro
On some architectures (like s390x) the kernel has the type int for
f_type, but long in userspace.
Assigning the 32 bit magic constants from linux/magic.h to the 31 bit
signed f_type in the kernel, causes f_type to be negative for some
constants.
glibc extends the int to long for those architecures in 64 bit mode, so
the negative int becomes a negative long, which cannot be simply
compared to the original magic constant, because the compiler would
automatically cast the constant to long.
To workaround this issue, we also compare to the (int)MAGIC value in a
macro. Of course, we could do #ifdef with the architecure, but it has to
be maintained, and the magic constants are 32 bit anyway.

Someday, when the int is unsigned or long for all architectures, we can
remove this macro again. Until then, keep it as simple as it can be.
2013-04-18 07:34:25 +02:00
Harald Hoyer c4073a27c5 fixup for cddf148028
Instead of making a type up, just use __SWORD_TYPE, after reading
statfs(2).

Too bad, this does not fix s390x because __SWORD_TYPE is (long int) and
the kernel uses (int) to fill in the field!!!!!!
2013-04-17 19:00:50 +02:00
Harald Hoyer cddf148028 fixup 8c68a7017 and cast to (unsigned long) 2013-04-17 18:23:17 +02:00
Harald Hoyer 8c68a70170 fixed statfs.f_type signed vs unsigned comparisons
statfs.f_type is signed but the filesystem magics are unsigned.
Casting the magics to signed will not make the signed.

Problem seen on big-endian 64bit s390x with __fsword_t 8 bytes.

Casting statfs.f_type to unsigned on the other hand will get us what we
need.

https://bugzilla.redhat.com/show_bug.cgi?id=953217
2013-04-17 18:14:25 +02:00
Harald Hoyer cd34b3c667 journal: add one more level on top with AND
When using "-p" and "-b" in combination with "-u", the output is not
what you would expect. The reason is the sd_journal_add_disjunction()
call in add_matches_for_unit() and add_matches_for_user_unit(), which
adds two ORs without taking the other conditions to every OR.

Adding another level on top with AND and sd_journal_add_conjunction()
solves the problem.

Output before:

$ journalctl -o short-monotonic -ab -p 0 -u sshd.service

-- Reboot --
[    3.216305] lenovo systemd[1]: Starting OpenSSH server daemon...
-- Reboot --
[    3.168666] lenovo systemd[1]: Starting OpenSSH server daemon...
[    3.169639] lenovo systemd[1]: Started OpenSSH server daemon.
[36285.635389] lenovo systemd[1]: Stopped OpenSSH server daemon.
-- Reboot --
[   10.838657] lenovo systemd[1]: Starting OpenSSH server daemon...
[   10.913698] lenovo systemd[1]: Started OpenSSH server daemon.
[ 6881.035183] lenovo systemd[1]: Stopped OpenSSH server daemon.
-- Reboot --
[    6.636228] lenovo systemd[1]: Starting OpenSSH server daemon...
[    6.662573] lenovo systemd[1]: Started OpenSSH server daemon.
[    6.681148] lenovo sshd[397]: Server listening on 0.0.0.0 port 22.
[    6.681379] lenovo sshd[397]: Server listening on :: port 22.

As we see, the output is from _every_ boot and priority 0 is not taken
into account.

Output after patch:

$ journalctl -o short-monotonic -ab -p 0 -u sshd.service
-- Logs begin at Sun 2013-02-24 20:54:44 CET, end at Tue 2013-03-19 14:58:21 CET. --

Increasing the priority:

$ journalctl -o short-monotonic -ab -p 6 -u sshd.service
-- Logs begin at Sun 2013-02-24 20:54:44 CET, end at Tue 2013-03-19 14:59:12 CET. --
[    6.636228] lenovo systemd[1]: Starting OpenSSH server daemon...
[    6.662573] lenovo systemd[1]: Started OpenSSH server daemon.
[    6.681148] lenovo sshd[397]: Server listening on 0.0.0.0 port 22.
[    6.681379] lenovo sshd[397]: Server listening on :: port 22.
2013-04-17 09:15:23 +02:00
Marius Vollmer 23e97f7d92 journal: Fix typo
This would break backwards skipping.

https://bugs.freedesktop.org/show_bug.cgi?id=63250
2013-04-08 11:08:38 +02:00
Lennart Poettering 39c155ea0d journal: add sd_journal_get_timeout() call to public API
Let's do the wake-up logic on NFS internally, making things simpler for
users.
2013-04-04 20:07:48 +02:00
Lennart Poettering ee531d949c journal: add public API call sd_journal_get_events()
This function should be used when filling in "struct pollfd"'s .events
field for watching the journal. It will always return POLLIN for now,
but we should keep our options open to change this later on.

This mimics libsystemd-bus' sd_bus_get_events() call with the same
purpose.
2013-04-04 17:22:28 +02:00
Zbigniew Jędrzejewski-Szmek 844ec79b3c catalog: open up catalog internals
In order to write tests for the catalog functions, they
are made non-static and start taking a 'database' parameter,
which is the name of a file with the preprocessed catalog
entries.

This makes it possible to make test-catalog part of the
normal test suite, since it now only operates on files
in /tmp.

Some more tests are added.
2013-03-28 23:45:59 -04:00
Lennart Poettering 54b1da83ed journal: don't access j->files after use
https://bugs.freedesktop.org/show_bug.cgi?id=62605
2013-03-23 04:14:20 +01:00
Lennart Poettering 3ac251b81a journalctl: various fixes to the access check logic
- Reword messages a bit

- Correct check whether EACCES is in the set of errors

- Don't complain if no journal files are found

- allocate Set object for errors lazily since in the best case we don't
  need it at all.

- don't consider it an error if /run/log/journal doesn't exist (because
  that's the usual case actually, if storage is enabled)
2013-03-23 01:12:22 +01:00
Zbigniew Jędrzejewski-Szmek 6fe391c56d journalctl: be smarter about journal error checks
There are many ways in which we can get those checks wrong, so it is
better to warn and then error out on a real access failure.

The error messages are wrapped to <80 lines, because their primary
use is to be displayed in the terminal, and it is easier to read them
this way. Reading them in the journal can be a bit trickier, but
this is a bug in logs-show.c.
2013-03-22 15:31:45 -04:00
Zbigniew Jędrzejewski-Szmek 8cb17a6dc8 sd-journal: do not require path to be absolute
Seems natural to be able to specify relative directory,
e.g. with journalctl -D. And even if, this should be checked
in front-end code, not in the library.
2013-03-18 19:49:33 -04:00
Zbigniew Jędrzejewski-Szmek a50d7d4389 journal: use _cleanup_
One log_debug() moved to match order in other functions.
2013-03-18 18:53:59 -04:00
Zbigniew Jędrzejewski-Szmek 6180fc611b journal: use sd_journal_close on error in sd_journal_new 2013-03-18 18:53:59 -04:00
Zbigniew Jędrzejewski-Szmek 99613ec5d7 libsystemd-journal: return 0 on success in get_data()
The man page says so. Right now 0 would be returned if the data was encrypted,
1 otherwise.
2013-03-07 00:45:56 -05:00
Zbigniew Jędrzejewski-Szmek d95b1fb315 log-show: look at everything in /run/log/journal
Logs written by journald from the initramfs may be written to a
directory with the name created from a random machine-id. Afterwards,
when the root filesystem has been mounted and machine-id reinitalized,
logs will be written to the directory with a name created from the
proper machine-id. When logs are flushed to /var/log/journal,
everything is copied to one output directory.

When journalctl without '-m' is run after the logs have been flushed
to /var/log/journal, all messages are shown. However, when run while
logs are still in /run/log/journal, those stored under the random
machine-id will not be shown.

Make journalctl behave the same regardless whether persistent storage
has been enabled or not, and slurp all files from /run/log/journal
even without '-m'.
2013-02-26 23:16:58 -05:00
Zbigniew Jędrzejewski-Szmek 6f47ad3025 journal: sd_journal_get_cursor should return 0 on success
Documentation states that 0 is correct, and all other
similar functions return 0 on success.

Pointed-out-by: Steven Hiscocks <steven-systemd@hiscocks.me.uk>
2013-02-22 11:19:00 +01: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 8f1e860f8a journal: add sd_journal_get_catalog_for_message_id() as API to get catalog entry for any message ID without requiring an open journal file 2012-11-20 21:39:16 +01:00
Zbigniew Jędrzejewski-Szmek 943aad8ca5 journal, shared: fix warnings during compilation on 32 bits
Some filesystem magics are too big to fit in 31 bits,
and are wrapped to negative. f_type is an int on 32 bits, so
it is signed, and we get a warning on comparison.
2012-11-16 23:26:44 +01:00
Lennart Poettering d4205751d4 journal: implement message catalog
The message catalog can be used to attach short help texts to log lines,
keyed by their MESSAGE_ID= fields. This is useful to help the
administrator understand the context and cause of a message, find
possible solutions and find further related documentation.

Since this is keyed off MESSAGE_ID= this will only work for native
journal messages.

The message catalog supports i18n, and is useful to augment english
language system messages with explanations in the local language.

This commit only includes short explanatory messages for a few example
message IDs, we'll add more complete documentation for the relevant
systemd messages later on.
2012-11-15 23:09:07 +01:00
Lennart Poettering 85210bffd8 journal: provide an API that allows client to figure out whether they need to recheck the journal manually for changes in regular intervals
Network file systems generally do not offer inotify() that would work
across the network. We hence cannot rely on inotify() exclusiely in
those case. Provide an API to determine these cases, and suggest doing
manual regular rechecks.

Note that this is not complete yet, as we need to rescan journal dirs on
network file systems explicitly to find new/removed files
2012-10-26 20:07:33 +02:00
Lennart Poettering 0f91dd8749 journal: properly determine cutoff max date 2012-10-26 01:18:41 +02:00
Lennart Poettering bdc02927f7 journal: typo fix 2012-10-18 22:36:50 +02:00
Lennart Poettering d5c4ed623b journal: validate field name in sd_journal_query_unique() 2012-10-18 22:34:42 +02:00
Zbigniew Jędrzejewski-Szmek 115646c789 libsystemd-journal: export sd_journal_restart_unique 2012-10-18 19:18:20 +00:00
Lennart Poettering 3c1668da62 journal: add ability to list values a specified field can take in all entries of the journal
The new 'unique' API allows listing all unique field values that a field
specified by a field name can take in all entries of the journal. This
allows answering queries such as "What units logged to the journal?",
"What hosts have logged into the journal?", "Which boot IDs have logged
into the journal?".

Ultimately this allows implementation of tools similar to lastlog based
on journal data.

Note that listing these field values will not work for journal files
created with older journald, as the field values are not indexed in
older files.
2012-10-18 03:35:18 +02:00
Lennart Poettering 5e6870eab5 journalctl: properly track rotated journals in follow mode 2012-10-16 23:00:04 +02:00
Lennart Poettering 44a5fa34d9 sd-journal: fix bad memory access 2012-10-16 22:59:28 +02:00
Lennart Poettering c6511e859c journal: when browsing the journal via browse.html allow clicking on entries to show their details 2012-10-10 22:41:03 +02:00
Lennart Poettering 934a316cbf journal: drop path name from cursor strings
we had this mostly for debugging purposes and it was ignored when
parsing anyway, so let's get rid of it
2012-10-10 22:41:02 +02:00
Lennart Poettering a87247dd5d journal: make sure sd_journal_seek_cursor() seeks to the specified entry if it exists, not one after it 2012-10-10 01:34:27 +02:00
Lennart Poettering be3ea5eaf2 sd-journal: properly parse cursor strings 2012-09-28 00:55:24 +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 468b21de7c journal: when comparing two entries from separate files make sure we reposition the mmap window
The mmap cache doesn't guarantee that we can look at two files at the
same time. Hence make sure to look at the entries to compare one
after the other, instead of at the same time when comparing them, and
reposition the window in between.
2012-09-19 09:58:34 +02:00
Lennart Poettering a1a03e3075 journal: add call to determine current journal file disk usage 2012-09-07 23:20:28 +02:00
Lukas Nykryn f284860764 sd-journal: return null when mmap_cache_new fails 2012-08-23 13:53:30 +02:00
Lennart Poettering 84168d8068 mmap: resize arrays dynamically 2012-08-18 01:46:20 +02:00
Lennart Poettering 16e9f408fa journal: implement generic sharable mmap caching logic
instead of having one simple per-file cache implement an more
comprehensive one that works for multiple files and can actually
maintain multiple maps per file and per object type.
2012-08-16 17:10:56 +02:00
Lennart Poettering 7560fffcd2 journald: initial version of FSPRG hookup
This adds forward-secure authentication of journal files. This patch
includes key generation as well as tagging of journal files,
Verification of journal files will be added in a later patch.
2012-08-13 20:31:10 +02:00
Lennart Poettering de2c390731 journalctl: include corrupted files in output
If a journal file was rotated away because it was corrupted or dirty we
should still show its contents via "journalctl".
2012-08-07 00:51:17 +02:00
Lennart Poettering 4a842cadb8 journal: allow watching symlinked journal dirs 2012-07-19 03:22:07 +02:00
Lennart Poettering 7827b1a10f journal: when watching directories actually watch the directories asked for 2012-07-19 03:21:49 +02:00
Lennart Poettering 6f5878a286 journal: follow symlinks when enumerating journals 2012-07-19 02:35:17 +02:00
Lennart Poettering 9f8d29834b journald: don't choke on journal files with no cutoff date 2012-07-19 02:03:22 +02:00
Lennart Poettering 4a92baf3fa journal: size journal data hash table based on maximum file size metrics
The default of 2047 hash table entries turned out to result in way too
many collisions for bigger files, hence scale the hash table size by the
estimated maximum file size.
2012-07-17 00:59:03 +02:00
Lennart Poettering dca6219e04 journal: automatically rotate journal files if the data hash table is full > 75%
Previously, when the main data hash table grows too full the performance
simply started to decrease drastically. Instead, now simply rotate to a
new journal file as the hash table gets to full, so that we can start
with a new fresh empty hash table.
2012-07-17 00:59:03 +02:00