From 1ae9bac5488adcb55c4c589e3c3892ac6e6430ca Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Mon, 27 Feb 2023 12:14:21 +0800 Subject: [PATCH] dump: improve error printing and readability of task_comm_info This addresses Andrei comments from https://github.com/checkpoint-restore/criu/pull/2064 - Add comment about '\n' fixing - Replace ret with more self explainting is_read - Print warings if we failed to print comm for some reason Signed-off-by: Pavel Tikhomirov --- criu/seize.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/criu/seize.c b/criu/seize.c index 0758410e52..91090ae1a7 100644 --- a/criu/seize.c +++ b/criu/seize.c @@ -26,7 +26,7 @@ char *task_comm_info(pid_t pid, char *comm, size_t size) { - int ret = 0; + bool is_read = false; if (!pr_quelled(LOG_INFO)) { int saved_errno = errno; @@ -37,18 +37,21 @@ char *task_comm_info(pid_t pid, char *comm, size_t size) fd = open(path, O_RDONLY); if (fd >= 0) { ssize_t n = read(fd, comm, size); - if (n > 0) + if (n > 0) { + is_read = true; + /* Replace '\n' printed by kernel with '\0' */ comm[n - 1] = '\0'; - else - ret = -1; + } else { + pr_warn("Failed to read %s: %s\n", path, strerror(errno)); + } close(fd); } else { - ret = -1; + pr_warn("Failed to open %s: %s\n", path, strerror(errno)); } errno = saved_errno; } - if (ret || (pr_quelled(LOG_INFO) && comm[0])) + if (!is_read) comm[0] = '\0'; return comm;