diff mbox series

[V2] client: Return non-zero exit status on failure

Message ID a35179b4-895c-4d65-9ae3-7834b6bf3598@googlegroups.com
State Accepted
Headers show
Series [V2] client: Return non-zero exit status on failure | expand

Commit Message

'Darko Komljenovic' via swupdate March 27, 2019, 12:09 a.m. UTC
Ensure that the 'client' helper utility returns non-zero exit status on
error.  This is useful to check for success when scripting updates.

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

Comments

Stefano Babic March 28, 2019, 3:22 p.m. UTC | #1
On 27/03/19 01:09, austin.phillips via swupdate wrote:
> Ensure that the 'client' helper utility returns non-zero exit status on
> error.  This is useful to check for success when scripting updates.
> 
> Signed-off-by: Austin Phillips <austin.phillips@planetinnovation.com.au>
> ---
>  tools/client.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/client.c b/tools/client.c
> index 73fef47..6dd378c 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 = EXIT_SUCCESS;
>  
>  pthread_mutex_t mymutex;
>  
> @@ -82,6 +83,8 @@ static int printstatus(ipc_message *msg)
>   */
>  static int end(RECOVERY_STATUS status)
>  {
> +	end_status = (status == SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
> +
>  	printf("Swupdate %s\n",
>  		status == FAILURE ? "*failed* !" :
>  			"was successful !");
> @@ -103,6 +106,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 = EXIT_SUCCESS;
> +
>  	rc = swupdate_async_start(readimage, printstatus,
>  				end, dryrun);
>  	if (rc)
> @@ -114,7 +122,7 @@ static int send_file(const char* filename) {
>  	/* End called, unlock and exit */
>  	pthread_mutex_unlock(&mymutex);
>  
> -	return 0;
> +	return end_status;
>  }
>  
>  
> 
Applied to -master, thanks!

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/tools/client.c b/tools/client.c
index 73fef47..6dd378c 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 = EXIT_SUCCESS;
 
 pthread_mutex_t mymutex;
 
@@ -82,6 +83,8 @@  static int printstatus(ipc_message *msg)
  */
 static int end(RECOVERY_STATUS status)
 {
+	end_status = (status == SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
+
 	printf("Swupdate %s\n",
 		status == FAILURE ? "*failed* !" :
 			"was successful !");
@@ -103,6 +106,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 = EXIT_SUCCESS;
+
 	rc = swupdate_async_start(readimage, printstatus,
 				end, dryrun);
 	if (rc)
@@ -114,7 +122,7 @@  static int send_file(const char* filename) {
 	/* End called, unlock and exit */
 	pthread_mutex_unlock(&mymutex);
 
-	return 0;
+	return end_status;
 }