<commit_before>#define _XOPEN_SOURCE
#include <stdlib.h>
#include "zdtmtst.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <termios.h>
#include <sys/ioctl.h>

const char *test_doc	= "Check a non-controling terminal";
const char *test_author	= "<NAME> <<EMAIL>>";

static void sighup_handler(int signo)
{
	test_msg("SIGHUP is here\n");
}

int main(int argc, char ** argv)
{
	int fdm, fds;
	char *slavename;
	pid_t sid;

	test_init(argc, argv);

	signal(SIGHUP, sighup_handler);

	setsid();

	fdm = open("/dev/ptmx", O_RDWR);
	if (fdm == -1) {
		err("Can't open a master pseudoterminal");
		return 1;
	}

	grantpt(fdm);
	unlockpt(fdm);
	slavename = ptsname(fdm);

	/* set up a controlling terminal */
	fds = open(slavename, O_RDWR);
	if (fds == -1) {
		err("Can't open a slave pseudoterminal %s", slavename);
		return 1;
	}

	if (ioctl(fds, TIOCNOTTY)) {
		err("Unable to detach a terminal");
		return 1;
	}

	test_daemon();
	test_waitsig();

	if (ioctl(fds, TIOCGSID, &sid) != -1 || errno != ENOTTY) {
		fail("The tty is a controlling for someone");
		return 1;
	}

	pass();

	return 0;
}<commit_msg>tty02: open a slave tty with O_NOCTTY<commit_after>#define _XOPEN_SOURCE
#include <stdlib.h>
#include "zdtmtst.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>
#include <termios.h>
#include <sys/ioctl.h>

const char *test_doc	= "Check a non-controling terminal";
const char *test_author	= "<NAME> <<EMAIL>>";

int main(int argc, char ** argv)
{
	int fdm, fds;
	char *slavename;
	pid_t sid;

	test_init(argc, argv);

	setsid();

	fdm = open("/dev/ptmx", O_RDWR);
	if (fdm == -1) {
		err("Can't open a master pseudoterminal");
		return 1;
	}

	grantpt(fdm);
	unlockpt(fdm);
	slavename = ptsname(fdm);

	/* set up a controlling terminal */
	fds = open(slavename, O_RDWR | O_NOCTTY);
	if (fds == -1) {
		err("Can't open a slave pseudoterminal %s", slavename);
		return 1;
	}

	test_daemon();
	test_waitsig();

	if (ioctl(fds, TIOCGSID, &sid) != -1 || errno != ENOTTY) {
		fail("The tty is a controlling for someone");
		return 1;
	}

	pass();

	return 0;
}
{'fraction_non_alphanumeric': 0.16946842344388915, 'fraction_numerical': 0.007723761926397092, 'mean_word_length': 4.156908665105386, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '1529516', 'n_tokens_mistral': 981, 'n_tokens_neox': 930, 'n_words': 238}