#include "compress.h"
#include "def.h"
#include "fd-util.h"
-#include "fileio.h"
#include "fs-util.h"
#include "journal-internal.h"
#include "journal-util.h"
#include "pager.h"
#include "parse-util.h"
#include "path-util.h"
+#include "pretty-print.h"
#include "process-util.h"
#include "rlimit-util.h"
#include "sigbus.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
+#include "tmpfile-util.h"
#include "user-util.h"
#include "util.h"
#include "verbs.h"
break;
case 'o':
- if (arg_output) {
- log_error("Cannot set output more than once.");
- return -EINVAL;
- }
+ if (arg_output)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot set output more than once.");
arg_output = optarg;
break;
break;
case 'F':
- if (arg_field) {
- log_error("Cannot use --field/-F more than once.");
- return -EINVAL;
- }
+ if (arg_field)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Cannot use --field/-F more than once.");
arg_field = optarg;
break;
}
if (arg_since != USEC_INFINITY && arg_until != USEC_INFINITY &&
- arg_since > arg_until) {
- log_error("--since= must be before --until=.");
- return -EINVAL;
- }
+ arg_since > arg_until)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--since= must be before --until=.");
return 1;
}
assert(arg_field);
/* A (user-specified) field may appear more than once for a given entry.
- * We will print all of the occurences.
+ * We will print all of the occurrences.
* This is different below for fields that systemd-coredump uses,
* because they cannot meaningfully appear more than once.
*/
r = sd_journal_previous(j);
if (r < 0)
return log_error_errno(r, "Failed to search journal: %m");
- if (r == 0) {
- log_error("No match found.");
- return -ESRCH;
- }
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
+ "No match found.");
return r;
}
/* If neither path or file are specified, we will write to stdout. Let's now check
* if stdout is connected to a tty. We checked that the file exists, or that the
* core might be stored in the journal. In this second case, if we found the entry,
- * in all likelyhood we will be able to access the COREDUMP= field. In either case,
+ * in all likelihood we will be able to access the COREDUMP= field. In either case,
* we stop before doing any "real" work, i.e. before starting decompression or
* reading from the file or creating temporary files.
*/
if (!file) {
if (on_tty())
- return log_error_errno(ENOTTY, "Refusing to dump core to tty"
+ return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
+ "Refusing to dump core to tty"
" (use shell redirection or specify --output).");
file = stdout;
}
error:
if (temp) {
- unlink(temp);
+ (void) unlink(temp);
log_debug("Removed temporary file %s", temp);
}
return r;
static int run_debug(int argc, char **argv, void *userdata) {
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
- _cleanup_free_ char *exe = NULL, *path = NULL;
+ _cleanup_free_ char *exe = NULL, *path = NULL, *debugger = NULL;
bool unlink_path = false;
const char *data, *fork_name;
size_t len;
arg_debugger = "gdb";
}
+ debugger = strdup(arg_debugger);
+ if (!debugger)
+ return -ENOMEM;
+
if (arg_field) {
log_error("Option --field/-F only makes sense with list");
return -EINVAL;
/* Don't interfere with gdb and its handling of SIGINT. */
(void) ignore_signals(SIGINT, -1);
- fork_name = strjoina("(", arg_debugger, ")");
+ fork_name = strjoina("(", debugger, ")");
- r = safe_fork(fork_name, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_LOG, &pid);
+ r = safe_fork(fork_name, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid);
if (r < 0)
goto finish;
if (r == 0) {
- execlp(arg_debugger, arg_debugger, exe, "-c", path, NULL);
+ execlp(debugger, debugger, exe, "-c", path, NULL);
log_open();
- log_error_errno(errno, "Failed to invoke %s: %m", arg_debugger);
+ log_error_errno(errno, "Failed to invoke %s: %m", debugger);
_exit(EXIT_FAILURE);
}
- r = wait_for_terminate_and_check(arg_debugger, pid, WAIT_LOG_ABNORMAL);
+ r = wait_for_terminate_and_check(debugger, pid, WAIT_LOG_ABNORMAL);
finish:
(void) default_signals(SIGINT, -1);
if (unlink_path) {
log_debug("Removed temporary file %s", path);
- unlink(path);
+ (void) unlink(path);
}
return r;
}
static int check_units_active(void) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r, units_active;
setlocale(LC_ALL, "");
+ log_show_color(true);
log_parse_environment();
log_open();