lbl-anp/docker_images

help flag to docker command wreakes havoc

Closed this issue · 2 comments

docker run lblanp/ros_base_noetic_x86 rosbag

runs just fine, but

docker run lblanp/ros_base_noetic_x86 rosbag --help

raises the following trace.

docker run lblanp/ros_base_noetic_x86 rosbag --help
/tmp/setup.sh.GV4ugvoE02: line 1: usage:: command not found
/tmp/setup.sh.GV4ugvoE02: line 3: Generates: command not found
/tmp/setup.sh.GV4ugvoE02: line 5: optional: command not found
/tmp/setup.sh.GV4ugvoE02: line 6: -h,: command not found
/tmp/setup.sh.GV4ugvoE02: line 7: --extend: command not found
/tmp/setup.sh.GV4ugvoE02: line 8: --local: command not found
/tmp/setup.sh.GV4ugvoE02: line 9: the: command not found
/opt/ros/noetic/setup.sh: line 83: [: 0: unary operator expected
/entrypoint.sh: line 5: exec: rosbag: not found
WARNING: No file to source: /workspace/devel_isolated/setup.bash

The same happens with any other command line argument such as python --help, cat --help, etc.

It must be something in the entry point which doesn't handle the --help flag.

The problem is:

source /opt/ros/noetic/setup.bash

which uses $@:

root@84d1e26dc7ba:/workspace# grep '$@' /opt/ros/noetic/setup.sh 
CATKIN_SHELL=$CATKIN_SHELL "$_SETUP_UTIL" $@ ${CATKIN_SETUP_UTIL_ARGS:-} >> "$_SETUP_TMP"
    echo "Failed to run '\"$_SETUP_UTIL\" $@': return code $_RC"

As it is sourceed that means the code is run as it would be just part of the script and in the context of the scrip $@ is defined as the command to be executed. The way to fix this is to store away the command values and then recall them later (see https://stackoverflow.com/questions/39096093/bash-restrict-parent-script-command-line-arguments-carry-forward-to-child-script)

args=( $@ )
set --
source /opt/ros/noetic/setup.bash
set -- $args

only works in bash though as it uses bash arrays. This is required though to not get into trouble if any of the commands contain white spaces.

Nice find. Sounds like an easy patch?