Systemd shutdown, halt and reboot handling
-
Hi all. I am trying to handle actiins mentioned in topic and faced with issue.
I use signalfd and qsocketnotifier to get information about signals. Mask SIGTERM signal with pthread_mask function. Inside lambda, connected to qsocketnotifier, i invoke qml function, that change the screen and start the qml Timer (fired after 100 ms) and in the timer onTriggered invokeQt.callLater(Qt.quit)
. This timeout is neccesary to give qt time to update the screen.The issue is timer
onTriggered
is not invoked each time as system halted or rebooted or shutdown. From time to time this event just dissapear.I did some tests inside lambda, connected to notifier: in particulary, instead of setup timer in qml, did a simple loop with
qApp->processEvents()
and check time difference at each loop. From time to time eventprocessEvents
method hangs.I guess it is the reason, why timer was not invoked. But main qustion - why event loop can be freezed?
Need to mention, that sending signals from command line always works as expected.
-
Hi,
What exactly are you trying to do ? Session management ? -
@SGaist No. My application provide gui for embedded device on small screen wit linuxfb as backend. This aaplication allows the user to control device settings and check its status. I just want to display one of the mentioned states. For example, when device rebooted, clear screen and set "Reboot" text on the screen until system boot.
-
That's rather something you should do at the system level i.e. dump a picture in your frame buffer after your application has closed.
-
I understood that. However as already written, that's not for your application to do because it's going to be stopped before the shutdown and reboot are going to happen. So if you trigger that from within your application then you can already show something but you still have to setup your system to show more information once your application is stopped because the frame buffer is likely going to be cleared at that point.
If you don't handle the shutdown through your application then how is it happening ?
-
Then as I already suggested, dump a picture in your frame buffer as part of the procedure. Your application will be killed quickly so it won't have the time to show anything special in that case.
-
In addition to what @SGaist wrote, there are limitations of what you can and can't do in signal handlers. Not everything is allowed.
-
@kshegunov it is done not from signal handler, but from slot, connected to qsocketnotifier.
-
Depending on what you do, you will get a
SIGTERM
and aSIGKILL
right after. The later you can't interrupt nor try to do some more stuff. -
60 second per running process ?
-
Can you find that information again ?
-
@SGaist No. Maybe i am mistaken. I found some info here: http://manpages.ubuntu.com/manpages/cosmic/en/man5/systemd.service.5.html
Check section about
TimeoutStopSec=
. On my system it is commented out, but here stated, that it is even 90 s. As i understand it is applied per-unit. -
Is your application started as a systemd service ?
-
@SGaist Yes, it is started as systemd service. Finally i found the reason, why it hangs. It is happened because I made blocking syscall from event loop. So this thread can be closed and marked as resolved. Appproach with QSocketNotifier and signalfd works.