mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 13:28:27 +00:00
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 <ptikhomirov@virtuozzo.com>
This commit is contained in:
parent
11c71656bd
commit
1ae9bac548
15
criu/seize.c
15
criu/seize.c
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
char *task_comm_info(pid_t pid, char *comm, size_t size)
|
char *task_comm_info(pid_t pid, char *comm, size_t size)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
bool is_read = false;
|
||||||
|
|
||||||
if (!pr_quelled(LOG_INFO)) {
|
if (!pr_quelled(LOG_INFO)) {
|
||||||
int saved_errno = errno;
|
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);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
ssize_t n = read(fd, comm, size);
|
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';
|
comm[n - 1] = '\0';
|
||||||
else
|
} else {
|
||||||
ret = -1;
|
pr_warn("Failed to read %s: %s\n", path, strerror(errno));
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
ret = -1;
|
pr_warn("Failed to open %s: %s\n", path, strerror(errno));
|
||||||
}
|
}
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret || (pr_quelled(LOG_INFO) && comm[0]))
|
if (!is_read)
|
||||||
comm[0] = '\0';
|
comm[0] = '\0';
|
||||||
|
|
||||||
return comm;
|
return comm;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user