Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/thisroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ getTrueShellExeName() { # mklement0 https://stackoverflow.com/a/23011530/7471760
local trueExe nextTarget 2>/dev/null # ignore error in shells without `local`
# Determine the shell executable filename.
if [ -r "/proc/$$/cmdline" ]; then
trueExe=$(cut -d '' -f1 /proc/$$/cmdline 2>/dev/null) || trueExe=$(xargs -0 -n 1 < /proc/$$/cmdline | head -n 1) || return 1
trueExe=$(tr '\0' '\n' < /proc/$$/cmdline 2>/dev/null | sed -n '1p') || trueExe=$(xargs -0 -n 1 < /proc/$$/cmdline | head -n 1) || return 1

@ferdymercury ferdymercury Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also work to do instead:

head -n 1 /proc/$$/cmdline 2>/dev/null | cut -d '' -f1

or does that file with long commands also?

as suggested by mkelement0 in https://stackoverflow.com/a/23011530/7471760

and what about basename -- "$(readlink /proc/$$/exe)"

# Qemu emulation has cmdline start with the emulator
if [ "${trueExe##*qemu*}" != "${trueExe}" ]; then
# but qemu sets comm to the emulated command
Expand Down
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ set(root_exe $<TARGET_FILE:root.exe>)
#---environment-------------------------------------------------------------------------------
ROOT_ADD_TEST(show-environment COMMAND ${CMAKE_COMMAND} -E environment)

if(thisroot_scripts AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
foreach(shell IN ITEMS bash zsh)
find_program(THISROOT_${shell}_EXECUTABLE NAMES ${shell})
if(THISROOT_${shell}_EXECUTABLE)
ROOT_ADD_TEST(test-thisroot-${shell}
COMMAND ${THISROOT_${shell}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testThisroot.sh
${THISROOT_${shell}_EXECUTABLE} ${CMAKE_BINARY_DIR})
endif()
endforeach()
endif()

#---hworld------------------------------------------------------------------------------------
ROOT_EXECUTABLE(hworld hworld.cxx LIBRARIES Gpad)

Expand Down
32 changes: 32 additions & 0 deletions test/testThisroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

set -eu

shell=$1
root_dir=$2
shell_name=${shell##*/}
unset ROOTSYS

# Variables are expanded by the child shell.
# shellcheck disable=SC2016
shell_command='
if [ -n "${BASH_VERSION-}" ]; then shopt -s extdebug; fi;
. "$1/bin/thisroot.sh" || exit 1;
test "$ROOTSYS" = "$1" || exit 1;
test "$SHELLNAME" = "$2" || exit 1;
'

single_line_command=$(printf '%s' "$shell_command" | tr '\n' ' ')

for layout in single multiline long; do
printf 'Checking %s with %s commands\n' "$shell_name" "$layout"
case "$layout" in
single) command_text=$single_line_command ;;
multiline) command_text=$shell_command ;;
long)
padding=$(printf '%65536s' '')
command_text="set -o pipefail; $single_line_command #$padding"
;;
esac
"$shell" -c "$command_text" thisroot-test "$root_dir" "$shell_name"
done
Loading