Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Systemd shutdown, halt and reboot handling
Forum Updated to NodeBB v4.3 + New Features

Systemd shutdown, halt and reboot handling

Scheduled Pinned Locked Moved Solved General and Desktop
systemdpoweroffhaltreboot
19 Posts 3 Posters 2.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    egor.utsov
    wrote on 11 Jan 2019, 19:30 last edited by
    #1

    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 invoke Qt.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 event processEvents 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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Jan 2019, 20:06 last edited by
      #2

      Hi,
      What exactly are you trying to do ? Session management ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      E 1 Reply Last reply 11 Jan 2019, 20:15
      0
      • S SGaist
        11 Jan 2019, 20:06

        Hi,
        What exactly are you trying to do ? Session management ?

        E Offline
        E Offline
        egor.utsov
        wrote on 11 Jan 2019, 20:15 last edited by egor.utsov 1 Nov 2019, 20:15
        #3

        @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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Jan 2019, 20:17 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          E 2 Replies Last reply 11 Jan 2019, 20:20
          1
          • S SGaist
            11 Jan 2019, 20:17

            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.

            E Offline
            E Offline
            egor.utsov
            wrote on 11 Jan 2019, 20:20 last edited by
            #5

            @SGaist but then i will need separate application, that will distinguish between event types.

            1 Reply Last reply
            0
            • S SGaist
              11 Jan 2019, 20:17

              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.

              E Offline
              E Offline
              egor.utsov
              wrote on 11 Jan 2019, 20:20 last edited by
              #6

              @SGaist By the events i meant poweroff, reboot, etc..

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 11 Jan 2019, 20:28 last edited by
                #7

                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 ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                E 1 Reply Last reply 11 Jan 2019, 20:32
                1
                • S SGaist
                  11 Jan 2019, 20:28

                  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 ?

                  E Offline
                  E Offline
                  egor.utsov
                  wrote on 11 Jan 2019, 20:32 last edited by
                  #8

                  @SGaist It can happen when user login through ssh and cissue systemctl poweroff for example

                  K 1 Reply Last reply 12 Jan 2019, 04:13
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 11 Jan 2019, 20:41 last edited by
                    #9

                    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.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • E egor.utsov
                      11 Jan 2019, 20:32

                      @SGaist It can happen when user login through ssh and cissue systemctl poweroff for example

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 12 Jan 2019, 04:13 last edited by kshegunov 1 Dec 2019, 04:13
                      #10

                      In addition to what @SGaist wrote, there are limitations of what you can and can't do in signal handlers. Not everything is allowed.

                      Read and abide by the Qt Code of Conduct

                      E 1 Reply Last reply 12 Jan 2019, 05:35
                      1
                      • K kshegunov
                        12 Jan 2019, 04:13

                        In addition to what @SGaist wrote, there are limitations of what you can and can't do in signal handlers. Not everything is allowed.

                        E Offline
                        E Offline
                        egor.utsov
                        wrote on 12 Jan 2019, 05:35 last edited by
                        #11

                        @kshegunov it is done not from signal handler, but from slot, connected to qsocketnotifier.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 12 Jan 2019, 21:29 last edited by
                          #12

                          Depending on what you do, you will get a SIGTERM and a SIGKILL right after. The later you can't interrupt nor try to do some more stuff.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          E 1 Reply Last reply 13 Jan 2019, 18:03
                          0
                          • S SGaist
                            12 Jan 2019, 21:29

                            Depending on what you do, you will get a SIGTERM and a SIGKILL right after. The later you can't interrupt nor try to do some more stuff.

                            E Offline
                            E Offline
                            egor.utsov
                            wrote on 13 Jan 2019, 18:03 last edited by
                            #13

                            @SGaist but as i remember systemd documentation stated, that process have 60 seconds until sigkill

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 13 Jan 2019, 20:29 last edited by
                              #14

                              60 second per running process ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              E 1 Reply Last reply 14 Jan 2019, 15:47
                              0
                              • S SGaist
                                13 Jan 2019, 20:29

                                60 second per running process ?

                                E Offline
                                E Offline
                                egor.utsov
                                wrote on 14 Jan 2019, 15:47 last edited by egor.utsov
                                #15

                                @SGaist i guessed so. Saw it somewhere in docs.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 14 Jan 2019, 20:32 last edited by
                                  #16

                                  Can you find that information again ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  E 1 Reply Last reply 14 Jan 2019, 22:55
                                  0
                                  • S SGaist
                                    14 Jan 2019, 20:32

                                    Can you find that information again ?

                                    E Offline
                                    E Offline
                                    egor.utsov
                                    wrote on 14 Jan 2019, 22:55 last edited by
                                    #17

                                    @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.

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 15 Jan 2019, 23:17 last edited by
                                      #18

                                      Is your application started as a systemd service ?

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      E 1 Reply Last reply 20 Jan 2019, 19:47
                                      0
                                      • S SGaist
                                        15 Jan 2019, 23:17

                                        Is your application started as a systemd service ?

                                        E Offline
                                        E Offline
                                        egor.utsov
                                        wrote on 20 Jan 2019, 19:47 last edited by
                                        #19

                                        @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.

                                        1 Reply Last reply
                                        2

                                        1/19

                                        11 Jan 2019, 19:30

                                        • Login

                                        • Login or register to search.
                                        1 out of 19
                                        • First post
                                          1/19
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved