proot icon indicating copy to clipboard operation
proot copied to clipboard

Proot PATH search is broken when in another proot environment

Open guillon opened this issue 11 years ago • 2 comments

Copy, chmod and run the test below: env PROOT=/abspath_to/proot ./proot_path_test.sh

Here is the shell script:

#!/bin/sh                                                                                                                                                                                                        
#                                                                                                                                                                                                                
# Apparently when in a recursive proot context,                                                                                                                                                                  
# if the top proot does not habve the same PATH as the                                                                                                                                                           
# inner proot, the search for the inner proot-ed program                                                                                                                                                         
# will be done in the topmost proot PATH context.                                                                                                                                                                
#                                                                                                                                                                                                                
# This has the effect of not finding programs when the                                                                                                                                                           
# PATH is changed in the top proot sub process tree.                                                                                                                                                             
#                            
#                                                                                                                                                                                                                
# usage: env PROOT=/abspath_to/proot ./proot_path_test.sh                                                                                                                                                        
#                                                                                                                                                                                                                
PROOT=${PROOT-proot}

# Save PATH                                                                                                                                                                                                      
OLD_PATH="$PATH"

mkdir -p tmppath

# The executable that we want to run                                                                                                                                                                             
cat >tmppath/hello.sh <<EOF                                                                                                                                                                                      
#!/bin/sh                                                                                                                                                                                                        
echo hello                                                                                                                                                                                                       
EOF                                                                                                                                                                                                              
chmod 755 tmppath/hello.sh

# Test that it works                                                                                                                                                                                             
tmppath/hello.sh

# Test that it works from proot                                                                                                                                                                                  
$PROOT -r / tmppath/hello.sh

# Test that it works from proot of proot                                                                                                                                                                         
$PROOT -r / $PROOT -r / tmppath/hello.sh

# Set PATH to catch hello.sh                                                                                                                                                                                     
PATH=$PWD/tmppath:$PATH

# Test that it works from PATH                                                                                                                                                                                   
hello.sh

# Test that it works from proot                                                                                                                                                                                  
$PROOT -r / hello.sh

# Test that it works from proot of proot                                                                                                                                                                         
$PROOT -r / $PROOT -r / hello.sh

# Now change path in between and reset PATH                                                                                                                                                                      
PATH="$OLD_PATH"
cat >path_to_hello.sh <<EOF                                                                                                                                                                                      
#!/bin/sh                                                                                                                                                                                                        
PATH=$PAD/tmppath:$PATH                                                                                                                                                                                          
$PROOT -r / hello.sh                                                                                                                                                                                             
EOF                                                                                                                                                                                                              
chmod 755 path_to_hello.sh

# Test that it works                                                                                                                                                                                             
./path_to_hello.sh

# Oups, it is broken from proot                                                                                                                                                                                  
$PROOT -r / ./path_to_hello.sh

guillon avatar May 24 '13 10:05 guillon

I have tested the script. Replacing: PATH=$PAD/tmppath:$PATH with: PATH=$PWD/tmppath:$PATH fixes the issue.

dead-end avatar Jul 25 '19 14:07 dead-end

Interesting. I for one, never noticed that little typo.

oxr463 avatar Jul 25 '19 15:07 oxr463