Skip to contentSkip to conversation

daemonlib.sh: call tty before executing service

PATCH New Yang Xu 2 participants 5 messages Jun 21, 2019 – Aug 1, 2019

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH 1/1 daemonlib.sh: call tty before executing service

On my machine, polkit-0.112-22.el7.x86_64 has contained the [1] patch.

This patch leads service acitons(such as restart) don't stop if it doesn't find controlling terminal. Even the service has been executed successfully. You can reproduce it with the following code:

test.sh
----------------------------------------------
echo "restart daemon"
systemctl restart rsyslog.service >/dev/null 2>&1
echo "restart success"
----------------------------------------------
./test.sh & (it doesn't stop)
restart daemon

ps -auxf
--------------------------------------------------

.... pts/1    T      \_ /bin/bash ./test.sh
.... pts/1    T        \_ systemctl restart rsyslog.service
.... pts/1    Tl         \_ /usr/bin/pkttyagent --notify-fd 6

-------------------------------------------------

/var/log/secure
------------------------------------------------
polkitd[1310]: Registered Authentication Agent for unix-process:18472:252325 (system bus name :1.105 [/usr/bin/pkttyagent --notify-fd 6 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
------------------------------------------------

This change leads to syslog[1-10] testcase hang. I fix it by adding tty beforce service, so these cases don't hang.

(pkttyagent: PolkitAgentTextListener leaves echo tty disabled if SIGINT/SIGTERM) [1]https://gitlab.freedesktop.org/polkit/polkit/commit/bfb722bbe5a503095cc7e860f282b142f5aa75f1

---
 testcases/lib/daemonlib.sh | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
testcases/lib/daemonlib.sh +12 -12
index 0de3f86af..5807cbea0 100644
@@ -47,43 +47,43 @@ fi
 start_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl start $1.service > /dev/null 2>&1
+		tty | systemctl start $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 start > /dev/null 2>&1
+		tty | service $1 start > /dev/null 2>&1
 	else
-		/etc/init.d/$1 start > /dev/null 2>&1
+		tty |/etc/init.d/$1 start > /dev/null 2>&1
 	fi
 }
 
 stop_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl stop $1.service > /dev/null 2>&1
+		tty | systemctl stop $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 stop > /dev/null 2>&1
+		tty | service $1 stop > /dev/null 2>&1
 	else
-		/etc/init.d/$1 stop > /dev/null 2>&1
+		tty | /etc/init.d/$1 stop > /dev/null 2>&1
 	fi
 }
 
 status_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl is-active $1.service > /dev/null 2>&1
+		tty | systemctl is-active $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 status > /dev/null 2>&1
+		tty | service $1 status > /dev/null 2>&1
 	else
-		/etc/init.d/$1 status > /dev/null 2>&1
+		tty | /etc/init.d/$1 status > /dev/null 2>&1
 	fi
 }
 
 restart_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl restart $1.service > /dev/null 2>&1
+		tty | systemctl restart $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 restart > /dev/null 2>&1
+		tty | service $1 restart > /dev/null 2>&1
 	else
-		/etc/init.d/$1 restart > /dev/null 2>&1
+		tty | /etc/init.d/$1 restart > /dev/null 2>&1
 	fi
 }
Signature · 1 line
2.18.1
#1 lore raw

PATCH 1/1 daemonlib.sh: call tty before executing service

----- Original Message -----

Quoted 30 lines

On my machine, polkit-0.112-22.el7.x86_64 has contained the [1] patch.

This patch leads service acitons(such as restart) don't stop if it doesn't find controlling terminal. Even the service has been executed successfully. You can reproduce it with the following code:

test.sh
----------------------------------------------
echo "restart daemon"
systemctl restart rsyslog.service >/dev/null 2>&1
echo "restart success"
----------------------------------------------
./test.sh & (it doesn't stop)
restart daemon

ps -auxf
--------------------------------------------------

.... pts/1    T      \_ /bin/bash ./test.sh
.... pts/1    T        \_ systemctl restart rsyslog.service
.... pts/1    Tl         \_ /usr/bin/pkttyagent --notify-fd 6

-------------------------------------------------

/var/log/secure
------------------------------------------------
polkitd[1310]: Registered Authentication Agent for unix-process:18472:252325 (system bus name :1.105 [/usr/bin/pkttyagent --notify-fd 6 --fallback], object
path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
------------------------------------------------

Quoted 3 lines

This change leads to syslog[1-10] testcase hang. I fix it by adding tty beforce
service, so these cases don't hang.

Bug 1711536 - polkit-0.112-22.el7 breaks restarting services from background process
https://bugzilla.redhat.com/show_bug.cgi?id=1711536

Not sure though we should be adding workarounds for what seems like a bug.

Regards,
Jan

Quoted 79 lines

(pkttyagent: PolkitAgentTextListener leaves echo tty disabled if
SIGINT/SIGTERM) [1]https://gitlab.freedesktop.org/polkit/polkit/commit/bfb722bbe5a503095cc7e860f282b142f5aa75f1

---
 testcases/lib/daemonlib.sh | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
testcases/lib/daemonlib.sh +12 -13
index 0de3f86af..5807cbea0 100644
@@ -47,43 +47,43 @@ fi
 start_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl start $1.service > /dev/null 2>&1
+		tty | systemctl start $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 start > /dev/null 2>&1
+		tty | service $1 start > /dev/null 2>&1
 	else
-		/etc/init.d/$1 start > /dev/null 2>&1
+		tty |/etc/init.d/$1 start > /dev/null 2>&1
 	fi
 }
 
 stop_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl stop $1.service > /dev/null 2>&1
+		tty | systemctl stop $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 stop > /dev/null 2>&1
+		tty | service $1 stop > /dev/null 2>&1
 	else
-		/etc/init.d/$1 stop > /dev/null 2>&1
+		tty | /etc/init.d/$1 stop > /dev/null 2>&1
 	fi
 }
 
 status_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl is-active $1.service > /dev/null 2>&1
+		tty | systemctl is-active $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 status > /dev/null 2>&1
+		tty | service $1 status > /dev/null 2>&1
 	else
-		/etc/init.d/$1 status > /dev/null 2>&1
+		tty | /etc/init.d/$1 status > /dev/null 2>&1
 	fi
 }
 
 restart_daemon()
 {
 	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl restart $1.service > /dev/null 2>&1
+		tty | systemctl restart $1.service > /dev/null 2>&1
 	elif command -v service >/dev/null 2>&1; then
-		service $1 restart > /dev/null 2>&1
+		tty | service $1 restart > /dev/null 2>&1
 	else
-		/etc/init.d/$1 restart > /dev/null 2>&1
+		tty | /etc/init.d/$1 restart > /dev/null 2>&1
 	fi
 }
--

2.18.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

author
#2 lore raw

PATCH 1/1 daemonlib.sh: call tty before executing service

Quoted 32 lines

----- Original Message -----

Quoted 30 lines

On my machine, polkit-0.112-22.el7.x86_64 has contained the [1] patch.

This patch leads service acitons(such as restart) don't stop if it doesn't find controlling terminal. Even the service has been executed successfully. You can reproduce it with the following code:

test.sh
----------------------------------------------
echo "restart daemon"
systemctl restart rsyslog.service>/dev/null 2>&1
echo "restart success"
----------------------------------------------
./test.sh& (it doesn't stop)
restart daemon

ps -auxf
--------------------------------------------------

.... pts/1    T      \_ /bin/bash ./test.sh
.... pts/1    T        \_ systemctl restart rsyslog.service
.... pts/1    Tl         \_ /usr/bin/pkttyagent --notify-fd 6

-------------------------------------------------

/var/log/secure
------------------------------------------------
polkitd[1310]: Registered Authentication Agent for unix-process:18472:252325 (system bus name :1.105 [/usr/bin/pkttyagent --notify-fd 6 --fallback], object
path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
------------------------------------------------

Quoted 7 lines
Quoted 3 lines

This change leads to syslog[1-10] testcase hang. I fix it by adding tty beforce
service, so these cases don't hang.

Bug 1711536 - polkit-0.112-22.el7 breaks restarting services from background process
https://bugzilla.redhat.com/show_bug.cgi?id=1711536

Not sure though we should be adding workarounds for what seems like a bug.

Hi Jan

I also think it may be a polkit rpm bug because this action is too abnormal.
Or, we can ask polkit mantainer about it on gitlab.

Regards
Yang Xu

Quoted 84 lines

Regards,
Jan

Quoted 75 lines

(pkttyagent: PolkitAgentTextListener leaves echo tty disabled if
SIGINT/SIGTERM) [1]https://gitlab.freedesktop.org/polkit/polkit/commit/bfb722bbe5a503095cc7e860f282b142f5aa75f1

---
  testcases/lib/daemonlib.sh | 24 ++++++++++++------------
  1 file changed, 12 insertions(+), 12 deletions(-)
testcases/lib/daemonlib.sh +12 -13
index 0de3f86af..5807cbea0 100644
@@ -47,43 +47,43 @@ fi
  start_daemon()
  {
  	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl start $1.service>  /dev/null 2>&1
+		tty | systemctl start $1.service>  /dev/null 2>&1
  	elif command -v service>/dev/null 2>&1; then
-		service $1 start>  /dev/null 2>&1
+		tty | service $1 start>  /dev/null 2>&1
  	else
-		/etc/init.d/$1 start>  /dev/null 2>&1
+		tty |/etc/init.d/$1 start>  /dev/null 2>&1
  	fi
  }
 
  stop_daemon()
  {
  	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl stop $1.service>  /dev/null 2>&1
+		tty | systemctl stop $1.service>  /dev/null 2>&1
  	elif command -v service>/dev/null 2>&1; then
-		service $1 stop>  /dev/null 2>&1
+		tty | service $1 stop>  /dev/null 2>&1
  	else
-		/etc/init.d/$1 stop>  /dev/null 2>&1
+		tty | /etc/init.d/$1 stop>  /dev/null 2>&1
  	fi
  }
 
  status_daemon()
  {
  	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl is-active $1.service>  /dev/null 2>&1
+		tty | systemctl is-active $1.service>  /dev/null 2>&1
  	elif command -v service>/dev/null 2>&1; then
-		service $1 status>  /dev/null 2>&1
+		tty | service $1 status>  /dev/null 2>&1
  	else
-		/etc/init.d/$1 status>  /dev/null 2>&1
+		tty | /etc/init.d/$1 status>  /dev/null 2>&1
  	fi
  }
 
  restart_daemon()
  {
  	if [ $HAVE_SYSTEMCTL -eq 1 ]; then
-		systemctl restart $1.service>  /dev/null 2>&1
+		tty | systemctl restart $1.service>  /dev/null 2>&1
  	elif command -v service>/dev/null 2>&1; then
-		service $1 restart>  /dev/null 2>&1
+		tty | service $1 restart>  /dev/null 2>&1
  	else
-		/etc/init.d/$1 restart>  /dev/null 2>&1
+		tty | /etc/init.d/$1 restart>  /dev/null 2>&1
  	fi
  }
--

2.18.1

Quoted 3 lines

--
Mailing list info: https://lists.linux.it/listinfo/ltp

.

author
#3 lore raw

PATCH 1/1 daemonlib.sh: call tty before executing service

In reply to Jan Stancek
Quoted 5 lines

Bug 1711536 - polkit-0.112-22.el7 breaks restarting services from background process
https://bugzilla.redhat.com/show_bug.cgi?id=1711536

Not sure though we should be adding workarounds for what seems like a bug.

Hi Jan

This bug has been sloved on gitlab after commit 75c8b8afaa ("pkttyagent: process stopped by SIGTTOU if run in background job") ,as below:

https://gitlab.freedesktop.org/polkit/polkit/issues/85
https://gitlab.freedesktop.org/polkit/polkit/commit/75c8b8afaa8e1fba0efb63c3c7b66b5b5f713a35

I think my patch was meaningless.

Thanks
Yang Xu

#4 lore raw

PATCH 1/1 daemonlib.sh: call tty before executing service

----- Original Message -----

Quoted 5 lines
Quoted 5 lines

Bug 1711536 - polkit-0.112-22.el7 breaks restarting services from background process
https://bugzilla.redhat.com/show_bug.cgi?id=1711536

Quoted 8 lines
Quoted 1 line

Not sure though we should be adding workarounds for what seems like a bug.

Hi Jan

This bug has been sloved on gitlab after commit 75c8b8afaa ("pkttyagent:
process stopped by SIGTTOU if run in background job") ,as below:

https://gitlab.freedesktop.org/polkit/polkit/issues/85
https://gitlab.freedesktop.org/polkit/polkit/commit/75c8b8afaa8e1fba0efb63c3c7b66b5b5f713a35

Thanks for info, good to see there's a fix.

Quoted 9 lines

I think my patch was meaningless.

Thanks
Yang Xu