e69bab9
From dbaa50c025dbfc3d8574e57ddbfa8e4cbf1b89d5 Mon Sep 17 00:00:00 2001
e69bab9
From: Dalibor Pospisil <dapospis@redhat.com>
e69bab9
Date: Sun, 28 Apr 2019 21:02:59 +0200
e69bab9
Subject: [PATCH 2/2] do not suppress getopt error
e69bab9
e69bab9
getopt was often used with -q option
e69bab9
now the stderr output is processed and logged as an error message
e69bab9
---
e69bab9
 src/infrastructure.sh  | 12 ++++++------
e69bab9
 src/logging.sh         |  2 +-
e69bab9
 src/storage.sh         |  2 +-
e69bab9
 src/synchronisation.sh |  8 ++++----
e69bab9
 src/testing.sh         |  6 +++---
e69bab9
 5 files changed, 15 insertions(+), 15 deletions(-)
e69bab9
e69bab9
diff --git a/src/infrastructure.sh b/src/infrastructure.sh
e69bab9
index 4c76736..1c97205 100644
e69bab9
--- a/src/infrastructure.sh
e69bab9
+++ b/src/infrastructure.sh
e69bab9
@@ -219,7 +219,7 @@ Returns 0 if mounting the share was successful.
e69bab9
 
e69bab9
 rlMount() {
e69bab9
     local OPTIONS=''
e69bab9
-    local GETOPT=$(getopt -q -o o: -- "$@"); eval set -- "$GETOPT"
e69bab9
+    local GETOPT=$(getopt -o o: -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done)); eval set -- "$GETOPT"
e69bab9
     while true; do
e69bab9
       case $1 in
e69bab9
         --) shift; break; ;;
e69bab9
@@ -288,7 +288,7 @@ options, 2 otherwise.
e69bab9
 
e69bab9
 rlCheckMount() {
e69bab9
     local MNTOPTS=''
e69bab9
-    local GETOPT=$(getopt -q -o o: -- "$@"); eval set -- "$GETOPT"
e69bab9
+    local GETOPT=$(getopt -o o: -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done)); eval set -- "$GETOPT"
e69bab9
     while true; do
e69bab9
       case $1 in
e69bab9
         --) shift; break; ;;
e69bab9
@@ -383,7 +383,7 @@ the mountpoint uses all the given options.
e69bab9
 
e69bab9
 rlAssertMount() {
e69bab9
     local MNTOPTS=''
e69bab9
-    local GETOPT=$(getopt -q -o o: -- "$@"); eval set -- "$GETOPT"
e69bab9
+    local GETOPT=$(getopt -o o: -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done)); eval set -- "$GETOPT"
e69bab9
     while true; do
e69bab9
       case $1 in
e69bab9
         --) shift; break; ;;
e69bab9
@@ -461,7 +461,7 @@ Returns 0 if success.
e69bab9
 =cut
e69bab9
 
e69bab9
 rlHash() {
e69bab9
-  local GETOPT=$(getopt -q -o a: -l decode,algorithm:,stdin -- "$@"); eval set -- "$GETOPT"
e69bab9
+  local GETOPT=$(getopt -o a: -l decode,algorithm:,stdin -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done)); eval set -- "$GETOPT"
e69bab9
   local decode=0 alg="$rlHashAlgorithm" stdin=0
e69bab9
   while true; do
e69bab9
     case $1 in
e69bab9
@@ -637,7 +637,7 @@ rlFileBackup() {
e69bab9
     local IFS
e69bab9
 
e69bab9
     # getopt will cut off first long opt when no short are defined
e69bab9
-    OPTS=$(getopt -o "." -l "clean,namespace:,no-missing-ok,missing-ok" -- "$@")
e69bab9
+    OPTS=$(getopt -o "." -l "clean,namespace:,no-missing-ok,missing-ok" -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     [ $? -ne 0 ] && return 1
e69bab9
 
e69bab9
     eval set -- "$OPTS"
e69bab9
@@ -813,7 +813,7 @@ rlFileRestore() {
e69bab9
     local IFS
e69bab9
 
e69bab9
     # getopt will cut off first long opt when no short are defined
e69bab9
-    OPTS=$(getopt -o "n:" -l "namespace:" -- "$@")
e69bab9
+    OPTS=$(getopt -o "n:" -l "namespace:" -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     [ $? -ne 0 ] && return 1
e69bab9
 
e69bab9
     eval set -- "$OPTS"
e69bab9
diff --git a/src/logging.sh b/src/logging.sh
e69bab9
index e49dcb4..79df02b 100644
e69bab9
--- a/src/logging.sh
e69bab9
+++ b/src/logging.sh
e69bab9
@@ -487,7 +487,7 @@ rlFileSubmit -s '_' /etc/passwd -> etc_passwd
e69bab9
 =cut
e69bab9
 
e69bab9
 rlFileSubmit() {
e69bab9
-    GETOPT=$(getopt -q -o s: -- "$@")
e69bab9
+    GETOPT=$(getopt -o s: -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     eval set -- "$GETOPT"
e69bab9
 
e69bab9
     SEPARATOR='-'
e69bab9
diff --git a/src/storage.sh b/src/storage.sh
e69bab9
index b3f7636..a1b4ae3 100644
e69bab9
--- a/src/storage.sh
e69bab9
+++ b/src/storage.sh
e69bab9
@@ -46,7 +46,7 @@ __INTERNAL_STORAGE_DEFAULT_NAMESPACE="GENERIC"
e69bab9
 __INTERNAL_ST_OPTION_PARSER='
e69bab9
   local namespace="$__INTERNAL_STORAGE_DEFAULT_NAMESPACE"
e69bab9
   local section="$__INTERNAL_STORAGE_DEFAULT_SECTION"
e69bab9
-  local GETOPT=$(getopt -o : -l namespace:,section: -- "$@") || return 126
e69bab9
+  local GETOPT=$(getopt -o : -l namespace:,section: -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done)) || return 126
e69bab9
   eval set -- "$GETOPT"
e69bab9
   while true; do
e69bab9
     case $1 in
e69bab9
diff --git a/src/synchronisation.sh b/src/synchronisation.sh
e69bab9
index 3c7c275..dcff59d 100644
e69bab9
--- a/src/synchronisation.sh
e69bab9
+++ b/src/synchronisation.sh
e69bab9
@@ -118,7 +118,7 @@ __INTERNAL_wait_for_cmd() {
e69bab9
     shift 1
e69bab9
 
e69bab9
     # that is the GNU extended getopt syntax!
e69bab9
-    local TEMP=$(getopt -o t:p:m:d:r: -n '$routine_name' -- "$@")
e69bab9
+    local TEMP=$(getopt -o t:p:m:d:r: -n '$routine_name' -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     if [[ $? != 0 ]] ; then
e69bab9
         rlLogError "$routine_name: Can't parse command options, terminating..."
e69bab9
         return 127
e69bab9
@@ -345,7 +345,7 @@ rlWaitForFile() {
e69bab9
     local file=""
e69bab9
 
e69bab9
     # that is the GNU extended getopt syntax!
e69bab9
-    local TEMP=$(getopt -o t:p:d: -n 'rlWaitForFile' -- "$@")
e69bab9
+    local TEMP=$(getopt -o t:p:d: -n 'rlWaitForFile' -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     if [[ $? != 0 ]] ; then
e69bab9
         rlLogError "rlWaitForSocket: Can't parse command options, terminating..."
e69bab9
         return 127
e69bab9
@@ -436,7 +436,7 @@ rlWaitForSocket(){
e69bab9
     local field="5"
e69bab9
 
e69bab9
     # that is the GNU extended getopt syntax!
e69bab9
-    local TEMP=$(getopt -o t:p:d: --longoptions close,remote -n 'rlWaitForSocket' -- "$@")
e69bab9
+    local TEMP=$(getopt -o t:p:d: --longoptions close,remote -n 'rlWaitForSocket' -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     if [[ $? != 0 ]] ; then
e69bab9
         rlLogError "rlWaitForSocket: Can't parse command options, terminating..."
e69bab9
         return 127
e69bab9
@@ -530,7 +530,7 @@ Signal used to kill the process, optional SIGTERM by default.
e69bab9
 
e69bab9
 rlWait() {
e69bab9
     # that is the GNU extended getopt syntax!
e69bab9
-    local TEMP=$(getopt -o t:s: -n 'rlWait' -- "$@")
e69bab9
+    local TEMP=$(getopt -o t:s: -n 'rlWait' -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     if [[ $? != 0 ]]; then
e69bab9
         rlLogError "rlWait: Can't parse command options, terminating..."
e69bab9
         return 128
e69bab9
diff --git a/src/testing.sh b/src/testing.sh
e69bab9
index e97bd01..eceb402 100644
e69bab9
--- a/src/testing.sh
e69bab9
+++ b/src/testing.sh
e69bab9
@@ -717,7 +717,7 @@ explain what are you doing here).
e69bab9
 Returns the exit code of the command run. Asserts PASS when
e69bab9
 command\'s exit status is in the list of expected exit codes.
e69bab9
 
e69bab9
-Note: 
e69bab9
+Note:
e69bab9
 
e69bab9
 =over
e69bab9
 
e69bab9
@@ -754,7 +754,7 @@ B<Warning:> using C<unbuffer> tool is now disabled because of bug 547686.
e69bab9
 #'
e69bab9
 
e69bab9
 rlRun() {
e69bab9
-    local __INTERNAL_rlRun_GETOPT=$(getopt -q -o lcts -- "$@")
e69bab9
+    local __INTERNAL_rlRun_GETOPT=$(getopt -o lcts -- "$@" 2> >(while read -r line; do rlLogError "$FUNCNAME: $line"; done))
e69bab9
     eval set -- "$__INTERNAL_rlRun_GETOPT"
e69bab9
 
e69bab9
     local __INTERNAL_rlRun_DO_LOG=false
e69bab9
@@ -1194,7 +1194,7 @@ __INTERNAL_rlIsDistro(){
e69bab9
   local whole="$(beakerlib-lsb_release -rs)"
e69bab9
   local major="$(beakerlib-lsb_release -rs | cut -d '.' -f 1)"
e69bab9
   local IFS
e69bab9
-  
e69bab9
+
e69bab9
   rlLogDebug "distro='$distro'"
e69bab9
   rlLogDebug "major='$major'"
e69bab9
   rlLogDebug "whole='$whole'"
e69bab9
-- 
e69bab9
2.17.2
e69bab9