--- scripts/pika-bind.sh.in 2025-06-11 19:18:08.000000000 +0800 +++ scripts/pika-bind.sh.in 2026-07-28 06:02:15.000000000 +0800 @@ -126,10 +126,15 @@ exit 0 fi -method_pattern="\<${method}\>" -if [[ ! ${valid_methods[@]} =~ ${method_pattern} ]]; then +valid=0 +for m in "${valid_methods[@]}"; do + if [[ "${m}" == "${method}" ]]; then + valid=1 + break + fi +done +if [[ ${valid} -eq 0 ]]; then pika-bind-error "Invalid method: ${method}. See pika-bind --help for available methods." - exit 1 fi if [[ ${print_bind} -eq 0 ]]; then @@ -165,8 +170,11 @@ # Expecting: # 0x7f00000007f if method-enabled "hwloc" && [[ -z "${PIKA_PROCESS_MASK}" ]]; then + if ! command -v hwloc-bind &>/dev/null; then + pika-bind-verbose "Skipping hwloc-bind because hwloc-bind is not available" + else pika-bind-verbose "Trying to use hwloc-bind CPU mask" - hwloc_output=$(hwloc-bind --get --taskset) + hwloc_output=$(hwloc-bind --get --taskset 2>/dev/null) hwloc_exit_code=$? if [[ $hwloc_exit_code -eq 0 ]]; then if [[ "${hwloc_output}" =~ 0x[0-9a-f]+ ]]; then @@ -178,11 +186,15 @@ else pika-bind-verbose "Skipping hwloc-bind because hwloc-bind failed with exit code $hwloc_exit_code and output \"$hwloc_output\"" fi + fi fi # Expecting: # pid 19304's current affinity mask: 7f00000007f if method-enabled "taskset" && [[ -z "${PIKA_PROCESS_MASK}" ]]; then + if ! command -v taskset &>/dev/null; then + pika-bind-verbose "Skipping taskset because taskset is not available" + else taskset_output=$(taskset --pid $$) taskset_exit_code=$? if [[ ${taskset_exit_code} -eq 0 ]]; then @@ -196,6 +208,7 @@ else pika-bind-verbose "Skipping taskset because taskset failed with exit code $taskset_exit_code and output \"$taskset_output\"" fi + fi fi if [[ -z "${PIKA_PROCESS_MASK}" ]]; then