diff mbox series

[2/2] swupdate-progress: multiline file redirected stdout progress

Message ID 20240221170426.18518-1-mweshahy@yahoo.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series None | expand

Commit Message

Mostafa Weshahy Feb. 21, 2024, 5:04 p.m. UTC
This commit adds a check to swupdate-progress to multiline the progress
bar if stdout is redirected to a file. This is done to prevent having
very long line in the stdout redirected file.

Signed-off-by: Mostafa Weshahy <mweshahy@yahoo.com>
---
 tools/swupdate-progress.c | 5 +++++
 1 file changed, 5 insertions(+), 0 deletions(-)

Comments

Stefano Babic Feb. 21, 2024, 5:49 p.m. UTC | #1
On 21.02.24 18:04, 'Mostafa Weshahy' via swupdate wrote:
> This commit adds a check to swupdate-progress to multiline the progress
> bar if stdout is redirected to a file. This is done to prevent having
> very long line in the stdout redirected file.
>
> Signed-off-by: Mostafa Weshahy <mweshahy@yahoo.com>
> ---
>   tools/swupdate-progress.c | 5 +++++
>   1 file changed, 5 insertions(+), 0 deletions(-)
>
>
> diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
> index 487e72b..584910d 100644
> --- a/tools/swupdate-progress.c
> +++ b/tools/swupdate-progress.c
> @@ -233,6 +233,7 @@ int main(int argc, char **argv)
>   	char *script = NULL;
>   	bool wait_update = true;
>   	bool disable_reboot = false;
> +	bool redirected = false;
>
>   	/* Process options with getopt */
>   	while ((c = getopt_long(argc, argv, "cwprhs:e:q",
> @@ -280,6 +281,8 @@ int main(int argc, char **argv)
>   		snprintf(psplash_pipe_path, sizeof(psplash_pipe_path), "%s/psplash_fifo", rundir);
>   	}
>   	connfd = -1;
> +	redirected = !isatty(fileno(stdout));
> +
>   	while (1) {
>   		if (connfd < 0) {
>   			connfd = progress_ipc_connect(opt_w);
> @@ -385,6 +388,8 @@ int main(int argc, char **argv)
>   						bar,
>   						msg.cur_step, msg.nsteps, msg.cur_percent,
>   						msg.cur_image, msg.dwl_percent, msg.dwl_bytes);
> +					if (redirected)
> +						fprintf(stdout, "\n");
>   					fflush(stdout);
>   				}
>
>

Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>

Best regards,
Stefano
Stefano Babic Feb. 29, 2024, 8:45 a.m. UTC | #2
On 21.02.24 18:49, Stefano Babic wrote:
> 
> 
> On 21.02.24 18:04, 'Mostafa Weshahy' via swupdate wrote:
>> This commit adds a check to swupdate-progress to multiline the progress
>> bar if stdout is redirected to a file. This is done to prevent having
>> very long line in the stdout redirected file.
>>
>> Signed-off-by: Mostafa Weshahy <mweshahy@yahoo.com>
>> ---
>>   tools/swupdate-progress.c | 5 +++++
>>   1 file changed, 5 insertions(+), 0 deletions(-)
>>
>>
>> diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
>> index 487e72b..584910d 100644
>> --- a/tools/swupdate-progress.c
>> +++ b/tools/swupdate-progress.c
>> @@ -233,6 +233,7 @@ int main(int argc, char **argv)
>>       char *script = NULL;
>>       bool wait_update = true;
>>       bool disable_reboot = false;
>> +    bool redirected = false;
>>
>>       /* Process options with getopt */
>>       while ((c = getopt_long(argc, argv, "cwprhs:e:q",
>> @@ -280,6 +281,8 @@ int main(int argc, char **argv)
>>           snprintf(psplash_pipe_path, sizeof(psplash_pipe_path), 
>> "%s/psplash_fifo", rundir);
>>       }
>>       connfd = -1;
>> +    redirected = !isatty(fileno(stdout));
>> +
>>       while (1) {
>>           if (connfd < 0) {
>>               connfd = progress_ipc_connect(opt_w);
>> @@ -385,6 +388,8 @@ int main(int argc, char **argv)
>>                           bar,
>>                           msg.cur_step, msg.nsteps, msg.cur_percent,
>>                           msg.cur_image, msg.dwl_percent, msg.dwl_bytes);
>> +                    if (redirected)
>> +                        fprintf(stdout, "\n");
>>                       fflush(stdout);
>>                   }
>>
>>
> 
> Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>
> 
> Best regards,
> Stefano
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
index 487e72b..584910d 100644
--- a/tools/swupdate-progress.c
+++ b/tools/swupdate-progress.c
@@ -233,6 +233,7 @@  int main(int argc, char **argv)
 	char *script = NULL;
 	bool wait_update = true;
 	bool disable_reboot = false;
+	bool redirected = false;
 
 	/* Process options with getopt */
 	while ((c = getopt_long(argc, argv, "cwprhs:e:q",
@@ -280,6 +281,8 @@  int main(int argc, char **argv)
 		snprintf(psplash_pipe_path, sizeof(psplash_pipe_path), "%s/psplash_fifo", rundir);
 	}
 	connfd = -1;
+	redirected = !isatty(fileno(stdout));
+
 	while (1) {
 		if (connfd < 0) {
 			connfd = progress_ipc_connect(opt_w);
@@ -385,6 +388,8 @@  int main(int argc, char **argv)
 						bar,
 						msg.cur_step, msg.nsteps, msg.cur_percent,
 						msg.cur_image, msg.dwl_percent, msg.dwl_bytes);
+					if (redirected)
+						fprintf(stdout, "\n");
 					fflush(stdout);
 				}