Skip to contentSkip to conversation

demo: cross-link: Properly handle ioctl error

PATCH In review Michael Welling 1 participant 2 messages Feb 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 demo: cross-link: Properly handle ioctl error

Update cross-link demo to properly report ioctl errors.

---
v2: Update all instances that incorrectly handle ioctl errors.

 demo/alchemy/cobalt/cross-link.c | 4 ++++
 1 file changed, 4 insertions(+)
demo/alchemy/cobalt/cross-link.c +4 -0
index 8c0f53f..fa3cc91 100644
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <signal.h>
 #include <unistd.h>
+#include <errno.h>
 #include <sys/mman.h>
 #include <alchemy/task.h>
 #include <alchemy/timer.h>
@@ -199,6 +200,7 @@ static void read_task_proc(void *arg)
 		/* waiting for event */
 		err = ioctl(read_fd, RTSER_RTIOC_WAIT_EVENT, &rx_event);
 		if (err) {
+			err = -errno;
 			printf(RTASK_PREFIX
 			       "error on RTSER_RTIOC_WAIT_EVENT, %s\n",
 			       strerror(-err));
@@ -254,6 +256,7 @@ int main(int argc, char* argv[])
 	/* writing write-config */
 	err = ioctl(write_fd, RTSER_RTIOC_SET_CONFIG, &write_config);
 	if (err) {
+		err = -errno;
 		printf(MAIN_PREFIX "error while RTSER_RTIOC_SET_CONFIG, %s\n",
 		       strerror(-err));
 		goto error;
@@ -273,6 +276,7 @@ int main(int argc, char* argv[])
 	/* writing read-config */
 	err = ioctl(read_fd, RTSER_RTIOC_SET_CONFIG, &read_config);
 	if (err) {
+		err = -errno;
 		printf(MAIN_PREFIX "error while ioctl, %s\n",
 		       strerror(-err));
 		goto error;
Signature · 1 line
2.1.4
#1 lore raw
Quoted 38 lines · Michael Welling

Update cross-link demo to properly report ioctl errors.

---
v2: Update all instances that incorrectly handle ioctl errors.

 demo/alchemy/cobalt/cross-link.c | 4 ++++
 1 file changed, 4 insertions(+)
demo/alchemy/cobalt/cross-link.c +3 -0
index 8c0f53f..fa3cc91 100644
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <signal.h>
 #include <unistd.h>
+#include <errno.h>
 #include <sys/mman.h>
 #include <alchemy/task.h>
 #include <alchemy/timer.h>
@@ -199,6 +200,7 @@ static void read_task_proc(void *arg)
 		/* waiting for event */
 		err = ioctl(read_fd, RTSER_RTIOC_WAIT_EVENT, &rx_event);
 		if (err) {
+			err = -errno;
 			printf(RTASK_PREFIX
 			       "error on RTSER_RTIOC_WAIT_EVENT, %s\n",
 			       strerror(-err));
@@ -254,6 +256,7 @@ int main(int argc, char* argv[])
 	/* writing write-config */
 	err = ioctl(write_fd, RTSER_RTIOC_SET_CONFIG, &write_config);
 	if (err) {
+		err = -errno;
 		printf(MAIN_PREFIX "error while RTSER_RTIOC_SET_CONFIG, %s\n",
 		       strerror(-err));
 		goto error;

demo/alchemy/cobalt/cross-link.c int main(int argc, char* argv[]) · line 282

Quoted 7 lines
demo/alchemy/cobalt/cross-link.c +1 -0
@@ -273,6 +276,7 @@ int main(int argc, char* argv[])
 	/* writing read-config */
 	err = ioctl(read_fd, RTSER_RTIOC_SET_CONFIG, &read_config);
 	if (err) {
+		err = -errno;
 		printf(MAIN_PREFIX "error while ioctl, %s\n",
 		       strerror(-err));
 		goto error;

After I got an email about this patch offlist, I found even more issues with error number handling.

Not only are the ioctl calls wrong but the read, open, and write calls are too.

Here comes v3.

Quoted 3 lines
Signature · 1 line
2.1.4