LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-26-2005, 11:59 PM   #1
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
SIGPWR sent to init, and /etc/inittab


The /etc/inittab has this line to define init's behavior on receiving SIGPWR
pf:owerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

Then it has this line
pr:12345owerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

But what signal (or other) actually invokes this ?
 
Old 03-27-2005, 12:05 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Check out man 7 signal:
Code:
SIGPWR      29,30,19    Term    Power failure (System V)
The signal is sent by the kernel. If you have the correct cable hooked up to your UPS, it will tell the kernel that there's been a power failure.

Last edited by itsme86; 03-27-2005 at 12:07 AM.
 
Old 03-27-2005, 12:29 AM   #3
randyding
Member
 
Registered: May 2004
Posts: 552

Original Poster
Rep: Reputation: 31
I may be mistaken about this, and doing it totally wrong, but I thought SIGPWR was actually sent to PID #1 by powerd, a daemon that monitors the serial port CTS line (* goes active on power failure *).
Right now I wrote and installed my own powerd that does exactly this. When CTS goes active, I do in C code...
Code:
kill(1,SIGPWR);
Then if CTS goes inactive (before shutdown kills my daemon) I do this in C code...
Code:
system("/sbin/shutdown -c \"Power restored.\"");
My system() function call here bypasses the action defined in the /etc/inittab for power-restore.

Is my powerd doing this incorrectly then ?
 
Old 03-27-2005, 12:34 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Oh, I see. You're trying to find out how to tell init that the power has been restored...I'm not quite sure how that's done...hmm...
 
Old 03-27-2005, 12:40 AM   #5
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
I think this is the information you're looking for:
Code:
# powerwait – The process will be executed when init receives the SIGPWR signal. Init will wait for the process to finish before continuing.
# powerfail – Same as powerwait but init does not wait for the process to complete.
# powerokwait – The process will be executed when init receives the SIGPWR signal provided there is a file called "/etc/powerstatus" containing the word "OK".
So it looks like when your program sees that power is okay, it should write OK to /etc/powerstatus and then send SIGPWR to init again.
 
Old 03-27-2005, 12:53 AM   #6
randyding
Member
 
Registered: May 2004
Posts: 552

Original Poster
Rep: Reputation: 31
Yes, thanks. All other code I found via google did it the way I showed,
which didn't feel right.
I'll have to experiment and dig into it some more then. Its not clear
at first glance when the /etc/powerstatus file has to be unlinked.
I'm assuming prior to the next power failure at a minimum.
Thanks again...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel Panic No init found. Try passing init..... Adrian Baker Mandriva 2 02-28-2005 11:47 AM
Redhat linux9.0:System hangs,if gives init 3 or init 4 Sailaja Reddy Linux - Newbie 4 09-16-2004 03:19 AM
Kernal Panic: No init found. Try passing init= option to kernel raees Linux - General 12 03-18-2004 11:10 PM
error: No init found. Try passing the init= option to the Kernel neylitalo Linux - Laptop and Netbook 3 01-22-2004 09:34 PM
error "Kernel panic: No init found. Try passing init= option Anauj0101 Linux - Newbie 3 05-06-2003 10:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration