@@ -213,7 +213,7 @@ function hadoop_privilege_check
213213 [[ " ${EUID} " = 0 ]]
214214}
215215
216- # # @description Execute a command via su when running as root
216+ # # @description Execute a command via sudo when running as root
217217# # @description if the given user is found or exit with
218218# # @description failure if not.
219219# # @description otherwise just run it. (This is intended to
@@ -224,14 +224,14 @@ function hadoop_privilege_check
224224# # @param user
225225# # @param commandstring
226226# # @return exitstatus
227- function hadoop_su
227+ function hadoop_sudo
228228{
229229 declare user=$1
230230 shift
231231
232232 if hadoop_privilege_check; then
233233 if hadoop_verify_user_resolves user; then
234- su -l " ${user} " -- " $@ "
234+ sudo -u " ${user} " -- " $@ "
235235 else
236236 hadoop_error " ERROR: Refusing to run as root: ${user} account is not found. Aborting."
237237 return 1
@@ -241,7 +241,7 @@ function hadoop_su
241241 fi
242242}
243243
244- # # @description Execute a command via su when running as root
244+ # # @description Execute a command via sudo when running as root
245245# # @description with extra support for commands that might
246246# # @description legitimately start as root (e.g., datanode)
247247# # @description (This is intended to
@@ -259,7 +259,7 @@ function hadoop_uservar_su
259259 #
260260 # if $EUID != 0, then exec
261261 # if $EUID =0 then
262- # if hdfs_subcmd_user is defined, call hadoop_su to exec
262+ # if hdfs_subcmd_user is defined, call hadoop_sudo to exec
263263 # if hdfs_subcmd_user is not defined, error
264264 #
265265 # For secure daemons, this means both the secure and insecure env vars need to be
@@ -283,7 +283,7 @@ function hadoop_uservar_su
283283 svar=$( hadoop_build_custom_subcmd_var " ${program} " " ${command} " SECURE_USER)
284284
285285 if [[ -n " ${! uvar} " ]]; then
286- hadoop_su " ${! uvar} " " $@ "
286+ hadoop_sudo " ${! uvar} " " $@ "
287287 elif [[ -n " ${! svar} " ]]; then
288288 # # if we are here, then SECURE_USER with no USER defined
289289 # # we are already privileged, so just run the command and hope
@@ -2051,7 +2051,8 @@ function hadoop_start_secure_daemon_wrapper
20512051 hadoop_error " ERROR: Cannot disconnect ${daemonname} process $! "
20522052 fi
20532053 # capture the ulimit output
2054- su " ${HADOOP_SECURE_USER} " -c ' bash -c "ulimit -a"' >> " ${jsvcoutfile} " 2>&1
2054+ # shellcheck disable=SC2024
2055+ sudo -u " ${HADOOP_SECURE_USER} " bash -c " ulimit -a" >> " ${jsvcoutfile} " 2>&1
20552056 # shellcheck disable=SC2086
20562057 if ! ps -p $! > /dev/null 2>&1 ; then
20572058 return 1
0 commit comments