TT#106202 Add tty check for ngcpcfg 'read' calls

On a Carrier cluster setup the command 'ngcpcfg clean --all' can be executed
on several nodes in parallel (e.g. using ngcp-parallel-ssh).

Which can get stuck on the yes/no question if the operator forgot to use '--force'.
In practice it causes 100% CPU usage after several days due to logs rotation
(reason is not 100% clear). Strace for such case:

> read(0, "", 1)                          = 0
> select(1, [0], NULL, [0], {tv_sec=0, tv_usec=0}) = 1 (in [0], left {tv_sec=0, tv_usec=0})
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(0, TCGETS, 0x7fff317e39a0)        = -1 ENOTTY (Inappropriate ioctl for device)
> lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
> read(0, "", 1)                          = 0
> select(1, [0], NULL, [0], {tv_sec=0, tv_usec=0}) = 1 (in [0], left {tv_sec=0, tv_usec=0})
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(0, TCGETS, 0x7fff317e39a0)        = -1 ENOTTY (Inappropriate ioctl for device)
> lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
> read(0, "", 1)                          = 0
> select(1, [0], NULL, [0], {tv_sec=0, tv_usec=0}) = 1 (in [0], left {tv_sec=0, tv_usec=0})
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(0, TCGETS, 0x7fff317e39a0)        = -1 ENOTTY (Inappropriate ioctl for device)
> lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
> read(0, "", 1)                          = 0
> select(1, [0], NULL, [0], {tv_sec=0, tv_usec=0}) = 1 (in [0], left {tv_sec=0, tv_usec=0})
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(0, TCGETS, 0x7fff317e39a0)        = -1 ENOTTY (Inappropriate ioctl for device)
> lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
> read(0, "", 1)                          = 0
> select(1, [0], NULL, [0], {tv_sec=0, tv_usec=0}) = 1 (in [0], left {tv_sec=0, tv_usec=0})
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(0, TCGETS, 0x7fff317e39a0)        = -1 ENOTTY (Inappropriate ioctl for device)
> lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
> read(0, "", 1)                          = 0
> select(1, [0], NULL, [0], {tv_sec=0, tv_usec=0}) = 1 (in [0], left {tv_sec=0, tv_usec=0})
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(0, TCGETS, 0x7fff317e39a0)        = -1 ENOTTY (Inappropriate ioctl for device)
> lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
> read(0, "", 1)                          = 0

The idea here is to check tty invocation and skip questions if no tty found.
JFYI, there is no tty when running scripts under ngcp-parallel-ssh.

Change-Id: Ia8ded3ada4d48ecb374f36859161645776381c31
mr10.0
Alexander Lutay 4 years ago committed by Oleksandr Lutai
parent 45de0f4e8a
commit 567318c578

@ -35,6 +35,11 @@ request_confirmation() {
return 0
fi
if ! tty -s; then
log_warn "Cannot request confirmation (no tty). Hint: use option '--force'."
return 1
fi
log_info_n "Please confirm 'yes' or 'no': "
# clearing STDIN

@ -43,6 +43,11 @@ if ! type -p gpg &>/dev/null ; then
exit 1
fi
if ! tty -s; then
log_error "Cannot request gpg password (no tty). Aborting."
exit 1
fi
# ensure created files can be read by root only
umask 066

Loading…
Cancel
Save