[haiku-3rdparty-dev] Re: How to detect if a shutdown is in progress?

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Mon, 30 Jan 2012 03:09:40 +0100

On 2012-01-29 at 13:48:41 [+0100], Brian Hill <perelandra777@xxxxxxxxx> wrote:
> Here is some background on my question.  I have written a daemon which 
> monitors when applications quit and provides an alert if certain 
> applications defined by the user quit.  As a background application, the 
> daemon is one of the last processes quit during a system shutdown so this 
> daemon throws alerts for all the applications it is watching when you shut 
> down.  In BeOS there was a user shutdown script that I used to quit the 
> daemon quickly on a shutdown to prevent these alerts (since obviously you 
> are shutting the system down and want everything the quit).  Haiku does not 
> have this shutdown script function yet.

If that's the case, then patches to fix it are definitely welcome. :-)

> Is there any way to query the shutdown status of the system?  I have been 
> looking through all the Registrar, TRoster, BRoster, etc code and have not 
> found an easy way to query if the system is currently doing a shutdown.  
> The only thing I have come up with as an idea is to call 
> BRoster::Private.AddApplication with some bogus information and see if it 
> returns a B_SHUTTING_DOWN error from the TRoster.  Any ideas on how to 
> better get the shutdown status?

Using private API isn't that good an idea, since it can change at any time. I 
suppose you could use the same strategy just with public API, i.e. 
BRoster::Launch() your daemon (which would have to be single/exclusive 
launch, so it isn't actually run again). Another option would be to script 
the registrar to find out whether the shutdown window is shown, though that 
might be a bit fragile as well.

The preferred way would be to add a BRoster::IsShuttingDown() of course. 
Again, patches welcome. :-)

CU, Ingo

Other related posts: