Skip to content

TTY Tests in base.sh Cause Failures #2

@s-fairchild

Description

@s-fairchild

Problem

I'm attempting to use logging.sh for my scripts.
Sourcing base.sh then logging.sh fails due to trap statements, and issues with the tty checks.
Sourcing in the reverse order logging.sh then base.sh fails, as REQUIRES_CMDS is set in base.sh.

++++ set -o nounset
++++ set -o errexit
++++ set -o pipefail
++++ set -o errtrace
++++ shopt -s dotglob
++++ shopt -s inherit_errexit
++++ IFS='
'
++++ trap 'log_quit SIGINT' SIGINT
++++ trap 'log_quit SIGPIPE' SIGPIPE
++++ trap 'log_quit SIGQUIT' SIGQUIT
++++ trap 'log_quit SIGTSTP' SIGTSTP
++++ trap 'log_quit TIMEOUT' SIGALRM
++++ trap 'log_quit $? "${BASH_SOURCE//$PWD/.}:${LINENO} ${FUNCNAME:-}($(IFS=" "; echo "$*"))"' ERR
++++++ dirname hack/opt/bash-utils/util/base.sh
+++++ cd hack/opt/bash-utils/util
+++++ cd ..
+++++ pwd
++++ SCRIPTS_DIR=/home/steven/src/github/s-fairchild/titan/hack/opt/bash-utils
++++ ROOT_PID=218993
++++ PARENT_PID=171765
++++ [[ ! -t 0 ]]
++++++ IFS=' '
++++++ echo deploy/butane/overlays/prod/main.bu
+++++ log_quit 1 'hack/opt/bash-utils/util/base.sh:28 (deploy/butane/overlays/prod/main.bu)'
hack/opt/bash-utils/util/base.sh: line 28: log_quit: command not found

Questions

  1. Can you provide some documentation as to how these files are intended to be sourced?
  2. What is the purpose of this?
    • test exit code 0 is causing traps to be triggered. Which intern fail themselves, as log_quit is unset.
      # Script output with set -xtrace
      ++++ [[ ! -t 0 ]]
      ++++++ IFS=' '
      ++++++ echo deploy/butane/overlays/prod/main.bu
      +++++ log_quit 1 'hack/opt/bash-utils/util/base.sh:28 (deploy/butane/overlays/prod/main.bu)'
      hack/opt/bash-utils/util/base.sh: line 28: log_quit: command not **found**
    • Is IS_TTY currently used? Or for future use?
    • What is the intended purpose here? Test returns exit code 0 within the shell script. There is no difference when I do the same in an interactive terminal.
      steven@r10:~$ for i in {0..2}; do [[ ! -t $i ]]; echo -n $?; done
      111
      
      steven@r10:~$ tty
      /dev/pts/0
      
      steven@r10:~$ ls /dev/pts
      0  1  2  3  4  5  6  7  8  9  ptmx
  3. If traps are triggered, they fail, as logging.sh cannot be sourced before base.sh. log_quit is unset.

Additional Notes

When I remove the tty tests everything works as expected.
I am planning on creating a fork to remove this, but I hate to have a fork just for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions