]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/coredump/coredump.c
zsh: add completion for dbus bus address
[thirdparty/systemd.git] / src / coredump / coredump.c
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
f5e04665 2
73a99163 3#include "sd-daemon.h"
4f5dd394 4
fa30374e 5#include "coredump-backtrace.h"
25685485 6#include "coredump-config.h"
4131e3a8 7#include "coredump-context.h"
4fcd5f8b 8#include "coredump-kernel-helper.h"
ab2e98b4 9#include "coredump-receive.h"
c8715007 10#include "coredump-util.h"
4f5dd394 11#include "log.h"
5e332028 12#include "main-func.h"
07630cea 13#include "string-util.h"
34727273 14
4515a95e 15static int run(int argc, char *argv[]) {
3c171f0b 16 int r;
fee80f69 17
9aa82023
ZJS
18 /* First, log to a safe place, since we don't know what crashed and it might
19 * be journald which we'd rather not log to then. */
8d4e028f 20
1e344c1d 21 log_set_target_and_open(LOG_TARGET_KMSG);
8d4e028f 22
3c171f0b 23 /* Make sure we never enter a loop */
9ce8e3e4 24 (void) set_dumpable(SUID_DUMP_DISABLE);
8d4e028f 25
3c171f0b 26 /* Ignore all parse errors */
25685485 27 (void) coredump_parse_config();
fee80f69 28
3c171f0b 29 r = sd_listen_fds(false);
4515a95e
ZJS
30 if (r < 0)
31 return log_error_errno(r, "Failed to determine the number of file descriptors: %m");
fee80f69 32
9aa82023
ZJS
33 /* If we got an fd passed, we are running in coredumpd mode. Otherwise we
34 * are invoked from the kernel as coredump handler. */
988e89ee
ZJS
35 if (r == 0) {
36 if (streq_ptr(argv[1], "--backtrace"))
fa30374e 37 return coredump_backtrace(argc, argv);
988e89ee 38 else
4fcd5f8b 39 return coredump_kernel_helper(argc, argv);
988e89ee 40 } else if (r == 1)
ab2e98b4 41 return coredump_receive(SD_LISTEN_FDS_START);
f5e04665 42
baaa35ad
ZJS
43 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
44 "Received unexpected number of file descriptors.");
f5e04665 45}
4515a95e
ZJS
46
47DEFINE_MAIN_FUNCTION(run);