libreoffice-online/common/SigUtil.hpp
Ashod Nakashian b74306acd5 wsd: replace mutex in signal handler
There are a few things acceptable/safe in a
signal handler, and taking locks is not one of them.

This replaces the logic with a simple counter that
serves the purpose just as well.

If we get a double signal, we log and ignore.

Change-Id: If589c18492468c120d00c213805467bcbba05d27
Reviewed-on: https://gerrit.libreoffice.org/83150
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-11-19 16:12:29 +01:00

85 lines
2.4 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SIGNALUTIL_HPP
#define INCLUDED_SIGNALUTIL_HPP
#include <atomic>
#include <mutex>
#if MOBILEAPP
static constexpr bool ShutdownRequestFlag(false);
extern std::atomic<bool> MobileTerminationFlag;
#endif
namespace SigUtil
{
/// Get the flag used to commence clean shutdown.
/// requestShutdown() is used to set the flag.
bool getShutdownRequestFlag();
/// Get the flag to stop pump loops forcefully.
bool getTerminationFlag();
/// Set the flag to stop pump loops forcefully.
void setTerminationFlag();
#if MOBILEAPP
/// Reset the flag to stop pump loops forcefully.
/// Only necessary in Mobile.
void resetTerminationFlag();
#endif
/// Get the flag to dump internal state.
bool getDumpGlobalState();
/// Reset the flag to dump internal state.
void resetDumpGlobalState();
#if !MOBILEAPP
/// Wait for the signal handler, if any,
/// and prevent _Exit while collecting backtrace.
void waitSigHandlerTrap();
/// Returns the name of the signal.
const char* signalName(int signo);
/// Register a wakeup function when changing
/// Trap signals to cleanup and exit the process gracefully.
void setTerminationSignals();
/// Trap all fatal signals to assist debugging.
void setFatalSignals();
/// Trap generally useful signals
void setUserSignals();
/// Requests the server to initiate graceful shutdown.
/// Shutting down is a multi-stage process, because
/// it can be requested via signals.
/// Since we need to notify clients, we can't
/// invoke the sockets while in a signal handler.
/// This flags the server to notify clients first
/// then flags for shutdown.
void requestShutdown();
/// Kills a child process and returns true when
/// child pid is removed from the process table
/// after a certain (short) timeout.
bool killChild(const int pid);
/// Dump a signal-safe back-trace
void dumpBacktrace();
#endif // !MOBILEAPP
} // end namespace SigUtil
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */