char *tmp;
int r;
- set = set_new(trivial_hash_func, trivial_compare_func);
+ set = set_new(NULL);
if (!set) {
log_oom();
return NULL;
r = set_consume(set, tmp);
if (r < 0) {
- log_error("failed to add to set: %s", strerror(-r));
+ log_error_errno(r, "failed to add to set: %m");
set_free(set);
return NULL;
}
log_debug("Adding pattern: %s", pattern);
r = set_consume(set, pattern);
if (r < 0) {
- log_error("Failed to add pattern '%s': %s",
- pattern, strerror(-r));
+ log_error_errno(r, "Failed to add pattern: %m");
goto fail;
}
return 0;
fail:
- log_error("Failed to add match: %s", strerror(-r));
- return r;
+ return log_error_errno(r, "Failed to add match: %m");
}
static void help(void) {
}
output = fopen(optarg, "we");
- if (!output) {
- log_error("writing to '%s': %m", optarg);
- return -errno;
- }
+ if (!output)
+ return log_error_errno(errno, "writing to '%s': %m", optarg);
break;
}
r = sd_journal_get_realtime_usec(j, &t);
- if (r < 0) {
- log_error("Failed to get realtime timestamp: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get realtime timestamp: %m");
format_timestamp(buf, sizeof(buf), t);
present = filename && access(filename, F_OK) == 0;
r = sd_journal_seek_tail(j);
if (r == 0)
r = sd_journal_previous(j);
- if (r < 0) {
- log_error("Failed to search journal: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to search journal: %m");
if (r == 0) {
log_error("No match found.");
return -ESRCH;
* compressed file (probably uncached). */
r = sd_journal_get_data(j, "COREDUMP_FILENAME", (const void**) &data, &len);
if (r < 0 && r != -ENOENT)
- log_warning("Failed to retrieve COREDUMP_FILENAME: %s", strerror(-r));
+ log_warning_errno(r, "Failed to retrieve COREDUMP_FILENAME: %m");
else if (r == 0)
retrieve(data, len, "COREDUMP_FILENAME", &filename);
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;
}
r = decompress_stream(filename, fdf, fd, -1);
if (r < 0) {
- log_error("Failed to decompress %s: %s", filename, strerror(-r));
+ log_error_errno(r, "Failed to decompress %s: %m", filename);
goto error;
}
#else
if (r == -ENOENT)
log_error("Cannot retrieve coredump from journal nor disk.");
else
- log_error("Failed to retrieve COREDUMP field: %s", strerror(-r));
+ log_error_errno(r, "Failed to retrieve COREDUMP field: %m");
goto error;
}
}
r = save_core(j, output ? fileno(output) : STDOUT_FILENO, NULL, NULL);
- if (r < 0) {
- log_error("Coredump retrieval failed: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Coredump retrieval failed: %m");
r = sd_journal_previous(j);
if (r >= 0)
fputs("\n", stdout);
r = sd_journal_get_data(j, "COREDUMP_EXE", (const void**) &data, &len);
- if (r < 0) {
- log_error("Failed to retrieve COREDUMP_EXE field: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to retrieve COREDUMP_EXE field: %m");
assert(len > strlen("COREDUMP_EXE="));
data += strlen("COREDUMP_EXE=");
}
r = save_core(j, -1, &path, &unlink_path);
- if (r < 0) {
- log_error("Failed to retrieve core: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to retrieve core: %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;
}
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
if (r < 0) {
- log_error("Failed to open journal: %s", strerror(-r));
+ log_error_errno(r, "Failed to open journal: %m");
goto end;
}
SET_FOREACH(match, matches, it) {
r = sd_journal_add_match(j, match, strlen(match));
if (r != 0) {
- log_error("Failed to add match '%s': %s",
- match, strerror(-r));
+ log_error_errno(r, "Failed to add match '%s': %m",
+ match);
goto end;
}
}