Skip to content

Commit ca98269

Browse files
marc-hbxiulipan
authored andcommitted
Make func_lib_check_sudo() a warning cause sudo() message is better
See long comment in the function header. Also remove very bad SUDO_PASSWD suggestion from the error message and replace it with less insecure NOPASSWD and cache credentials suggestions. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 61271a3 commit ca98269

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

case-lib/lib.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,19 @@ func_lib_start_log_collect()
127127
sudo "$loggerCmd" &
128128
}
129129

130+
# Calling this function is often a mistake because the error message
131+
# from the actual sudo() function in hijack.sh is better: it is
132+
# guaranteed to print the command that needs sudo and give more
133+
# information. func_lib_check_sudo() is useful only when sudo is
134+
# optional and when its warning can be ignored (with '|| true') but in
135+
# the past it has been used to abort the test immediately and lose the
136+
# better error message from sudo().
130137
func_lib_check_sudo()
131138
{
139+
local cmd="${1:-Unknown command}"
132140
func_hijack_setup_sudo_level || {
133-
dlogw "Command needs root privilege to run, please configure SUDO_PASSWD in case-lib/config.sh"
134-
exit 2
141+
dlogw "$cmd needs root privilege to run, please use NOPASSWD or cached credentials"
142+
return 2
135143
}
136144
}
137145

@@ -144,7 +152,7 @@ func_lib_disable_pulseaudio()
144152
# store current pulseaudio command
145153
readarray -t PULSECMD_LST < <(ps -C pulseaudio -o user,cmd --no-header)
146154
[[ "${#PULSECMD_LST[@]}" -eq 0 ]] && return
147-
func_lib_check_sudo
155+
func_lib_check_sudo 'disabling pulseaudio'
148156
# get all running pulseaudio paths
149157
readarray -t PULSE_PATHS < <(ps -C pulseaudio -o cmd --no-header | awk '{print $1}'|sort -u)
150158
for PA_PATH in "${PULSE_PATHS[@]}"
@@ -167,7 +175,7 @@ func_lib_disable_pulseaudio()
167175
func_lib_restore_pulseaudio()
168176
{
169177
[[ "${#PULSECMD_LST[@]}" -eq 0 ]] && return
170-
func_lib_check_sudo
178+
func_lib_check_sudo 're-enabling pulseaudio'
171179
# restore pulseaudio
172180
for PA_PATH in "${PULSE_PATHS[@]}"
173181
do

0 commit comments

Comments
 (0)