diff mbox

[FFmpeg-devel,V4,2/2] configure: replace 'pr' with printf since busybox does not support pr

Message ID 1556112460-20434-1-git-send-email-yejun.guo@intel.com
State Superseded
Headers show

Commit Message

Guo, Yejun April 24, 2019, 1:27 p.m. UTC
It is part of change from https://trac.ffmpeg.org/ticket/5680 provided
by Kylie McClain <somasis@exherbo.org> at Wed, 29 Jun 2016 16:37:20 -0400.

That change contains two parts, in function log_file and in function print_in_columns.

The second part is not good, so I have send out a new patch for print_in_columns.

As for the change in the first part, it is good. Just to make the whole thing completed,
i send out this patch to copy exactally the change in function log_file.

contributor: Kylie McClain <somasis@exherbo.org>
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
 configure | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)


avih April 24, 2019, 7:52 a.m. UTC | #1
>  log_file(){
>     log BEGIN $1
> -    pr -n -t $1 >> $logfile
> +    i=1

Shell variables are global. This means that any part of the code which ends
up calling `log_file` directly or through some other function (and not isolated
in a subshell) will get its `i` variable clobbered by `log_file`. This can be
very tricky to debug and identify.

Please use a variable name which is unlikely to be used by other functions,
like `log_file_i`. Same goes for `line` below. This is critical especially in
functions which end up get called by a lot of other function - like `log_file`.

> +    while read line;do

This needs to be `while IFS= read -r line; do`.

Without the IFS= part trailing white spaces will be trimmed, and without
the -r part backslash ('\') will be interpreted an an escape char.

> +        printf '%5s  %s\n' "${i}" "${line}"
> +        i=$(($i+1))
> +    done < $1 >> $logfile

While the previous version of the function used `$1` unquoted, it's generally
a very bad practice, as it cannot handle white spaces in file names and is
subjected to globbing and open for attacks. In general always quote _all_
strings unless you know for a fact that it's not required. In this case it _is_

>     log END $1
> }
diff mbox


diff --git a/configure b/configure
index 8941063..9d2d7be 100755
--- a/configure
+++ b/configure
@@ -503,7 +503,11 @@  log(){
     log BEGIN $1
-    pr -n -t $1 >> $logfile
+    i=1
+    while read line;do
+        printf '%5s   %s\n' "${i}" "${line}"
+        i=$(($i+1))
+    done < $1 >> $logfile
     log END $1