#include <fcntl.h>
#include <unistd.h>
-#include "systemd/sd-journal.h"
-
+#include "sd-journal.h"
#include "build.h"
#include "set.h"
#include "util.h"
#include "journal-internal.h"
#include "copy.h"
#include "compress.h"
+#include "sigbus.h"
static enum {
ACTION_NONE,
static int arg_no_pager = false;
static int arg_no_legend = false;
static int arg_one = false;
-
-static FILE* output = NULL;
+static FILE* arg_output = NULL;
static Set *new_matches(void) {
Set *set;
break;
case 'o':
- if (output) {
+ if (arg_output) {
log_error("cannot set output more than once");
return -EINVAL;
}
- output = fopen(optarg, "we");
- if (!output) {
- log_error("writing to '%s': %m", optarg);
- return -errno;
- }
+ arg_output = fopen(optarg, "we");
+ if (!arg_output)
+ return log_error_errno(errno, "writing to '%s': %m", optarg);
break;
return log_oom();
fdt = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC);
- if (fdt < 0) {
- log_error("Failed to create temporary file: %m");
- return -errno;
- }
+ if (fdt < 0)
+ return log_error_errno(errno, "Failed to create temporary file: %m");
log_debug("Created temporary file %s", temp);
fd = fdt;
sz = write(fdt, data, len);
if (sz < 0) {
- log_error("Failed to write temporary file: %m");
+ log_error_errno(errno, "Failed to write temporary file: %m");
r = -errno;
goto error;
}
fdf = open(filename, O_RDONLY | O_CLOEXEC);
if (fdf < 0) {
- log_error("Failed to open %s: %m", filename);
+ log_error_errno(errno, "Failed to open %s: %m", filename);
r = -errno;
goto error;
}
if (r < 0)
return r;
- print_info(output ? stdout : stderr, j, false);
+ print_info(arg_output ? stdout : stderr, j, false);
- if (on_tty() && !output) {
+ if (on_tty() && !arg_output) {
log_error("Refusing to dump core to tty.");
return -ENOTTY;
}
- r = save_core(j, output ? fileno(output) : STDOUT_FILENO, NULL, NULL);
+ r = save_core(j, arg_output ? fileno(arg_output) : STDOUT_FILENO, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Coredump retrieval failed: %m");
pid = fork();
if (pid < 0) {
- log_error("Failed to fork(): %m");
+ log_error_errno(errno, "Failed to fork(): %m");
r = -errno;
goto finish;
}
if (pid == 0) {
execlp("gdb", "gdb", exe, path, NULL);
- log_error("Failed to invoke gdb: %m");
+ log_error_errno(errno, "Failed to invoke gdb: %m");
_exit(1);
}
r = wait_for_terminate(pid, &st);
if (r < 0) {
- log_error("Failed to wait for gdb: %m");
+ log_error_errno(errno, "Failed to wait for gdb: %m");
goto finish;
}
if (arg_action == ACTION_NONE)
goto end;
+ sigbus_install();
+
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
if (r < 0) {
log_error_errno(r, "Failed to open journal: %m");
}
}
- if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) {
+ if (_unlikely_(log_get_max_level() >= LOG_DEBUG)) {
_cleanup_free_ char *filter;
filter = journal_make_match_string(j);
end:
pager_close();
- if (output)
- fclose(output);
+ if (arg_output)
+ fclose(arg_output);
return r >= 0 ? r : EXIT_FAILURE;
}