All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] [PATCH v2] demo/alchemy/cross-link: Properly handle syscall errors
@ 2016-02-23  0:22 Michael Welling
  2016-10-19 20:48 ` Michael Welling
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Welling @ 2016-02-23  0:22 UTC (permalink / raw)
  To: xenomai, Gilles Chanteperdrix, Jan Kiszka, Lowell Gilbert

Update cross link demo to properly handle errors returned from syscalls.

Signed-off-by: Michael Welling <mwelling@ieee.org>
---
v2: Fixes up error handling it close_file.
Makes sure error is properly returned in main.

 demo/alchemy/cobalt/cross-link.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/demo/alchemy/cobalt/cross-link.c b/demo/alchemy/cobalt/cross-link.c
index 8c0f53f..0dbd415 100644
--- a/demo/alchemy/cobalt/cross-link.c
+++ b/demo/alchemy/cobalt/cross-link.c
@@ -78,6 +78,7 @@ static int close_file( int fd, char *name)
 	do {
 		i++;
 		err = close(fd);
+		err = err < 0 ? -errno : 0;
 		switch (err) {
 		case -EAGAIN:
 			printf(MAIN_PREFIX "%s -> EAGAIN (%d times)\n",
@@ -158,7 +159,7 @@ static void write_task_proc(void *arg)
 		written = write(write_fd, &write_time, sz);
 		if (written < 0 ) {
 			printf(WTASK_PREFIX "error on write, %s\n",
-			       strerror(-err));
+			       strerror(errno));
 			break;
 		} else if (written != sz) {
 			printf(WTASK_PREFIX "only %d / %zd byte transmitted\n",
@@ -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));
@@ -218,7 +220,7 @@ static void read_task_proc(void *arg)
 			nr++;
 		} else if (rd < 0 ) {
 			printf(RTASK_PREFIX "error on read, code %s\n",
-			       strerror(-err));
+			       strerror(errno));
 			break;
 		} else {
 			printf(RTASK_PREFIX "only %d / %zd byte received \n",
@@ -244,8 +246,9 @@ int main(int argc, char* argv[])
 	/* open rtser0 */
 	write_fd = open( WRITE_FILE, 0);
 	if (write_fd < 0) {
+		err = -errno;
 		printf(MAIN_PREFIX "can't open %s (write), %s\n", WRITE_FILE,
-		       strerror(-write_fd));
+		       strerror(-err));
 		goto error;
 	}
 	write_state |= STATE_FILE_OPENED;
@@ -254,6 +257,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;
@@ -263,8 +267,9 @@ int main(int argc, char* argv[])
 	/* open rtser1 */
 	read_fd = open( READ_FILE, 0 );
 	if (read_fd < 0) {
+		err = -errno;
 		printf(MAIN_PREFIX "can't open %s (read), %s\n", READ_FILE,
-		       strerror(-read_fd));
+		       strerror(-err));
 		goto error;
 	}
 	read_state |= STATE_FILE_OPENED;
@@ -273,6 +278,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;
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Xenomai] [PATCH v2] demo/alchemy/cross-link: Properly handle syscall errors
  2016-02-23  0:22 [Xenomai] [PATCH v2] demo/alchemy/cross-link: Properly handle syscall errors Michael Welling
@ 2016-10-19 20:48 ` Michael Welling
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Welling @ 2016-10-19 20:48 UTC (permalink / raw)
  To: xenomai, Jan Kiszka, Lowell Gilbert

Anything blocking this blocking from being submitted?
ACKs, NAKs, reviews?

On Mon, Feb 22, 2016 at 06:22:06PM -0600, Michael Welling wrote:
> Update cross link demo to properly handle errors returned from syscalls.
> 
> Signed-off-by: Michael Welling <mwelling@ieee.org>
> ---
> v2: Fixes up error handling it close_file.
> Makes sure error is properly returned in main.
> 
>  demo/alchemy/cobalt/cross-link.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/demo/alchemy/cobalt/cross-link.c b/demo/alchemy/cobalt/cross-link.c
> index 8c0f53f..0dbd415 100644
> --- a/demo/alchemy/cobalt/cross-link.c
> +++ b/demo/alchemy/cobalt/cross-link.c
> @@ -78,6 +78,7 @@ static int close_file( int fd, char *name)
>  	do {
>  		i++;
>  		err = close(fd);
> +		err = err < 0 ? -errno : 0;
>  		switch (err) {
>  		case -EAGAIN:
>  			printf(MAIN_PREFIX "%s -> EAGAIN (%d times)\n",
> @@ -158,7 +159,7 @@ static void write_task_proc(void *arg)
>  		written = write(write_fd, &write_time, sz);
>  		if (written < 0 ) {
>  			printf(WTASK_PREFIX "error on write, %s\n",
> -			       strerror(-err));
> +			       strerror(errno));
>  			break;
>  		} else if (written != sz) {
>  			printf(WTASK_PREFIX "only %d / %zd byte transmitted\n",
> @@ -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));
> @@ -218,7 +220,7 @@ static void read_task_proc(void *arg)
>  			nr++;
>  		} else if (rd < 0 ) {
>  			printf(RTASK_PREFIX "error on read, code %s\n",
> -			       strerror(-err));
> +			       strerror(errno));
>  			break;
>  		} else {
>  			printf(RTASK_PREFIX "only %d / %zd byte received \n",
> @@ -244,8 +246,9 @@ int main(int argc, char* argv[])
>  	/* open rtser0 */
>  	write_fd = open( WRITE_FILE, 0);
>  	if (write_fd < 0) {
> +		err = -errno;
>  		printf(MAIN_PREFIX "can't open %s (write), %s\n", WRITE_FILE,
> -		       strerror(-write_fd));
> +		       strerror(-err));
>  		goto error;
>  	}
>  	write_state |= STATE_FILE_OPENED;
> @@ -254,6 +257,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;
> @@ -263,8 +267,9 @@ int main(int argc, char* argv[])
>  	/* open rtser1 */
>  	read_fd = open( READ_FILE, 0 );
>  	if (read_fd < 0) {
> +		err = -errno;
>  		printf(MAIN_PREFIX "can't open %s (read), %s\n", READ_FILE,
> -		       strerror(-read_fd));
> +		       strerror(-err));
>  		goto error;
>  	}
>  	read_state |= STATE_FILE_OPENED;
> @@ -273,6 +278,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;
> -- 
> 2.1.4
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-19 20:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23  0:22 [Xenomai] [PATCH v2] demo/alchemy/cross-link: Properly handle syscall errors Michael Welling
2016-10-19 20:48 ` Michael Welling

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.