From ef81ec7a47979cce056dae5ab795ee2450f2faab Mon Sep 17 00:00:00 2001 From: Andreas Stieger Date: Tue, 17 Nov 2015 15:42:01 +0100 Subject: [PATCH] Add helper functions in preparation of fixing #97, #98, #99 get_docker_cumulative_command_line_args: new get_docker_effective_command_line_args: new Signed-off-by: Andreas Stieger --- helper_lib.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/helper_lib.sh b/helper_lib.sh index 2c39b6b..0e8c296 100644 --- a/helper_lib.sh +++ b/helper_lib.sh @@ -46,3 +46,38 @@ get_command_line_args() { tr "\0" " " < /proc/"$PID"/cmdline done } + +# Extract the cumulative command line arguments for the docker daemon +# +# If specified multiple times, all matches are returned. +# Accounts for long and short variants, call with short option. +# Does not account for option defaults or implicit options. +get_docker_cumulative_command_line_args() { + OPTION="$1" + + get_command_line_args docker | + # normalize known long options to their short versions + sed \ + -e 's/\-\-debug/-D/g' \ + -e 's/\-\-host/-H/g' \ + -e 's/\-\-log-level/-l/g' \ + -e 's/\-\-version/-v/g' \ + | + # normalize parameters separated by space(s) to -O=VALUE + sed \ + -e 's/\-\([DHlv]\)[= ]\([^- ][^ ]\)/-\1=\2/g' \ + | + # get the last interesting option + tr ' ' "\n" | + grep "^${OPTION}" +} + +# Extract the effective command line arguments for the docker daemon +# +# Accounts for multiple specifications, takes the last option. +# Accounts for long and short variants, call with short option +# Does not account for option default or implicit options. +get_docker_effective_command_line_args() { + OPTION="$1" + get_docker_cumulative_command_line_args $OPTION | tail -n1 +}