<commit_before>/**
 * signal.c
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 */

#include "signals.h"

/**
 * Run cleanup on SIGHUP or SIGINT.
 */
void on_signal (int signal) {
	switch (signal) {
		case SIGHUP:
			printf("Caught SIGHUP, hanging up...\n");
			break;
		case SIGINT:
			printf("Caught SIGINT, terminating...\n");
			exit(EXIT_SUCCESS);
		default:
			fprintf(stderr, "Caught wrong signal: %d\n", signal);
			return;
	}
}

/**
 * Run tasks during awake period.
 */
void on_awake (int signal) {
	if (signal != SIGALRM) {
		fprintf(stderr, "Caught wrong signal: %d\n", signal);
	}
}

/**
 * Augmented sleep function for signal handling.
 */
void nap (int seconds) {
	struct sigaction action;
	sigset_t mask;

	action.sa_handler = &on_awake;
	action.sa_flags = SA_RESETHAND;

	sigfillset(&action.sa_mask);
	sigaction(SIGALRM, &action, NULL);
	sigprocmask(0, NULL, &mask);
	sigdelset(&mask, SIGALRM);

	alarm(seconds);
	sigsuspend(&mask);

	printf("nap: sigsuspend returned.\n");
}<commit_msg>Remove unused printf from nap<commit_after>/**
 * signal.c
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 */

#include "signals.h"

/**
 * Run cleanup on SIGHUP or SIGINT.
 */
void on_signal (int signal) {
	switch (signal) {
		case SIGHUP:
			printf("Caught SIGHUP, hanging up...\n");
			break;
		case SIGINT:
			printf("Caught SIGINT, terminating...\n");
			exit(EXIT_SUCCESS);
		default:
			fprintf(stderr, "Caught wrong signal: %d\n", signal);
			return;
	}
}

/**
 * Run tasks during awake period.
 */
void on_awake (int signal) {
	if (signal != SIGALRM) {
		fprintf(stderr, "Caught wrong signal: %d\n", signal);
	}

	/**
	 * @todo: Finish building this.
	 */
}

/**
 * Augmented sleep function with signal handling.
 */
void nap (int seconds) {
	struct sigaction action;
	sigset_t mask;

	action.sa_handler = &on_awake;
	action.sa_flags = SA_RESETHAND;

	sigfillset(&action.sa_mask);
	sigaction(SIGALRM, &action, NULL);
	sigprocmask(0, NULL, &mask);
	sigdelset(&mask, SIGALRM);

	alarm(seconds);
	sigsuspend(&mask);
}
{'fraction_non_alphanumeric': 0.16021825396825398, 'fraction_numerical': 0.00496031746031746, 'mean_word_length': 3.7570754716981134, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '53495', 'n_tokens_mistral': 804, 'n_tokens_neox': 750, 'n_words': 191}