Commit f42bc583 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Pavel Emelyanov

zdtm: sanitize pr_perror() usage

Log function pr_perror() automatically adds
 - numeric errno value
 - string errno value (aka strerror(errno), aka %m)
 - a newline

So, its callers don't have to do all these things.

While at it, also
 - fix or improve some message texts
 - replace fnprintf() with pr_perror()
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Acked-by: 's avatarAndrew Vagin <avagin@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d0335779
...@@ -27,7 +27,7 @@ int tcp_init_server(int family, int *port) ...@@ -27,7 +27,7 @@ int tcp_init_server(int family, int *port)
sock = socket(family, SOCK_STREAM, IPPROTO_TCP); sock = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (sock == -1) { if (sock == -1) {
pr_perror("socket() failed %m"); pr_perror("socket() failed");
return -1; return -1;
} }
...@@ -54,12 +54,12 @@ int tcp_init_server(int family, int *port) ...@@ -54,12 +54,12 @@ int tcp_init_server(int family, int *port)
} }
if (ret == -1) { if (ret == -1) {
pr_perror("bind() failed %m"); pr_perror("bind() failed");
return -1; return -1;
} }
if (listen(sock, 1) == -1) { if (listen(sock, 1) == -1) {
pr_perror("listen() failed %m"); pr_perror("listen() failed");
return -1; return -1;
} }
return sock; return sock;
...@@ -77,7 +77,7 @@ int tcp_accept_server(int sock) ...@@ -77,7 +77,7 @@ int tcp_accept_server(int sock)
sock2 = accept(sock,(struct sockaddr *) &maddr, &addrlen); sock2 = accept(sock,(struct sockaddr *) &maddr, &addrlen);
if (sock2 == -1) { if (sock2 == -1) {
pr_perror("accept() failed %m"); pr_perror("accept() failed");
return -1; return -1;
} }
...@@ -93,7 +93,7 @@ int tcp_init_client(int family, char *servIP, unsigned short servPort) ...@@ -93,7 +93,7 @@ int tcp_init_client(int family, char *servIP, unsigned short servPort)
union sockaddr_inet servAddr; union sockaddr_inet servAddr;
if ((sock = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0) { if ((sock = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
pr_perror("can't create socket %m"); pr_perror("can't create socket");
return -1; return -1;
} }
/* Construct the server address structure */ /* Construct the server address structure */
...@@ -108,7 +108,7 @@ int tcp_init_client(int family, char *servIP, unsigned short servPort) ...@@ -108,7 +108,7 @@ int tcp_init_client(int family, char *servIP, unsigned short servPort)
inet_pton(AF_INET6, servIP, &servAddr.v6.sin6_addr); inet_pton(AF_INET6, servIP, &servAddr.v6.sin6_addr);
} }
if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) { if (connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) {
pr_perror("can't connect to server %m"); pr_perror("can't connect to server");
return -1; return -1;
} }
return sock; return sock;
......
...@@ -132,7 +132,7 @@ int main(int argc, char *argv[]) ...@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("can't fork %m"); pr_perror("can't fork");
exit(1); exit(1);
} }
......
...@@ -109,7 +109,7 @@ int main(int argc, char **argv) ...@@ -109,7 +109,7 @@ int main(int argc, char **argv)
addr.sll_family = AF_PACKET; addr.sll_family = AF_PACKET;
addr.sll_ifindex = 1; /* loopback should be 1 in all namespaces */ addr.sll_ifindex = 1; /* loopback should be 1 in all namespaces */
if (bind(sk2, (struct sockaddr *)&addr, sizeof(addr)) < 0) { if (bind(sk2, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
pr_perror("Can't bind socket %m"); pr_perror("Can't bind socket");
return 1; return 1;
} }
...@@ -127,13 +127,13 @@ int main(int argc, char **argv) ...@@ -127,13 +127,13 @@ int main(int argc, char **argv)
ver = TPACKET_V2; ver = TPACKET_V2;
if (setsockopt(sk1, SOL_PACKET, PACKET_VERSION, &ver, sizeof(ver)) < 0) { if (setsockopt(sk1, SOL_PACKET, PACKET_VERSION, &ver, sizeof(ver)) < 0) {
pr_perror("Can't set version %m"); pr_perror("Can't set version");
return 1; return 1;
} }
yes = 1; yes = 1;
if (setsockopt(sk1, SOL_PACKET, PACKET_AUXDATA, &yes, sizeof(yes)) < 0) { if (setsockopt(sk1, SOL_PACKET, PACKET_AUXDATA, &yes, sizeof(yes)) < 0) {
pr_perror("Can't set auxdata %m"); pr_perror("Can't set auxdata");
return 1; return 1;
} }
...@@ -143,25 +143,25 @@ int main(int argc, char **argv) ...@@ -143,25 +143,25 @@ int main(int argc, char **argv)
ring.tp_frame_size = 1024; ring.tp_frame_size = 1024;
ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr; ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr;
if (setsockopt(sk1, SOL_PACKET, PACKET_RX_RING, &ring, sizeof(ring)) < 0) { if (setsockopt(sk1, SOL_PACKET, PACKET_RX_RING, &ring, sizeof(ring)) < 0) {
pr_perror("Can't set rx ring %m"); pr_perror("Can't set rx ring");
return 1; return 1;
} }
rsv = SK_RESERVE; rsv = SK_RESERVE;
if (setsockopt(sk2, SOL_PACKET, PACKET_RESERVE, &rsv, sizeof(rsv)) < 0) { if (setsockopt(sk2, SOL_PACKET, PACKET_RESERVE, &rsv, sizeof(rsv)) < 0) {
pr_perror("Can't set reserve %m"); pr_perror("Can't set reserve");
return 1; return 1;
} }
yes = 1; yes = 1;
if (setsockopt(sk2, SOL_PACKET, PACKET_ORIGDEV, &yes, sizeof(yes)) < 0) { if (setsockopt(sk2, SOL_PACKET, PACKET_ORIGDEV, &yes, sizeof(yes)) < 0) {
pr_perror("Can't set origdev %m"); pr_perror("Can't set origdev");
return 1; return 1;
} }
yes = DEF_FANOUT; yes = DEF_FANOUT;
if (setsockopt(sk2, SOL_PACKET, PACKET_FANOUT, &yes, sizeof(yes)) < 0) { if (setsockopt(sk2, SOL_PACKET, PACKET_FANOUT, &yes, sizeof(yes)) < 0) {
pr_perror("Can't configure fanout %m"); pr_perror("Can't configure fanout");
return 1; return 1;
} }
...@@ -169,7 +169,7 @@ int main(int argc, char **argv) ...@@ -169,7 +169,7 @@ int main(int argc, char **argv)
mreq.mr_ifindex = 1; mreq.mr_ifindex = 1;
mreq.mr_type = PACKET_MR_PROMISC; mreq.mr_type = PACKET_MR_PROMISC;
if (setsockopt(sk1, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { if (setsockopt(sk1, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
pr_perror("Can't add promisc member %m"); pr_perror("Can't add promisc member");
return 1; return 1;
} }
...@@ -178,7 +178,7 @@ int main(int argc, char **argv) ...@@ -178,7 +178,7 @@ int main(int argc, char **argv)
mreq.mr_type = PACKET_MR_UNICAST; mreq.mr_type = PACKET_MR_UNICAST;
mreq.mr_alen = LO_ADDR_LEN; mreq.mr_alen = LO_ADDR_LEN;
if (setsockopt(sk2, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { if (setsockopt(sk2, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
pr_perror("Can't add ucast member %m"); pr_perror("Can't add ucast member");
return 1; return 1;
} }
...@@ -188,7 +188,7 @@ int main(int argc, char **argv) ...@@ -188,7 +188,7 @@ int main(int argc, char **argv)
ring.tp_frame_size = 1024; ring.tp_frame_size = 1024;
ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr; ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr;
if (setsockopt(sk2, SOL_PACKET, PACKET_TX_RING, &ring, sizeof(ring)) < 0) { if (setsockopt(sk2, SOL_PACKET, PACKET_TX_RING, &ring, sizeof(ring)) < 0) {
pr_perror("Can't set tx ring %m"); pr_perror("Can't set tx ring");
return 1; return 1;
} }
......
...@@ -74,7 +74,7 @@ int main(int argc, char **argv) ...@@ -74,7 +74,7 @@ int main(int argc, char **argv)
ring.tp_frame_size = 1024; ring.tp_frame_size = 1024;
ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr; ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr;
if (setsockopt(sk, SOL_PACKET, PACKET_RX_RING, &ring, sizeof(ring)) < 0) { if (setsockopt(sk, SOL_PACKET, PACKET_RX_RING, &ring, sizeof(ring)) < 0) {
pr_perror("Can't set rx ring %m"); pr_perror("Can't set rx ring");
return 1; return 1;
} }
...@@ -84,13 +84,13 @@ int main(int argc, char **argv) ...@@ -84,13 +84,13 @@ int main(int argc, char **argv)
ring.tp_frame_size = 1024; ring.tp_frame_size = 1024;
ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr; ring.tp_frame_nr = (ring.tp_block_size / ring.tp_frame_size) * ring.tp_block_nr;
if (setsockopt(sk, SOL_PACKET, PACKET_TX_RING, &ring, sizeof(ring)) < 0) { if (setsockopt(sk, SOL_PACKET, PACKET_TX_RING, &ring, sizeof(ring)) < 0) {
pr_perror("Can't set tx ring %m"); pr_perror("Can't set tx ring");
return 1; return 1;
} }
mem = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, sk, 0); mem = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FILE, sk, 0);
if (mem == MAP_FAILED) { if (mem == MAP_FAILED) {
pr_perror("Can't mmap socket %m"); pr_perror("Can't mmap socket");
return 1; return 1;
} }
......
...@@ -42,7 +42,7 @@ int main(int argc, char **argv) ...@@ -42,7 +42,7 @@ int main(int argc, char **argv)
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("fork failed. Return %d %m", pid); pr_perror("fork failed");
return 1; return 1;
} }
...@@ -61,7 +61,7 @@ int main(int argc, char **argv) ...@@ -61,7 +61,7 @@ int main(int argc, char **argv)
aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_nbytes = BUF_SIZE;
ret = aio_read(&aiocb); ret = aio_read(&aiocb);
if (ret < 0) { if (ret < 0) {
pr_perror("aio_read failed %m"); pr_perror("aio_read failed");
return 1; return 1;
} }
...@@ -74,7 +74,7 @@ int main(int argc, char **argv) ...@@ -74,7 +74,7 @@ int main(int argc, char **argv)
res = 0; res = 0;
again: again:
if (aio_suspend(aioary, 1, NULL) < 0 && errno != EINTR) { if (aio_suspend(aioary, 1, NULL) < 0 && errno != EINTR) {
pr_perror("aio_suspend failed %m"); pr_perror("aio_suspend failed");
res = 1; res = 1;
} }
...@@ -91,7 +91,7 @@ again: ...@@ -91,7 +91,7 @@ again:
} }
if (aio_return(&aiocb) != BUF_SIZE) { if (aio_return(&aiocb) != BUF_SIZE) {
pr_perror("Error at aio_return() %m"); pr_perror("Error at aio_return()");
res = 1; res = 1;
} }
...@@ -120,7 +120,7 @@ again: ...@@ -120,7 +120,7 @@ again:
if (wait(&status) < 0) { if (wait(&status) < 0) {
pr_perror("wait failed %m"); pr_perror("wait failed");
goto error; goto error;
} }
......
...@@ -53,11 +53,11 @@ int main(int argc, char **argv) ...@@ -53,11 +53,11 @@ int main(int argc, char **argv)
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
if (sigaction(SIGCHLD, &sa, NULL)) if (sigaction(SIGCHLD, &sa, NULL))
fprintf(stderr, "Can't set SIGTERM handler: %m\n"); pr_perror("Can't set SIGCHLD handler");
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("fork failed. Return %d %m", pid); pr_perror("fork failed");
return 1; return 1;
} }
...@@ -100,7 +100,7 @@ int main(int argc, char **argv) ...@@ -100,7 +100,7 @@ int main(int argc, char **argv)
if (wait(&status) < 0) { if (wait(&status) < 0) {
pr_perror("wait failed %m"); pr_perror("wait failed");
goto error; goto error;
} }
......
...@@ -21,7 +21,7 @@ int main(int argc, char ** argv) ...@@ -21,7 +21,7 @@ int main(int argc, char ** argv)
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
pr_perror("Fork failed %m"); pr_perror("fork failed");
exit(1); exit(1);
} else if (!pid) { } else if (!pid) {
pause(); pause();
...@@ -32,7 +32,7 @@ int main(int argc, char ** argv) ...@@ -32,7 +32,7 @@ int main(int argc, char ** argv)
if (chdir(cwd1) < 0) { if (chdir(cwd1) < 0) {
kill(pid, SIGKILL); kill(pid, SIGKILL);
pr_perror("Chdir failed %m"); pr_perror("chdir failed");
exit(1); exit(1);
} }
...@@ -49,7 +49,7 @@ int main(int argc, char ** argv) ...@@ -49,7 +49,7 @@ int main(int argc, char ** argv)
len = readlink("/proc/self/cwd", cwd1, sizeof(cwd1)); len = readlink("/proc/self/cwd", cwd1, sizeof(cwd1));
if (len < 0) { if (len < 0) {
pr_perror("can't read cwd symlink %m"); pr_perror("can't read cwd symlink");
exit(1); exit(1);
} }
cwd1[len] = 0; cwd1[len] = 0;
......
...@@ -41,7 +41,7 @@ int main(int argc, char ** argv) ...@@ -41,7 +41,7 @@ int main(int argc, char ** argv)
for (i = 0; i < NR_ZOMBIES; i++) { for (i = 0; i < NR_ZOMBIES; i++) {
zombie[i].pid = fork(); zombie[i].pid = fork();
if (zombie[i].pid < 0) { if (zombie[i].pid < 0) {
pr_perror("Fork failed %m"); pr_perror("fork failed");
exit(1); exit(1);
} }
......
...@@ -49,20 +49,20 @@ int main(int argc, char **argv) ...@@ -49,20 +49,20 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (mkfifo(file_path, mode)) { if (mkfifo(file_path, mode)) {
pr_perror("can't make fifo \"%s\"\n", file_path); pr_perror("can't make fifo \"%s\"", file_path);
exit(1); exit(1);
} }
} }
if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) { if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) {
pr_perror("can't set SIGCHLD handler\n"); pr_perror("can't set SIGCHLD handler");
exit(1); exit(1);
} }
for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ for (i = 1; i < num_procs; i++) { /* i = 0 - parent */
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("Can't fork\n"); pr_perror("Can't fork");
kill(0, SIGKILL); kill(0, SIGKILL);
exit(1); exit(1);
} }
...@@ -70,7 +70,7 @@ int main(int argc, char **argv) ...@@ -70,7 +70,7 @@ int main(int argc, char **argv)
file_path = path[i - 1]; file_path = path[i - 1];
readfd = open(file_path, O_RDONLY); readfd = open(file_path, O_RDONLY);
if (readfd < 0) { if (readfd < 0) {
pr_perror("open(%s, O_RDONLY) Failed\n", pr_perror("open(%s, O_RDONLY) failed",
file_path); file_path);
ret = errno; ret = errno;
return ret; return ret;
...@@ -78,7 +78,7 @@ int main(int argc, char **argv) ...@@ -78,7 +78,7 @@ int main(int argc, char **argv)
file_path = path[i]; file_path = path[i];
writefd = open(file_path, O_WRONLY); writefd = open(file_path, O_WRONLY);
if (writefd < 0) { if (writefd < 0) {
pr_perror("open(%s, O_WRONLY) Failed\n", pr_perror("open(%s, O_WRONLY) failed",
file_path); file_path);
ret = errno; ret = errno;
return ret; return ret;
...@@ -99,7 +99,7 @@ int main(int argc, char **argv) ...@@ -99,7 +99,7 @@ int main(int argc, char **argv)
file_path = path[0]; file_path = path[0];
writefd = open(file_path, O_WRONLY); writefd = open(file_path, O_WRONLY);
if (writefd < 0) { if (writefd < 0) {
pr_perror("open(%s, O_WRONLY) Failed\n", file_path); pr_perror("open(%s, O_WRONLY) failed", file_path);
kill(0, SIGKILL); kill(0, SIGKILL);
exit(1); exit(1);
} }
...@@ -107,7 +107,7 @@ int main(int argc, char **argv) ...@@ -107,7 +107,7 @@ int main(int argc, char **argv)
file_path = path[i - 1]; file_path = path[i - 1];
readfd = open(file_path, O_RDONLY); readfd = open(file_path, O_RDONLY);
if (readfd < 0) { if (readfd < 0) {
pr_perror("open(%s, O_RDONLY) Failed\n", file_path); pr_perror("open(%s, O_RDONLY) failed", file_path);
kill(0, SIGKILL); kill(0, SIGKILL);
exit(1); exit(1);
} }
......
...@@ -27,15 +27,14 @@ int main(int argc, char **argv) ...@@ -27,15 +27,14 @@ int main(int argc, char **argv)
fd = mkstemp(tmpfname); fd = mkstemp(tmpfname);
if (fd == -1) { if (fd == -1) {
pr_perror("Error at open(): %s", strerror(errno)); pr_perror("mkstemp() failed");
exit(1); exit(1);
} }
unlink(tmpfname); unlink(tmpfname);
if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { if (write(fd, buf, BUF_SIZE) != BUF_SIZE) {
pr_perror("Error at write(): %s", pr_perror("Error at write()");
strerror(errno));
exit(1); exit(1);
} }
...@@ -52,12 +51,12 @@ int main(int argc, char **argv) ...@@ -52,12 +51,12 @@ int main(int argc, char **argv)
if (ret < 0) { if (ret < 0) {
if ((errno == EINTR) && (!test_go())) if ((errno == EINTR) && (!test_go()))
break; break;
pr_perror("aio_read failed %m"); pr_perror("aio_read failed");
return 1; return 1;
} }
if (ret < 0) { if (ret < 0) {
pr_perror("aio_read failed %s\n", strerror(errno)); pr_perror("aio_read failed");
exit(1); exit(1);
} }
/* Wait for request completion */ /* Wait for request completion */
...@@ -68,7 +67,7 @@ again: ...@@ -68,7 +67,7 @@ again:
if ((errno == EINTR) && (! test_go())) if ((errno == EINTR) && (! test_go()))
break; break;
if (errno != EINTR) { if (errno != EINTR) {
pr_perror("aio_suspend failed %m"); pr_perror("aio_suspend failed");
return 1; return 1;
} }
} }
...@@ -89,11 +88,11 @@ again: ...@@ -89,11 +88,11 @@ again:
if (ret < 0) { if (ret < 0) {
if ((errno == EINTR) && (!test_go())) if ((errno == EINTR) && (!test_go()))
break; break;
pr_perror("aio_return failed %m"); pr_perror("aio_return failed");
return 1; return 1;
} }
if (ret != BUF_SIZE) { if (ret != BUF_SIZE) {
pr_perror("Error at aio_return()\n"); pr_perror("Error at aio_return()");
exit(1); exit(1);
} }
} }
......
...@@ -74,7 +74,7 @@ int main(int argc, char *argv[]) ...@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (fd<0){ if (fd<0){
pr_perror("socket "); pr_perror("socket");
goto out; goto out;
} }
// setup local address & bind using // setup local address & bind using
...@@ -83,7 +83,7 @@ int main(int argc, char *argv[]) ...@@ -83,7 +83,7 @@ int main(int argc, char *argv[])
la.nl_family = AF_NETLINK; la.nl_family = AF_NETLINK;
la.nl_pid = getpid(); la.nl_pid = getpid();
if (bind(fd, (struct sockaddr*) &la, sizeof(la))){ if (bind(fd, (struct sockaddr*) &la, sizeof(la))){
pr_perror("bind failed "); pr_perror("bind failed");
goto out; goto out;
} }
//Preperation: //Preperation:
......
...@@ -44,19 +44,19 @@ int main(int argc, char **argv) ...@@ -44,19 +44,19 @@ int main(int argc, char **argv)
for (i = 0; i < num_procs; i++) for (i = 0; i < num_procs; i++)
if (pipe(pipes + i * 2)) { if (pipe(pipes + i * 2)) {
pr_perror("Can't create pipes\n"); pr_perror("Can't create pipes");
exit(1); exit(1);
} }
if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) { if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) {
pr_perror("can't set SIGCHLD handler\n"); pr_perror("can't set SIGCHLD handler");
exit(1); exit(1);
} }
for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ for (i = 1; i < num_procs; i++) { /* i = 0 - parent */
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("Can't fork\n"); pr_perror("Can't fork");
kill(0, SIGKILL); kill(0, SIGKILL);
exit(1); exit(1);
} }
......
...@@ -44,19 +44,19 @@ int main(int argc, char **argv) ...@@ -44,19 +44,19 @@ int main(int argc, char **argv)
} }
if (pipe(pipes)) { if (pipe(pipes)) {
pr_perror("Can't create pipes\n"); pr_perror("Can't create pipes");
exit(1); exit(1);
} }
if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) { if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) {
pr_perror("can't set SIGCHLD handler\n"); pr_perror("can't set SIGCHLD handler");
exit(1); exit(1);
} }
for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ for (i = 1; i < num_procs; i++) { /* i = 0 - parent */
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("Can't fork\n"); pr_perror("can't fork");
kill(0, SIGKILL); kill(0, SIGKILL);
exit(1); exit(1);
} }
......
...@@ -45,19 +45,19 @@ int main(int argc, char **argv) ...@@ -45,19 +45,19 @@ int main(int argc, char **argv)
for (i = 0; i < num_procs; i++) for (i = 0; i < num_procs; i++)
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, socks + i * 2)) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, socks + i * 2)) {
pr_perror("Can't create socks\n"); pr_perror("can't create sockets");
exit(1); exit(1);
} }
if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) { if (signal(SIGCHLD, inc_num_exited) == SIG_ERR) {
pr_perror("can't set SIGCHLD handler\n"); pr_perror("can't set SIGCHLD handler");
exit(1); exit(1);
} }
for (i = 1; i < num_procs; i++) { /* i = 0 - parent */ for (i = 1; i < num_procs; i++) { /* i = 0 - parent */
pid = test_fork(); pid = test_fork();
if (pid < 0) { if (pid < 0) {
pr_perror("Can't fork\n"); pr_perror("Can't fork");
kill(0, SIGKILL); kill(0, SIGKILL);
exit(1); exit(1);
} }
......
...@@ -65,7 +65,7 @@ static int setup_srv_sock(void) ...@@ -65,7 +65,7 @@ static int setup_srv_sock(void)
} }
if (listen(sock, 1) < 0) { if (listen(sock, 1) < 0) {
pr_perror("can't listen on a socket \"%s\"\n", filename); pr_perror("can't listen on a socket \"%s\"", filename);
goto err; goto err;
} }
......
...@@ -111,35 +111,35 @@ int main(int argc, char **argv) ...@@ -111,35 +111,35 @@ int main(int argc, char **argv)
} }
if (signal(SIGUSR2, do_stop) == SIG_ERR) { if (signal(SIGUSR2, do_stop) == SIG_ERR) {
pr_perror("Can't setup handler\n"); pr_perror("Can't setup signal handler");
exit(1); exit(1);
} }
if ((efd = epoll_create(scale)) < 0) { if ((efd = epoll_create(scale)) < 0) {
pr_perror("Can't create epoll\n"); pr_perror("Can't create epoll");
exit(1); exit(1);
} }
for (i = 0; i < scale; i++) { for (i = 0; i < scale; i++) {
if (pipe(fds[i]) < 0) { if (pipe(fds[i]) < 0) {
pr_perror("Can't create pipe[%d]\n", i); pr_perror("Can't create pipe[%d]", i);
killall(); killall();
exit(1); exit(1);
} }
if (fcntl(fds[i][0], F_SETFL, O_NONBLOCK) < 0) { if (fcntl(fds[i][0], F_SETFL, O_NONBLOCK) < 0) {
pr_perror("Can't set O_NONBLOCK flag on fd[%d]\n", i); pr_perror("Can't set O_NONBLOCK flag on fd[%d]", i);
killall(); killall();
exit(1); exit(1);
} }
event.data.fd = fds[i][0]; event.data.fd = fds[i][0];
if (epoll_ctl(efd, EPOLL_CTL_ADD, fds[i][0], &event) < 0) { if (epoll_ctl(efd, EPOLL_CTL_ADD, fds[i][0], &event) < 0) {
pr_perror("Can't add fd[%d]\n", i); pr_perror("Can't add fd[%d]", i);
killall(); killall();
exit(1); exit(1);
} }
if ((rv = test_fork()) < 0) { if ((rv = test_fork()) < 0) {
pr_perror("Can't fork[%d]\n", i); pr_perror("Can't fork[%d]", i);
killall(); killall();
exit(1); exit(1);
} }
...@@ -150,7 +150,7 @@ int main(int argc, char **argv) ...@@ -150,7 +150,7 @@ int main(int argc, char **argv)
} }
if ((events = (struct epoll_event*) malloc (sizeof(struct epoll_event)*scale)) == NULL) { if ((events = (struct epoll_event*) malloc (sizeof(struct epoll_event)*scale)) == NULL) {
pr_perror("Can't allocate memory\n"); pr_perror("Can't allocate memory");
killall(); killall();
exit(1); exit(1);
} }
...@@ -159,14 +159,14 @@ int main(int argc, char **argv) ...@@ -159,14 +159,14 @@ int main(int argc, char **argv)
while (test_go()) { while (test_go()) {
if ((rv = epoll_wait(efd, events, scale, rand() % 999)) < 0 && errno != EINTR) { if ((rv = epoll_wait(efd, events, scale, rand() % 999)) < 0 && errno != EINTR) {
pr_perror("epoll_wait error\n"); pr_perror("epoll_wait error");
killall(); killall();
exit(1); exit(1);
} }
for (i = 0; i < rv; i++) { for (i = 0; i < rv; i++) {
while (read(events[i].data.fd, buf, buf_size) > 0); while (read(events[i].data.fd, buf, buf_size) > 0);
if (errno != EAGAIN && errno != 0 && errno) { if (errno != EAGAIN && errno != 0 && errno) {
pr_perror("read error\n"); pr_perror("read error");
killall(); killall();
exit(1); exit(1);
} }
......
...@@ -165,7 +165,7 @@ static void chew_some_file(int num) ...@@ -165,7 +165,7 @@ static void chew_some_file(int num)
sprintf(str, "standard_%s.%d", filename, num); sprintf(str, "standard_%s.%d", filename, num);
fd1 = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0666); fd1 = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (write(fd1, buf, FILE_SIZE) != FILE_SIZE) if (write(fd1, buf, FILE_SIZE) != FILE_SIZE)
pr_perror("can't write %s\n", str); pr_perror("can't write %s", str);
close(fd1); close(fd1);
goto out_exit; goto out_exit;
} }
...@@ -192,14 +192,14 @@ int main(int argc, char **argv) ...@@ -192,14 +192,14 @@ int main(int argc, char **argv)
} }
if (signal(SIGUSR2, do_stop) == SIG_ERR) { if (signal(SIGUSR2, do_stop) == SIG_ERR) {
pr_perror("Can't setup handler\n"); pr_perror("Can't setup signal handler");
exit(-1); exit(-1);
} }
for (i = 0; i < scale; i++) { for (i = 0; i < scale; i++) {
rv = test_fork(); rv = test_fork();
if (rv == -1) { if (rv == -1) {
pr_perror("Can't fork\n"); pr_perror("Can't fork");
killall(); killall();
exit(-1); exit(-1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment