Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to catch any OS shut down and execute some actions before letting the OS be shutted down. I'm using Fedora 19 and C++.

I'm able to catch a shutdown signal given by the console with the following C++ code :

myAct.sa_handler = myStructure::mySignalHandler;
sigaction(mySignal, &act, NULL);

The mySignal signal can be activated via /etc/init.d and a custom code executed before a shutdown is made.

On Fedora 12 Kernel 2.6, this solutions works perfectly. The solution works on Fedora 19 Kernel 3.9.5 if I try to shut down the computer using the graphic interface.

However, I can't manage to execute my code when a command is used in a terminal to reboot or shut down the computer on Fedora 19 kernel 3.9.5 The solution doesn't work anymore since it dropped the usual init.d script system.

Putting my script on the /usr/lib/systemsd location doesn't work, the script is executed, but the other scripts are also executed. Thus, the systems shuts down not treating my commands.

How may I solve that problem?

share|improve this question
    
A shutdown doesn't send a “shutdown signal”: there's no such thing. Usually shutdown sends SIGTERM, waits a little, then sends SIGKILL. What signal are you catching? –  Gilles Apr 23 at 21:33
    
I want to execute code before the SIGTERM signal is sent by the OS. –  Xaltar Apr 24 at 7:47
    
Then you would not be getting a signal. You would need to run your code from the shutdown code invoked by systemd. I think this requires being root (it does with sysvinit and upstart, and probably does with systemd as well since otherwise a user could block a shutdown). –  Gilles Apr 24 at 10:24
    
That's precisely what I'm trying to do ... –  Xaltar Apr 24 at 11:13
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.