2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00

test/zdtm: pr_err / pr_perror fixes

1. Use pr_perror where errno needs to be shown.

2. Use pr_err in cases where errno is not set
   by the previous failed call.

3. Make sure pr_err's first argument do not have \n.

4. While at it, fix some error messages.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-04-22 17:36:05 -07:00
committed by Andrei Vagin
parent dca0eb5b4a
commit 10c619adb9
25 changed files with 98 additions and 98 deletions

View File

@@ -43,13 +43,13 @@ int tcp_init_server_with_opts(int family, int *port, struct zdtm_tcp_opts *opts)
if (opts->reuseport && if (opts->reuseport &&
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(int)) == -1) { setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(int)) == -1) {
pr_perror(""); pr_perror("setsockopt(SO_REUSEPORT) failed");
return -1; return -1;
} }
if (opts->reuseaddr && if (opts->reuseaddr &&
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) { setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) {
pr_perror("setsockopt() error"); pr_perror("setsockopt(SO_REUSEATTR) failed");
return -1; return -1;
} }

View File

@@ -114,7 +114,7 @@ extern int write_pidfile(int pid);
#define __stringify(x) __stringify_1(x) #define __stringify(x) __stringify_1(x)
/* /*
* Macro to define stack alignment. * Macro to define stack alignment.
* aarch64 requires stack to be aligned to 16 bytes. * aarch64 requires stack to be aligned to 16 bytes.
*/ */
#define __stack_aligned__ __attribute__((aligned(16))) #define __stack_aligned__ __attribute__((aligned(16)))

View File

@@ -437,11 +437,11 @@ static int automountd_serve(const char *mountpoint, struct autofs_params *p,
res = autofs_mount_direct(mountpoint, v5_packet); res = autofs_mount_direct(mountpoint, v5_packet);
break; break;
case autofs_ptype_expire_indirect: case autofs_ptype_expire_indirect:
pr_err("%d: expire request for indirect mount %s?", pr_err("%d: expire request for indirect mount %s?\n",
getpid(), v5_packet->name); getpid(), v5_packet->name);
return -EINVAL; return -EINVAL;
case autofs_ptype_expire_direct: case autofs_ptype_expire_direct:
pr_err("%d: expire request for direct mount?", pr_err("%d: expire request for direct mount?\n",
getpid()); getpid());
return -EINVAL; return -EINVAL;
default: default:
@@ -507,7 +507,7 @@ static int automountd(struct autofs_params *p, int control_fd)
autofs_path = xsprintf("%s/%s", dirname, p->mountpoint); autofs_path = xsprintf("%s/%s", dirname, p->mountpoint);
if (!autofs_path) { if (!autofs_path) {
pr_err("failed to allocate autofs path"); pr_err("failed to allocate autofs path\n");
goto err; goto err;
} }

View File

@@ -97,7 +97,7 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) {
/* skip hierarchy no. */ /* skip hierarchy no. */
pos = strstr(buf, ":"); pos = strstr(buf, ":");
if (!pos) { if (!pos) {
pr_err("invalid /proc/pid/cgroups file"); pr_err("invalid /proc/pid/cgroups file\n");
goto out; goto out;
} }
pos++; pos++;
@@ -105,7 +105,7 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) {
pos = strstr(pos, ":"); pos = strstr(pos, ":");
if (!pos) { if (!pos) {
pr_err("invalid /proc/pid/cgroups file"); pr_err("invalid /proc/pid/cgroups file\n");
goto out; goto out;
} }

View File

@@ -95,7 +95,7 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) {
/* skip hierarchy no. */ /* skip hierarchy no. */
pos = strstr(buf, ":"); pos = strstr(buf, ":");
if (!pos) { if (!pos) {
pr_err("invalid /proc/pid/cgroups file"); pr_err("invalid /proc/pid/cgroups file\n");
goto out; goto out;
} }
pos++; pos++;
@@ -103,7 +103,7 @@ static bool pid_in_cgroup(pid_t pid, const char *controller, const char *path) {
pos = strstr(pos, ":"); pos = strstr(pos, ":");
if (!pos) { if (!pos) {
pr_err("invalid /proc/pid/cgroups file"); pr_err("invalid /proc/pid/cgroups file\n");
goto out; goto out;
} }
@@ -190,7 +190,7 @@ int main(int argc, char **argv)
} }
if (pid != waitpid(pid, &status, 0)) { if (pid != waitpid(pid, &status, 0)) {
pr_err("wrong pid"); pr_perror("wrong pid");
goto out; goto out;
} }

View File

@@ -96,7 +96,7 @@ int cr_plugin_restore_file(int id)
e = criu_rtc__unpack(NULL, len, buf); e = criu_rtc__unpack(NULL, len, buf);
if (e == NULL) { if (e == NULL) {
pr_err("Unable to parse the RTC message %#x", id); pr_err("Unable to parse the RTC message %#x\n", id);
return -1; return -1;
} }

View File

@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
for (i = 0; i < ARRAY_SIZE(pipes); i++) { for (i = 0; i < ARRAY_SIZE(pipes); i++) {
if (pipe(pipes[i].pipefd)) { if (pipe(pipes[i].pipefd)) {
pr_err("Can't create pipe %d\n", i); pr_perror("Can't create pipe %d", i);
exit(1); exit(1);
} }
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
nfd = dup2(pipes[i].pipefd[0], i + 700); nfd = dup2(pipes[i].pipefd[0], i + 700);
if (nfd < 0) { if (nfd < 0) {
pr_err("dup2"); pr_perror("dup2");
exit(1); exit(1);
} }
close(pipes[i].pipefd[0]); close(pipes[i].pipefd[0]);

View File

@@ -96,7 +96,7 @@ static int check_file_lock(int fd, char *expected_type,
snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd);
fp_locks = fopen(path, "r"); fp_locks = fopen(path, "r");
if (!fp_locks) { if (!fp_locks) {
pr_err("Can't open %s\n", path); pr_perror("Can't open %s", path);
return -1; return -1;
} }
@@ -113,7 +113,7 @@ static int check_file_lock(int fd, char *expected_type,
fl_flag, fl_type, fl_option, &fl_owner, fl_flag, fl_type, fl_option, &fl_owner,
&maj, &min, &i_no); &maj, &min, &i_no);
if (num < 7) { if (num < 7) {
pr_perror("Invalid lock info."); pr_err("Invalid lock info\n");
break; break;
} }

View File

@@ -34,7 +34,7 @@ static int num_of_handles(int fd)
snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd);
f = fopen(path, "r"); f = fopen(path, "r");
if (!f) { if (!f) {
pr_err("Can't open %s", path); pr_perror("Can't open %s", path);
return -1; return -1;
} }
@@ -59,13 +59,13 @@ int main (int argc, char *argv[])
test_init(argc, argv); test_init(argc, argv);
if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
pr_err("Can't create directory %s", dirname); pr_perror("Can't create directory %s", dirname);
exit(1); exit(1);
} }
fd = inotify_init1(IN_NONBLOCK); fd = inotify_init1(IN_NONBLOCK);
if (fd < 0) { if (fd < 0) {
pr_err("inotify_init failed"); pr_perror("inotify_init failed");
exit(1); exit(1);
} }
@@ -73,12 +73,12 @@ int main (int argc, char *argv[])
snprintf(temp[i], sizeof(temp[0]), "d.%03d", i); snprintf(temp[i], sizeof(temp[0]), "d.%03d", i);
snprintf(path, sizeof(path), "%s/%s", dirname, temp[i]); snprintf(path, sizeof(path), "%s/%s", dirname, temp[i]);
if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
pr_err("Can't create %s", path); pr_perror("Can't create %s", path);
exit(1); exit(1);
} }
if (inotify_add_watch(fd, path, mask) < 0) { if (inotify_add_watch(fd, path, mask) < 0) {
pr_err("inotify_add_watch failed on %s", path); pr_perror("inotify_add_watch failed on %s", path);
exit(1); exit(1);
} }
} }

View File

@@ -36,7 +36,7 @@ int main(int argc, char ** argv)
MAP_SHARED | MAP_ANONYMOUS, -1, 0); MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (m == MAP_FAILED) { if (m == MAP_FAILED) {
pr_err("Failed to mmap %lu Mb shared anonymous R/W memory\n", pr_perror("Failed to mmap %lu Mb shared anonymous R/W memory",
MEM_SIZE >> 20); MEM_SIZE >> 20);
goto err; goto err;
} }
@@ -45,14 +45,14 @@ int main(int argc, char ** argv)
MAP_SHARED | MAP_ANONYMOUS, -1, 0); MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) { if (p == MAP_FAILED) {
pr_err("Failed to mmap %ld Mb shared anonymous R/W memory\n", pr_perror("Failed to mmap %ld Mb shared anonymous R/W memory",
MEM_SIZE >> 20); MEM_SIZE >> 20);
goto err; goto err;
} }
p2 = mmap(NULL, MEM_OFFSET, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); p2 = mmap(NULL, MEM_OFFSET, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p2 == MAP_FAILED) { if (p2 == MAP_FAILED) {
pr_err("Failed to mmap %lu Mb anonymous memory\n", pr_perror("Failed to mmap %lu Mb anonymous memory",
MEM_OFFSET >> 20); MEM_OFFSET >> 20);
goto err; goto err;
} }
@@ -67,7 +67,7 @@ int main(int argc, char ** argv)
p3 = mmap(NULL, MEM_OFFSET3, PROT_READ | PROT_WRITE, p3 = mmap(NULL, MEM_OFFSET3, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p3 == MAP_FAILED) { if (p3 == MAP_FAILED) {
pr_err("Failed to mmap %lu Mb anonymous R/W memory\n", pr_perror("Failed to mmap %lu Mb anonymous R/W memory",
MEM_OFFSET3 >> 20); MEM_OFFSET3 >> 20);
goto err; goto err;
} }

View File

@@ -67,7 +67,7 @@ int main(int argc, char **argv)
ret = nl_connect(sk, NETLINK_ROUTE); ret = nl_connect(sk, NETLINK_ROUTE);
if (ret < 0) { if (ret < 0) {
nl_socket_free(sk); nl_socket_free(sk);
pr_err("Unable to connect socket: %s", nl_geterror(ret)); pr_err("Unable to connect socket: %s\n", nl_geterror(ret));
return -1; return -1;
} }

View File

@@ -37,7 +37,7 @@ static int parse_self_fdinfo(int fd, struct fdinfo *fi)
while (fgets(line, sizeof(line), file)) { while (fgets(line, sizeof(line), file)) {
if (fdinfo_field(line, "flags")) { if (fdinfo_field(line, "flags")) {
if (sscanf(line, "%*s %llo", &val) != 1) { if (sscanf(line, "%*s %llo", &val) != 1) {
pr_err("failed to read flags: %s", line); pr_err("failed to read flags: %s\n", line);
goto fail; goto fail;
} }
pr_debug("Open flags = %llu\n", val); pr_debug("Open flags = %llu\n", val);

View File

@@ -37,11 +37,11 @@ int fill_sock_buf(int fd)
flags = fcntl(fd, F_GETFL, 0); flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) { if (flags == -1) {
pr_err("Can't get flags"); pr_perror("Can't get flags");
return -1; return -1;
} }
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
pr_err("Can't set flags"); pr_perror("Can't set flags");
return -1; return -1;
} }
@@ -52,14 +52,14 @@ int fill_sock_buf(int fd)
if (ret == -1) { if (ret == -1) {
if (errno == EAGAIN) if (errno == EAGAIN)
break; break;
pr_err("write"); pr_perror("write");
return -1; return -1;
} }
size += ret; size += ret;
} }
if (fcntl(fd, F_SETFL, flags) == -1) { if (fcntl(fd, F_SETFL, flags) == -1) {
pr_err("Can't set flags"); pr_perror("Can't set flags");
return -1; return -1;
} }
@@ -77,7 +77,7 @@ static int clean_sk_buf(int fd)
while (1) { while (1) {
ret = read(fd, buf, sizeof(buf)); ret = read(fd, buf, sizeof(buf));
if (ret == -1) { if (ret == -1) {
pr_err("read"); pr_perror("read");
return -11; return -11;
} }
@@ -192,7 +192,7 @@ int main(int argc, char **argv)
test_init(argc, argv); test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) { if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) {
pr_err("initializing server failed"); pr_err("initializing server failed\n");
return 1; return 1;
} }
@@ -208,13 +208,13 @@ int main(int argc, char **argv)
*/ */
fd = tcp_accept_server(fd_s); fd = tcp_accept_server(fd_s);
if (fd < 0) { if (fd < 0) {
pr_err("can't accept client connection"); pr_err("can't accept client connection\n");
return 1; return 1;
} }
ctl_fd = tcp_accept_server(fd_s); ctl_fd = tcp_accept_server(fd_s);
if (ctl_fd < 0) { if (ctl_fd < 0) {
pr_err("can't accept client connection"); pr_err("can't accept client connection\n");
return 1; return 1;
} }

View File

@@ -28,7 +28,7 @@ static int check_socket_closed(int sk)
pr_perror("Can't get socket state"); pr_perror("Can't get socket state");
return -1; return -1;
} else if (info.tcpi_state != TCP_CLOSE) { } else if (info.tcpi_state != TCP_CLOSE) {
pr_err("Invalid socket state (%i)", (int)info.tcpi_state); pr_err("Invalid socket state (%i)\n", (int)info.tcpi_state);
return -1; return -1;
} }

View File

@@ -128,7 +128,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
if (memcmp(&addr, &dst_addr, aux)) { if (memcmp(&addr, &dst_addr, aux)) {
pr_err("A destination address mismatch"); pr_err("A destination address mismatch\n");
return 1; return 1;
} }
@@ -137,7 +137,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
if (memcmp(&addr, &src_addr, aux)) { if (memcmp(&addr, &src_addr, aux)) {
pr_err("A source address mismatch"); pr_err("A source address mismatch\n");
return 1; return 1;
} }

View File

@@ -37,11 +37,11 @@ int fill_sock_buf(int fd)
flags = fcntl(fd, F_GETFL, 0); flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) { if (flags == -1) {
pr_err("Can't get flags"); pr_perror("Can't get flags");
return -1; return -1;
} }
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
pr_err("Can't set flags"); pr_perror("Can't set flags");
return -1; return -1;
} }
@@ -52,14 +52,14 @@ int fill_sock_buf(int fd)
if (ret == -1) { if (ret == -1) {
if (errno == EAGAIN) if (errno == EAGAIN)
break; break;
pr_err("write"); pr_perror("write");
return -1; return -1;
} }
size += ret; size += ret;
} }
if (fcntl(fd, F_SETFL, flags) == -1) { if (fcntl(fd, F_SETFL, flags) == -1) {
pr_err("Can't set flags"); pr_perror("Can't set flags");
return -1; return -1;
} }
@@ -77,7 +77,7 @@ static int clean_sk_buf(int fd)
while (1) { while (1) {
ret = read(fd, buf, sizeof(buf)); ret = read(fd, buf, sizeof(buf));
if (ret == -1) { if (ret == -1) {
pr_err("read"); pr_perror("read");
return -11; return -11;
} }
@@ -104,13 +104,13 @@ int main(int argc, char **argv)
test_init(argc, argv); test_init(argc, argv);
if (pipe(pfd)) { if (pipe(pfd)) {
pr_err("pipe() failed"); pr_perror("pipe() failed");
return 1; return 1;
} }
extpid = fork(); extpid = fork();
if (extpid < 0) { if (extpid < 0) {
pr_err("fork() failed"); pr_perror("fork() failed");
return 1; return 1;
} else if (extpid == 0) { } else if (extpid == 0) {
int size = 0; int size = 0;
@@ -121,7 +121,7 @@ int main(int argc, char **argv)
close(pfd[1]); close(pfd[1]);
if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) { if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) {
pr_err("Can't read port\n"); pr_perror("Can't read port");
return 1; return 1;
} }
@@ -138,17 +138,17 @@ int main(int argc, char **argv)
return 1; return 1;
if (shutdown(fd, SHUT_WR) == -1) { if (shutdown(fd, SHUT_WR) == -1) {
pr_err("shutdown"); pr_perror("shutdown");
return 1; return 1;
} }
if (write(ctl_fd, &size, sizeof(size)) != sizeof(size)) { if (write(ctl_fd, &size, sizeof(size)) != sizeof(size)) {
pr_err("write"); pr_perror("write");
return 1; return 1;
} }
if (read(ctl_fd, &c, 1) != 0) { if (read(ctl_fd, &c, 1) != 0) {
pr_err("read"); pr_perror("read");
return 1; return 1;
} }
@@ -166,13 +166,13 @@ int main(int argc, char **argv)
test_init(argc, argv); test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) { if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) {
pr_err("initializing server failed"); pr_err("initializing server failed\n");
return 1; return 1;
} }
close(pfd[0]); close(pfd[0]);
if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) { if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) {
pr_err("Can't send port"); pr_perror("Can't send port");
return 1; return 1;
} }
close(pfd[1]); close(pfd[1]);
@@ -182,13 +182,13 @@ int main(int argc, char **argv)
*/ */
fd = tcp_accept_server(fd_s); fd = tcp_accept_server(fd_s);
if (fd < 0) { if (fd < 0) {
pr_err("can't accept client connection %m"); pr_err("can't accept client connection\n");
return 1; return 1;
} }
ctl_fd = tcp_accept_server(fd_s); ctl_fd = tcp_accept_server(fd_s);
if (ctl_fd < 0) { if (ctl_fd < 0) {
pr_err("can't accept client connection %m"); pr_err("can't accept client connection\n");
return 1; return 1;
} }
@@ -197,12 +197,12 @@ int main(int argc, char **argv)
return 1; return 1;
if (shutdown(fd, SHUT_WR) == -1) { if (shutdown(fd, SHUT_WR) == -1) {
pr_err("shutdown"); pr_perror("shutdown");
return 1; return 1;
} }
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) { if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
pr_err("read"); pr_perror("read");
return 1; return 1;
} }
@@ -224,12 +224,12 @@ int main(int argc, char **argv)
} }
if (shutdown(ctl_fd, SHUT_WR) == -1) { if (shutdown(ctl_fd, SHUT_WR) == -1) {
pr_err("shutdown"); pr_perror("shutdown");
return 1; return 1;
} }
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) { if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
pr_err("read"); pr_perror("read");
return 1; return 1;
} }

View File

@@ -38,11 +38,11 @@ int fill_sock_buf(int fd)
flags = fcntl(fd, F_GETFL, 0); flags = fcntl(fd, F_GETFL, 0);
if (flags == -1) { if (flags == -1) {
pr_err("Can't get flags"); pr_perror("Can't get flags");
return -1; return -1;
} }
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
pr_err("Can't set flags"); pr_perror("Can't set flags");
return -1; return -1;
} }
@@ -53,14 +53,14 @@ int fill_sock_buf(int fd)
if (ret == -1) { if (ret == -1) {
if (errno == EAGAIN) if (errno == EAGAIN)
break; break;
pr_err("write"); pr_perror("write");
return -1; return -1;
} }
size += ret; size += ret;
} }
if (fcntl(fd, F_SETFL, flags) == -1) { if (fcntl(fd, F_SETFL, flags) == -1) {
pr_err("Can't set flags"); pr_perror("Can't set flags");
return -1; return -1;
} }
@@ -78,7 +78,7 @@ static int clean_sk_buf(int fd)
while (1) { while (1) {
ret = read(fd, buf, sizeof(buf)); ret = read(fd, buf, sizeof(buf));
if (ret == -1) { if (ret == -1) {
pr_err("read"); pr_perror("read");
return -11; return -11;
} }
@@ -106,13 +106,13 @@ int main(int argc, char **argv)
test_init(argc, argv); test_init(argc, argv);
if (pipe(pfd)) { if (pipe(pfd)) {
pr_err("pipe() failed"); pr_perror("pipe() failed");
return 1; return 1;
} }
extpid = fork(); extpid = fork();
if (extpid < 0) { if (extpid < 0) {
pr_err("fork() failed"); pr_perror("fork() failed");
return 1; return 1;
} else if (extpid == 0) { } else if (extpid == 0) {
int size = 0; int size = 0;
@@ -123,7 +123,7 @@ int main(int argc, char **argv)
close(pfd[1]); close(pfd[1]);
if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) { if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) {
pr_err("Can't read port\n"); pr_perror("Can't read port");
return 1; return 1;
} }
@@ -137,17 +137,17 @@ int main(int argc, char **argv)
return 1; return 1;
if (read(ctl_fd, &c, 1) != 0) { if (read(ctl_fd, &c, 1) != 0) {
pr_err("read"); pr_perror("read");
return 1; return 1;
} }
if (write(fd, &TEST_MSG[2], sizeof(TEST_MSG) - 2) != sizeof(TEST_MSG) - 2) { if (write(fd, &TEST_MSG[2], sizeof(TEST_MSG) - 2) != sizeof(TEST_MSG) - 2) {
pr_err("write"); pr_perror("write");
return 1; return 1;
} }
if (shutdown(fd, SHUT_WR) == -1) { if (shutdown(fd, SHUT_WR) == -1) {
pr_err("shutdown"); pr_perror("shutdown");
return 1; return 1;
} }
@@ -165,13 +165,13 @@ int main(int argc, char **argv)
test_init(argc, argv); test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) { if ((fd_s = tcp_init_server(ZDTM_SRV_FAMILY, &port)) < 0) {
pr_err("initializing server failed"); pr_err("initializing server failed\n");
return 1; return 1;
} }
close(pfd[0]); close(pfd[0]);
if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) { if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) {
pr_err("Can't send port"); pr_perror("Can't send port");
return 1; return 1;
} }
close(pfd[1]); close(pfd[1]);
@@ -181,13 +181,13 @@ int main(int argc, char **argv)
*/ */
fd = tcp_accept_server(fd_s); fd = tcp_accept_server(fd_s);
if (fd < 0) { if (fd < 0) {
pr_err("can't accept client connection %m"); pr_err("can't accept client connection\n");
return 1; return 1;
} }
ctl_fd = tcp_accept_server(fd_s); ctl_fd = tcp_accept_server(fd_s);
if (ctl_fd < 0) { if (ctl_fd < 0) {
pr_err("can't accept client connection %m"); pr_err("can't accept client connection\n");
return 1; return 1;
} }
@@ -198,7 +198,7 @@ int main(int argc, char **argv)
#endif #endif
if (shutdown(fd, SHUT_WR) == -1) { if (shutdown(fd, SHUT_WR) == -1) {
pr_err("shutdown"); pr_perror("shutdown");
return 1; return 1;
} }
@@ -207,18 +207,18 @@ int main(int argc, char **argv)
test_waitsig(); test_waitsig();
if (shutdown(ctl_fd, SHUT_WR) == -1) { if (shutdown(ctl_fd, SHUT_WR) == -1) {
pr_err("shutdown"); pr_perror("shutdown");
return 1; return 1;
} }
if (recv(fd, buf, sizeof(buf), MSG_WAITALL) != sizeof(TEST_MSG) || if (recv(fd, buf, sizeof(buf), MSG_WAITALL) != sizeof(TEST_MSG) ||
strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) { strncmp(buf, TEST_MSG, sizeof(TEST_MSG))) {
pr_err("read"); pr_perror("recv: expected %s, got %s", TEST_MSG, buf);
return 1; return 1;
} }
if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) { if (read(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
pr_err("read"); pr_perror("read");
return 1; return 1;
} }

View File

@@ -86,7 +86,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
if (memcmp(&addr, &src_addr, aux)) { if (memcmp(&addr, &src_addr, aux)) {
pr_err("A source address mismatch"); pr_err("A source address mismatch\n");
return 1; return 1;
} }

View File

@@ -31,7 +31,7 @@ int main(int argc, char **argv)
sk1 = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); sk1 = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
sk2 = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); sk2 = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sk1 < 0 || sk2 < 0) { if (sk1 < 0 || sk2 < 0) {
pr_err("Can't create socket"); pr_perror("Can't create socket");
exit(1); exit(1);
return 1; return 1;
} }
@@ -49,19 +49,19 @@ int main(int argc, char **argv)
if (bind(sk1, (struct sockaddr *)&addr1, len) < 0 || if (bind(sk1, (struct sockaddr *)&addr1, len) < 0 ||
bind(sk2, (struct sockaddr *)&addr2, len) < 0) { bind(sk2, (struct sockaddr *)&addr2, len) < 0) {
pr_err("Can't bind socket"); pr_perror("Can't bind socket");
return 1; return 1;
} }
if (connect(sk1, (struct sockaddr *)&addr2, len) || if (connect(sk1, (struct sockaddr *)&addr2, len) ||
connect(sk2, (struct sockaddr *)&addr1, len)) { connect(sk2, (struct sockaddr *)&addr1, len)) {
pr_err("Can't connect"); pr_perror("Can't connect");
return 1; return 1;
} }
if (shutdown(sk1, SHUT_WR) || if (shutdown(sk1, SHUT_WR) ||
shutdown(sk2, SHUT_RD)) { shutdown(sk2, SHUT_RD)) {
pr_err("Can't shutdown\n"); pr_perror("Can't shutdown");
return 1; return 1;
} }
@@ -75,17 +75,17 @@ int main(int argc, char **argv)
ret = recvfrom(sk1, buf, sizeof(buf), 0, ret = recvfrom(sk1, buf, sizeof(buf), 0,
(struct sockaddr *)&addr, &len); (struct sockaddr *)&addr, &len);
if (ret <= 0) { if (ret <= 0) {
pr_err("Can't receive data"); pr_perror("Can't receive data");
return 1; return 1;
} }
if (len != sizeof(struct sockaddr_in) || memcmp(&addr2, &addr, len)) { if (len != sizeof(struct sockaddr_in) || memcmp(&addr2, &addr, len)) {
pr_err("Data received from wrong peer"); pr_err("Data received from wrong peer\n");
return 1; return 1;
} }
if (ret != sizeof(MSG1) || memcmp(buf, MSG1, ret)) { if (ret != sizeof(MSG1) || memcmp(buf, MSG1, ret)) {
pr_err("Wrong message received"); pr_err("Wrong message received\n");
return 1; return 1;
} }
@@ -102,17 +102,17 @@ int main(int argc, char **argv)
ret = recvfrom(sk1, buf, sizeof(buf), 0, ret = recvfrom(sk1, buf, sizeof(buf), 0,
(struct sockaddr *)&addr, &len); (struct sockaddr *)&addr, &len);
if (ret <= 0) { if (ret <= 0) {
pr_err("Can't receive data"); pr_perror("Can't receive data");
return 1; return 1;
} }
if (len != sizeof(struct sockaddr_in) || memcmp(&addr2, &addr, len)) { if (len != sizeof(struct sockaddr_in) || memcmp(&addr2, &addr, len)) {
pr_err("Data received from wrong peer"); pr_err("Data received from wrong peer\n");
return 1; return 1;
} }
if (ret != sizeof(MSG1) || memcmp(buf, MSG1, ret)) { if (ret != sizeof(MSG1) || memcmp(buf, MSG1, ret)) {
pr_err("Wrong message received"); pr_err("Wrong message received\n");
return 1; return 1;
} }

View File

@@ -59,7 +59,7 @@ int main(int argc, char **argv)
test_waitsig(); test_waitsig();
if (umount("a/b") || umount("a") || umount("a") || umount("a/b/c") || umount("a/b") || umount("a/b")) { if (umount("a/b") || umount("a") || umount("a") || umount("a/b/c") || umount("a/b") || umount("a/b")) {
pr_err("umount"); pr_perror("umount");
return 1; return 1;
} }

View File

@@ -34,11 +34,11 @@ int main(int argc, char **argv)
} }
if (pid == 0) { if (pid == 0) {
if (mount("zdtm", dirname, "tmpfs", 0, "") < 0) { if (mount("zdtm", dirname, "tmpfs", 0, "") < 0) {
pr_err("Can't mount tmpfs"); pr_perror("Can't mount tmpfs");
return 1; return 1;
} }
if (chdir(dirname)) { if (chdir(dirname)) {
pr_err("chdir"); pr_perror("chdir");
return 1; return 1;
} }

View File

@@ -42,7 +42,7 @@ static int parse_maps(struct vm_area *vmas)
maps = fopen("/proc/self/maps", "r"); maps = fopen("/proc/self/maps", "r");
if (maps == NULL) { if (maps == NULL) {
pr_err("Failed to open maps file: %m\n"); pr_perror("Failed to open maps file");
return -1; return -1;
} }
@@ -74,7 +74,7 @@ static int parse_maps(struct vm_area *vmas)
} }
if (fclose(maps)) { if (fclose(maps)) {
pr_err("Failed to close maps file: %m\n"); pr_perror("Failed to close maps file");
return -1; return -1;
} }
@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
test_msg("[NOTE]\tMappings before:\n"); test_msg("[NOTE]\tMappings before:\n");
nr_before = parse_maps(vmas_before); nr_before = parse_maps(vmas_before);
if (nr_before < 0) { if (nr_before < 0) {
pr_perror("Failed to parse maps"); pr_err("Failed to parse maps\n");
return -1; return -1;
} }
@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
test_msg("[NOTE]\tMappings after:\n"); test_msg("[NOTE]\tMappings after:\n");
nr_after = parse_maps(vmas_after); nr_after = parse_maps(vmas_after);
if (nr_after < 0) { if (nr_after < 0) {
pr_perror("Failed to parse maps"); pr_err("Failed to parse maps\n");
return -1; return -1;
} }

View File

@@ -23,7 +23,7 @@ int main(int argc, char ** argv)
* in the child */ * in the child */
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
pr_err("fork failed: %m"); pr_perror("fork failed");
exit(1); exit(1);
} }

View File

@@ -62,7 +62,7 @@ int main(int argc, char **argv)
} }
if (!*cpid) { if (!*cpid) {
pr_err("Don't know grand child's pid"); pr_err("Don't know grand child's pid\n");
goto err; goto err;
} }

View File

@@ -109,7 +109,7 @@ static void check_mem_eq(void *addr1, size_t size1, void *addr2, size_t size2)
static void xmunmap(void *map, size_t size) static void xmunmap(void *map, size_t size)
{ {
if (munmap(map, size)) { if (munmap(map, size)) {
pr_err("xmunmap"); pr_perror("xmunmap");
exit(1); exit(1);
} }
} }
@@ -507,7 +507,7 @@ int main(int argc, char **argv)
}; };
if (atexit(kill_pstree_from_root)) { if (atexit(kill_pstree_from_root)) {
pr_err("Can't setup atexit cleanup func"); pr_err("Can't setup atexit cleanup func\n");
exit(1); exit(1);
} }
return proc1_func(); return proc1_func();