Commit Graph

69 Commits

Author SHA1 Message Date
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Lennart Poettering 6990fb6bc6 tree-wide: (void)ify a few unlink() and rmdir()
Let's be helpful to static analyzers which care about whether we
knowingly ignore return values. We do in these cases, since they are
usually part of error paths.
2019-03-27 18:09:56 +01:00
Zbigniew Jędrzejewski-Szmek 871fa294ff Merge pull request #10935 from poettering/rlimit-nofile-safe
Merged by hand to resolve a trivial conflict in TODO.
2018-12-06 17:19:21 +01:00
Lennart Poettering e4de72876e util-lib: split out all temporary file related calls into tmpfiles-util.c
This splits out a bunch of functions from fileio.c that have to do with
temporary files. Simply to make the header files a bit shorter, and to
group things more nicely.

No code changes, just some rearranging of source files.
2018-12-02 13:22:29 +01:00
Lennart Poettering 0672e2c6f8 tree-wide: use FORK_RLIMIT_NOFILE_SAFE wherever possible
Similar to the previous commit: in many cases no further fd processing
needs to be done in forked of children before execve() or any of its
flavours are called. In those case we can use FORK_RLIMIT_NOFILE_SAFE
instead.
2018-12-01 12:50:45 +01:00
Zbigniew Jędrzejewski-Szmek 886cf317c4 coccinelle: also mark previous synthetic errnos as such 2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +01:00
Zbigniew Jędrzejewski-Szmek 7add4883cb coredumpctl: fix "leak" of bus connection
$ valgrind --show-leak-kinds=all --leak-check=full build/coredumpctl dump --output /tmp/ff
...
==16431== HEAP SUMMARY:
==16431==     in use at exit: 3,680 bytes in 13 blocks
==16431==   total heap usage: 831 allocs, 818 frees, 197,776 bytes allocated
==16431==
==16431== 2 bytes in 1 blocks are still reachable in loss record 1 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x4C4D5AD: strdup (strdup.c:42)
==16431==    by 0x49B2387: bus_message_parse_fields (bus-message.c:5300)
==16431==    by 0x49A23AF: bus_message_from_malloc (bus-message.c:560)
==16431==    by 0x49C459B: bus_socket_make_message (bus-socket.c:1099)
==16431==    by 0x49C4C5B: bus_socket_read_message (bus-socket.c:1213)
==16431==    by 0x49CE4CE: bus_read_message (sd-bus.c:1777)
==16431==    by 0x49CFA2C: sd_bus_call (sd-bus.c:2176)
==16431==    by 0x1105F3: check_units_active (coredumpctl.c:1029)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==    by 0x110A45: main (coredumpctl.c:1100)
==16431==
==16431== 9 bytes in 1 blocks are still reachable in loss record 2 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x4939067: malloc_multiply (alloc-util.h:78)
==16431==    by 0x493921D: hexmem (hexdecoct.c:62)
==16431==    by 0x49C2B75: bus_socket_start_auth_client (bus-socket.c:626)
==16431==    by 0x49C2D78: bus_socket_start_auth (bus-socket.c:665)
==16431==    by 0x49C3B09: bus_socket_connect (bus-socket.c:915)
==16431==    by 0x49CBB08: bus_start_address (sd-bus.c:1103)
==16431==    by 0x49CBFEA: sd_bus_start (sd-bus.c:1187)
==16431==    by 0x49CC452: sd_bus_open_system_with_description (sd-bus.c:1294)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==
==16431== 9 bytes in 1 blocks are still reachable in loss record 3 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x4C4D5AD: strdup (strdup.c:42)
==16431==    by 0x497364E: free_and_strdup (string-util.c:1013)
==16431==    by 0x49C9FB1: hello_callback (sd-bus.c:547)
==16431==    by 0x49D0A3A: process_reply (sd-bus.c:2498)
==16431==    by 0x49D13E0: process_message (sd-bus.c:2677)
==16431==    by 0x49D165F: process_running (sd-bus.c:2739)
==16431==    by 0x49D20DD: bus_process_internal (sd-bus.c:2957)
==16431==    by 0x49D21E8: sd_bus_process (sd-bus.c:2984)
==16431==    by 0x49CF21E: bus_ensure_running (sd-bus.c:2053)
==16431==    by 0x49CF51F: sd_bus_call (sd-bus.c:2095)
==16431==    by 0x1105F3: check_units_active (coredumpctl.c:1029)
==16431==
==16431== 24 bytes in 1 blocks are still reachable in loss record 4 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x495CB0D: malloc_multiply (alloc-util.h:78)
==16431==    by 0x495CB2A: prioq_new (prioq.c:35)
==16431==    by 0x495CC02: prioq_ensure_allocated (prioq.c:60)
==16431==    by 0x49CEF84: sd_bus_call_async (sd-bus.c:1995)
==16431==    by 0x49CA0E6: bus_send_hello (sd-bus.c:581)
==16431==    by 0x49CC019: sd_bus_start (sd-bus.c:1196)
==16431==    by 0x49CC452: sd_bus_open_system_with_description (sd-bus.c:1294)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==
==16431== 38 bytes in 1 blocks are still reachable in loss record 5 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x4C4D5AD: strdup (strdup.c:42)
==16431==    by 0x497364E: free_and_strdup (string-util.c:1013)
==16431==    by 0x49C7F97: sd_bus_set_address (sd-bus.c:269)
==16431==    by 0x49CC314: bus_set_address_system (sd-bus.c:1262)
==16431==    by 0x49CC3E0: sd_bus_open_system_with_description (sd-bus.c:1281)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==    by 0x110A45: main (coredumpctl.c:1100)
==16431==
==16431== 64 bytes in 1 blocks are still reachable in loss record 6 of 13
==16431==    at 0x4838748: malloc (vg_replace_malloc.c:298)
==16431==    by 0x483AD63: realloc (vg_replace_malloc.c:826)
==16431==    by 0x4902663: greedy_realloc (alloc-util.c:55)
==16431==    by 0x49C7D7D: sd_bus_new (sd-bus.c:255)
==16431==    by 0x49CC398: sd_bus_open_system_with_description (sd-bus.c:1271)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==    by 0x110A45: main (coredumpctl.c:1100)
==16431==
==16431== 64 bytes in 1 blocks are still reachable in loss record 7 of 13
==16431==    at 0x4838748: malloc (vg_replace_malloc.c:298)
==16431==    by 0x483AD63: realloc (vg_replace_malloc.c:826)
==16431==    by 0x4902663: greedy_realloc (alloc-util.c:55)
==16431==    by 0x49CE54E: bus_rqueue_make_room (sd-bus.c:1786)
==16431==    by 0x49C44FC: bus_socket_make_message (bus-socket.c:1087)
==16431==    by 0x49C4C5B: bus_socket_read_message (bus-socket.c:1213)
==16431==    by 0x49CE4CE: bus_read_message (sd-bus.c:1777)
==16431==    by 0x49CE6AF: dispatch_rqueue (sd-bus.c:1814)
==16431==    by 0x49D162E: process_running (sd-bus.c:2733)
==16431==    by 0x49D20DD: bus_process_internal (sd-bus.c:2957)
==16431==    by 0x49D21E8: sd_bus_process (sd-bus.c:2984)
==16431==    by 0x49CF21E: bus_ensure_running (sd-bus.c:2053)
==16431==
==16431== 65 bytes in 1 blocks are still reachable in loss record 8 of 13
==16431==    at 0x483AB1A: calloc (vg_replace_malloc.c:752)
==16431==    by 0x496E5D6: getpeersec (socket-util.c:969)
==16431==    by 0x49C291C: bus_get_peercred (bus-socket.c:594)
==16431==    by 0x49C2CB2: bus_socket_start_auth (bus-socket.c:650)
==16431==    by 0x49C3B09: bus_socket_connect (bus-socket.c:915)
==16431==    by 0x49CBB08: bus_start_address (sd-bus.c:1103)
==16431==    by 0x49CBFEA: sd_bus_start (sd-bus.c:1187)
==16431==    by 0x49CC452: sd_bus_open_system_with_description (sd-bus.c:1294)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==
==16431== 181 bytes in 1 blocks are still reachable in loss record 9 of 13
==16431==    at 0x483AD19: realloc (vg_replace_malloc.c:826)
==16431==    by 0x49C4791: bus_socket_read_message (bus-socket.c:1143)
==16431==    by 0x49CE4CE: bus_read_message (sd-bus.c:1777)
==16431==    by 0x49CFA2C: sd_bus_call (sd-bus.c:2176)
==16431==    by 0x1105F3: check_units_active (coredumpctl.c:1029)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==    by 0x110A45: main (coredumpctl.c:1100)
==16431==
==16431== 256 bytes in 1 blocks are still reachable in loss record 10 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x496E740: getpeergroups (socket-util.c:998)
==16431==    by 0x49C29BD: bus_get_peercred (bus-socket.c:599)
==16431==    by 0x49C2CB2: bus_socket_start_auth (bus-socket.c:650)
==16431==    by 0x49C3B09: bus_socket_connect (bus-socket.c:915)
==16431==    by 0x49CBB08: bus_start_address (sd-bus.c:1103)
==16431==    by 0x49CBFEA: sd_bus_start (sd-bus.c:1187)
==16431==    by 0x49CC452: sd_bus_open_system_with_description (sd-bus.c:1294)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==
==16431== 256 bytes in 1 blocks are still reachable in loss record 11 of 13
==16431==    at 0x4838748: malloc (vg_replace_malloc.c:298)
==16431==    by 0x483AD63: realloc (vg_replace_malloc.c:826)
==16431==    by 0x495D1A0: prioq_put (prioq.c:162)
==16431==    by 0x49CF0EA: sd_bus_call_async (sd-bus.c:2023)
==16431==    by 0x49CA0E6: bus_send_hello (sd-bus.c:581)
==16431==    by 0x49CC019: sd_bus_start (sd-bus.c:1196)
==16431==    by 0x49CC452: sd_bus_open_system_with_description (sd-bus.c:1294)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==
==16431== 856 bytes in 1 blocks are still reachable in loss record 12 of 13
==16431==    at 0x483AB1A: calloc (vg_replace_malloc.c:752)
==16431==    by 0x49A1F33: bus_message_from_header (bus-message.c:458)
==16431==    by 0x49A22B1: bus_message_from_malloc (bus-message.c:535)
==16431==    by 0x49C459B: bus_socket_make_message (bus-socket.c:1099)
==16431==    by 0x49C4C5B: bus_socket_read_message (bus-socket.c:1213)
==16431==    by 0x49CE4CE: bus_read_message (sd-bus.c:1777)
==16431==    by 0x49CFA2C: sd_bus_call (sd-bus.c:2176)
==16431==    by 0x1105F3: check_units_active (coredumpctl.c:1029)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==    by 0x110A45: main (coredumpctl.c:1100)
==16431==
==16431== 1,856 bytes in 1 blocks are still reachable in loss record 13 of 13
==16431==    at 0x483880B: malloc (vg_replace_malloc.c:299)
==16431==    by 0x49C6EDF: malloc_multiply (alloc-util.h:78)
==16431==    by 0x49C7C81: sd_bus_new (sd-bus.c:235)
==16431==    by 0x49CC398: sd_bus_open_system_with_description (sd-bus.c:1271)
==16431==    by 0x49CC4C6: sd_bus_open_system (sd-bus.c:1303)
==16431==    by 0x49D4424: bus_default (sd-bus.c:3655)
==16431==    by 0x49D44BC: sd_bus_default_system (sd-bus.c:3668)
==16431==    by 0x110444: check_units_active (coredumpctl.c:1007)
==16431==    by 0x110998: run (coredumpctl.c:1087)
==16431==    by 0x110A45: main (coredumpctl.c:1100)
==16431==
==16431== LEAK SUMMARY:
==16431==    definitely lost: 0 bytes in 0 blocks
==16431==    indirectly lost: 0 bytes in 0 blocks
==16431==      possibly lost: 0 bytes in 0 blocks
==16431==    still reachable: 3,680 bytes in 13 blocks
==16431==         suppressed: 0 bytes in 0 blocks
==16431==
2018-11-20 16:48:21 +01:00
Zbigniew Jędrzejewski-Szmek c118b577fa coredumpctl: define main through macro
We want to propagate the return value from gdb, hence this commit makes
use of the liberalization of DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE()
in previous commit.
2018-11-20 16:48:21 +01:00
Zbigniew Jędrzejewski-Szmek 158ecef56b coredumpctl: open output file only before writing
We would open the file very early, which is not nice, if we e.g. fail when
parsing later options. Let's do the usual thing and just open it just before
writing, and close immediately after writing.
2018-11-20 16:48:21 +01:00
Zbigniew Jędrzejewski-Szmek 0221d68a13 basic/pager: convert the pager options to a flags argument
Pretty much everything uses just the first argument, and this doesn't make this
common pattern more complicated, but makes it simpler to pass multiple options.
2018-11-14 16:25:11 +01:00
Yu Watanabe 9d77ca39e5 coredump: include error cause in log message 2018-10-20 01:43:13 +09:00
Lennart Poettering 1abaf4887d tree-wide: uniformly bump RLIMIT_NOFILE in all our tools that access the journal
This makes use of rlimit_nofile_bump() in all tools that access the
journal. In some cases this replaces older code to achieve this, and
others we add it in where it was missing.
2018-10-16 16:33:55 +02:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Lion Yang 2fafabfdc4 coredumpctl: info shows the last entry by default
Closes #9524.
2018-07-23 17:45:53 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +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
Lennart Poettering abdf29f50d coredumpctl: always output proper english sentence
Let's uppercase the first character, and finish them in a full stop.
2018-05-22 13:14:18 +02:00
Ryan Gonzalez c5896b6a8c coredumpctl: Add debug as a gdb alias, and add lldb support (closes #8722) (#8744) 2018-04-18 21:32:17 +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 f5c4b520ba coccinelle: run safe_fclose.cocci again 2018-03-23 16:32:48 +01:00
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 43bfe75032 coredumpctl: drop unnecessary NULL initialization, and use const where possible (#8515) 2018-03-21 11:46:08 +01:00
Yu Watanabe ee5324aa04 tree-wide: voidify pager_open()
Even if pager_open() fails, in general, we should continue the operations.
All erroneous cases in pager_open() show log message in the function.
So, it is not necessary to check the returned value.
2018-03-19 21:04:02 +09:00
Yu Watanabe 5ce97d33d0 coredumpctl: use dispatch_verb() 2018-03-19 21:03:36 +09:00
Yu Watanabe e8fb0238cd coredump: do not leak memory (#8352)
Fixes #8351.
2018-03-05 08:39:52 +01:00
Lennart Poettering 0b1f3c768c tree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children
In a number of occasions we use FORK_CLOSE_ALL_FDS when forking off a
child, since we don't want to pass fds to the processes spawned (either
because we later want to execve() some other process there, or because
our child might hang around for longer than expected, in which case it
shouldn't keep our fd pinned). This also closes any logging fds, and
thus means logging is turned off in the child. If we want to do proper
logging, explicitly reopen the logs hence in the child at the right
time.

This is particularly crucial in the umount/remount children we fork off
the shutdown binary, as otherwise the children can't log, which is
why #8155 is harder to debug than necessary: the log messages we
generate about failing mount() system calls aren't actually visible on
screen, as they done in the child processes where the log fds are
closed.
2018-02-22 00:35:00 +01:00
Zbigniew Jędrzejewski-Szmek e79d0b59c8 journalctl: improve hint about lack of access for --user-unit=...
When running journalctl --user-unit=foo as an unprivileged user we could get
the usual hint:
Hint: You are currently not seeing messages from the system and other users.
      Users in groups 'adm', 'systemd-journal', 'wheel' can see all messages.
      ...
But with --user-unit our filter is:
(((_UID=0 OR _UID=1000) AND OBJECT_SYSTEMD_USER_UNIT=foo.service) OR
 ((_UID=0 OR _UID=1000) AND COREDUMP_USER_UNIT=foo.service) OR
 (_UID=1000 AND USER_UNIT=foo.service) OR
 (_UID=1000 AND _SYSTEMD_USER_UNIT=foo.service))
so we would never see messages from other users.

We could still see messages from the system. In fact, on my machine the
only messages with OBJECT_SYSTEMD_USER_UNIT= are from the system:
journalctl  $(journalctl -F OBJECT_SYSTEMD_USER_UNIT|sed 's/.*/OBJECT_SYSTEMD_USER_UNIT=\0/')

Thus, a more correct hint is that we cannot see messages from the system.
Make it so.

Fixes #7887.
2018-02-20 22:36:01 +01:00
Lennart Poettering 2e87a1fde9 tree-wide: make use of wait_for_terminate_and_check() at various places
Using wait_for_terminate_and_check() instead of wait_for_terminate()
let's us simplify, shorten and unify the return value checking and
logging of waitid().  Hence, let's use it all over the place.
2018-01-04 13:27:27 +01:00
Lennart Poettering b6e1fff13d process-util: add another fork_safe() flag for enabling LOG_ERR/LOG_WARN logging 2018-01-04 13:27:26 +01:00
Lennart Poettering a45d7127e7 tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we can 2017-12-25 11:48:21 +01:00
Lennart Poettering 4c253ed1ca tree-wide: introduce new safe_fork() helper and port everything over
This adds a new safe_fork() wrapper around fork() and makes use of it
everywhere. The new wrapper does a couple of things we previously did
manually and separately in a safer, more correct and automatic way:

1. Optionally resets signal handlers/mask in the child

2. Sets a name on all processes we fork off right after forking off (and
   the patch assigns useful names for all processes we fork off now,
   following a systematic naming scheme: always enclosed in () – in order
   to indicate that these are not proper, exec()ed processes, but only
   forked off children, and if the process is long-running with only our
   own code, without execve()'ing something else, it gets am "sd-" prefix.)

3. Optionally closes all file descriptors in the child

4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe
   way so that the parent dying before this happens being handled
   safely.

5. Optionally reopens the logs

6. Optionally connects stdin/stdout/stderr to /dev/null

7. Debug logs about the forked off processes.
2017-12-25 11:48:21 +01:00
Lennart Poettering f1d34068ef tree-wide: add DEBUG_LOGGING macro that checks whether debug logging is on (#7645)
This makes things a bit easier to read I think, and also makes sure we
always use the _unlikely_ wrapper around it, which so far we used
sometimes and other times we didn't. Let's clean that up.
2017-12-15 11:09:00 +01:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +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
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 501551e803 coredump: define a macro for a "short bus call timeout"
I think it would be a good idea to move such fixed, picked values out of
the main sources into the head of a file, to make sure they are
ultimately tunables.
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 eb5877a024 coredumpctl: avoid spurious warning about systemd-coredump@0.service
Fixes #5477.
2017-02-28 21:47:45 -05:00
Zbigniew Jędrzejewski-Szmek b9aaa7f480 coredumpctl: print a hint when no journal files are found
[guest@fedora ~]$ coredumpctl
No coredumps found.

[guest@fedora ~]$ ./coredumpctl
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal', 'wheel' can see all messages.
      Pass -q to turn off this notice.
No coredumps found.

Fixes #1733.
2017-02-28 21:38:47 -05:00
Zbigniew Jędrzejewski-Szmek 7d8e7c0e19 coredumpctl: use a 3s timeout for checking units
This is just a hint, so we shouldn't wait too long. A short timeout
helps for the case where pid1 of dbus have crashed.
2017-02-28 21:34:53 -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 7bbf2d8423 coredumpctl: add debug information which services count towards the warning
A few times I have seen the hint unexpectedly. Add this so debug info
so it's easier to see what's happening.

...
Unit systemd-coredump@0-3119-0.service is failed/failed, not counting it.
Unit systemd-coredump@1-3854-0.service is activating/start-pre, counting it.
...
-- Notice: 1 systemd-coredump@.service unit is running, output may be incomplete.
2017-02-26 19:45:10 -05:00
Giedrius Statkevičius 32485d0904 coredumpctl: implement --since/--until (-S/-U) for info/list verbs
Implement --since/--until (-S/-U) in the same fashion as journalctl.
This lets the user filter the results a bit so it would be easier to
find relevant info in case there were many core dumps.
2017-02-24 21:29:40 +02:00
Thomas H. P. Andersen 0f5a443e8c coredump: fix assign in while loop (#5417)
From: #5393
2017-02-22 00:14:54 +01:00
Zbigniew Jędrzejewski-Szmek 012f2b7de7 coredumpctl: print a hint if any coredumps are in flight (#5393)
Fixes #4685.
2017-02-21 11:08:35 +01:00
Zbigniew Jędrzejewski-Szmek a7581ff940 coredumpctl: display non-coredump coredump entries too
$ ./coredumpctl --no-pager -1
TIME                            PID   UID   GID SIG COREFILE EXE
Sun 2016-11-06 10:10:51 EST   29514  1002  1002   - -        /usr/bin/python3.5

$ ./coredumpctl info 29514
           PID: 29514 (python3)
           UID: 1002 (zbyszek)
           GID: 1002 (zbyszek)
        Reason: ZeroDivisionError
     Timestamp: Sun 2016-11-06 10:10:51 EST (3h 22min ago)
  Command Line: python3 systemd_coredump_exception_handler.py
    Executable: /usr/bin/python3.5
 Control Group: /user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service
          Unit: user@1002.service
     User Unit: gnome-terminal-server.service
         Slice: user-1002.slice
     Owner UID: 1002 (zbyszek)
       Boot ID: 1531fd22ec84429e85ae888b12fadb91
    Machine ID: 519a16632fbd4c71966ce9305b360c9c
      Hostname: laptop
       Storage: none
       Message: Process 29514 (systemd_coredump_exception_handler.py) of user zbyszek failed with ZeroDivisionError: division by

                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>
2017-02-15 00:45:12 -05:00