diff options
Diffstat (limited to 'src/syncevo/SuspendFlags.h')
-rw-r--r-- | src/syncevo/SuspendFlags.h | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/syncevo/SuspendFlags.h b/src/syncevo/SuspendFlags.h index a45c1154..e6f9c07f 100644 --- a/src/syncevo/SuspendFlags.h +++ b/src/syncevo/SuspendFlags.h @@ -56,7 +56,9 @@ class SuspendFlags /** suspend sync request received again (only written to event FD, not returned by getState()) */ SUSPEND_AGAIN, /** abort sync request received again (only written to event FD, not returned by getState()) */ - ABORT_AGAIN + ABORT_AGAIN, + + ABORT_MAX }; /** access to singleton */ @@ -73,6 +75,12 @@ class SuspendFlags State getState() const; /** + * Returns or-ed mask of all signals handled so far. + * See activate(). + */ + uint32_t getReceivedSignals() const { return m_receivedSignals; } + + /** * Throws a "aborting as requested by user" StatusException with * LOCERR_USERABORT as status code if the current state is not * NORMAL. In other words, suspend and abort are both @@ -83,7 +91,7 @@ class SuspendFlags /** * Users of this class can read a single char for each received * signal from this file descriptor. The char is the State that - * was entered by that signal. This can be used to be notified + * was entered by that signal. This can be used to be notified * immediately about changes, without having to poll. * * -1 if not activated. @@ -96,11 +104,25 @@ class SuspendFlags }; /** - * Allocate file descriptors, set signal handlers for SIGINT and - * SIGTERM. Once the returned guard is freed, it will - * automatically deactivate signal handling. + * Allocate file descriptors, set signal handlers for the chosen + * signals (SIGINT and SIGTERM by default). Once the returned + * guard is freed, it will automatically deactivate signal + * handling. + * + * Additional signals like SIGURG or SIGIO may also be used. It is + * unlikely that any library used by SyncEvolution occupies these + * signals for its own use. + * + * Only SIGINT and SIGTERM influence the overall State. All + * received signals, including SIGINT and SIGTERM, are recorded + * and can be retrieved via getReceivedSignals(). + * + * It is possible to call activate multiple times. All following + * calls do nothing except creating a new reference to the same + * guard. In particular they cannot add or remove handled + * signals. */ - boost::shared_ptr<Guard> activate(); + boost::shared_ptr<Guard> activate(uint32_t sigmask = (1<<SIGINT)|(1<<SIGTERM)); /** * Retrieve state changes pushed into pipe by signal @@ -162,12 +184,18 @@ class SuspendFlags /** state as observed by signal handler */ State m_state; + /** or-ed bit mask of all received signals */ + uint32_t m_receivedSignals; + /** time is measured inside signal handler */ time_t m_lastSuspend; int m_senderFD, m_receiverFD; - struct sigaction m_oldSigInt, m_oldSigTerm; + // For the sake of simplicity we only support signals in the 1-31 range. + uint32_t m_activeSignals; + struct sigaction m_oldSignalHandlers[32]; + boost::weak_ptr<Guard> m_guard; boost::weak_ptr<StateBlocker> m_suspendBlocker, m_abortBlocker; boost::shared_ptr<StateBlocker> block(boost::weak_ptr<StateBlocker> &blocker); }; |