Exemplo n.º 1
0
static int run_all_tests(int childcount)
{
	int dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute;
	int result = 0;

	for (dropMode = 0; dropMode != 1 << (full ? 12 : 8); dropMode++)
	for (serverFinishedPermute = 0; serverFinishedPermute < 2; serverFinishedPermute++)
	for (serverHelloPermute = 0; serverHelloPermute < (full ? 120 : 6); serverHelloPermute++)
	for (clientFinishedPermute = 0; clientFinishedPermute < (full ? 120 : 6); clientFinishedPermute++) {
		int pid;
		if (!(pid = fork())) {
			exit(run_one_test(dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute));
		} else if (pid < 0) {
			rperror("fork");
			result = 4;
			break;
		} else {
			register_child(pid);
			result |= wait_children(childcount);
		}
	}

	result |= wait_children(0);

	return result;
}
Exemplo n.º 2
0
static char		*check_slash(char **cmd)
{
	if (ft_strcmp(cmd[0], "/") == 0)
	{
		wait_children();
		g_exit_status = NOT_FOUND_EXIT_STATUS;
		print_err(cmd[0], NO_SUCH_FILE_OR_DIR);
		return (NULL);
	}
	if (access(cmd[0], F_OK) != -1 && ft_strchr(cmd[0], '/'))
	{
		if (access(cmd[0], X_OK) != -1)
			return (ft_strdup(cmd[0]));
		wait_children();
		g_exit_status = PERM_DENIED_EXIT_STATUS;
		print_err(cmd[0], PERMISSION_DENIED);
	}
	else if (ft_strchr(cmd[0], '/'))
	{
		wait_children();
		g_exit_status = NOT_FOUND_EXIT_STATUS;
		print_err(cmd[0], NO_SUCH_FILE_OR_DIR);
	}
	return (NULL);
}
Exemplo n.º 3
0
static int run_tests_from_id_list(int childcount)
{
	int test_id;
	int ret;
	int result = 0;

	while ((ret = fscanf(stdin, "%i\n", &test_id)) > 0) {
		int pid;
		if (test_id < 0 || test_id > 2 * (full ? 120 * 120 * (1 << 12) : 6 * 6 * 256)) {
			fprintf(stderr, "Invalid test id %i\n", test_id);
			break;
		}
		if (!(pid = fork())) {
			exit(run_test_by_id(test_id));
		} else if (pid < 0) {
			rperror("fork");
			result = 4;
			break;
		} else {
			register_child(pid);
			result |= wait_children(childcount);
		}
	}

	if (ret < 0 && ret != EOF) {
		fprintf(stderr, "Error reading test id list\n");
	}

	result |= wait_children(0);

	return result;
}
Exemplo n.º 4
0
void
test_main (void) 
{
  pid_t children[CHILD_CNT];
  int fd;

  CHECK (create (filename, sizeof buf), "create \"%s\"", filename);
  CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
  random_bytes (buf, sizeof buf);
  CHECK (write (fd, buf, sizeof buf) > 0, "write \"%s\"", filename);
  msg ("close \"%s\"", filename);
  close (fd);

  exec_children ("child-syn-read", children, CHILD_CNT);
  wait_children (children, CHILD_CNT);
}
Exemplo n.º 5
0
void
test_main (void) 
{
  pid_t children[CHILD_CNT];
  int fd;

  CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);

  exec_children ("child-syn-wrt", children, CHILD_CNT);
  wait_children (children, CHILD_CNT);

  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
  CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", file_name);
  random_bytes (buf2, sizeof buf2);
  compare_bytes (buf1, buf2, sizeof buf1, 0, file_name);
}
Exemplo n.º 6
0
Arquivo: b_env.c Projeto: Azhr4n/42Sh
static void	b_env_find_exec(char **arg, char **env)
{
	char	*path;
	pid_t	father;

	path = find_cmd(arg);
	if (path)
	{
		father = fork();
		if (father == 0)
		{
			if (execve(path, arg, env) < 0)
				exit(0);
		}
		wait_children();
		free(path);
		return ;
	}
	g_exit_status = NOT_FOUND_EXIT_STATUS;
	print_err(arg[0], NO_SUCH_FILE_OR_DIR);
}
Exemplo n.º 7
0
static char		*find_cmd_loop(char **exec, int i, char **cmd)
{
	char	*path;

	path = add_file_to_path(exec[i], *cmd);
	if (access(path, F_OK) != -1)
	{
		if (access(path, X_OK) != -1)
		{
			strfree_2d(exec);
			return (path);
		}
		else
		{
			wait_children();
			g_exit_status = PERM_DENIED_EXIT_STATUS;
			print_err(path, PERMISSION_DENIED);
		}
	}
	free(path);
	return (0);
}
Exemplo n.º 8
0
static char		*check_in_path(char **cmd)
{
	char		*path;
	int			i;
	char		**exec;

	if ((path = ft_getenv("PATH")) != NULL)
	{
		exec = ft_strsplit(path, ':');
		i = 0;
		while (exec[i])
		{
			if ((path = find_cmd_loop(exec, i++, cmd)))
				return (path);
		}
		strfree_2d(exec);
	}
	if (g_exit_status > 0)
		return (NULL);
	wait_children();
	g_exit_status = NOT_FOUND_EXIT_STATUS;
	print_err(cmd[0], CMD_NOT_FOUND);
	return (NULL);
}
Exemplo n.º 9
0
Arquivo: udpxy.c Projeto: avble/udpxy
/* wait for the children who already terminated
 */
void
wait_terminated( struct server_ctx* ctx ) { wait_children( ctx, WNOHANG ); }
Exemplo n.º 10
0
Arquivo: udpxy.c Projeto: avble/udpxy
/* wait for all children to quit
 */
void
wait_all( struct server_ctx* ctx ) { wait_children( ctx, 0 ); }
Exemplo n.º 11
0
int main(int argc, char ** argv)
{
	int status;
	pid_t pid, pid2;
	int fd, i;

	test_init(argc, argv);

	if (pipe(fork_pfd)) {
		pr_perror("pipe");
		return 1;
	}

	pid = clone_child(child, CLONE_FILES);
	if (pid < 0)
		return 1;

	pid2 = clone_child(child2, CLONE_FILES);
	if (pid2 < 0)
		return 1;

	wait_children();

	test_daemon();
	test_waitsig();

	fd = open(filename, O_RDWR | O_CREAT, 0666);
	if (fd == -1) {
		pr_perror("Can't open /dev/zero");
		return -1;
	}

	for (i = 0; i < 3; i++)
		if (write(fd, TEST_STRING, sizeof(TEST_STRING)) != sizeof(TEST_STRING)) {
			pr_perror("Unable to write a test string");
			return -1;
		}

	fd = dup2(fd, TEST_FD);
	if (fd == -1) {
		pr_perror("Can't dup fd %d to %d", fd, TEST_FD);
		return -1;
	}

	lseek(fd, 0, SEEK_SET);

	kill(pid2, SIGTERM);
	waitpid(pid2, &status, 0);
	kill(pid, SIGTERM);

	if (status) {
		fail("The child returned %d\n", status);
		return 1;
	}

	waitpid(pid, &status, 0);
	if (status) {
		fail("The child returned %d\n", status);
		return 1;
	}

	if (close(TEST_FD) == 0) {
		fail("%d was not closed\n", TEST_FD);
		return 1;
	}

	pass();

	return 0;
}