summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Shutdown_Utilities.cpp
blob: 26f1a46526a6bee5cde5f295c02d7203e5fa3032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// $Id$

//ACE_RCSID(orbsvcs, Shutdown_Utilities, "$Id$")

#include "Shutdown_Utilities.h"

Service_Shutdown::Service_Shutdown (Shutdown_Functor& sf)
  : functor_(sf)
{
  ACE_Sig_Set std_signals;
#if !defined(ACE_LACKS_UNIX_SIGNALS)
  std_signals.sig_add (SIGINT);
  std_signals.sig_add (SIGTERM);
#endif
  this->set_signals (std_signals);
}

Service_Shutdown::Service_Shutdown (Shutdown_Functor& sf, ACE_Sig_Set& which_signals)
  : functor_(sf)
{
  this->set_signals (which_signals);
}

// It would be nice if we could rely on a portable #define that
// declared the largest signal held in sigset_t, but we can't.
// So, for now, we'll make a possibly bold assumption that sigset_t
// will be at least four bytes.  If somebody wants to use a signal
// greater than that, then they'll have to redefine ACE_NSIG.
//
// It would be even nicer if the register_handler() method just took
// an ACE_Sig_Set as an argument and handled all this stuff itself.
// 
void
Service_Shutdown::set_signals (ACE_Sig_Set& which_signals)
{
  // iterate over all the signals in which_signals and register them...
  int did_register = 0;
  for (int i = 1; i < ACE_NSIG; i++)
    if (which_signals.is_member (i))
      {
        if (this->shutdown_.register_handler (i, this) == -1)
          ACE_DEBUG ((LM_WARNING,
                      "WARNING: Failed to register signal handler for signal %d: %p\n",
                      i));
        else
          did_register = 1;
      }

  if (! did_register)
    ACE_DEBUG ((LM_WARNING,
                "WARNING: Service_Shutdown did not register any signals.\n"));
}

Service_Shutdown::~Service_Shutdown ()
{
}

int
Service_Shutdown::handle_signal (int signum,
                                 siginfo_t*, ucontext_t*)
{
  this->functor_(signum);
  return 0;
}