libassa 3.5.1
Loading...
Searching...
No Matches
SigAction.h
Go to the documentation of this file.
1// -*- c++ -*-
2//------------------------------------------------------------------------------
3// SigAction.h
4//------------------------------------------------------------------------------
5// Copyright (c) 1997 by Vladislav Grinchenko
6//
7// This library is free software; you can redistribute it and/or
8// modify it under the terms of the GNU Library General Public
9// License as published by the Free Software Foundation; either
10// version 2 of the License, or (at your option) any later version.
11//------------------------------------------------------------------------------
12
13#ifndef _SigAction_h
14#define _SigAction_h
15
16// System includes
17//
18#include <signal.h>
19#include <errno.h>
20
21#include "assa/Assure.h"
22#include "assa/SigSet.h"
23
24// some convenient typedefs
25//
26extern "C" {
27typedef struct sigaction SIGACTION;
28typedef void (*C_SIG_HANDLER)( int );
29}
30
31namespace ASSA {
32
33#if !defined(WIN32)
34
95{
96public:
100 SigAction();
101
115 SigSet* sig_mask_ = 0,
116 int flags_ = 0);
117
134 int signum_,
135 SigSet* sig_mask_ = 0,
136 int flags_ = 0);
137
150
160
167 int retrieve_action (int signum_);
168
172 void action (SIGACTION * sa_);
173
177 SIGACTION * action ();
178
182 void flags (int new_flags_);
183
187 int flags ();
188
191 void mask (SigSet & mask_set_);
192
195 SigSet mask ();
196
200
204
209 operator SIGACTION *();
210
211private:
214};
215
216//-------------------------------------------------------------------------
217//------------------------Inline functions---------------------------------
218//-------------------------------------------------------------------------
219inline
221SigAction ()
222{
223 trace_with_mask("SigAction::SigAction", SIGACT);
224
225 m_sa.sa_flags = 0;
226 sigemptyset(&m_sa.sa_mask);
227 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) 0;
228}
229
230inline
234 int flags_)
235{
236 trace_with_mask("SigAction::SigAction(,,)", SIGACT);
237
238 m_sa.sa_flags = flags_;
239 if (sig_mask_ == NULL) {
240 sigemptyset(&m_sa.sa_mask);
241 }
242 else {
243 /*---
244 here, suppose to do bitwise structure assignment,
245 but does it really do so?
246 = *sig_mask_
247 = *(sig_mask_.operator *())
248 = *(SigSet *tmp = &sig_mask_.m_sa) ????
249 ---*/
250 m_sa.sa_mask = **sig_mask_;
251 }
252 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) handler_;
253}
254
255inline
258 int signum_,
260 int flags_)
261{
262 trace_with_mask("SigAction::SigAction(,,,)", SIGACT);
263
264 m_sa.sa_flags = flags_;
265 if (sig_mask_ == NULL) {
266 sigemptyset(&m_sa.sa_mask);
267 }
268 else {
269 /*--- same problem as above... ---*/
270 m_sa.sa_mask = **sig_mask_;
271 }
272 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) handler_;
273
274 /*--- installing disposition... ---*/
275 sigaction (signum_, &m_sa, 0);
276}
277
278inline void
281{
282 trace_with_mask("SigAction::action", SIGACT);
283 m_sa = *sa_;
284}
285
286inline SIGACTION *
288action ()
289{
290 trace_with_mask("SigAction::action", SIGACT);
291
292 return &m_sa;
293}
294
295inline void
297flags (int new_flags_)
298{
299 trace_with_mask("void SigAction::flags()", SIGACT);
300
301 m_sa.sa_flags = new_flags_;
302}
303
304inline int
306flags ()
307{
308 trace_with_mask("int SigAction::flags()", SIGACT);
309
310 return m_sa.sa_flags;
311}
312
313inline void
316{
317 trace_with_mask("void SigAction::mask()", SIGACT);
318
319 m_sa.sa_mask = *mask_set_;
320}
321
322inline SigSet
324mask ()
325{
326 trace_with_mask("SigSet SigAction::mask()", SIGACT);
327
328 SigSet tmpset(&m_sa.sa_mask);
329 return tmpset;
330}
331
332inline void
335{
336 trace_with_mask("void SigAction::handler()", SIGACT);
337
338 *(C_SIG_HANDLER*) &m_sa.sa_handler = (C_SIG_HANDLER) sha_;
339}
340
341inline C_SIG_HANDLER
343handler ()
344{
345 trace_with_mask("C_SIG_HANDLER SigAction::handler()", SIGACT);
346
347 return (C_SIG_HANDLER) m_sa.sa_handler;
348}
349
350inline
351SigAction::operator SIGACTION * ()
352{
353 trace_with_mask("SigAction::operator SIGACTION * ()", SIGACT);
354
355 return &m_sa;
356}
357
358inline int
361{
362 trace_with_mask("SigAction::register_action()", SIGACT);
363
364 /*--- place here recursive mutex lock to guard ... ---*/
365 struct sigaction *osa = oaction_ == 0 ? 0 : oaction_->action();
366 return sigaction(signum_, &m_sa, osa);
367}
368
369inline int
372{
373 trace_with_mask("SigAction::restore_action()", SIGACT);
374
375 m_sa = *oaction_.action();
376 return sigaction(signum_, &m_sa, 0);
377}
378
379inline int
382{
383 trace_with_mask("SigAction::retrieve_action()", SIGACT);
384
385 return sigaction(signum_, 0, &m_sa);
386}
387
388#endif // !defined(WIN32)
389
390} // end namespace ASSA
391
392
393#endif /* _SigAction_h */
A collection of assert function wrappers.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
void(* C_SIG_HANDLER)(int)
Definition SigAction.h:28
struct sigaction SIGACTION
Definition SigAction.h:27
SigSet is a wrapper for UNIX sigset_t structure that provides all manipulators on this structure as w...
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
int restore_action(int signum_, SigAction &oaction_)
Change object's disposition to oaction_, and install it as current disposition for the signal signum_...
Definition SigAction.h:371
SigAction()
Default constructor creates SigAction object with null-action.
Definition SigAction.h:221
int retrieve_action(int signum_)
Retrieve current disposition for the signal signum_ into this object.
Definition SigAction.h:381
C_SIG_HANDLER handler()
Retrieve current signal handler function.
Definition SigAction.h:343
SigSet mask()
Retrieve current signal mask.
Definition SigAction.h:324
SIGACTION m_sa
sigaction structure itself
Definition SigAction.h:213
int flags()
Retrieve current flags.
Definition SigAction.h:306
int register_action(int signum_, SigAction *oaction_=0)
Register this object as current disposition for signal signum_, and store old disposition in oaction_...
Definition SigAction.h:360
SIGACTION * action()
Retrieve current sigaction.
Definition SigAction.h:288
@ SIGACT
Class SigACtion messages
Definition LogMask.h:48