Commit graph

51 commits

Author SHA1 Message Date
Lennart Poettering 760877e90c util: split out sorting related calls to new sort-util.[ch] 2019-03-13 12:16:43 +01:00
Lennart Poettering 180e7f4e62 journal: fix some type confusion in journal_directory_vacuum()
Let's store array sizes and indexes in size_t. And let's count numbers
of files in uint64_t (simply because that is the type of the input
parameter for this of the function)
2018-10-25 21:43:09 +02:00
Lennart Poettering ab41da087d journald: use structured initialization 2018-10-25 21:42:05 +02:00
Lennart Poettering 6761e0a2fd journald: use usec_sub_unsigned() where we can 2018-10-25 21:42:05 +02:00
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Lennart Poettering 47c073aa82 coredump,journal: when vacuuming use new unlinkat_deallocate() calls
This ensures that clients can't keep all files pinned interfering with
our vacuuming logic.

This should fix the last issue pointed out in #7998 and #8032

Fixes: #7998
2018-02-12 11:27:11 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering 3cc44bf91b journalctl: say in which directory we vacuum stuff
Fixes: #4060
2016-10-12 20:25:20 +02: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
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
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 89a5a90cb0 util-lib: split xattr-related calls into xattr-util.[ch] 2015-10-27 13:25:56 +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 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +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 3741b696f4 journal: fix bad memory freeing 2015-10-19 23:07:18 +02: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
Lennart Poettering 7b5195e274 journal: don't affect atime of journal files when vacuuming
Let's try to use O_NOATIME if we can when vacuuming old journal files,
if we have the permissions for it, so that vacuuming doesn't count as
proper journal read access.
2015-10-02 22:39:24 +02:00
Lennart Poettering 2e14c544a9 journal: port over to fd_getcrtime_at()
Let's use fd_getcrtime_at(), since that *at() family of calls is how we
read the rest of the file metadata, too.
2015-10-02 22:31:35 +02:00
Daniel Mack 45d9a30414 tree-wide: do not use _cleanup_free_ on const pointers
free() cannot be used with const pointers. However, our _cleanup_free_
handler features cast logic that hides that qualifier, so we don't get a
warning.
2015-07-24 13:52:30 +02:00
Harald Hoyer a7f7d1bde4 fix gcc warnings about uninitialized variables
like:

src/shared/install.c: In function ‘unit_file_lookup_state’:
src/shared/install.c:1861:16: warning: ‘r’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
         return r < 0 ? r : state;
                ^
src/shared/install.c:1796:13: note: ‘r’ was declared here
         int r;
             ^
2015-03-27 14:57:38 +01: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 4a4d89b682 util: make creation time xattr logic more generic 2014-12-24 16:53:04 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Lennart Poettering 26d8ff0491 journald: fix memory leak on error path 2014-11-03 23:10:34 +01:00
Lennart Poettering 332076b45b journald: also check journal file size to deduce if it is empty 2014-11-03 23:10:21 +01:00
Lennart Poettering dbd2a83fbf journalctl: add new --vacuum-size= and --vacuum-time= commands to clean up journal files based on a size/time limit
This is equivalent to the effect of SystemMaxUse= and RetentionSec=,
however can be invoked directly instead of implicitly.
2014-11-03 23:08:33 +01:00
Kay Sievers 3a43da2832 time-util: add and use USEC/NSEC_INFINIY 2014-07-29 13:20:20 +02:00
Lennart Poettering 168562d7ed journald: invoking fstatvfs() is now redundant in the vacuuming code 2014-06-27 19:35:57 +02:00
Kay Sievers d2edfae0f9 build-sys: use glibc's xattr support instead of requiring libattr 2014-05-28 17:36:40 +08:00
Lennart Poettering 3bb621e1e6 journal: downgrade vaccuum message to debug level
https://bugzilla.redhat.com/show_bug.cgi?id=1047148
2014-02-23 17:05:37 +01:00
Zbigniew Jędrzejewski-Szmek 348ced9097 journald: do not free space when disk space runs low
Before, journald would remove journal files until both MaxUse= and
KeepFree= settings would be satisfied. The first one depends (if set
automatically) on the size of the file system and is constant.  But
the second one depends on current use of the file system, and a spike
in disk usage would cause journald to delete journal files, trying to
reach usage which would leave 15% of the disk free. This behaviour is
surprising for the user who doesn't expect his logs to be purged when
disk usage goes above 85%, which on a large disk could be some
gigabytes from being full. In addition attempting to keep 15% free
provides an attack vector where filling the disk sufficiently disposes
of almost all logs.

Instead, obey KeepFree= only as a limit on adding additional files.
When replacing old files with new, ignore KeepFree=. This means that
if journal disk usage reached some high point that at some later point
start to violate the KeepFree= constraint, journald will not add files
to go above this point, but it will stay (slightly) below it. When
journald is restarted, it forgets the previous maximum usage value,
and sets the limit based on the current usage, so if disk remains to
be filled, journald might use one journal-file-size less on each
restart, if restarts happen just after rotation. This seems like a
reasonable compromise between implementation complexity and robustness.
2014-01-11 16:54:59 -05:00
Florian Weimer 78a5d04dd6 journal/vacuum: replace readdir_r with readdir 2013-12-21 18:35:55 -05:00
Zbigniew Jędrzejewski-Szmek 7ff7394d9e Never call qsort on potentially NULL arrays
This extends 62678ded 'efi: never call qsort on potentially
NULL arrays' to all other places where qsort is used and it
is not obvious that the count is non-zero.
2013-10-13 17:56:54 -04:00
Lennart Poettering 2ee0591d12 journald: fix minor memory leak 2013-10-09 04:08:00 +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
George McCollister 489798614c journald: fix fd leak in journal_file_empty
Before my previous patch, journal_file_empty wasn't be called with the
correct filename. Now that it's being called with the correct filename
it leaks file descriptors. This patch closes the file descriptors before
returning.

Signed-off-by: George McCollister <george.mccollister@gmail.com>

[Edit harald@redhat.com: make use of _cleanup_close_ instead]
2013-09-06 07:11:25 +02:00
George McCollister 629bfc5a7f journald: fix vacuuming of archived journals
d_name is modified on line 227 so if the entire journal name is needed
again p must be used. Before this change when journal_file_empty was called
on archived journals it would always return with -2.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
2013-09-06 07:07:54 +02:00
Zbigniew Jędrzejewski-Szmek 9d64774057 journald: always vacuum empty offline files
Corrupted empty files are relatively common. I think they are created
when a coredump for a user who never logged anything before is
attempted to be written, but the write does not succeed because the
coredump is too big, but there are probably other ways to create
those, especially if the machine crashes at the right time.
Non-corrupted empty files can also happen, e.g. if a journal file is
opened, but nothing is ever successfully written to it and it is
rotated because of MaxFileSec=. Either way, each "empty" journal file
costs around 3 MB, and there's little point in keeping them around.
2013-06-24 21:06:06 -04:00
Zbigniew Jędrzejewski-Szmek 30cb029b8b journal/vacuum: cleanup 2013-06-24 21:06:06 -04:00
Jan Alexander Steffens (heftig) 6c142648aa Fix vacuum logic error
The vacuum code used to stop vacuuming after one deletion, even
when max_use was still exceeded.

Also make usage a uint64_t, as the code already pretends it is one.

Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
2013-03-21 23:24:38 -04:00
Lennart Poettering 4fa25d62bd journal: fix potential integer overflow 2012-10-17 21:25:42 +02: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
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 2b43f939a4 journald: avoid logging to kmsg in the normal paths 2012-09-06 00:32:51 -07:00