diff options
author | Jan Macku <jamacku@redhat.com> | 2019-08-07 11:58:59 +0200 |
---|---|---|
committer | Jan Macku <jamacku@redhat.com> | 2019-08-07 12:18:51 +0200 |
commit | 62e93c3e251b10f52786993b4e761eaa1dc3106f (patch) | |
tree | adb8ce317de706858bc582ba9b80e717c19071ad | |
parent | bfda3cc2acdea827909e6c89bda5bbb5140cda6c (diff) | |
download | initscripts-62e93c3e251b10f52786993b4e761eaa1dc3106f.tar initscripts-62e93c3e251b10f52786993b4e761eaa1dc3106f.tar.gz initscripts-62e93c3e251b10f52786993b4e761eaa1dc3106f.tar.bz2 initscripts-62e93c3e251b10f52786993b4e761eaa1dc3106f.tar.xz initscripts-62e93c3e251b10f52786993b4e761eaa1dc3106f.zip |
rc.d/functions: fix escape sequence being output under systemd service units
When functions provided by /etc/rc.d/functions is used, escape
sequence is output under systemd service units and logged into
/var/log/messages as follows:
# LANG=C systemctl cat foobar.service
# /etc/systemd/system/foobar.service
[Unit]
Description=FOOBAR
[Service]
Type=oneshot
ExecStart=/usr/bin/foobar.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
# cat /usr/bin/foobar.sh
#! /bin/bash
. /etc/init.d/functions
echo_success
# LANG=C grep foobar.sh /var/log/messages
Aug 7 09:29:54 localhost foobar.sh[29607]: #033[60G[#033[1;32m OK #033[0;39m]#015#033[60G[#033[1;31mFAILED#033[0;39m]
This is a regression issue caused by the commit f88dbd98e992 where
consoletype command was dropped.
Under systemd service units, standard input is associated with
/dev/null by default:
# systemctl show -p StandardInput foobar.service
StandardInput=null
man 5 systemd.exec:
StandardInput=
Controls where file descriptor 0 (STDIN) of the executed
processes is connected to. Takes one of null, tty,
tty-force, tty-fail, data, file:path, socket or fd:name.
If null is selected, standard input will be connected to
/dev/null, i.e. all read attempts by the process will
result in immediate EOF.
consoletype command interprets /dev/null as serial:
# consoletype < /dev/null
warning: consoletype is now deprecated, and will be removed in the near future!
warning: use tty (1) instead! More info: 'man 1 tty'
serial
The commit f88dbd98e992 overlooks this situation.
To fix this issue, check also "not a tty" to cover the case where
standard input is /dev/null.
Note that LANG=C is needed because the message "not a tty" varies
depending on locales.
(cherry picked from commit fdcc55839df2334d7a7567de1f02f07ee7a69561)
-rw-r--r-- | etc/rc.d/init.d/functions | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/etc/rc.d/init.d/functions b/etc/rc.d/init.d/functions index dd6a3165..1473d3b0 100644 --- a/etc/rc.d/init.d/functions +++ b/etc/rc.d/init.d/functions @@ -84,8 +84,9 @@ if [ -z "${BOOTUP:-}" ]; then LOGLEVEL=1 fi - # NOTE: /dev/ttyS* is serial console. - if tty | grep --quiet -e '/dev/ttyS'; then + # NOTE: /dev/ttyS* is serial console. "not a tty" is such as + # /dev/null associated when executed under systemd service units. + if LANG=C tty | grep --quiet -e '\(/dev/ttyS\|not a tty\)'; then BOOTUP=serial MOVE_TO_COL= SETCOLOR_SUCCESS= |