diff mbox series

client: Return non-zero exit status on failure

Message ID 19443ee7-b8a1-4b63-bced-14afee65304c@googlegroups.com
State Changes Requested
Headers show
Series client: Return non-zero exit status on failure | expand

Commit Message

'Darko Komljenovic' via swupdate March 26, 2019, 4:53 a.m. UTC
Hi,

This change ensures that the 'client' helper utility returns a non-zero exit status on error.  This is useful when scripting and update using this utility.

Regards
Austin

Signed-off-by: Austin Phillips <austin.phillips@planetinnovation.com.au>
---
 tools/client.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Stefano Babic March 26, 2019, 7:06 p.m. UTC | #1
Hi Austin,

On 26/03/19 05:53, austin.phillips via swupdate wrote:
> Hi,
> 
> This change ensures that the 'client' helper utility returns a non-zero exit status on error.  This is useful when scripting and update using this utility.
> 

Please read the contributing page in the doc how to submit patches. The
lines above are part of the commit message, they should not be. Instead,
write a commit message explaining what you want to fix.

> Regards
> Austin
> 
> Signed-off-by: Austin Phillips <austin.phillips@planetinnovation.com.au>
> ---
>  tools/client.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/client.c b/tools/client.c
> index 73fef47..e9eab4c 100644
> --- a/tools/client.c
> +++ b/tools/client.c
> @@ -41,6 +41,7 @@ char buf[256];
>  int fd;
>  int verbose = 1;
>  bool dryrun = false;
> +int end_status = 0;
>  
>  pthread_mutex_t mymutex;
>  
> @@ -82,6 +83,13 @@ static int printstatus(ipc_message *msg)
>   */
>  static int end(RECOVERY_STATUS status)
>  {
> +	if (status != FAILURE) {
> +		end_status = 0;
> +	}
> +	else {
> +		end_status = 1;
> +	}
> +

why not a more concise

	end_status = (status == SUCCESS) ? EXIT_SUCCESS :EXIT_FAILURE;

>  	printf("Swupdate %s\n",
>  		status == FAILURE ? "*failed* !" :
>  			"was successful !");
> @@ -103,6 +111,11 @@ static int send_file(const char* filename) {
>  
>  	/* synchronize with a mutex */
>  	pthread_mutex_lock(&mymutex);
> +
> +
> +	/* May be set non-zero by end() function on failure */
> +	end_status = 0;
> +
>  	rc = swupdate_async_start(readimage, printstatus,
>  				end, dryrun);
>  	if (rc)
> @@ -114,7 +127,7 @@ static int send_file(const char* filename) {
>  	/* End called, unlock and exit */
>  	pthread_mutex_unlock(&mymutex);
>  
> -	return 0;


> +	return end_status;

Use stdlib.h and return EXIT_SUCCESS or EXIT_FAILURE, see above.

>  }
>  
>  
> 

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/tools/client.c b/tools/client.c
index 73fef47..e9eab4c 100644
--- a/tools/client.c
+++ b/tools/client.c
@@ -41,6 +41,7 @@  char buf[256];
 int fd;
 int verbose = 1;
 bool dryrun = false;
+int end_status = 0;
 
 pthread_mutex_t mymutex;
 
@@ -82,6 +83,13 @@  static int printstatus(ipc_message *msg)
  */
 static int end(RECOVERY_STATUS status)
 {
+	if (status != FAILURE) {
+		end_status = 0;
+	}
+	else {
+		end_status = 1;
+	}
+
 	printf("Swupdate %s\n",
 		status == FAILURE ? "*failed* !" :
 			"was successful !");
@@ -103,6 +111,11 @@  static int send_file(const char* filename) {
 
 	/* synchronize with a mutex */
 	pthread_mutex_lock(&mymutex);
+
+
+	/* May be set non-zero by end() function on failure */
+	end_status = 0;
+
 	rc = swupdate_async_start(readimage, printstatus,
 				end, dryrun);
 	if (rc)
@@ -114,7 +127,7 @@  static int send_file(const char* filename) {
 	/* End called, unlock and exit */
 	pthread_mutex_unlock(&mymutex);
 
-	return 0;
+	return end_status;
 }