Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 13 Nov 2018, 18:32
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
bash Tracing Wierdness & Input Args
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
s243a

Joined: 02 Sep 2014
Posts: 1268

PostPosted: Tue 09 Oct 2018, 00:36    Post subject:  bash Tracing Wierdness & Input Args  

I added some "sh -x" to the top of some scripts (savefile to be attached shortly).and echo as debugging statments. I was trying to test out TazPup's OnDemand features and track down a "CWD" error.

I started the script something like this:
Code:

sh -x
tazpup-ondemand 2>&1 | tee bla.txt


I noted that some of my debugging statments are showing up as input arguments in the "$@" variable. For instance I have

/usr/libexec/tazpkg
Code:

#!/bin/sh -x
echo "entering /usr/libexec/tazpkg/get"
# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
# get - TazPkg module
# Get package to the cache directory
echo "Entering /usr/libexec/tazpkg/get"
echo "sourcing /lib/libtaz.sh"
. /lib/libtaz.sh
echo "sourcing /usr/lib/slitaz/libpkg.sh"
. /usr/lib/slitaz/libpkg.sh
echo "sourcing /usr/libexec/tazpkg/getenv"
. /usr/libexec/tazpkg/getenv
echo "sourcing /usr/libexec/tazpkg/find-depends"
. /usr/libexec/tazpkg/find-depends
echo "sourcing finished"


/lib/libtaz.sh (lines 29 to 38
Code:

# Parse cmdline options and store values in a variable.
for opt in "$@"; do
   opt_name="${opt%%=*}"; opt_name="$(echo -n "${opt_name#--}" | tr -c 'a-zA-Z0-9' '_')"
   case "$opt" in
      --[0-9]*=*)   export _$opt_name="${opt#*=}" ;;
      --[0-9]*)   export _$opt_name=yes ;;
      --*=*)      export  $opt_name="${opt#*=}" ;;
      --*)      export  $opt_name=yes ;;
   esac
done


producing the output:

Code:

Entering /usr/libexec/tazpkg/get
sourcing /lib/libtaz.sh
sourcing /usr/lib/slitaz/libpkg.sh
sourcing /usr/libexec/tazpkg/getenv
sourcing /usr/libexec/tazpkg/find-depends
sourcing finished
/var/cache/tazpkg/5.0/packages/cups-pdf-2.6.1.tazpkg'
+ echo Entering /usr/libexec/tazpkg/intall
Entering /usr/libexec/tazpkg/intall
+ echo sourcing /lib/libtaz.sh
sourcing /lib/libtaz.sh
+ . /lib/libtaz.sh
+ . /usr/bin/gettext.sh
+ alias sed=busybox sed
+ lgettext Done
+ gettext -d slitaz-base Done
+ okmsg=Done
+ lgettext Failed
+ gettext -d slitaz-base Failed
+ ermsg=Failed
+ : 32
+ : 31
+ : 36
+ opt_name=entering /usr/libexec/tazpkg/get


It is though putting an echo statment directly under the shebang causes the input arguments to be replaced. Is this documented anywhere and what might cause this. I noticed that some places in the code there is an "unset IFS", I wonder if that has anything to do with this wierdness.
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1268

PostPosted: Tue 09 Oct 2018, 00:45    Post subject:  

For security reasons I only attached the four files that I modified for tracing rather than the whole save file. I also manually created the folders so the premissions probably don't match.
traceWierdness.tar.gz
Description 
gz

 Download 
Filename  traceWierdness.tar.gz 
Filesize  10.72 KB 
Downloaded  12 Time(s) 
Back to top
View user's profile Send private message 
s243a

Joined: 02 Sep 2014
Posts: 1268

PostPosted: Tue 09 Oct 2018, 14:09    Post subject:  

I tried adding a space after the shebang and also removed the "-x" in the shebang that I hadded in a few places. The latter is redundent since I'm using "set -x". My second hypothesis was that the tracing was getting captured in something like a pipe. I found the following:

Code:

Command line: busybox basename entering /usr/libexec/tazpkg/get Entering /usr/libexec/tazpkg/get sourcing /lib/libtaz.sh sourcing /usr/lib/slitaz/libpkg.sh sourcing /usr/libexec/tazpkg/getenv sourcing /usr/libexec/tazpkg/find-depends sourcing finished /var/cache/tazpkg/5.0/packages/cups-2.0.2.tazpkg

BusyBox v1.27.2 (2018-06-04 11:30:05 CEST) multi-call binary.

Usage: basename FILE [SUFFIX]

Strip directory path and .SUFFIX from FILE
cpio: short read
/usr/libexec/tazpkg/install: .: line 498: can't open '/tmp/tmp.xqOAJi/receipt'
+ process_list
+ debug '\nprocess_list()\n  list='\'''\'''
+ '[' -n '' ']'
+ local tmp_list pkg
+ '[' -z '' ']'
+ return
+ exit 0



/usr/libexec/lib/tazpkg/install (lines 481 502)
Code:

[ -s "$UP_LIST" ] && sed -i "/^$PACKAGE\$/d" "$UP_LIST"
}

if [ "$(echo "$1" | cut -c 1-3)" != "../" ] && [ "$(echo "$1" | cut -c 1-2)" != "./" ] && [ "$(echo "$1" | cut -c 1)" != "/" ]; then
 xPKG="$(pwd)/$(basename $1)"
elif [ "$(echo "$1" | cut -c 1-2)" == "./" ] || [ "$(echo "$1" | cut -c 1-3)" == "../" ]; then
 xPKG="$(realpath "$1")"
else
 xPKG="$1"
fi

TMP_DIR=$(mktemp -d)

cd "$TMP_DIR"

cpio --quiet -i receipt < "$xPKG"

. $TMP_DIR/receipt

echo "Package name: $PACKAGE"

PACKAGE="$PACKAGE"


I wonder if cpio is capturing some of the trace output. I really don't understand cpio.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1157s ][ Queries: 13 (0.0498s) ][ GZIP on ]