<commit_before>#ifndef DUNE_STUFF_SIGNALS
#define DUNE_STUFF_SIGNALS

#include <signal.h>

#include <dune/stuff/logging.hh>

namespace Stuff {
	namespace Signals {
		void resetSignal(int signal)
		{
			struct sigaction new_action;
			new_action.sa_handler = SIG_DFL;
			sigemptyset (&new_action.sa_mask);
			new_action.sa_flags = 0;
			sigaction (signal, &new_action, NULL);
		}

		void handleInterrupt(int signal)
		{
			Logger().Info() << "forcefully terminated at " << Logging::TimeString() << std::endl;
			Logger().Flush();
			//reset signal handler and commit suicide
			resetSignal(signal);
			kill(getpid(), signal);
		}

		void installSignalHandlers()
		{
			struct sigaction new_action;

			/* Set up the structure to specify the new action. */
			new_action.sa_handler = handleInterrupt;
			sigemptyset (&new_action.sa_mask);
			new_action.sa_flags = 0;

			sigaction (SIGINT, &new_action, NULL);
		}
	}//end namespace signals
} //end namepsace stuff
#endif
<commit_msg>documentation and generalisation of signals<commit_after>#ifndef DUNE_STUFF_SIGNALS
#define DUNE_STUFF_SIGNALS

#include <signal.h>

#include <dune/stuff/logging.hh>

namespace Stuff {
	namespace Signals {

		//! reset given signal to default handler
		void resetSignal(int signal)
		{
			struct sigaction new_action;
			new_action.sa_handler = SIG_DFL;
			sigemptyset (&new_action.sa_mask);
			new_action.sa_flags = 0;
			sigaction (signal, &new_action, NULL);
		}

		//! example signal handler
		void handleInterrupt(int signal)
		{
			Logger().Info() << "forcefully terminated at " << Logging::TimeString() << std::endl;
			Logger().Flush();
			//reset signal handler and commit suicide
			resetSignal(signal);
			kill(getpid(), signal);
		}

		//! type of handler functions
		typedef void handler_type (int);

		//! calling this from your main() will install handler as callback when signal is received
		void installSignalHandler( int signal = SIGINT, handler_type handler = handleInterrupt )
		{
			struct sigaction new_action;

			/* Set up the structure to specify the new action. */
			new_action.sa_handler = handler;
			sigemptyset (&new_action.sa_mask);
			new_action.sa_flags = 0;

			sigaction (signal, &new_action, NULL);
		}
	}//end namespace signals
} //end namepsace stuff
#endif

{'fraction_non_alphanumeric': 0.10881965774462483, 'fraction_numerical': 0.0017551557700745941, 'mean_word_length': 4.010989010989011, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3465149', 'n_tokens_mistral': 845, 'n_tokens_neox': 728, 'n_words': 197}