<commit_before>#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>

#include "zdtmtst.h"

const char *test_doc	= "Open r/w and unlink file, and fork before migration;\n"
			  "check that the child can write to it and the parent\n"
			  "can read from it after migration";
const char *test_author	= "<NAME> <<EMAIL>>";

char *filename;
TEST_OPTION(filename, string, "file name", 1);

int main(int argc, char ** argv)
{
	int fd, child_fd, ret;
	pid_t pid;
	uint32_t crc;
	uint8_t buf[1000000];

	test_init(argc, argv);

	fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644);
	if (fd < 0) {
		pr_perror("can't open %s", filename);
		exit(1);
	}

	child_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644);
	if (fd < 0) {
		pr_perror("can't open %s", filename);
		exit(1);
	}

	if (unlink(filename)) {
		pr_perror("can't unlink %s", filename);
		exit(1);
	}

	pid = fork();
	if (pid < 0) {
		pr_perror("can't fork");
		exit(1);
	}

	if (pid == 0) {	/* child writes to the unlinked file and returns */
		close(fd);
		test_waitsig();

		crc = ~0;
		datagen(buf, sizeof(buf), &crc);
		if (write(child_fd, buf, sizeof(buf)) != sizeof(buf))<commit_msg>test: write_read_10 -- Fix typo in testing opened file descriptor<commit_after>#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>

#include "zdtmtst.h"

const char *test_doc	= "Open r/w and unlink file, and fork before migration;\n"
			  "check that the child can write to it and the parent\n"
			  "can read from it after migration";
const char *test_author	= "<NAME> <<EMAIL>>";

char *filename;
TEST_OPTION(filename, string, "file name", 1);

int main(int argc, char ** argv)
{
	int fd, child_fd, ret;
	pid_t pid;
	uint32_t crc;
	uint8_t buf[1000000];

	test_init(argc, argv);

	fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644);
	if (fd < 0) {
		pr_perror("can't open %s", filename);
		exit(1);
	}

	child_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644);
	if (child_fd < 0) {
		pr_perror("can't open %s", filename);
		exit(1);
	}

	if (unlink(filename)) {
		pr_perror("can't unlink %s", filename);
		exit(1);
	}

	pid = fork();
	if (pid < 0) {
		pr_perror("can't fork");
		exit(1);
	}

	if (pid == 0) {	/* child writes to the unlinked file and returns */
		close(fd);
		test_waitsig();

		crc = ~0;
		datagen(buf, sizeof(buf), &crc);
		if (write(child_fd, buf, sizeof(buf)) != sizeof(buf))
{'fraction_non_alphanumeric': 0.167458432304038, 'fraction_numerical': 0.022961203483768806, 'mean_word_length': 4.03386454183267, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, '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': '7541187', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1029, 'n_words': 287}