Message ID | 20240221082541.12873-1-mweshahy@yahoo.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [1/1] swupdate-progress: multiline file redirected stdout progress | expand |
Hi Mostafa, On 21.02.24 09:25, '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 | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletions(-) > > > diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c > index 487e72b..6720b56 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); > @@ -335,7 +338,7 @@ int main(int argc, char **argv) > /* > * Be sure that string in message are Null terminated > */ > - if (msg.infolen > 0) { > + if (msg.infolen > 0 || redirected) { > char *reboot_mode; > int n, cause; > > @@ -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); > } Because the progress bar is just useful in case of stdout, this use case was already treated adding the -q parameter: -q, --quiet : do not print progress bar Is it not suitable for your use case ? Best regards, Stefano
Hi Stefano, The quiet option inhibits the tool's output completely. In my use case, I need to get the progress logged in a log file which is also used by other processes and system components to be used for live monitoring of the system including the update process and also this log file is used to later debug any incidents happens during update. Best regards,Mostafa Weshahy On Wednesday, February 21, 2024 at 01:26:26 PM GMT+1, Stefano Babic <stefano.babic@swupdate.org> wrote: Hi Mostafa, On 21.02.24 09:25, '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 | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletions(-) > > > diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c > index 487e72b..6720b56 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); > @@ -335,7 +338,7 @@ int main(int argc, char **argv) > /* > * Be sure that string in message are Null terminated > */ > - if (msg.infolen > 0) { > + if (msg.infolen > 0 || redirected) { > char *reboot_mode; > int n, cause; > > @@ -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); > } Because the progress bar is just useful in case of stdout, this use case was already treated adding the -q parameter: -q, --quiet : do not print progress bar Is it not suitable for your use case ? Best regards, Stefano
On 21.02.24 15:56, 'M Weshahy' via swupdate wrote: > Hi Stefano, > > The quiet option inhibits the tool's output completely. In my use case, > I need to get the progress logged in a log file which is also used by > other processes and system components to be used for live monitoring of > the system including the update process and also this log file is used > to later debug any incidents happens during update. > Ok - I review the patch then. Regards, Stefano > Best regards, > Mostafa Weshahy > > On Wednesday, February 21, 2024 at 01:26:26 PM GMT+1, Stefano Babic > <stefano.babic@swupdate.org> wrote: > > > Hi Mostafa, > > On 21.02.24 09:25, '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 > <mailto:mweshahy@yahoo.com>> > > --- > > tools/swupdate-progress.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletions(-) > > > > > > diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c > > index 487e72b..6720b56 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); > > @@ -335,7 +338,7 @@ int main(int argc, char **argv) > > /* > > * Be sure that string in message are Null terminated > > */ > > - if (msg.infolen > 0) { > > + if (msg.infolen > 0 || redirected) { > > char *reboot_mode; > > int n, cause; > > > > @@ -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); > > > } > Because the progress bar is just useful in case of stdout, this use case > was already treated adding the -q parameter: > > -q, --quiet : do not print progress bar > > Is it not suitable for your use case ? > > Best regards, > Stefano > > > > -- > You received this message because you are subscribed to the Google > Groups "swupdate" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to swupdate+unsubscribe@googlegroups.com > <mailto:swupdate+unsubscribe@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/swupdate/1733158044.2894883.1708527383131%40mail.yahoo.com <https://groups.google.com/d/msgid/swupdate/1733158044.2894883.1708527383131%40mail.yahoo.com?utm_medium=email&utm_source=footer>.
Hi Mostafa, On 21.02.24 09:25, '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 | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletions(-) > > > diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c > index 487e72b..6720b56 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); > @@ -335,7 +338,7 @@ int main(int argc, char **argv) > /* > * Be sure that string in message are Null terminated > */ > - if (msg.infolen > 0) { > + if (msg.infolen > 0 || redirected) { It is not clear this line. This protect to access the INFO buffer if it empty. It is used by some external application (or from build system via sw-description) to add further information that are evaluated outside SWUpdate. But the test is skipped in redirect mode, writing at least an empty "INFO:" message. I do not understand why this is added. > char *reboot_mode; > int n, cause; > > @@ -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"); Fine here. > fflush(stdout); > } > > Best regards, Stefano
Hi Stefano, >> @@ -335,7 +338,7 @@ int main(int argc, char **argv) >> /* >> * Be sure that string in message are Null terminated>> */ >> - if (msg.infolen > 0) { >> + if (msg.infolen > 0 || redirected) { > >It is not clear this line. This protect to access the INFO buffer if it >empty. It is used by some external application (or from build system via >sw-description) to add further information that are evaluated outside >SWUpdate. > >But the test is skipped in redirect mode, writing at least an empty >"INFO:" message. I do not understand why this is added. > You are right this add extra unrequired "INFO :" to the log line. I will remove this line change. Best regards,Mostafa Weshahy
diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c index 487e72b..6720b56 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); @@ -335,7 +338,7 @@ int main(int argc, char **argv) /* * Be sure that string in message are Null terminated */ - if (msg.infolen > 0) { + if (msg.infolen > 0 || redirected) { char *reboot_mode; int n, cause; @@ -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); }
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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletions(-)