1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2012 Zbigniew Jędrzejewski-Szmek
16 #include "sd-journal.h"
17 #include "sd-messages.h"
19 #include "alloc-util.h"
20 #include "bus-error.h"
26 #include "journal-internal.h"
27 #include "journal-util.h"
31 #include "parse-util.h"
32 #include "path-util.h"
33 #include "process-util.h"
35 #include "signal-util.h"
36 #include "string-util.h"
38 #include "terminal-util.h"
39 #include "user-util.h"
43 #define SHORT_BUS_CALL_TIMEOUT_USEC (3 * USEC_PER_SEC)
45 static usec_t arg_since
= USEC_INFINITY
, arg_until
= USEC_INFINITY
;
46 static const char* arg_field
= NULL
;
47 static const char *arg_directory
= NULL
;
48 static bool arg_no_pager
= false;
49 static int arg_no_legend
= false;
50 static int arg_one
= false;
51 static FILE* arg_output
= NULL
;
52 static bool arg_reverse
= false;
53 static bool arg_quiet
= false;
55 static int add_match(sd_journal
*j
, const char *match
) {
56 _cleanup_free_
char *p
= NULL
;
57 const char* prefix
, *pattern
;
61 if (strchr(match
, '='))
63 else if (strchr(match
, '/')) {
64 r
= path_make_absolute_cwd(match
, &p
);
66 return log_error_errno(r
, "path_make_absolute_cwd(\"%s\"): %m", match
);
69 prefix
= "COREDUMP_EXE=";
70 } else if (parse_pid(match
, &pid
) >= 0)
71 prefix
= "COREDUMP_PID=";
73 prefix
= "COREDUMP_COMM=";
75 pattern
= strjoina(prefix
, match
);
76 log_debug("Adding match: %s", pattern
);
77 r
= sd_journal_add_match(j
, pattern
, 0);
79 return log_error_errno(r
, "Failed to add match \"%s\": %m", match
);
84 static int add_matches(sd_journal
*j
, char **matches
) {
88 r
= sd_journal_add_match(j
, "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR
, 0);
90 return log_error_errno(r
, "Failed to add match \"%s\": %m", "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR
);
92 r
= sd_journal_add_match(j
, "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR
, 0);
94 return log_error_errno(r
, "Failed to add match \"%s\": %m", "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR
);
96 STRV_FOREACH(match
, matches
) {
97 r
= add_match(j
, *match
);
105 static int acquire_journal(sd_journal
**ret
, char **matches
) {
106 _cleanup_(sd_journal_closep
) sd_journal
*j
= NULL
;
112 r
= sd_journal_open_directory(&j
, arg_directory
, 0);
114 return log_error_errno(r
, "Failed to open journals in directory: %s: %m", arg_directory
);
116 r
= sd_journal_open(&j
, SD_JOURNAL_LOCAL_ONLY
);
118 return log_error_errno(r
, "Failed to open journal: %m");
121 r
= journal_access_check_and_warn(j
, arg_quiet
, true);
125 r
= add_matches(j
, matches
);
130 _cleanup_free_
char *filter
;
132 filter
= journal_make_match_string(j
);
133 log_debug("Journal filter: %s", filter
);
141 static int help(void) {
142 printf("%s [OPTIONS...]\n\n"
143 "List or retrieve coredumps from the journal.\n\n"
145 " -h --help Show this help\n"
146 " --version Print version string\n"
147 " --no-pager Do not pipe output into a pager\n"
148 " --no-legend Do not print the column headers.\n"
149 " -1 Show information about most recent entry only\n"
150 " -S --since=DATE Only print coredumps since the date\n"
151 " -U --until=DATE Only print coredumps until the date\n"
152 " -r --reverse Show the newest entries first\n"
153 " -F --field=FIELD List all values a certain field takes\n"
154 " -o --output=FILE Write output to FILE\n"
155 " -D --directory=DIR Use journal files from directory\n\n"
156 " -q --quiet Do not show info messages and privilege warning\n"
158 " list [MATCHES...] List available coredumps (default)\n"
159 " info [MATCHES...] Show detailed information about one or more coredumps\n"
160 " dump [MATCHES...] Print first matching coredump to stdout\n"
161 " gdb [MATCHES...] Start gdb for the first matching coredump\n"
162 , program_invocation_short_name
);
167 static int parse_argv(int argc
, char *argv
[]) {
176 static const struct option options
[] = {
177 { "help", no_argument
, NULL
, 'h' },
178 { "version" , no_argument
, NULL
, ARG_VERSION
},
179 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
180 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
181 { "output", required_argument
, NULL
, 'o' },
182 { "field", required_argument
, NULL
, 'F' },
183 { "directory", required_argument
, NULL
, 'D' },
184 { "reverse", no_argument
, NULL
, 'r' },
185 { "since", required_argument
, NULL
, 'S' },
186 { "until", required_argument
, NULL
, 'U' },
187 { "quiet", no_argument
, NULL
, 'q' },
194 while ((c
= getopt_long(argc
, argv
, "ho:F:1D:rS:U:q", options
, NULL
)) >= 0)
207 arg_no_legend
= true;
212 log_error("cannot set output more than once");
216 arg_output
= fopen(optarg
, "we");
218 return log_error_errno(errno
, "writing to '%s': %m", optarg
);
223 r
= parse_timestamp(optarg
, &arg_since
);
225 return log_error_errno(r
, "Failed to parse timestamp: %s", optarg
);
229 r
= parse_timestamp(optarg
, &arg_until
);
231 return log_error_errno(r
, "Failed to parse timestamp: %s", optarg
);
236 log_error("cannot use --field/-F more than once");
247 arg_directory
= optarg
;
262 assert_not_reached("Unhandled option");
265 if (arg_since
!= USEC_INFINITY
&& arg_until
!= USEC_INFINITY
&&
266 arg_since
> arg_until
) {
267 log_error("--since= must be before --until=.");
274 static int retrieve(const void *data
,
282 ident
= strlen(name
) + 1; /* name + "=" */
287 if (memcmp(data
, name
, ident
- 1) != 0)
290 if (((const char*) data
)[ident
- 1] != '=')
293 v
= strndup((const char*)data
+ ident
, len
- ident
);
303 static int print_field(FILE* file
, sd_journal
*j
) {
312 /* A (user-specified) field may appear more than once for a given entry.
313 * We will print all of the occurences.
314 * This is different below for fields that systemd-coredump uses,
315 * because they cannot meaningfully appear more than once.
317 SD_JOURNAL_FOREACH_DATA(j
, d
, l
) {
318 _cleanup_free_
char *value
= NULL
;
321 r
= retrieve(d
, l
, arg_field
, &value
);
325 fprintf(file
, "%s\n", value
);
331 #define RETRIEVE(d, l, name, arg) \
333 int _r = retrieve(d, l, name, &arg); \
340 static int print_list(FILE* file
, sd_journal
*j
, int had_legend
) {
342 *mid
= NULL
, *pid
= NULL
, *uid
= NULL
, *gid
= NULL
,
343 *sgnl
= NULL
, *exe
= NULL
, *comm
= NULL
, *cmdline
= NULL
,
344 *filename
= NULL
, *truncated
= NULL
, *coredump
= NULL
;
348 char buf
[FORMAT_TIMESTAMP_MAX
];
351 bool normal_coredump
;
356 SD_JOURNAL_FOREACH_DATA(j
, d
, l
) {
357 RETRIEVE(d
, l
, "MESSAGE_ID", mid
);
358 RETRIEVE(d
, l
, "COREDUMP_PID", pid
);
359 RETRIEVE(d
, l
, "COREDUMP_UID", uid
);
360 RETRIEVE(d
, l
, "COREDUMP_GID", gid
);
361 RETRIEVE(d
, l
, "COREDUMP_SIGNAL", sgnl
);
362 RETRIEVE(d
, l
, "COREDUMP_EXE", exe
);
363 RETRIEVE(d
, l
, "COREDUMP_COMM", comm
);
364 RETRIEVE(d
, l
, "COREDUMP_CMDLINE", cmdline
);
365 RETRIEVE(d
, l
, "COREDUMP_FILENAME", filename
);
366 RETRIEVE(d
, l
, "COREDUMP_TRUNCATED", truncated
);
367 RETRIEVE(d
, l
, "COREDUMP", coredump
);
370 if (!pid
&& !uid
&& !gid
&& !sgnl
&& !exe
&& !comm
&& !cmdline
&& !filename
) {
371 log_warning("Empty coredump log entry");
375 r
= sd_journal_get_realtime_usec(j
, &t
);
377 return log_error_errno(r
, "Failed to get realtime timestamp: %m");
379 format_timestamp(buf
, sizeof(buf
), t
);
381 if (!had_legend
&& !arg_no_legend
)
382 fprintf(file
, "%-*s %*s %*s %*s %*s %-*s %s\n",
383 FORMAT_TIMESTAMP_WIDTH
, "TIME",
391 normal_coredump
= streq_ptr(mid
, SD_MESSAGE_COREDUMP_STR
);
394 if (access(filename
, R_OK
) == 0)
396 else if (errno
== ENOENT
)
402 else if (normal_coredump
)
407 if (STR_IN_SET(present
, "present", "journal") && truncated
&& parse_boolean(truncated
) > 0)
408 present
= "truncated";
410 fprintf(file
, "%-*s %*s %*s %*s %*s %-*s %s\n",
411 FORMAT_TIMESTAMP_WIDTH
, buf
,
415 3, normal_coredump
? strna(sgnl
) : "-",
417 strna(exe
?: (comm
?: cmdline
)));
422 static int print_info(FILE *file
, sd_journal
*j
, bool need_space
) {
424 *mid
= NULL
, *pid
= NULL
, *uid
= NULL
, *gid
= NULL
,
425 *sgnl
= NULL
, *exe
= NULL
, *comm
= NULL
, *cmdline
= NULL
,
426 *unit
= NULL
, *user_unit
= NULL
, *session
= NULL
,
427 *boot_id
= NULL
, *machine_id
= NULL
, *hostname
= NULL
,
428 *slice
= NULL
, *cgroup
= NULL
, *owner_uid
= NULL
,
429 *message
= NULL
, *timestamp
= NULL
, *filename
= NULL
,
430 *truncated
= NULL
, *coredump
= NULL
;
433 bool normal_coredump
;
439 SD_JOURNAL_FOREACH_DATA(j
, d
, l
) {
440 RETRIEVE(d
, l
, "MESSAGE_ID", mid
);
441 RETRIEVE(d
, l
, "COREDUMP_PID", pid
);
442 RETRIEVE(d
, l
, "COREDUMP_UID", uid
);
443 RETRIEVE(d
, l
, "COREDUMP_GID", gid
);
444 RETRIEVE(d
, l
, "COREDUMP_SIGNAL", sgnl
);
445 RETRIEVE(d
, l
, "COREDUMP_EXE", exe
);
446 RETRIEVE(d
, l
, "COREDUMP_COMM", comm
);
447 RETRIEVE(d
, l
, "COREDUMP_CMDLINE", cmdline
);
448 RETRIEVE(d
, l
, "COREDUMP_UNIT", unit
);
449 RETRIEVE(d
, l
, "COREDUMP_USER_UNIT", user_unit
);
450 RETRIEVE(d
, l
, "COREDUMP_SESSION", session
);
451 RETRIEVE(d
, l
, "COREDUMP_OWNER_UID", owner_uid
);
452 RETRIEVE(d
, l
, "COREDUMP_SLICE", slice
);
453 RETRIEVE(d
, l
, "COREDUMP_CGROUP", cgroup
);
454 RETRIEVE(d
, l
, "COREDUMP_TIMESTAMP", timestamp
);
455 RETRIEVE(d
, l
, "COREDUMP_FILENAME", filename
);
456 RETRIEVE(d
, l
, "COREDUMP_TRUNCATED", truncated
);
457 RETRIEVE(d
, l
, "COREDUMP", coredump
);
458 RETRIEVE(d
, l
, "_BOOT_ID", boot_id
);
459 RETRIEVE(d
, l
, "_MACHINE_ID", machine_id
);
460 RETRIEVE(d
, l
, "_HOSTNAME", hostname
);
461 RETRIEVE(d
, l
, "MESSAGE", message
);
467 normal_coredump
= streq_ptr(mid
, SD_MESSAGE_COREDUMP_STR
);
471 " PID: %s%s%s (%s)\n",
472 ansi_highlight(), strna(pid
), ansi_normal(), comm
);
476 ansi_highlight(), strna(pid
), ansi_normal());
481 if (parse_uid(uid
, &n
) >= 0) {
482 _cleanup_free_
char *u
= NULL
;
498 if (parse_gid(gid
, &n
) >= 0) {
499 _cleanup_free_
char *g
= NULL
;
514 const char *name
= normal_coredump
? "Signal" : "Reason";
516 if (normal_coredump
&& safe_atoi(sgnl
, &sig
) >= 0)
517 fprintf(file
, " %s: %s (%s)\n", name
, sgnl
, signal_to_string(sig
));
519 fprintf(file
, " %s: %s\n", name
, sgnl
);
525 r
= safe_atou64(timestamp
, &u
);
527 char absolute
[FORMAT_TIMESTAMP_MAX
], relative
[FORMAT_TIMESPAN_MAX
];
530 " Timestamp: %s (%s)\n",
531 format_timestamp(absolute
, sizeof(absolute
), u
),
532 format_timestamp_relative(relative
, sizeof(relative
), u
));
535 fprintf(file
, " Timestamp: %s\n", timestamp
);
539 fprintf(file
, " Command Line: %s\n", cmdline
);
541 fprintf(file
, " Executable: %s%s%s\n", ansi_highlight(), exe
, ansi_normal());
543 fprintf(file
, " Control Group: %s\n", cgroup
);
545 fprintf(file
, " Unit: %s\n", unit
);
547 fprintf(file
, " User Unit: %s\n", user_unit
);
549 fprintf(file
, " Slice: %s\n", slice
);
551 fprintf(file
, " Session: %s\n", session
);
555 if (parse_uid(owner_uid
, &n
) >= 0) {
556 _cleanup_free_
char *u
= NULL
;
560 " Owner UID: %s (%s)\n",
569 fprintf(file
, " Boot ID: %s\n", boot_id
);
571 fprintf(file
, " Machine ID: %s\n", machine_id
);
573 fprintf(file
, " Hostname: %s\n", hostname
);
578 inacc
= access(filename
, R_OK
) < 0;
579 trunc
= truncated
&& parse_boolean(truncated
) > 0;
582 fprintf(file
, " Storage: %s%s (%s%s%s)%s\n",
583 ansi_highlight_red(),
585 inacc
? "inaccessible" : "",
586 inacc
&& trunc
? ", " : "",
587 trunc
? "truncated" : "",
590 fprintf(file
, " Storage: %s\n", filename
);
594 fprintf(file
, " Storage: journal\n");
596 fprintf(file
, " Storage: none\n");
599 _cleanup_free_
char *m
= NULL
;
601 m
= strreplace(message
, "\n", "\n ");
603 fprintf(file
, " Message: %s\n", strstrip(m
?: message
));
609 static int focus(sd_journal
*j
) {
612 r
= sd_journal_seek_tail(j
);
614 r
= sd_journal_previous(j
);
616 return log_error_errno(r
, "Failed to search journal: %m");
618 log_error("No match found.");
624 static int print_entry(sd_journal
*j
, unsigned n_found
, bool verb_is_info
) {
628 return print_info(stdout
, j
, n_found
);
630 return print_field(stdout
, j
);
632 return print_list(stdout
, j
, n_found
);
635 static int dump_list(int argc
, char **argv
, void *userdata
) {
636 _cleanup_(sd_journal_closep
) sd_journal
*j
= NULL
;
637 unsigned n_found
= 0;
641 verb_is_info
= (argc
>= 1 && streq(argv
[0], "info"));
643 r
= acquire_journal(&j
, argv
+ 1);
647 (void) pager_open(arg_no_pager
, false);
649 /* The coredumps are likely to compressed, and for just
650 * listing them we don't need to decompress them, so let's
651 * pick a fairly low data threshold here */
652 sd_journal_set_data_threshold(j
, 4096);
659 return print_entry(j
, 0, verb_is_info
);
661 if (arg_since
!= USEC_INFINITY
&& !arg_reverse
)
662 r
= sd_journal_seek_realtime_usec(j
, arg_since
);
663 else if (arg_until
!= USEC_INFINITY
&& arg_reverse
)
664 r
= sd_journal_seek_realtime_usec(j
, arg_until
);
665 else if (arg_reverse
)
666 r
= sd_journal_seek_tail(j
);
668 r
= sd_journal_seek_head(j
);
670 return log_error_errno(r
, "Failed to seek to date: %m");
674 r
= sd_journal_next(j
);
676 r
= sd_journal_previous(j
);
679 return log_error_errno(r
, "Failed to iterate through journal: %m");
684 if (arg_until
!= USEC_INFINITY
&& !arg_reverse
) {
687 r
= sd_journal_get_realtime_usec(j
, &usec
);
689 return log_error_errno(r
, "Failed to determine timestamp: %m");
690 if (usec
> arg_until
)
694 if (arg_since
!= USEC_INFINITY
&& arg_reverse
) {
697 r
= sd_journal_get_realtime_usec(j
, &usec
);
699 return log_error_errno(r
, "Failed to determine timestamp: %m");
700 if (usec
< arg_since
)
704 r
= print_entry(j
, n_found
++, verb_is_info
);
709 if (!arg_field
&& n_found
<= 0) {
711 log_notice("No coredumps found.");
719 static int save_core(sd_journal
*j
, FILE *file
, char **path
, bool *unlink_temp
) {
721 _cleanup_free_
char *filename
= NULL
;
724 _cleanup_close_
int fdt
= -1;
727 assert(!(file
&& path
)); /* At most one can be specified */
728 assert(!!path
== !!unlink_temp
); /* Those must be specified together */
730 /* Look for a coredump on disk first. */
731 r
= sd_journal_get_data(j
, "COREDUMP_FILENAME", (const void**) &data
, &len
);
733 retrieve(data
, len
, "COREDUMP_FILENAME", &filename
);
736 return log_error_errno(r
, "Failed to retrieve COREDUMP_FILENAME field: %m");
737 /* Check that we can have a COREDUMP field. We still haven't set a high
738 * data threshold, so we'll get a few kilobytes at most.
741 r
= sd_journal_get_data(j
, "COREDUMP", (const void**) &data
, &len
);
743 return log_error_errno(r
, "Coredump entry has no core attached (neither internally in the journal nor externally on disk).");
745 return log_error_errno(r
, "Failed to retrieve COREDUMP field: %m");
749 if (access(filename
, R_OK
) < 0)
750 return log_error_errno(errno
, "File \"%s\" is not readable: %m", filename
);
752 if (path
&& !endswith(filename
, ".xz") && !endswith(filename
, ".lz4")) {
753 *path
= TAKE_PTR(filename
);
762 /* Create a temporary file to write the uncompressed core to. */
764 r
= var_tmp_dir(&vt
);
766 return log_error_errno(r
, "Failed to acquire temporary directory path: %m");
768 temp
= strjoin(vt
, "/coredump-XXXXXX");
772 fdt
= mkostemp_safe(temp
);
774 return log_error_errno(fdt
, "Failed to create temporary file: %m");
775 log_debug("Created temporary file %s", temp
);
779 /* If neither path or file are specified, we will write to stdout. Let's now check
780 * if stdout is connected to a tty. We checked that the file exists, or that the
781 * core might be stored in the journal. In this second case, if we found the entry,
782 * in all likelyhood we will be able to access the COREDUMP= field. In either case,
783 * we stop before doing any "real" work, i.e. before starting decompression or
784 * reading from the file or creating temporary files.
788 return log_error_errno(ENOTTY
, "Refusing to dump core to tty"
789 " (use shell redirection or specify --output).");
797 #if HAVE_XZ || HAVE_LZ4
798 _cleanup_close_
int fdf
;
800 fdf
= open(filename
, O_RDONLY
| O_CLOEXEC
);
802 r
= log_error_errno(errno
, "Failed to open %s: %m", filename
);
806 r
= decompress_stream(filename
, fdf
, fd
, -1);
808 log_error_errno(r
, "Failed to decompress %s: %m", filename
);
812 log_error("Cannot decompress file. Compiled without compression support.");
819 /* We want full data, nothing truncated. */
820 sd_journal_set_data_threshold(j
, 0);
822 r
= sd_journal_get_data(j
, "COREDUMP", (const void**) &data
, &len
);
824 return log_error_errno(r
, "Failed to retrieve COREDUMP field: %m");
830 sz
= write(fd
, data
, len
);
832 r
= log_error_errno(errno
, "Failed to write output: %m");
835 if (sz
!= (ssize_t
) len
) {
836 log_error("Short write to output.");
851 log_debug("Removed temporary file %s", temp
);
856 static int dump_core(int argc
, char **argv
, void *userdata
) {
857 _cleanup_(sd_journal_closep
) sd_journal
*j
= NULL
;
861 log_error("Option --field/-F only makes sense with list");
865 r
= acquire_journal(&j
, argv
+ 1);
873 print_info(arg_output
? stdout
: stderr
, j
, false);
875 r
= save_core(j
, arg_output
, NULL
, NULL
);
879 r
= sd_journal_previous(j
);
880 if (r
> 0 && !arg_quiet
)
881 log_notice("More than one entry matches, ignoring rest.");
886 static int run_gdb(int argc
, char **argv
, void *userdata
) {
887 _cleanup_(sd_journal_closep
) sd_journal
*j
= NULL
;
888 _cleanup_free_
char *exe
= NULL
, *path
= NULL
;
889 bool unlink_path
= false;
896 log_error("Option --field/-F only makes sense with list");
900 r
= acquire_journal(&j
, argv
+ 1);
908 print_info(stdout
, j
, false);
911 r
= sd_journal_get_data(j
, "COREDUMP_EXE", (const void**) &data
, &len
);
913 return log_error_errno(r
, "Failed to retrieve COREDUMP_EXE field: %m");
915 assert(len
> STRLEN("COREDUMP_EXE="));
916 data
+= STRLEN("COREDUMP_EXE=");
917 len
-= STRLEN("COREDUMP_EXE=");
919 exe
= strndup(data
, len
);
923 if (endswith(exe
, " (deleted)")) {
924 log_error("Binary already deleted.");
928 if (!path_is_absolute(exe
)) {
929 log_error("Binary is not an absolute path.");
933 r
= save_core(j
, NULL
, &path
, &unlink_path
);
937 /* Don't interfere with gdb and its handling of SIGINT. */
938 (void) ignore_signals(SIGINT
, -1);
940 r
= safe_fork("(gdb)", FORK_RESET_SIGNALS
|FORK_DEATHSIG
|FORK_CLOSE_ALL_FDS
|FORK_LOG
, &pid
);
944 execlp("gdb", "gdb", exe
, path
, NULL
);
946 log_error_errno(errno
, "Failed to invoke gdb: %m");
950 r
= wait_for_terminate_and_check("gdb", pid
, WAIT_LOG_ABNORMAL
);
953 (void) default_signals(SIGINT
, -1);
956 log_debug("Removed temporary file %s", path
);
963 static int check_units_active(void) {
964 _cleanup_(sd_bus_unrefp
) sd_bus
*bus
= NULL
;
965 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
966 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
967 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
969 const char *id
, *state
, *substate
;
974 r
= sd_bus_default_system(&bus
);
976 return log_error_errno(r
, "Failed to acquire bus: %m");
978 r
= sd_bus_message_new_method_call(
981 "org.freedesktop.systemd1",
982 "/org/freedesktop/systemd1",
983 "org.freedesktop.systemd1.Manager",
984 "ListUnitsByPatterns");
986 return bus_log_create_error(r
);
988 r
= sd_bus_message_append_strv(m
, NULL
);
990 return bus_log_create_error(r
);
992 r
= sd_bus_message_append_strv(m
, STRV_MAKE("systemd-coredump@*.service"));
994 return bus_log_create_error(r
);
996 r
= sd_bus_call(bus
, m
, SHORT_BUS_CALL_TIMEOUT_USEC
, &error
, &reply
);
998 return log_error_errno(r
, "Failed to check if any systemd-coredump@.service units are running: %s",
999 bus_error_message(&error
, r
));
1001 r
= sd_bus_message_enter_container(reply
, SD_BUS_TYPE_ARRAY
, "(ssssssouso)");
1003 return bus_log_parse_error(r
);
1005 while ((r
= sd_bus_message_read(
1006 reply
, "(ssssssouso)",
1007 &id
, NULL
, NULL
, &state
, &substate
,
1008 NULL
, NULL
, NULL
, NULL
, NULL
)) > 0) {
1009 bool found
= !STR_IN_SET(state
, "inactive", "dead", "failed");
1010 log_debug("Unit %s is %s/%s, %scounting it.", id
, state
, substate
, found
? "" : "not ");
1014 return bus_log_parse_error(r
);
1016 r
= sd_bus_message_exit_container(reply
);
1018 return bus_log_parse_error(r
);
1023 static int coredumpctl_main(int argc
, char *argv
[]) {
1025 static const Verb verbs
[] = {
1026 { "list", VERB_ANY
, VERB_ANY
, VERB_DEFAULT
, dump_list
},
1027 { "info", VERB_ANY
, VERB_ANY
, 0, dump_list
},
1028 { "dump", VERB_ANY
, VERB_ANY
, 0, dump_core
},
1029 { "gdb", VERB_ANY
, VERB_ANY
, 0, run_gdb
},
1033 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1036 int main(int argc
, char *argv
[]) {
1037 int r
, units_active
;
1039 setlocale(LC_ALL
, "");
1040 log_parse_environment();
1043 r
= parse_argv(argc
, argv
);
1049 units_active
= check_units_active(); /* error is treated the same as 0 */
1051 r
= coredumpctl_main(argc
, argv
);
1053 if (units_active
> 0)
1054 printf("%s-- Notice: %d systemd-coredump@.service %s, output may be incomplete.%s\n",
1055 ansi_highlight_red(),
1056 units_active
, units_active
== 1 ? "unit is running" : "units are running",
1061 safe_fclose(arg_output
);
1063 return r
>= 0 ? r
: EXIT_FAILURE
;