Commit Graph

67 Commits

Author SHA1 Message Date
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Lennart Poettering 8ac2f74fb6 tree-wide: make use of fsync_directory_of_file() all over the place
Let's make use this at various places we call fsync(), to make things
fully reliable, as the kernel devs suggest to first fsync() files and
then fsync() the directories they are located in.
2018-02-20 15:39:31 +01:00
Jakub Filak f45b801551 coredump: accept hostname on command line (#8033)
This commint adds a new command line parameter to sytemd-coredump. The
parameter should be mappend to core_pattern's placeholder %h - hostname.

The field _HOSTNAME holds the name from the kernel's namespaces which might be
different then the one comming from process' namespaces.

It is true that the real hostname is usually available in the field
COREDUMP_ENVIRON (environment variables) but I believe it is more reliable to
use the value passed by kernel.

----

The length of iovec is no longer static and hence I corrected the declarations
of the functions set_iovec_field and set_iovec_field_free.

Thank you @yuwata and @poettering!
2018-02-15 12:12:46 +01:00
Lennart Poettering e557b1a655 util: minor tweaks to disable_core_dumps()
First, let's rename it to disable_coredumps(), as in the rest of our
codebase we spell it "coredump" rather than "core_dump", so let's stick
to that.

However, also log about failures to turn off core dumpling on LOG_DEBUG,
because debug logging is always a good idea.
2018-01-10 18:44:09 +01:00
Jan Klötzke 9ce1759311 tree-wide: introduce disable_core_dumps helper and port existing users
Changes the core_pattern to prevent any core dumps by the kernel. Does
nothing if we're in a container environment as this is system wide
setting.
2018-01-10 10:54:40 +01:00
Lennart Poettering 0d53667334 tree-wide: use __fsetlocking() instead of fxyz_unlocked()
Let's replace usage of fputc_unlocked() and friends by __fsetlocking(f,
FSETLOCKING_BYCALLER). This turns off locking for the entire FILE*,
instead of doing individual per-call decision whether to use normal
calls or _unlocked() calls.

This has various benefits:

1. It's easier to read and easier not to forget

2. It's more comprehensive, as fprintf() and friends are covered too
   (as these functions have no _unlocked() counterpart)

3. Philosophically, it's a bit more correct, because it's more a
   property of the file handle really whether we ever pass it on to another
   thread, not of the operations we then apply to it.

This patch reworks all pieces of codes that so far used fxyz_unlocked()
calls to use __fsetlocking() instead. It also reworks all places that
use open_memstream(), i.e. use stdio FILE* for string manipulations.

Note that this in some way a revert of 4b61c87511.
2017-12-14 10:42:25 +01:00
Lennart Poettering 234519ae6d tree-wide: drop a few == NULL and != NULL comparison
Our CODING_STYLE suggests not comparing with NULL, but relying on C's
downgrade-to-bool feature for that. Fix up some code to match these
guidelines. (This is not comprehensive, the coccinelle output for this
is unfortunately kinda borked)
2017-12-11 16:05:40 +01:00
Lennart Poettering 05fd2156b7 journal,coredump: do not do ACL magic for "nobody" user either
The "nobody" user might possibly be seen by the journal or coredumping
code if unmapped userns-using processes are somehow visible to them.
Let's make sure we don't do the ACL magic for this user either, since
this is a special system user that might be backed by different real
users in different contexts.
2017-12-06 13:40:50 +01:00
Lennart Poettering 4e72397b00 coredump,journal: do not do ACL magic for processes of dynamic UIDs
Dynamic UIDs should be treated like system users in this regard.
2017-12-06 13:40:50 +01:00
Lennart Poettering ece877d434 user-util: add new uid_is_system() helper
This adds uid_is_system() and gid_is_system(), similar in style to
uid_is_dynamic(). That a helper like this is useful is illustrated by
the fact that test-condition.c didn't get the check right so far, which
this patch fixes.
2017-12-06 13:40:50 +01:00
Daniel Lockyer 4600a396d5 Remove NULL as last parameter to strjoin 2017-11-24 10:37:08 +00: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 bcde742e78 conf-parser: turn three bool function params into a flags fields
This makes things more readable and fixes some issues with incorrect
flag propagation between the various flavours of config_parse().
2017-11-13 10:24:03 +01:00
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 e6a7ec4b8e io-util: add new IOVEC_INIT/IOVEC_MAKE macros
This adds IOVEC_INIT() and IOVEC_MAKE() for initializing iovec structures
from a pointer and a size. On top of these IOVEC_INIT_STRING() and
IOVEC_MAKE_STRING() are added which take a string and automatically
determine the size of the string using strlen().

This patch removes the old IOVEC_SET_STRING() macro, given that
IOVEC_MAKE_STRING() is now useful for similar purposes. Note that the
old IOVEC_SET_STRING() invocations were two characters shorter than the
new ones using IOVEC_MAKE_STRING(), but I think the new syntax is more
readable and more generic as it simply resolves to a C99 literal
structure initialization. Moreover, we can use very similar syntax now
for initializing strings and pointer+size iovec entries. We canalso use
the new macros to initialize function parameters on-the-fly or array
definitions. And given that we shouldn't have so many ways to do the
same stuff, let's just settle on the new macros.

(This also converts some code to use _cleanup_ where dynamically
allocated strings were using IOVEC_SET_STRING() before, to modernize
things a bit)
2017-09-22 15:28:04 +02:00
Lennart Poettering 4b61c87511 tree-wide: fput[cs]() → fput[cs]_unlocked() wherever that makes sense (#6396)
As a follow-up for db3f45e2d2 let's do the
same for all other cases where we create a FILE* with local scope and
know that no other threads hence can have access to it.

For most cases this shouldn't change much really, but this should speed
dbus introspection and calender time formatting up a bit.
2017-07-21 10:35:45 +02:00
Djalal Harouni 74e941c022 Merge pull request #5774 from keszybz/printf-annotations
Printf annotation improvements
2017-04-23 01:03:42 +02:00
Zbigniew Jędrzejewski-Szmek ae2173d66b coredump: fix non-literal string used in printf
This was exposed by the previous commit. This could be potentially
unpleasant, but we are saved by the fact that this code path was only
taken for journald crashes, where we control COMM and know that it doesn't
contain any special characters. Use log_dispatch which does not do any
format processing to push the message out.
2017-04-21 13:39:50 -04:00
Yu Watanabe da4128543f tree-wide: fix wrong indent (#5757)
Fixes wrong indent introduced by the commit 43688c49d1.
2017-04-19 08:48:29 +02:00
Zbigniew Jędrzejewski-Szmek d74dc4f2d0 coredump: fix handling of premature-eof data for --backtrace
We'd fail with an assert in journal_importer_process_data(),
because that function requires the caller to handle EOF themselves.
2017-03-05 10:35:44 -05:00
Lennart Poettering b8cda92df5 coredump: introduce is_journald_crash() and is_pid1_crash() helpers
We check these a number of times, hence let's unify these checks here.
This also allows us to make the PID 1 check more elaborate as we can
check both the PID and the cgroup. Checking the PID has the benefit that
we'll also cover cases where PID 1 might still be in the root cgroup, and
the cgroup check has the benefit that we also cover crashes in forked
off crasher processes (the way we actually do it in systemd)
2017-03-01 18:13:00 +01:00
Lennart Poettering 32a1575fbd coredump: normalize generation/parsing of COREDUMP_TRUNCATED=
Given that this is a field primarily processed by computers, and not so
much by humans, assign "1" instead of "yes". Also, use parse_boolean()
as we usually do for parsing it again.

This makes things more alike udev options (as one example), such as
SYSTEMD_READY where we also spit out "1" and "0", and parse with
parse_boolean().
2017-03-01 18:13:00 +01:00
Zbigniew Jędrzejewski-Szmek 92e92d71fa coredump: process special crashes in an (almost) normal way
We would only log a terse message when pid1 or systemd-journald crashed.
It seems better to reuse the normal code paths as much as possible,
with the following differences:
- if pid1 crashes, we cannot launch the helper, so we don't analyze the
 coredump, just write it to file directly from the helper invoked by the
 kernel;
- if journald crashes, we can produce the backtrace, but we don't log full
  structured messages.

With comparison to previous code, advantages are:
- we go through most of the steps, so for example vacuuming is performed,
- we gather and log more data. In particular for journald and pid1 crashes we
  generate a backtrace, and for pid1 crashes we record the metadata (fdinfo,
  maps, etc.),
- coredumpctl shows pid1 crashes.

A disavantage (inefficiency) is that we gather metadata for journald crashes
which is then ignored because _TRANSPORT=kernel does not support structued
messages.

Messages for the systemd-journald "crash" have _TRANSPORT=kernel, and
_TRANSPORT=journal for the pid1 "crash".

Feb 26 16:27:55 systemd[1]: systemd-journald.service: Main process exited, code=dumped, status=11/SEGV
Feb 26 16:27:55 systemd[1]: systemd-journald.service: Unit entered failed state.
Feb 26 16:37:54 systemd-coredump[18801]: Process 18729 (systemd-journal) of user 0 dumped core.
Feb 26 16:37:54 systemd-coredump[18801]: Coredump diverted to /var/lib/systemd/coredump/core.systemd-journal.0.36c14bf3c6ce4c38914f441038990979.18729.1488145074000000.lz4
Feb 26 16:37:54 systemd-coredump[18801]: Stack trace of thread 18729:
Feb 26 16:37:54 systemd-coredump[18801]: #0  0x00007f46d6a06b8d fsync (libpthread.so.0)
Feb 26 16:37:54 systemd-coredump[18801]: #1  0x00007f46d71bfc47 journal_file_set_online (libsystemd-shared-233.so)
Feb 26 16:37:54 systemd-coredump[18801]: #2  0x00007f46d71c1c31 journal_file_append_object (libsystemd-shared-233.so)
Feb 26 16:37:54 systemd-coredump[18801]: #3  0x00007f46d71c3405 journal_file_append_data (libsystemd-shared-233.so)
Feb 26 16:37:54 systemd-coredump[18801]: #4  0x00007f46d71c4b7c journal_file_append_entry (libsystemd-shared-233.so)
Feb 26 16:37:54 systemd-coredump[18801]: #5  0x00005577688cf056 write_to_journal (systemd-journald)
Feb 26 16:37:54 systemd-coredump[18801]: #6  0x00005577688d2e98 dispatch_message_real (systemd-journald)
Feb 26 16:37:54 kernel: systemd-coredum: 9 output lines suppressed due to ratelimiting
Feb 26 16:37:54 systemd-journald[18810]: Journal started

Feb 26 16:50:59 systemd-coredump[19229]: Due to PID 1 having crashed coredump collection will now be turned off.
Feb 26 16:51:00 systemd[1]: Caught <SEGV>, dumped core as pid 19228.
Feb 26 16:51:00 systemd[1]: Freezing execution.
Feb 26 16:51:00 systemd-coredump[19229]: Process 19228 (systemd) of user 0 dumped core.

                                         Stack trace of thread 19228:
                                         #0  0x00007fab82075c47 kill (libc.so.6)
                                         #1  0x000055fdf7c38b6b crash (systemd)
                                         #2  0x00007fab824175c0 __restore_rt (libpthread.so.0)
                                         #3  0x00007fab82148573 epoll_wait (libc.so.6)
                                         #4  0x00007fab8366f84a sd_event_wait (libsystemd-shared-233.so)
                                         #5  0x00007fab836701de sd_event_run (libsystemd-shared-233.so)
                                         #6  0x000055fdf7c4a380 manager_loop (systemd)
                                         #7  0x000055fdf7c402c2 main (systemd)
                                         #8  0x00007fab82060401 __libc_start_main (libc.so.6)
                                         #9  0x000055fdf7c3818a _start (systemd)

Poor machine ;)
2017-02-28 21:33:52 -05:00
Zbigniew Jędrzejewski-Szmek cc4419ed92 coredumpctl,man: mark truncated messages as such in output
Unit systemd-coredump@1-3854-0.service is failed/failed, not counting it.
TIME                            PID   UID   GID SIG COREFILE  EXE
Fri 2017-02-24 11:11:00 EST   10002  1000  1000   6 none      /home/zbyszek/src/systemd-work/.libs/lt-Sat 2017-02-25 00:49:32 EST   26921     0     0  11 error     /usr/libexec/fprintd
Sat 2017-02-25 11:56:30 EST   30703  1000  1000   - -         /usr/bin/python3.5
Sat 2017-02-25 13:16:54 EST    3275  1000  1000  11 present   /usr/bin/bash
Sat 2017-02-25 17:25:40 EST    4049  1000  1000  11 truncated /usr/bin/bash

For info and gdb output, the filename is marked in red and "(truncated)" is
appended. (Red is necessary because the annotation is hard to see when running
under a pager.)

Fixed #3883.
2017-02-26 19:45:10 -05:00
Zbigniew Jędrzejewski-Szmek 0cd4e913da coredump: when storing an incomplete coredump, add COREDUMP_TRUNCATED=yes
We logged about this, but did not attach information directly to the log
entry. It *would* be nice to log the full untruncated size, but afaict, to do
this, we would have to read the full data from the kernel. Doing this just to
log that information seems a bit excessive, in particular when the limit could
be set quite low. So for now let's just add a boolean field.
2017-02-26 19:45:10 -05:00
Zbigniew Jędrzejewski-Szmek ea5cc2a8f6 coredump: do not try to access unitialized CONTEXT_COMM field
Most of the fields in the context array come from the kernel (passed
through argv), but two are special: comm and exe. We allocate them
ourselves. We forgot to initialize context[CONTEXT_COMM] with the value
we allocated (introduced in 9aa8202314).
To simplify things, just set context[CONTEXT_COMM] and context[CONTEXT_EXE],
and free those two fields at the end.

Fixes #5442.
2017-02-26 19:45:07 -05:00
Zbigniew Jędrzejewski-Szmek a6a73a10e8 coredump: slight simplification 2017-02-25 11:49:29 -05:00
Zbigniew Jędrzejewski-Szmek 52d1f5e569 Merge pull request #5373 from poettering/coredump-timestamp-fixes
various coredump fixes
2017-02-17 15:23:52 -05:00
Lennart Poettering 6d337300f2 coredump: store the full coredump kernel context in xattrs on the coredump file
We didn't include the resource limit field, add it.
2017-02-17 11:35:31 +01:00
Lennart Poettering 80002f6640 coredump: when reconstructing original kernel coredump context, chop off trailing zeroes
Our coredump handler operates on a "context" supplied by the kernel via
the core_pattern arguments. When we pass off a coredump for processing
to coredumpd we pass along enough information for this context to be
reconstructed. This information is passed in the usual journal fields,
and that means we extended the 1s granularity timestamp to 1µs
granularity by appending 6 zeroes. We need to chop them off again when
reconstructing the original kernel context.

Fixes: #4779
2017-02-17 11:35:19 +01:00
Lennart Poettering d14bcb4ea7 coredump: include signal name in journal metadata
(Note that we only do this for the journal metadata, not for the xattrs,
as the xattrs are only supposed to store the original 1:1 info we
acquired from the kernel.)
2017-02-17 11:18:18 +01:00
Lennart Poettering 86562420ff coredump: fix handling of special crashes
When we encounter a "special" crash we should not continue processing it
the usual way.
2017-02-17 10:59:21 +01:00
Lennart Poettering 1c876927e4 copy: change the various copy_xyz() calls to take a unified flags parameter
This adds a unified "copy_flags" parameter to all copy_xyz() function
calls, replacing the various boolean flags so far used. This should make
many invocations more readable as it is clear what behaviour is
precisely requested. This also prepares ground for adding support for
more modes later on.
2017-02-17 10:22:28 +01:00
Zbigniew Jędrzejewski-Szmek 561eede4d1 coredump: add note about lack of rollback on oom 2017-02-15 00:45:43 -05: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
Zbigniew Jędrzejewski-Szmek 5b45a16067 coredump: with --backtrace accept a journal entry on stdin
The entry must be a single entry in the journal export format, including the
terminating double newline. The MESSAGE field is now generated on the sender
side.

The advantage is that the reporter can easily pass additional metadata.
Continuing with the example of the python excepthook:

COREDUMP_PYTHON_EXECUTABLE=/usr/bin/python3
COREDUMP_PYTHON_VERSION=3.5.2 (default, Sep 14 2016, 11:28:32)
                        [GCC 6.2.1 20160901 (Red Hat 6.2.1-1)]
COREDUMP_PYTHON_THREAD_INFO=sys.thread_info(name='pthread', lock='semaphore', version='NPTL 2.24')
COREDUMP_PYTHON_EXCEPTION_TYPE=ZeroDivisionError
COREDUMP_PYTHON_EXCEPTION_VALUE=division by zero
MESSAGE=Process 29514 (systemd_coredump_exception_handler.py) of user zbyszek failed with ZeroDivisionError: division by zero

        Traceback (most recent call last):
          File "systemd_coredump_exception_handler.py", line 134, in <module>
            g()
          File "systemd_coredump_exception_handler.py", line 133, in g
            f()
          File "systemd_coredump_exception_handler.py", line 131, in f
            div0 = 1 / 0
        ZeroDivisionError: division by zero

        Local variables in innermost frame:
          a=3
          h=<function f at 0x7efdc14b6ea0>

One consideration is whether to use the Journal Export Format, or send packets
over a UNIX socket instead. The advantage of current solution is that although
parsing is more complicated on the receiver side, it is much easier to use on the
sender side. I hope this can be used by various languages for which writing
binary structures to a UNIX socket is harder and more likely to be done wrong
than piping of a simple textyish format.
2017-02-15 00:31:55 -05:00
Zbigniew Jędrzejewski-Szmek b18453eda6 Move export format parsing from src/journal-remote/ to src/basic/
No functional change.
2017-02-14 23:56:48 -05:00
Zbigniew Jędrzejewski-Szmek 988e89ee3b coredump: implement logging of external backtraces with --backtrace
This is useful for example for Python progams. By installing a python
sys.execepthook we can store the backtrace in the journal. We gather the
backtrace in the python process, and call systemd-coredump to attach additional
fields (COREDUMP_COMM, COREDUMP_EXE, COREDUMP_UNIT, COREDUMP_USER_UNIT,
COREDUMP_OWNER_UID, COREDUMP_SLICE, COREDUMP_CMDLINE, COREDUMP_CGROUP,
COREDUMP_OPEN_FDS, COREDUMP_PROC_STATUS, COREDUMP_PROC_MAPS,
COREDUMP_PROC_LIMITS, COREDUMP_PROC_MOUNTINFO, COREDUMP_CWD, COREDUMP_ROOT,
COREDUMP_ENVIRON, COREDUMP_CONTAINER_CMDLINE). This could also be done in the
python process, but doing this in systemd-coredump saves quite a bit of
duplicate work and unifies the handling of various tricky fields like
COREDUMP_CONTAINER_CMDLINE in one place.

(Of course this applies to any other language which does not dump cores
but wants to log a traceback, e.g. ruby.)

journal entry:
    _TRANSPORT=journal
    _UID=1002
    _GID=1002
    _CAP_EFFECTIVE=0
    _AUDIT_LOGINUID=1002
    _SYSTEMD_OWNER_UID=1002
    _SYSTEMD_SLICE=user-1002.slice
    _SYSTEMD_USER_SLICE=-.slice
    _SELINUX_CONTEXT=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
    _BOOT_ID=1531fd22ec84429e85ae888b12fadb91
    _MACHINE_ID=519a16632fbd4c71966ce9305b360c9c
    _HOSTNAME=laptop
    _AUDIT_SESSION=1
    _SYSTEMD_UNIT=user@1002.service
    _SYSTEMD_INVOCATION_ID=3c4238d790a44aca9576ecdb2c7576d3
    COREDUMP_UNIT=user@1002.service
    COREDUMP_USER_UNIT=gnome-terminal-server.service
    COREDUMP_UID=1002
    COREDUMP_GID=1002
    COREDUMP_OWNER_UID=1002
    COREDUMP_SLICE=user-1002.slice
    COREDUMP_CGROUP=/user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service
    COREDUMP_PROC_LIMITS=Limit                     Soft Limit           Hard Limit           Units
                         Max cpu time              unlimited            unlimited            seconds
                         Max file size             unlimited            unlimited            bytes
                         Max data size             unlimited            unlimited            bytes
                         Max stack size            8388608              unlimited            bytes
                         Max core file size        unlimited            unlimited            bytes
                         Max resident set          unlimited            unlimited            bytes
                         Max processes             15413                15413                processes
                         Max open files            4096                 4096                 files
                         Max locked memory         65536                65536                bytes
                         Max address space         unlimited            unlimited            bytes
                         Max file locks            unlimited            unlimited            locks
                         Max pending signals       15413                15413                signals
                         Max msgqueue size         819200               819200               bytes
                         Max nice priority         0                    0
                         Max realtime priority     0                    0
                         Max realtime timeout      unlimited            unlimited            us
    COREDUMP_PROC_CGROUP=1:name=systemd:/
                         0::/user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service
    COREDUMP_PROC_MOUNTINFO=17 39 0:17 / /sys rw,nosuid,nodev,noexec,relatime shared:6 - sysfs sysfs rw,seclabel
                            18 39 0:4 / /proc rw,nosuid,nodev,noexec,relatime shared:5 - proc proc rw
                            19 39 0:6 / /dev rw,nosuid shared:2 - devtmpfs devtmpfs rw,seclabel,size=1972980k,nr_inodes=493245,mode=755
                            20 17 0:18 / /sys/kernel/security rw,nosuid,nodev,noexec,relatime shared:7 - securityfs securityfs rw
                            21 19 0:19 / /dev/shm rw,nosuid,nodev shared:3 - tmpfs tmpfs rw,seclabel
                            22 19 0:20 / /dev/pts rw,nosuid,noexec,relatime shared:4 - devpts devpts rw,seclabel,gid=5,mode=620,ptmxmode=000
                            23 39 0:21 / /run rw,nosuid,nodev shared:12 - tmpfs tmpfs rw,seclabel,mode=755
                            24 17 0:22 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime shared:8 - cgroup2 cgroup rw
                            25 17 0:23 / /sys/fs/pstore rw,nosuid,nodev,noexec,relatime shared:9 - pstore pstore rw,seclabel
                            36 17 0:24 / /sys/kernel/config rw,relatime shared:10 - configfs configfs rw
                            39 0 0:26 /root / rw,relatime shared:1 - btrfs /dev/mapper/fedora-root2 rw,seclabel,ssd,space_cache,subvolid=257,subvol=/root
                            26 17 0:16 / /sys/fs/selinux rw,relatime shared:11 - selinuxfs selinuxfs rw
                            27 19 0:15 / /dev/mqueue rw,relatime shared:13 - mqueue mqueue rw,seclabel
                            28 18 0:30 / /proc/sys/fs/binfmt_misc rw,relatime shared:14 - autofs systemd-1 rw,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13663
                            29 17 0:7 / /sys/kernel/debug rw,relatime shared:15 - debugfs debugfs rw,seclabel
                            30 19 0:31 / /dev/hugepages rw,relatime shared:16 - hugetlbfs hugetlbfs rw,seclabel
                            31 18 0:32 / /proc/fs/nfsd rw,relatime shared:17 - nfsd nfsd rw
                            32 28 0:33 / /proc/sys/fs/binfmt_misc rw,relatime shared:18 - binfmt_misc binfmt_misc rw
                            57 39 0:34 / /tmp rw,relatime shared:19 - tmpfs none rw,seclabel
                            61 57 0:35 / /tmp/test rw,relatime shared:20 - autofs systemd-1 rw,fd=48,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18251
                            59 39 8:1 / /boot rw,relatime shared:21 - ext4 /dev/sda1 rw,seclabel,data=ordered
                            60 39 253:2 / /home rw,relatime shared:22 - ext4 /dev/mapper/fedora-home rw,seclabel,data=ordered
                            65 39 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime shared:23 - rpc_pipefs sunrpc rw
                            136 23 0:39 / /run/user/1002 rw,nosuid,nodev,relatime shared:91 - tmpfs tmpfs rw,seclabel,size=397432k,mode=700,uid=1002,gid=1002
                            211 23 0:41 / /run/user/42 rw,nosuid,nodev,relatime shared:163 - tmpfs tmpfs rw,seclabel,size=397432k,mode=700,uid=42,gid=42
                            329 136 0:44 / /run/user/1002/gvfs rw,nosuid,nodev,relatime shared:277 - fuse.gvfsd-fuse gvfsd-fuse rw,user_id=1002,group_id=1002
                            287 61 253:3 / /tmp/test rw,relatime shared:236 - ext4 /dev/mapper/fedora-test rw,seclabel,data=ordered
                            217 23 0:42 / /run/user/1000 rw,nosuid,nodev,relatime shared:168 - tmpfs tmpfs rw,seclabel,size=397432k,mode=700,uid=1000,gid=1000
                            225 217 0:43 / /run/user/1000/gvfs rw,nosuid,nodev,relatime shared:175 - fuse.gvfsd-fuse gvfsd-fuse rw,user_id=1000,group_id=1000
    COREDUMP_ROOT=/
    PRIORITY=2
    CODE_FILE=src/coredump/coredump.c
    SYSLOG_IDENTIFIER=lt-systemd-coredump
    _COMM=lt-systemd-core
    _SYSTEMD_CGROUP=/user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service
    _SYSTEMD_USER_UNIT=gnome-terminal-server.service
    MESSAGE_ID=1f4e0a44a88649939aaea34fc6da8c95
    CODE_FUNC=process_traceback
    COREDUMP_COMM=python3
    COREDUMP_EXE=/usr/bin/python3.5
    COREDUMP_CMDLINE=python3 systemd_coredump_exception_handler.py
    COREDUMP_CWD=/home/zbyszek/src/systemd-coredump-python
    COREDUMP_RLIMIT=-1
    COREDUMP_OPEN_FDS=0:/dev/pts/1
                      pos:	0
                      flags:	0102002
                      mnt_id:	22

                      1:/dev/pts/1
                      pos:	0
                      flags:	0102002
                      mnt_id:	22

                      2:/dev/pts/1
                      pos:	0
                      flags:	0102002
                      mnt_id:	22
    CODE_LINE=1284
    COREDUMP_SIGNAL=ZeroDivisionError: division by zero
    COREDUMP_ENVIRON=LANG=en_US.utf8
                     DISPLAY=:0
                     ...
                     MANWIDTH=90
                     LC_MESSAGES=en_US.utf8
                     PYTHONPATH=.
                     _=/usr/bin/python3
    COREDUMP_PID=14498
    COREDUMP_PROC_STATUS=Name:	python3
                         Umask:	0002
                         State:	S (sleeping)
                         Tgid:	14498
                         Ngid:	0
                         Pid:	14498
                         PPid:	16245
                         TracerPid:	0
                         Uid:	1002	1002	1002	1002
                         Gid:	1002	1002	1002	1002
                         FDSize:	64
                         Groups:
                         NStgid:	14498
                         NSpid:	14498
                         NSpgid:	14498
                         NSsid:	16245
                         VmPeak:	   34840 kB
                         VmSize:	   34792 kB
                         VmLck:	       0 kB
                         VmPin:	       0 kB
                         VmHWM:	    9332 kB
                         VmRSS:	    9332 kB
                         RssAnon:	    4872 kB
                         RssFile:	    4460 kB
                         RssShmem:	       0 kB
                         VmData:	    5012 kB
                         VmStk:	     136 kB
                         VmExe:	       4 kB
                         VmLib:	    5452 kB
                         VmPTE:	      84 kB
                         VmPMD:	      12 kB
                         VmSwap:	       0 kB
                         HugetlbPages:	       0 kB
                         Threads:	1
                         SigQ:	0/15413
                         SigPnd:	0000000000000000
                         ShdPnd:	0000000000000000
                         SigBlk:	0000000000000000
                         SigIgn:	0000000001001000
                         SigCgt:	0000000180000002
                         CapInh:	0000000000000000
                         CapPrm:	0000000000000000
                         CapEff:	0000000000000000
                         CapBnd:	0000003fffffffff
                         CapAmb:	0000000000000000
                         Seccomp:	0
                         Cpus_allowed:	f
                         Cpus_allowed_list:	0-3
                         Mems_allowed:	00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
                         Mems_allowed_list:	0
                         voluntary_ctxt_switches:	2
                         nonvoluntary_ctxt_switches:	47
    COREDUMP_PROC_MAPS=55cb7b7fe000-55cb7b7ff000 r-xp 00000000 00:1a 5289186                    /usr/bin/python3.5
                       55cb7b9ff000-55cb7ba00000 r--p 00001000 00:1a 5289186                    /usr/bin/python3.5
                       55cb7ba00000-55cb7ba01000 rw-p 00002000 00:1a 5289186                    /usr/bin/python3.5
                       55cb7c007000-55cb7c189000 rw-p 00000000 00:00 0                          [heap]
                       7f4da2d51000-7f4da2d54000 r-xp 00000000 00:1a 5279150                    /usr/lib64/python3.5/lib-dynload/resource.cpython-35m-x86_64-linux-gnu.so
                       7f4da2d54000-7f4da2f53000 ---p 00003000 00:1a 5279150                    /usr/lib64/python3.5/lib-dynload/resource.cpython-35m-x86_64-linux-gnu.so
                       7f4da2f53000-7f4da2f54000 r--p 00002000 00:1a 5279150                    /usr/lib64/python3.5/lib-dynload/resource.cpython-35m-x86_64-linux-gnu.so
                       7f4da2f54000-7f4da2f55000 rw-p 00003000 00:1a 5279150                    /usr/lib64/python3.5/lib-dynload/resource.cpython-35m-x86_64-linux-gnu.so
                       7f4da2f55000-7f4da2f5d000 r-xp 00000000 00:1a 5279143                    /usr/lib64/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
                       7f4da2f5d000-7f4da315c000 ---p 00008000 00:1a 5279143                    /usr/lib64/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
                       7f4da315c000-7f4da315d000 r--p 00007000 00:1a 5279143                    /usr/lib64/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
                       7f4da315d000-7f4da315f000 rw-p 00008000 00:1a 5279143                    /usr/lib64/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
                       7f4da315f000-7f4da319f000 rw-p 00000000 00:00 0
                       7f4da319f000-7f4da31a4000 r-xp 00000000 00:1a 5279151                    /usr/lib64/python3.5/lib-dynload/select.cpython-35m-x86_64-linux-gnu.so
                       7f4da31a4000-7f4da33a3000 ---p 00005000 00:1a 5279151                    /usr/lib64/python3.5/lib-dynload/select.cpython-35m-x86_64-linux-gnu.so
                       7f4da33a3000-7f4da33a4000 r--p 00004000 00:1a 5279151                    /usr/lib64/python3.5/lib-dynload/select.cpython-35m-x86_64-linux-gnu.so
                       7f4da33a4000-7f4da33a6000 rw-p 00005000 00:1a 5279151                    /usr/lib64/python3.5/lib-dynload/select.cpython-35m-x86_64-linux-gnu.so
                       7f4da33a6000-7f4da33a9000 r-xp 00000000 00:1a 5279130                    /usr/lib64/python3.5/lib-dynload/_posixsubprocess.cpython-35m-x86_64-linux-gnu.so
                       7f4da33a9000-7f4da35a8000 ---p 00003000 00:1a 5279130                    /usr/lib64/python3.5/lib-dynload/_posixsubprocess.cpython-35m-x86_64-linux-gnu.so
                       7f4da35a8000-7f4da35a9000 r--p 00002000 00:1a 5279130                    /usr/lib64/python3.5/lib-dynload/_posixsubprocess.cpython-35m-x86_64-linux-gnu.so
                       7f4da35a9000-7f4da35aa000 rw-p 00003000 00:1a 5279130                    /usr/lib64/python3.5/lib-dynload/_posixsubprocess.cpython-35m-x86_64-linux-gnu.so
                       7f4da35aa000-7f4da362a000 rw-p 00000000 00:00 0
                       7f4da362a000-7f4da362c000 r-xp 00000000 00:1a 5279122                    /usr/lib64/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
                       7f4da362c000-7f4da382b000 ---p 00002000 00:1a 5279122                    /usr/lib64/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
                       7f4da382b000-7f4da382c000 r--p 00001000 00:1a 5279122                    /usr/lib64/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
                       7f4da382c000-7f4da382e000 rw-p 00002000 00:1a 5279122                    /usr/lib64/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
                       7f4da382e000-7f4da39ee000 rw-p 00000000 00:00 0
                       7f4da39ee000-7f4da3bab000 r-xp 00000000 00:1a 4844904                    /usr/lib64/libc-2.24.so
                       7f4da3bab000-7f4da3daa000 ---p 001bd000 00:1a 4844904                    /usr/lib64/libc-2.24.so
                       7f4da3daa000-7f4da3dae000 r--p 001bc000 00:1a 4844904                    /usr/lib64/libc-2.24.so
                       7f4da3dae000-7f4da3db0000 rw-p 001c0000 00:1a 4844904                    /usr/lib64/libc-2.24.so
                       7f4da3db0000-7f4da3db4000 rw-p 00000000 00:00 0
                       7f4da3db4000-7f4da3ebc000 r-xp 00000000 00:1a 4844910                    /usr/lib64/libm-2.24.so
                       7f4da3ebc000-7f4da40bb000 ---p 00108000 00:1a 4844910                    /usr/lib64/libm-2.24.so
                       7f4da40bb000-7f4da40bc000 r--p 00107000 00:1a 4844910                    /usr/lib64/libm-2.24.so
                       7f4da40bc000-7f4da40bd000 rw-p 00108000 00:1a 4844910                    /usr/lib64/libm-2.24.so
                       7f4da40bd000-7f4da40bf000 r-xp 00000000 00:1a 4844928                    /usr/lib64/libutil-2.24.so
                       7f4da40bf000-7f4da42be000 ---p 00002000 00:1a 4844928                    /usr/lib64/libutil-2.24.so
                       7f4da42be000-7f4da42bf000 r--p 00001000 00:1a 4844928                    /usr/lib64/libutil-2.24.so
                       7f4da42bf000-7f4da42c0000 rw-p 00002000 00:1a 4844928                    /usr/lib64/libutil-2.24.so
                       7f4da42c0000-7f4da42c3000 r-xp 00000000 00:1a 4844908                    /usr/lib64/libdl-2.24.so
                       7f4da42c3000-7f4da44c2000 ---p 00003000 00:1a 4844908                    /usr/lib64/libdl-2.24.so
                       7f4da44c2000-7f4da44c3000 r--p 00002000 00:1a 4844908                    /usr/lib64/libdl-2.24.so
                       7f4da44c3000-7f4da44c4000 rw-p 00003000 00:1a 4844908                    /usr/lib64/libdl-2.24.so
                       7f4da44c4000-7f4da44dc000 r-xp 00000000 00:1a 4844920                    /usr/lib64/libpthread-2.24.so
                       7f4da44dc000-7f4da46dc000 ---p 00018000 00:1a 4844920                    /usr/lib64/libpthread-2.24.so
                       7f4da46dc000-7f4da46dd000 r--p 00018000 00:1a 4844920                    /usr/lib64/libpthread-2.24.so
                       7f4da46dd000-7f4da46de000 rw-p 00019000 00:1a 4844920                    /usr/lib64/libpthread-2.24.so
                       7f4da46de000-7f4da46e2000 rw-p 00000000 00:00 0
                       7f4da46e2000-7f4da4917000 r-xp 00000000 00:1a 5277535                    /usr/lib64/libpython3.5m.so.1.0
                       7f4da4917000-7f4da4b17000 ---p 00235000 00:1a 5277535                    /usr/lib64/libpython3.5m.so.1.0
                       7f4da4b17000-7f4da4b1c000 r--p 00235000 00:1a 5277535                    /usr/lib64/libpython3.5m.so.1.0
                       7f4da4b1c000-7f4da4b7f000 rw-p 0023a000 00:1a 5277535                    /usr/lib64/libpython3.5m.so.1.0
                       7f4da4b7f000-7f4da4baf000 rw-p 00000000 00:00 0
                       7f4da4baf000-7f4da4bd4000 r-xp 00000000 00:1a 4844897                    /usr/lib64/ld-2.24.so
                       7f4da4bdf000-7f4da4c10000 rw-p 00000000 00:00 0
                       7f4da4c10000-7f4da4c61000 r--p 00000000 00:1a 5225117                    /usr/lib/locale/pl_PL.utf8/LC_CTYPE
                       7f4da4c61000-7f4da4d91000 r--p 00000000 00:1a 4844827                    /usr/lib/locale/en_US.utf8/LC_COLLATE
                       7f4da4d91000-7f4da4d95000 rw-p 00000000 00:00 0
                       7f4da4dc1000-7f4da4dc2000 r--p 00000000 00:1a 4844832                    /usr/lib/locale/en_US.utf8/LC_NUMERIC
                       7f4da4dc2000-7f4da4dc3000 r--p 00000000 00:1a 4844795                    /usr/lib/locale/en_US.utf8/LC_TIME
                       7f4da4dc3000-7f4da4dc4000 r--p 00000000 00:1a 4844793                    /usr/lib/locale/en_US.utf8/LC_MONETARY
                       7f4da4dc4000-7f4da4dc5000 r--p 00000000 00:1a 4844830                    /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
                       7f4da4dc5000-7f4da4dc6000 r--p 00000000 00:1a 4844847                    /usr/lib/locale/en_US.utf8/LC_PAPER
                       7f4da4dc6000-7f4da4dc7000 r--p 00000000 00:1a 4844831                    /usr/lib/locale/en_US.utf8/LC_NAME
                       7f4da4dc7000-7f4da4dc8000 r--p 00000000 00:1a 4844790                    /usr/lib/locale/en_US.utf8/LC_ADDRESS
                       7f4da4dc8000-7f4da4dc9000 r--p 00000000 00:1a 4844794                    /usr/lib/locale/en_US.utf8/LC_TELEPHONE
                       7f4da4dc9000-7f4da4dca000 r--p 00000000 00:1a 4844792                    /usr/lib/locale/en_US.utf8/LC_MEASUREMENT
                       7f4da4dca000-7f4da4dd1000 r--s 00000000 00:1a 4845203                    /usr/lib64/gconv/gconv-modules.cache
                       7f4da4dd1000-7f4da4dd2000 r--p 00000000 00:1a 4844791                    /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
                       7f4da4dd2000-7f4da4dd4000 rw-p 00000000 00:00 0
                       7f4da4dd4000-7f4da4dd5000 r--p 00025000 00:1a 4844897                    /usr/lib64/ld-2.24.so
                       7f4da4dd5000-7f4da4dd6000 rw-p 00026000 00:1a 4844897                    /usr/lib64/ld-2.24.so
                       7f4da4dd6000-7f4da4dd7000 rw-p 00000000 00:00 0
                       7ffd24da1000-7ffd24dc2000 rw-p 00000000 00:00 0                          [stack]
                       7ffd24de8000-7ffd24dea000 r--p 00000000 00:00 0                          [vvar]
                       7ffd24dea000-7ffd24dec000 r-xp 00000000 00:00 0                          [vdso]
                       ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    COREDUMP_TIMESTAMP=1477877460000000
    MESSAGE=Process 14498 (python3) of user 1002 failed with ZeroDivisionError: division by zero:

            Traceback (most recent call last):
              File "systemd_coredump_exception_handler.py", line 89, in <module>
                g()
              File "systemd_coredump_exception_handler.py", line 88, in g
                f()
              File "systemd_coredump_exception_handler.py", line 86, in f
                div0 = 1 / 0  # pylint: disable=W0612
            ZeroDivisionError: division by zero

            Local variables in innermost frame:
              h=<function f at 0x7f4da3606e18>
              a=3
    _PID=14499
    _SOURCE_REALTIME_TIMESTAMP=1477877460025975
2017-02-14 23:56:48 -05:00
Zbigniew Jędrzejewski-Szmek 9aa8202314 coredump: split out metadata gathering to a separate function
In preparation for subsequenct changes...

Various stack allocations are changed to use the heap. This might be minimally
slower, but probably doesn't matter. The upside is that we will now properly
free all memory that is allocated.
2017-02-14 23:56:48 -05:00
Evgeny Vereshchagin d3cba4eaf6 coredump: really extract container cmdline (#5167)
Fixes:
```
root# systemd-nspawn -D ./cont/ --register=no /bin/sh -c '/bin/sh -c "kill -ABRT \$\$"'
...
Container cont failed with error code 134.

root# journalctl MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1 -o verbose | grep -i container_cmdline
...prints nothing...
...should be COREDUMP_CONTAINER_CMDLINE=systemd-nspawn -D ./cont/ --register=no /bin/sh -c /bin/sh -c "kill -ABRT \$\$"
```

Also, fixes CID #1368263
```
==352== 130 bytes in 1 blocks are definitely lost in loss record 1 of 2
==352==    at 0x4C2ED5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==352==    by 0x4ED8581: greedy_realloc (alloc-util.c:57)
==352==    by 0x4ECAAD5: get_process_cmdline (process-util.c:147)
==352==    by 0x10E385: get_process_container_parent_cmdline (coredump.c:645)
==352==    by 0x112949: process_kernel (coredump.c:1240)
==352==    by 0x113003: main (coredump.c:1297)
==352==
```
2017-01-31 11:04:20 -05:00
Zbigniew Jędrzejewski-Szmek 6e2b4a6994 coredump: bump type of arg_journal_size_max to uint64 too
For normal arches this doesn't matter, but on arm32 arg_journal_size_max was smaller
than the other *SizeMax variables. This doesn't seem useful.

This is anothet part of the fix in 5206a724a0.
2016-11-08 00:21:37 -05:00
Zbigniew Jędrzejewski-Szmek 5206a724a0 coredump: fix format string on 32 bits
In file included from ./src/basic/macro.h:415:0,
                 from ./src/shared/acl-util.h:28,
                 from src/coredump/coredump.c:36:
src/coredump/coredump.c: In function ‘submit_coredump’:
src/coredump/coredump.c:711:26: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 7 has type ‘uint64_t {aka long long unsigned int}’ [-Wformat=]
                 log_info("The core will not be stored: size %zu is greater than %zu (the configured maximum)",
                          ^
./src/basic/log.h:175:82: note: in definition of macro ‘log_full_errno’
                         ? log_internal(_level, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
                                                                                  ^~~~~~~~~~~
./src/basic/log.h:183:28: note: in expansion of macro ‘log_full’
 #define log_info(...)      log_full(LOG_INFO,    __VA_ARGS__)
                            ^~~~~~~~
src/coredump/coredump.c:711:17: note: in expansion of macro ‘log_info’
                 log_info("The core will not be stored: size %zu is greater than %zu (the configured maximum)",
                 ^~~~~~~~
src/coredump/coredump.c:711:26: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 8 has type ‘uint64_t {aka long long unsigned int}’ [-Wformat=]
                 log_info("The core will not be stored: size %zu is greater than %zu (the configured maximum)",
                          ^
./src/basic/log.h:175:82: note: in definition of macro ‘log_full_errno’
                         ? log_internal(_level, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
                                                                                  ^~~~~~~~~~~
./src/basic/log.h:183:28: note: in expansion of macro ‘log_full’
 #define log_info(...)      log_full(LOG_INFO,    __VA_ARGS__)
                            ^~~~~~~~
src/coredump/coredump.c:711:17: note: in expansion of macro ‘log_info’
                 log_info("The core will not be stored: size %zu is greater than %zu (the configured maximum)",
                 ^~~~~~~~
src/coredump/coredump.c:741:27: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 7 has type ‘uint64_t {aka long long unsigned int}’ [-Wformat=]
                 log_debug("Not generating stack trace: core size %zu is greater than %zu (the configured maximum)",
                           ^
./src/basic/log.h:175:82: note: in definition of macro ‘log_full_errno’
                         ? log_internal(_level, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
                                                                                  ^~~~~~~~~~~
./src/basic/log.h:182:28: note: in expansion of macro ‘log_full’
 #define log_debug(...)     log_full(LOG_DEBUG,   __VA_ARGS__)
                            ^~~~~~~~
src/coredump/coredump.c:741:17: note: in expansion of macro ‘log_debug’
                 log_debug("Not generating stack trace: core size %zu is greater than %zu (the configured maximum)",
                 ^~~~~~~~~
src/coredump/coredump.c:741:27: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 8 has type ‘uint64_t {aka long long unsigned int}’ [-Wformat=]
                 log_debug("Not generating stack trace: core size %zu is greater than %zu (the configured maximum)",
                           ^
./src/basic/log.h:175:82: note: in definition of macro ‘log_full_errno’
                         ? log_internal(_level, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
                                                                                  ^~~~~~~~~~~
./src/basic/log.h:182:28: note: in expansion of macro ‘log_full’
 #define log_debug(...)     log_full(LOG_DEBUG,   __VA_ARGS__)
                            ^~~~~~~~
src/coredump/coredump.c:741:17: note: in expansion of macro ‘log_debug’
                 log_debug("Not generating stack trace: core size %zu is greater than %zu (the configured maximum)",
                 ^~~~~~~~~
src/coredump/coredump.c:768:34: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 7 has type ‘uint64_t {aka long long unsigned int}’ [-Wformat=]
                         log_info("The core will not be stored: size %zu is greater than %zu (the configured maximum)",
                                  ^
./src/basic/log.h:175:82: note: in definition of macro ‘log_full_errno’
                         ? log_internal(_level, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
                                                                                  ^~~~~~~~~~~
./src/basic/log.h:183:28: note: in expansion of macro ‘log_full’
 #define log_info(...)      log_full(LOG_INFO,    __VA_ARGS__)
                            ^~~~~~~~
src/coredump/coredump.c:768:25: note: in expansion of macro ‘log_info’
                         log_info("The core will not be stored: size %zu is greater than %zu (the configured maximum)",
                         ^~~~~~~~
2016-11-07 11:46:42 -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
Stefan Schweter aa7530d681 coredump: use for() loop instead of while() 2016-10-12 22:49:01 +02:00
Zbigniew Jędrzejewski-Szmek 73a99163a7 coredump,catalog: give better notice when a core file is truncated
coredump had code to check if copy_bytes() hit the max_bytes limit,
and refuse further processing in that case.
But in 84ee096044, the return convention for copy_bytes() was changed
from -EFBIG to 1 for the case when the limit is hit, so the condition
check in coredump couldn't ever trigger.
But it seems that *do* want to process such truncated cores [1].
So change the code to detect truncation properly, but instead of
returning an error, give a nice log entry.

[1] https://github.com/systemd/systemd/issues/3883#issuecomment-239106337

Should fix (or at least alleviate) #3883.
2016-09-28 23:50:29 +02:00
Zbigniew Jędrzejewski-Szmek 6e9ef6038f coredump: log if the core is too large to store or generate backtrace
Another fix for #4161.
2016-09-28 23:49:01 +02:00
Zbigniew Jędrzejewski-Szmek fc6cec8613 coredump: remove Storage=both option
Back when external storage was initially added in 34c10968cb, this mode of
storage was added. This could have made some sense back when XZ compression was
used, and an uncompressed core on disk could be used as short-lived cache file
which does require costly decompression. But now fast LZ4 compression is used
(by default) both internally and externally, so we have duplicated storage,
using the same compression and same default maximum core size in both cases,
but with different expiration lifetimes. Even the uncompressed-external,
compressed-internal mode is not very useful: for small files, decompression
with LZ4 is fast enough not to matter, and for large files, decompression is
still relatively fast, but the disk-usage penalty is very big.

An additional problem with the two modes of storage is that it complicates
the code and makes it much harder to return a useful error message to the user
if we cannot find the core file, since if we cannot find the file we have to
check the internal storage first.

This patch drops "both" storage mode. Effectively this means that if somebody
configured coredump this way, they will get a warning about an unsupported
value for Storage, and the default of "external" will be used.
I'm pretty sure that this mode is very rarely used anyway.
2016-09-28 23:49:01 +02:00
Matej Habrnal a5ca3649d3 coredump: initialize coredump_size in submit_coredump() (#4219)
If ulimit is smaller than page_size(), function save_external_coredump()
returns -EBADSLT and this causes skipping whole core dumping part in
submit_coredump(). Initializing coredump_size to UINT64_MAX prevents
evaluating a condition with uninitialized varialbe which leads to
calling allocate_journal_field() with coredump_fd = -1 which causes
aborting.

Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
2016-09-26 11:28:58 -04:00
Zbigniew Jędrzejewski-Szmek 43688c49d1 tree-wide: rename config_parse_many to …_nulstr
In preparation for adding a version which takes a strv.
2016-09-16 10:32:03 -04:00
Zbigniew Jędrzejewski-Szmek 6998b54093 coredump: treat RLIMIT_CORE below page size as disabling coredumps (#3932)
The kernel treats values below a certain threshold (minfmt->min_coredump
which is initialized do ELF_EXEC_PAGESIZE, which varies between architectures,
but is usually the same as PAGE_SIZE) as disabling coredumps [1].
Any core image below ELF_EXEC_PAGESIZE will yield an invalid backtrace anyway [2],
so follow the kernel and not try to parse or store such images.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/coredump.c#n660
[2] systemd-coredump[16260]: Process 16258 (sleep) of user 1002 dumped core.
                                Stack trace of thread 16258:
                                #0  0x00007f1d8b3d3810 n/a (n/a)

https://bugzilla.redhat.com/show_bug.cgi?id=1309172#c19
2016-08-11 10:51:00 +02:00