Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump: improve error printing and readability of task_comm_info #2095

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions criu/seize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down