diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 23:40:44 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-22 10:54:38 +0100 |
commit | baaa35ad706419ae5aacc11d2bece5bd8b73ee42 (patch) | |
tree | bb4b9c576fc56b3237d59e959ded7c245917fcd7 /src/coredump | |
parent | 52d86690d68779b120a4380f7cc740825827fb0d (diff) | |
download | systemd-baaa35ad706419ae5aacc11d2bece5bd8b73ee42.tar.gz |
coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.
I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
Diffstat (limited to 'src/coredump')
-rw-r--r-- | src/coredump/coredump.c | 40 | ||||
-rw-r--r-- | src/coredump/coredumpctl.c | 28 |
2 files changed, 31 insertions, 37 deletions
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 243a880542..8c2cf7daa6 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -351,16 +351,15 @@ static int save_external_coredump( /* Is coredumping disabled? Then don't bother saving/processing the coredump. * Anything below PAGE_SIZE cannot give a readable coredump (the kernel uses * ELF_EXEC_PAGESIZE which is not easily accessible, but is usually the same as PAGE_SIZE. */ - log_info("Resource limits disable core dumping for process %s (%s).", - context[CONTEXT_PID], context[CONTEXT_COMM]); - return -EBADSLT; + return log_info_errno(SYNTHETIC_ERRNO(EBADSLT), + "Resource limits disable core dumping for process %s (%s).", + context[CONTEXT_PID], context[CONTEXT_COMM]); } process_limit = MAX(arg_process_size_max, storage_size_max()); - if (process_limit == 0) { - log_debug("Limits for coredump processing and storage are both 0, not dumping core."); - return -EBADSLT; - } + if (process_limit == 0) + return log_debug_errno(SYNTHETIC_ERRNO(EBADSLT), + "Limits for coredump processing and storage are both 0, not dumping core."); /* Never store more than the process configured, or than we actually shall keep or process */ max_size = MIN(rlimit, process_limit); @@ -484,10 +483,9 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s n = read(fd, field + 9, size); if (n < 0) return log_error_errno((int) n, "Failed to read core data: %m"); - if ((size_t) n < size) { - log_error("Core data too short."); - return -EIO; - } + if ((size_t) n < size) + return log_error_errno(SYNTHETIC_ERRNO(EIO), + "Core data too short."); *ret = TAKE_PTR(field); *ret_size = size + 9; @@ -1236,10 +1234,10 @@ static int process_kernel(int argc, char* argv[]) { log_debug("Processing coredump received from the kernel..."); - if (argc < CONTEXT_COMM + 1) { - log_error("Not enough arguments passed by the kernel (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1); - return -EINVAL; - } + if (argc < CONTEXT_COMM + 1) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Not enough arguments passed by the kernel (%i, expected %i).", + argc - 1, CONTEXT_COMM + 1 - 1); context[CONTEXT_PID] = argv[1 + CONTEXT_PID]; context[CONTEXT_UID] = argv[1 + CONTEXT_UID]; @@ -1293,10 +1291,10 @@ static int process_backtrace(int argc, char *argv[]) { log_debug("Processing backtrace on stdin..."); - if (argc < CONTEXT_COMM + 1) { - log_error("Not enough arguments passed (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1); - return -EINVAL; - } + if (argc < CONTEXT_COMM + 1) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Not enough arguments passed (%i, expected %i).", + argc - 1, CONTEXT_COMM + 1 - 1); context[CONTEXT_PID] = argv[2 + CONTEXT_PID]; context[CONTEXT_UID] = argv[2 + CONTEXT_UID]; @@ -1407,8 +1405,8 @@ static int run(int argc, char *argv[]) { } else if (r == 1) return process_socket(SD_LISTEN_FDS_START); - log_error("Received unexpected number of file descriptors."); - return -EINVAL; + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Received unexpected number of file descriptors."); } DEFINE_MAIN_FUNCTION(run); diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 9f867bb1e7..1f85d3deab 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -225,10 +225,9 @@ static int parse_argv(int argc, char *argv[]) { 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; @@ -246,10 +245,9 @@ static int parse_argv(int argc, char *argv[]) { 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; @@ -277,10 +275,9 @@ static int parse_argv(int argc, char *argv[]) { } 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; } @@ -628,10 +625,9 @@ static int focus(sd_journal *j) { 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; } |