<commit_before>#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

#define USAGE "Usage: %s\n"
#define CHILD_CTTY "/dev/tty0"
#define CHILD_CMD "rc"

pid_t start_child(void)
{
	sigset_t mask;
	pid_t pid;

	pid = fork();
	if (0 != pid)
		return pid;

	if (-1 == sigfillset(&mask))
		goto terminate;
	if (-1 == sigprocmask(SIG_UNBLOCK, &mask, NULL))
		goto terminate;

	if (((pid_t) -1) == setsid())
		goto terminate;

	if (-1 == close(STDIN_FILENO))
		goto terminate;
	if (-1 == open(CHILD_CTTY, O_RDONLY))
		goto terminate;

	if (-1 == close(STDOUT_FILENO))
		goto terminate;
	if (-1 == open(CHILD_CTTY, O_WRONLY))
		goto terminate;
	if (STDERR_FILENO != dup2(STDOUT_FILENO, STDERR_FILENO))
		goto terminate;

	(void) execlp(CHILD_CMD, CHILD_CMD, (char *) NULL);

terminate:
	exit(EXIT_FAILURE);

	/* not reached */
	return (-1);
}

int main(int argc, char *argv[])
{
	sigset_t mask;
	siginfo_t sig;
	pid_t child;
	int ret;

	if (1 != argc) {
		(void) fprintf(stderr, USAGE, argv[0]);
		goto end;
	}

	/* block SIGCHLD, SIGUSR1 (poweroff) and SIGUSR2 (reboot) */
	if (-1 == sigemptyset(&mask))
		goto end;
	if (-1 == sigaddset(&mask, SIGUSR1))
		goto end;
	if (-1 == sigaddset(&mask, SIGUSR2))
		goto end;
	if (-1 == sigaddset(&mask, SIGCHLD))
		goto end;
	if (-1 == sigprocmask(SIG_SETMASK, &mask, NULL))
		goto end;

	sig.si_signo = SIGUSR2;

	child = start_child();
	if (-1 == child)
		goto shutdown;
<commit_msg>Bug fixes.<commit_after>#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
#include <paths.h>
#include <errno.h>

#define USAGE "Usage: %s\n"
#define CHILD_CTTY _PATH_DEV"tty0"
#define CHILD_CMD "rc"

pid_t start_child(void)
{
	sigset_t mask;
	pid_t pid;

	pid = fork();
	if (0 != pid)
		return pid;

	if (-1 == sigfillset(&mask))
		goto terminate;
	if (-1 == sigprocmask(SIG_UNBLOCK, &mask, NULL))
		goto terminate;

	if (((pid_t) -1) == setsid())
		goto terminate;

	if (-1 == close(STDIN_FILENO))
		goto terminate;
	if (-1 == open(CHILD_CTTY, O_RDONLY))
		goto terminate;

	if (-1 == close(STDOUT_FILENO))
		goto terminate;
	if (-1 == open(CHILD_CTTY, O_WRONLY))
		goto terminate;
	if (STDERR_FILENO != dup2(STDOUT_FILENO, STDERR_FILENO))
		goto terminate;

	/* assign a controlling TTY */
	if (-1 == ioctl(STDIN_FILENO, TIOCSCTTY, 1))
		goto terminate;

	(void) execlp(CHILD_CMD, CHILD_CMD, (char *) NULL);

terminate:
	exit(EXIT_FAILURE);

	/* not reached */
	return (-1);
}

int main(int argc, char *argv[])
{
	sigset_t mask;
	siginfo_t sig;
	pid_t child;
	int ret;

	if (1 != argc) {
		(void) fprintf(stderr, USAGE, argv[0]);
		goto end;
	}

	/* mount a devtmpfs file system at /dev, to make the controlling TTY device
	 * node accessible */
	if (-1 == mount("dev", _PATH_DEV, "devtmpfs", 0UL, NULL)) {
		if (EBUSY != errno)
			goto end;
	}

	/* block SIGCHLD, SIGUSR1 (poweroff) and SIGUSR2 (reboot) */
	if (-1 == sigemptyset(&mask))
		goto end;
	if (-1 == sigaddset(&mask, SIGUSR1))
		goto end;
	if (-1 == sigaddset(&mask, SIGUSR2))
		goto end;
	if (-1 == sigaddset(&mask, SIGCHLD))
		goto end;
	if (-1 == sigprocmask(SIG_SETMASK, &mask, NULL))
		goto end;

	sig.si_signo = SIGUSR2;

	child = start_child();
	if (-1 == child)
		goto shutdown;

{'fraction_non_alphanumeric': 0.17020057306590258, 'fraction_numerical': 0.01489971346704871, 'mean_word_length': 3.944759206798867, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '3116981', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1454, 'n_words': 379}