3

In my Ubuntu application, I wanted to perform certain finalization for my application before the system is being shutdown. For that, I need to identify the shutdown event in my application.

From what I have read online, there are mainly two major solutions, that are being suggested.

  1. using the 'PrepareForShutdown' dbus signal.
  2. trapping the SIGTERM signal that is send to the running applications prior to shutdown.

However, I have tried both the ways and they don't seem to work for me. The handler that I m registering for 'PrepareForShutdown' never gets invoked.

For method 2, I have observed that my application does not receive SIGTERM signal, instead it receives some other signal a moment before being terminated using SIGKILL.

Can someone help me out, what should I be using to identify the shutdown correctly? I do not intend to read it from certain OS files, please provide an event based solution.

1 Answers1

0

You can use libportal for that, there is a demo in Workbench (also available here: https://github.com/workbenchdev/demos/tree/main/src/Session%20Monitor%20and%20Inhibit)

Currently there are sample codes in Vala, Python and JavaScript; but you can port it to C++ to use with GTK or Qt.

Xut
  • 1