From f10425e0530e64b73c994e68bdf4829e4a173ff4 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 22 Apr 2021 17:57:49 -0700 Subject: [PATCH] criu: end pr_(err|warn|msg|info|debug) with \n Unlike pr_perror, pr_err and other macros do not append \n to the message being printed, so the caller needs to take care of it. Sometimes it was not done, so let's add this manually. To make sure it won't happen again, add a line to Makefile under the linter target to check for such missing \n. NOTE this check is only done for part of such cases (where the pr_* statement fits in one line and there's no comment after), but it's better than nothing. Add comments after pr_msg and pr_info statements where we deliberately don't add \n, so that the above check ignores them. Signed-off-by: Kir Kolyshkin --- Makefile | 2 ++ criu/config.c | 6 +++--- criu/cr-check.c | 4 ++-- criu/cr-restore.c | 2 +- criu/crtools.c | 2 +- criu/files-reg.c | 2 +- criu/ipc_ns.c | 2 +- criu/kerndat.c | 2 +- criu/net.c | 2 +- criu/sk-unix.c | 4 ++-- 10 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4b13a8d42..572a21d1a 100644 --- a/Makefile +++ b/Makefile @@ -411,6 +411,8 @@ lint: ! git --no-pager grep -E '^\s*\<(pr_perror|fail)\>.*%m' # Do not use errno with pr_perror or fail ! git --no-pager grep -E '^\s*\<(pr_perror|fail)\>\(".*".*errno' + # End pr_(err|warn|msg|info|debug) with \n + ! git --no-pager grep -En '^\s*\.*);$$' | grep -v '\\n' # No EOL whitespace for C files ! git --no-pager grep -E '\s+$$' \*.c \*.h .PHONY: lint diff --git a/criu/config.c b/criu/config.c index 08606fb33..36be023f7 100644 --- a/criu/config.c +++ b/criu/config.c @@ -187,7 +187,7 @@ static int next_config(char **argv, char ***_argv, bool no_default_config, break; home_dir = getenv("HOME"); if (!home_dir) { - pr_info("Unable to get $HOME directory, local configuration file will not be used."); + pr_info("Unable to get $HOME directory, local configuration file will not be used.\n"); } else { snprintf(local_filepath, PATH_MAX, "%s/%s%s", home_dir, USER_CONFIG_DIR, DEFAULT_CONFIG_FILENAME); @@ -755,7 +755,7 @@ int parse_options(int argc, char **argv, bool *usage_error, break; case 1065: if (!add_fsname_auto(optarg)) { - pr_err("Failed while parsing --enable-fs option: %s", optarg); + pr_err("Failed while parsing --enable-fs option: %s\n", optarg); return 1; } break; @@ -767,7 +767,7 @@ int parse_options(int argc, char **argv, bool *usage_error, break; case 1070: if (irmap_scan_path_add(optarg)) { - pr_err("Failed while parsing --irmap-scan-path option: %s", optarg); + pr_err("Failed while parsing --irmap-scan-path option: %s\n", optarg); return -1; } break; diff --git a/criu/cr-check.c b/criu/cr-check.c index 2fdc4408a..f095d59b0 100644 --- a/criu/cr-check.c +++ b/criu/cr-check.c @@ -1528,10 +1528,10 @@ void pr_check_features(const char *offset, const char *sep, int width) pr_msg("\n%s", offset); pos = offset_len; } - pr_msg("%s", fl->name); + pr_msg("%s", fl->name); // no \n pos += len; if ((fl + 1)->name) { // not the last item - pr_msg("%s", sep); + pr_msg("%s", sep); // no \n pos += sep_len; } } diff --git a/criu/cr-restore.c b/criu/cr-restore.c index 53cae3509..0d85db6ce 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -1462,7 +1462,7 @@ static inline int fork_with_pid(struct pstree_item *item) ret = set_next_pid((void *)&pid); } if (ret != 0) { - pr_err("Setting PID failed"); + pr_err("Setting PID failed\n"); goto err_unlock; } } diff --git a/criu/crtools.c b/criu/crtools.c index 47b01af44..c78570e58 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -174,7 +174,7 @@ int main(int argc, char *argv[], char *envp[]) if (strcmp(argv[optind], "service")) { ret = open_image_dir(opts.imgs_dir, image_dir_mode(argv, optind)); if (ret < 0) { - pr_err("Couldn't open image dir: %s", opts.imgs_dir); + pr_err("Couldn't open image dir %s\n", opts.imgs_dir); return 1; } } diff --git a/criu/files-reg.c b/criu/files-reg.c index 7d42d435e..d0a6fae60 100644 --- a/criu/files-reg.c +++ b/criu/files-reg.c @@ -1536,7 +1536,7 @@ static int get_build_id(const int fd, const struct stat *fd_status, mapped_size = min_t(size_t, fd_status->st_size, BUILD_ID_MAP_SIZE); start_addr = mmap(0, mapped_size, PROT_READ, MAP_PRIVATE | MAP_FILE, fd, 0); if (start_addr == MAP_FAILED) { - pr_warn("Couldn't mmap file with fd %d", fd); + pr_warn("Couldn't mmap file with fd %d\n", fd); return -1; } diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c index e7049599f..1c8de41a8 100644 --- a/criu/ipc_ns.c +++ b/criu/ipc_ns.c @@ -58,7 +58,7 @@ static void fill_ipc_desc(int id, IpcDescEntry *desc, const struct ipc_perm *ipc static void pr_ipc_sem_array(int nr, u16 *values) { while (nr--) - pr_info(" %-5d", values[nr]); + pr_info(" %-5d", values[nr]); // no \n pr_info("\n"); } diff --git a/criu/kerndat.c b/criu/kerndat.c index 2327a8e25..a559756f8 100644 --- a/criu/kerndat.c +++ b/criu/kerndat.c @@ -54,7 +54,7 @@ static int check_pagemap(void) fd = __open_proc(PROC_SELF, EPERM, O_RDONLY, "pagemap"); if (fd < 0) { if (errno == EPERM) { - pr_info("Pagemap disabled"); + pr_info("Pagemap disabled\n"); kdat.pmap = PM_DISABLED; return 0; } diff --git a/criu/net.c b/criu/net.c index f6b6c8c09..38dc73ea1 100644 --- a/criu/net.c +++ b/criu/net.c @@ -2428,7 +2428,7 @@ static inline int restore_nftables(int pid) return -1; if (empty_image(img)) { /* Backward compatibility */ - pr_info("Skipping nft restore, no image"); + pr_info("Skipping nft restore, no image\n"); ret = 0; goto image_close_out; } diff --git a/criu/sk-unix.c b/criu/sk-unix.c index e589da8de..d628e32cb 100644 --- a/criu/sk-unix.c +++ b/criu/sk-unix.c @@ -665,7 +665,7 @@ static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, fd = ioctl(lfd, SIOCUNIXFILE); if (fd < 0) { - pr_warn("Unable to get a socket file descriptor with SIOCUNIXFILE ioctl."); + pr_warn("Unable to get a socket file descriptor with SIOCUNIXFILE ioctl: %m\n"); goto fallback; } @@ -716,7 +716,7 @@ out: return ret; fallback: - pr_warn("Trying to resolve unix socket with obsolete method"); + pr_warn("Trying to resolve unix socket with obsolete method\n"); ret = unix_resolve_name_old(lfd, id, d, ue, p); if (ret < 0) pr_err("Unable to resolve unix socket name with obsolete method. Try a linux kernel newer than 4.10\n");