Commit db0a60a2 authored by Wolfgang Grandegger via Xenomai's avatar Wolfgang Grandegger via Xenomai Committed by Jan Kiszka

utils/can: fix error handling, use errno instead of -ret

rtcansend and rtcanrecv test and evaluate the return code of POSIX
functions instead of errno. This bug sneaked in with:

d245d6e6 utils/can: drop dependencies on obsolete rt_dev API

As we are at it, a few missing "\n" of some error messages have been
added as well.
Signed-off-by: Wolfgang Grandegger's avatarWolfgang Grandegger <wg@grandegger.com>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent faaf6790
......@@ -64,7 +64,7 @@ static void cleanup(void)
ret = close(s);
s = -1;
if (ret) {
fprintf(stderr, "close: %s\n", strerror(-ret));
fprintf(stderr, "close: %s\n", strerror(errno));
}
exit(EXIT_SUCCESS);
}
......@@ -106,17 +106,17 @@ static void rt_task(void)
ret = recvfrom(s, (void *)&frame, sizeof(can_frame_t), 0,
(struct sockaddr *)&addr, &addrlen);
if (ret < 0) {
switch (ret) {
case -ETIMEDOUT:
switch (errno) {
case ETIMEDOUT:
if (verbose)
printf("recv: timed out");
printf("recv: timed out\n");
continue;
case -EBADF:
case EBADF:
if (verbose)
printf("recv: aborted because socket was closed");
printf("recv: aborted because socket was closed\n");
break;
default:
fprintf(stderr, "recv: %s\n", strerror(-ret));
fprintf(stderr, "recv: %s\n", strerror(errno));
}
break;
}
......@@ -235,7 +235,7 @@ int main(int argc, char **argv)
ret = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (ret < 0) {
fprintf(stderr, "socket: %s\n", strerror(-ret));
fprintf(stderr, "socket: %s\n", strerror(errno));
return -1;
}
s = ret;
......@@ -255,7 +255,7 @@ int main(int argc, char **argv)
ret = ioctl(s, SIOCGIFINDEX, &ifr);
if (ret < 0) {
fprintf(stderr, "ioctl GET_IFINDEX: %s\n", strerror(-ret));
fprintf(stderr, "ioctl GET_IFINDEX: %s\n", strerror(errno));
goto failure;
}
}
......@@ -264,7 +264,7 @@ int main(int argc, char **argv)
ret = setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
&err_mask, sizeof(err_mask));
if (ret < 0) {
fprintf(stderr, "setsockopt: %s\n", strerror(-ret));
fprintf(stderr, "setsockopt: %s\n", strerror(errno));
goto failure;
}
if (verbose)
......@@ -276,7 +276,7 @@ int main(int argc, char **argv)
&recv_filter, filter_count *
sizeof(struct can_filter));
if (ret < 0) {
fprintf(stderr, "setsockopt: %s\n", strerror(-ret));
fprintf(stderr, "setsockopt: %s\n", strerror(errno));
goto failure;
}
}
......@@ -286,7 +286,7 @@ int main(int argc, char **argv)
ret = bind(s, (struct sockaddr *)&recv_addr,
sizeof(struct sockaddr_can));
if (ret < 0) {
fprintf(stderr, "bind: %s\n", strerror(-ret));
fprintf(stderr, "bind: %s\n", strerror(errno));
goto failure;
}
......@@ -295,7 +295,7 @@ int main(int argc, char **argv)
printf("Timeout: %lld ns\n", (long long)timeout);
ret = ioctl(s, RTCAN_RTIOC_RCV_TIMEOUT, &timeout);
if (ret) {
fprintf(stderr, "ioctl RCV_TIMEOUT: %s\n", strerror(-ret));
fprintf(stderr, "ioctl RCV_TIMEOUT: %s\n", strerror(errno));
goto failure;
}
}
......@@ -303,7 +303,7 @@ int main(int argc, char **argv)
if (with_timestamp) {
ret = ioctl(s, RTCAN_RTIOC_TAKE_TIMESTAMP, RTCAN_TAKE_TIMESTAMPS);
if (ret) {
fprintf(stderr, "ioctl TAKE_TIMESTAMP: %s\n", strerror(-ret));
fprintf(stderr, "ioctl TAKE_TIMESTAMP: %s\n", strerror(errno));
goto failure;
}
}
......
......@@ -59,7 +59,7 @@ static void cleanup(void)
ret = close(s);
s = -1;
if (ret) {
fprintf(stderr, "close: %s\n", strerror(-ret));
fprintf(stderr, "close: %s\n", strerror(errno));
}
exit(EXIT_SUCCESS);
}
......@@ -88,17 +88,17 @@ static void rt_task(void)
ret = sendto(s, (void *)&frame, sizeof(can_frame_t), 0,
(struct sockaddr *)&to_addr, sizeof(to_addr));
if (ret < 0) {
switch (ret) {
case -ETIMEDOUT:
switch (errno) {
case ETIMEDOUT:
if (verbose)
printf("send(to): timed out");
printf("send(to): timed out\n");
break;
case -EBADF:
case EBADF:
if (verbose)
printf("send(to): aborted because socket was closed");
printf("send(to): aborted because socket was closed\n");
break;
default:
fprintf(stderr, "send: %s\n", strerror(-ret));
fprintf(stderr, "send: %s\n", strerror(errno));
break;
}
i = loops; /* abort */
......@@ -216,7 +216,7 @@ int main(int argc, char **argv)
ret = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (ret < 0) {
fprintf(stderr, "socket: %s\n", strerror(-ret));
fprintf(stderr, "socket: %s\n", strerror(errno));
return -1;
}
s = ret;
......@@ -225,7 +225,7 @@ int main(int argc, char **argv)
ret = setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
&loopback, sizeof(loopback));
if (ret < 0) {
fprintf(stderr, "setsockopt: %s\n", strerror(-ret));
fprintf(stderr, "setsockopt: %s\n", strerror(errno));
goto failure;
}
if (verbose)
......@@ -238,7 +238,7 @@ int main(int argc, char **argv)
ret = ioctl(s, SIOCGIFINDEX, &ifr);
if (ret < 0) {
fprintf(stderr, "ioctl: %s\n", strerror(-ret));
fprintf(stderr, "ioctl: %s\n", strerror(errno));
goto failure;
}
......@@ -249,13 +249,13 @@ int main(int argc, char **argv)
/* Suppress definiton of a default receive filter list */
ret = setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
if (ret < 0) {
fprintf(stderr, "setsockopt: %s\n", strerror(-ret));
fprintf(stderr, "setsockopt: %s\n", strerror(errno));
goto failure;
}
ret = bind(s, (struct sockaddr *)&to_addr, sizeof(to_addr));
if (ret < 0) {
fprintf(stderr, "bind: %s\n", strerror(-ret));
fprintf(stderr, "bind: %s\n", strerror(errno));
goto failure;
}
}
......@@ -283,7 +283,7 @@ int main(int argc, char **argv)
printf("Timeout: %lld ns\n", (long long)timeout);
ret = ioctl(s, RTCAN_RTIOC_SND_TIMEOUT, &timeout);
if (ret) {
fprintf(stderr, "ioctl SND_TIMEOUT: %s\n", strerror(-ret));
fprintf(stderr, "ioctl SND_TIMEOUT: %s\n", strerror(errno));
goto failure;
}
}
......
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