Beispiel #1
0
int main(int argc, char **argv) {
  int forkres, i;

  /* Get subtest number */
  if(argc != 2) {
    printf("Usage: %s subtest_no\n", argv[0]);
    exit(-2);
  } else if(sscanf(argv[1], "%d", &subtest) != 1) {
    printf("Usage: %s subtest_no\n", argv[0]);
    exit(-2);
  }
  
  /* Fork off a bunch of children */
  for(i = 0; i < NUMCHILDREN; i++) {
      forkres = fork();
      if(forkres == 0) do_child(i);
      else if(forkres < 0) {
	perror("Unable to fork");
	exit(-1);
      }
  }
  /* do_child always calls exit(), so when we end up here, we're the parent. */
  do_parent();

  exit(-2); /* We're not supposed to get here. Both do_* routines should exit.*/
}
Beispiel #2
0
int main(int ac, char **av)
{
	pid_t pid;
	int status;

	tst_parse_opts(ac, av, options, NULL);

	if (sflag)
		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);

	setup();

	switch (pid = fork()) {
	case -1:
		tst_brkm(TBROK | TERRNO, cleanup, "fork");
	case 0:
		/* set  the user ID of the child to the non root user */
		if (setuid(ltp_uid) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "setuid");
		do_child();
		tst_exit();
	default:
		if (waitpid(pid, &status, 0) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
	}
	cleanup();
	tst_exit();
}
Beispiel #3
0
int main(void)
{
  pid_t r;
  subtest = 1;

#ifdef __GNUC__
	printf("Test 52 (GCC) ");
#else
	printf("Test 52 (ACK) ");
#endif
  fflush(stdout);

  if (pipe(pipefdc) == -1) err(1);
  if (pipe(pipefdp) == -1) err(2);

  r = fork();
  if(r < 0) {
	err(3);
  } else if(r == 0) {
	/* Child */
	do_child();
  } else {
	/* Parent */
	do_parent();
  }

  return(0); /* Never reached */

}
Beispiel #4
0
int main(int argc, char **argv) {
  int forkres;

  /* Get subtest number */
  if(argc != 2) {
    printf("Usage: %s subtest_no\n", argv[0]);
    exit(-2);
  } else if(sscanf(argv[1], "%d", &subtest) != 1) {
    printf("Usage: %s subtest_no\n", argv[0]);
    exit(-2);
  }
  
  /* Set up anonymous pipe */
  if(pipe(fd_ap) < 0) {
    perror("Could not create anonymous pipe");
    exit(-1);
  }

  forkres = fork();
  if(forkres == 0) do_child();
  else if(forkres > 0)  do_parent(forkres);
  else { /* Fork failed */
    perror("Unable to fork");
    exit(-1);
  }

  exit(-2); /* We're not supposed to get here. Both do_* routines should exit*/
  
}
Beispiel #5
0
pid_t
start_server(struct sockaddr_in *ssin, struct sockaddr_un *ssun)
{
    pid_t pid;

    sfd = socket(PF_INET, SOCK_STREAM, 0);
    if (sfd < 0)
	return -1;
    if (bind(sfd, (struct sockaddr *)ssin, sizeof(*ssin)) < 0)
	return -1;
    if (listen(sfd, 10) < 0)
	return -1;

    /* set up UNIX-domain socket */
    ufd = socket(PF_UNIX, SOCK_STREAM, 0);
    if (ufd < 0)
	return -1;
    if (bind(ufd, (struct sockaddr *)ssun, sizeof(*ssun)))
	return -1;
    if (listen(ufd, 10) < 0)
	return -1;

    switch (pid = fork()) {
    case 0:		/* child */
	do_child();
	break;
    case -1:			/* fall through */
    default:			/* parent */
	(void)close(sfd);
	return pid;
    }

    return -1;
}
Beispiel #6
0
int main(int ac, char **av)
{
	int pid;
	void do_child(void);

	tst_parse_opts(ac, av, NULL, NULL);

	setup();		/* global setup */

	if ((pid = FORK_OR_VFORK()) == -1) {
		tst_brkm(TBROK, cleanup, "could not fork");
	}

	if (pid == 0) {		/* child */
		/* set  the user ID of the child to the non root user */
		if (setuid(ltp_uid) == -1) {
			tst_resm(TBROK, "setuid() failed");
			exit(1);
		}

		do_child();
	} else {
		/* wait for the child to return */
		SAFE_WAITPID(cleanup, pid, NULL, 0);

		/* if it exists, remove the shared memory resource */
		rm_shm(shm_id_1);

		tst_rmdir();
	}

	cleanup();
	tst_exit();
}
Beispiel #7
0
pid_t
start_server(struct sockaddr_in *sin0)
{
    struct sockaddr_in sin1 = *sin0;
    pid_t pid;

    sfd = socket(PF_INET, SOCK_STREAM, 0);
    if (sfd < 0)
	return -1;
    if (bind(sfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0)
	return -1;
    if (listen(sfd, 10) < 0)
	return -1;

    switch (pid = fork()) {
    case 0:		/* child */
	do_child();
	break;
    case -1:			/* fall through */
    default:			/* parent */
	(void)close(sfd);
	return pid;
    }

    return -1;
}
Beispiel #8
0
int main(int ac, char **av)
{
	const char *msg;
	int status;
	pid_t pid;

	msg = parse_opts(ac, av, options, &help);
	if (msg != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	if (sflag)
		hugepages = SAFE_STRTOL(NULL, nr_opt, 0, LONG_MAX);

	setup();

	switch (pid = fork()) {
	case -1:
		tst_brkm(TBROK | TERRNO, cleanup, "fork");
	case 0:
		if (setuid(ltp_uid) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "setuid");
		do_child();
		tst_exit();
	default:
		if (waitpid(pid, &status, 0) == -1)
			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
	}
	cleanup();
	tst_exit();
}
Beispiel #9
0
/*
 * do_child_uclinux() - capture signals again, then run do_child()
 */
void
do_child_uclinux()
{
	tst_sig(FORK, sighandler, cleanup);

	do_child();
}
Beispiel #10
0
int main(int argc, char **argv) {
    int forkres;
    int master, slave;

    /* Get subtest number */
    if(argc != 2) {
        printf("Usage: %s subtest_no\n", argv[0]);
        exit(-1);
    } else if(sscanf(argv[1], "%d", &subtest) != 1) {
        printf("Usage: %s subtest_no\n", argv[0]);
        exit(-1);
    }

    open_terminal(&master, &slave);

    forkres = fork();
    if(forkres == 0) do_child(master);
    else if(forkres > 0)  do_parent(forkres, slave);
    else { /* Fork failed */
        perror("Unable to fork");
        exit(-1);
    }

    exit(-2); /* We're not supposed to get here. Both do_* routines should exit*/

}
int main(void)
{
	int sp[2];

	if (-1 == socketpair(AF_UNIX, SOCK_STREAM, 0, sp)) {
		fprintf(stderr, "socketpair(): %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}

	switch (fork()) {
	case -1:
		fprintf(stderr, "fork(): %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	case 0:
		close(sp[0]);
		do_child(sp[1]);
		break;
	default:
		close(sp[1]);
		do_parent(sp[0]);
		break;
	}

	exit(EXIT_SUCCESS);
}
Beispiel #12
0
int main(int ac, char **av)
{
	int lc;
	int i;

	tst_parse_opts(ac, av, NULL, NULL);
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {
			pid2 = tst_fork();

			if (pid2 == -1)
				tst_brkm(TBROK, cleanup, "fork failed");

			if (!pid2)
				do_child(&test_cases[i]);
			else
				tst_record_childstatus(cleanup, pid2);
			tst_count++;
		}
	}

	cleanup();
	tst_exit();
}
Beispiel #13
0
int main(int ac, char **av)
{
	int lc;				/* loop counter */
	char *msg;			/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
	}

#ifdef UCLINUX
	maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
#endif

	setup();			/* global setup */

	/* The following loop checks looping state if -i option given */

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		/*
		 * fork a child that will attempt to read a non-existent
		 * message from the queue
		 */
		if ((c_pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "could not fork");
		}

		if (c_pid == 0) {		/* child */
			/*
			 * Attempt to read a message without IPC_NOWAIT.
			 * With no message to read, the child sleeps.
			 */
#ifdef UCLINUX
			if (self_exec(av[0], "d", msg_q_1) < 0) {
				tst_brkm(TBROK, cleanup, "could not self_exec");
			}
#else
			do_child();
#endif
		} else {			/* parent */
			usleep(250000);

			/* send a signal that must be caught to the child */
			if (kill(c_pid, SIGHUP) == -1) {
				tst_brkm(TBROK, cleanup, "kill failed");
			}

			waitpid(c_pid, NULL, 0);
		}
	}

	cleanup();

	/*NOTREACHED*/
	return(0);
}
Beispiel #14
0
/*
 * do_child_uclinux() - as above, but mallocs rdbuf first
 */
void do_child_uclinux()
{
	if ((rdbuf = (char *)malloc(szcharbuf)) == (char *)0) {
		tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
	 }

	do_child();
}
Beispiel #15
0
Datei: pipe11.c Projekt: 1587/ltp
/*
 * do_child_uclinux() - as above, but mallocs rdbuf first
 */
void do_child_uclinux(void)
{
	if ((rdbuf = malloc(szcharbuf)) == NULL) {
		tst_brkm(TBROK, cleanup, "malloc of rdbuf failed");
	}

	do_child();
}
Beispiel #16
0
static void do_test(int i)
{
	pid_t cpid;

	cpid = tst_fork();
	if (cpid < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");

	if (cpid == 0)
		do_child(i);

	fd = SAFE_OPEN(cleanup, "file", O_RDONLY);

	TEST(fcntl(fd, F_SETLEASE, test_cases[i].lease_type));
	if (TEST_RETURN == -1) {
		tst_resm(TFAIL | TTERRNO, "fcntl() failed to set lease");
		SAFE_WAITPID(cleanup, cpid, NULL, 0);
		SAFE_CLOSE(cleanup, fd);
		fd = 0;
		return;
	}

	/* Wait for SIGIO caused by lease breaker. */
	TEST(sigtimedwait(&newset, NULL, &timeout));
	if (TEST_RETURN == -1) {
		if (TEST_ERRNO == EAGAIN) {
			tst_resm(TFAIL | TTERRNO, "failed to receive SIGIO "
				 "within %lis", timeout.tv_sec);
			SAFE_WAITPID(cleanup, cpid, NULL, 0);
			SAFE_CLOSE(cleanup, fd);
			fd = 0;
			return;
		}
		tst_brkm(TBROK | TTERRNO, cleanup, "sigtimedwait() failed");
	}

	/* Try to downgrade or remove the lease. */
	switch (test_cases[i].lease_type) {
	case F_WRLCK:
		TEST(fcntl(fd, F_SETLEASE, F_RDLCK));
		if (TEST_RETURN == 0)
			break;
	case F_RDLCK:
		TEST(fcntl(fd, F_SETLEASE, F_UNLCK));
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO,
				 "fcntl() failed to remove the lease");
		}
		break;
	default:
		break;
	}

	tst_record_childstatus(cleanup, cpid);

	SAFE_CLOSE(cleanup, fd);
	fd = 0;
}
/* The code should barf on TDBs created with rwlocks. */
int main(int argc, char *argv[])
{
	struct tdb_context *tdb;
	unsigned int log_count;
	struct tdb_logging_context log_ctx = { log_fn, &log_count };
	int ret, status;
	pid_t child, wait_ret;
	int fromchild[2];
	int tochild[2];
	char c;
	int tdb_flags;
	bool runtime_support;

	runtime_support = tdb_runtime_check_for_robust_mutexes();

	if (!runtime_support) {
		skip(1, "No robust mutex support");
		return exit_status();
	}

	key.dsize = strlen("hi");
	key.dptr = discard_const_p(uint8_t, "hi");
	data.dsize = strlen("world");
	data.dptr = discard_const_p(uint8_t, "world");

	pipe(fromchild);
	pipe(tochild);

	tdb_flags = TDB_INCOMPATIBLE_HASH|
		TDB_MUTEX_LOCKING|
		TDB_CLEAR_IF_FIRST;

	child = fork();
	if (child == 0) {
		close(fromchild[0]);
		close(tochild[1]);
		return do_child(tdb_flags, fromchild[1], tochild[0]);
	}
	close(fromchild[1]);
	close(tochild[0]);

	read(fromchild[0], &c, sizeof(c));

	tdb = tdb_open_ex("mutex-allrecord-trylock.tdb", 0, tdb_flags,
			  O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
	ok(tdb, "tdb_open_ex should succeed");

	ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_NOWAIT, false);
	ok(ret == -1, "tdb_allrecord_lock (nowait) should not succeed");

	write(tochild[1], &c, sizeof(c));

	wait_ret = wait(&status);
	ok(wait_ret == child, "child should have exited correctly");

	diag("done");
	return exit_status();
}
Beispiel #18
0
/*
 * do_child_uclinux() - capture signals again, then run do_child()
 */
void do_child_uclinux()
{
	if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_create failed");

	tst_sig(FORK, SIG_IGN, cleanup);

	do_child();
}
Beispiel #19
0
int main(int argc, char** argv)
{
  // We need to keep the original parameters in order to pass them to the
  // model-checked process:
  int argc_copy = argc;
  char** argv_copy = argvdup(argc, argv);
  xbt_log_init(&argc_copy, argv_copy);
  sg_config_init(&argc_copy, argv_copy);

  if (argc < 2)
    xbt_die("Missing arguments.\n");

  bool server_mode = true;
  char* env = std::getenv("SIMGRID_MC_MODE");
  if (env) {
    if (std::strcmp(env, "server") == 0)
      server_mode = true;
    else if (std::strcmp(env, "standalone") == 0)
      server_mode = false;
    else
      xbt_die("Unrecognised value for SIMGRID_MC_MODE (server/standalone)");
  }

  if (!server_mode) {
    setenv(MC_ENV_VARIABLE, "1", 1);
    execvp(argv[1], argv+1);

    std::perror("simgrid-mc");
    return 127;
  }

  // Create a AF_LOCAL socketpair:
  int res;

  int sockets[2];
  res = socketpair(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0, sockets);
  if (res == -1) {
    perror("simgrid-mc");
    return MC_SERVER_ERROR;
  }

  XBT_DEBUG("Created socketpair");

  pid_t pid = fork();
  if (pid < 0) {
    perror("simgrid-mc");
    return MC_SERVER_ERROR;
  } else if (pid == 0) {
    close(sockets[1]);
    return do_child(sockets[0], argv);
  } else {
    close(sockets[0]);
    return do_parent(sockets[1], pid);
  }

  return 0;
}
Beispiel #20
0
/*
 * do_child_uclinux() - capture signals, initialize buffer, then run do_child()
 */
void do_child_uclinux(void)
{
    /* initialize the message buffer */
    init_buf(&msg_buf, MSGTYPE, MSGSIZE);

    tst_sig(FORK, sighandler, cleanup);

    do_child();
}
Beispiel #21
0
/*
 * do_child_uclinux()
 */
void do_child_uclinux()
{
	/* Catch SIGINT */
	if (signal(SIGINT, sig_handle) == SIG_ERR) {
		tst_brkm(TBROK, cleanup, "signal() fails to catch SIGINT");
	}

	do_child();
}
Beispiel #22
0
void exec_processes( struct process *p )
{
	struct process *proc = p;
	int in_pipe[2];
	int out_pipe[2];

	// Find our final process
	while( proc->next_process != NULL && !proc->next_process->is_file )
	{
		proc = proc->next_process;
	}

	// For each process, fork and create any necessary pipes
	while( proc != NULL && !proc->is_file )
	{

		//the old in-pipe is the new out-pipe
		out_pipe[0] = in_pipe[0];
		out_pipe[1] = in_pipe[1];

		if( pipe( in_pipe ) < 0 )
		{
			perror( "PIPE" );
			exit( EXIT_FAILURE );
		}

		switch( fork() )
		{
			case -1:
				perror( "FORK" );
				exit( EXIT_FAILURE );
		
			case 0:
				//printf("doing child\n");
				do_child( proc, in_pipe, out_pipe );
				/* NOTREACHED */
			default:
				//fflush(NULL);
				//printf("Waiting for Child\n");
				sleep( 1 );
				close( out_pipe[1]);
				close(in_pipe[0]);
				
				/*fsync(stdout);
				fflush(stdout);

				fsync(stdin);
				fflush(stdin);*/
								
		}


		proc = proc->prev_process;
	}

}
Beispiel #23
0
int create_server(void)
{
	static int count = 0;
	socklen_t slen = sizeof(sin1);

	sockfd = socket(PF_INET, SOCK_DGRAM, 0);
	if (sockfd < 0) {
		tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
			 strerror(errno));
		return -1;
	}
	sin1.sin_family = AF_INET;
	sin1.sin_port = 0; /* pick random free port */
	sin1.sin_addr.s_addr = INADDR_ANY;
	count++;
	if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
		tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
			 strerror(errno));
		return -1;
	}
	if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");

	child_pid = FORK_OR_VFORK();
	if (child_pid < 0) {
		tst_brkm(TBROK, cleanup, "client/server fork failed: %s",
			 strerror(errno));
		return -1;
	}
	if (!child_pid) {	/* child */
#ifdef UCLINUX
		if (self_exec(argv0, "") < 0) {
			tst_brkm(TBROK, cleanup, "self_exec failed");
			return -1;

		}
#else
		do_child();
#endif
	}

	s = socket(PF_INET, SOCK_DGRAM, 0);
	inet_aton("127.0.0.1", &sin1.sin_addr);
	if (s < 0) {
		tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
			 strerror(errno));
		return -1;
	}
	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
		tst_brkm(TBROK, cleanup, "call to connect() failed: %s",
			 strerror(errno));
	}
	return s;

}
Beispiel #24
0
int main(int ac, char **av)
{
    int lc;
    pid_t c_pid;

    tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
    maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
#endif

    setup();		/* global setup */

    /* The following loop checks looping state if -i option given */

    for (lc = 0; TEST_LOOPING(lc); lc++) {
        /* reset tst_count in case we are looping */
        tst_count = 0;

        /*
         * fork a child that will attempt to write a message
         * to the queue without IPC_NOWAIT
         */
        if ((c_pid = FORK_OR_VFORK()) == -1) {
            tst_brkm(TBROK, cleanup, "could not fork");
        }

        if (c_pid == 0) {	/* child */
            /*
             * Attempt to write another message to the full queue.
             * Without the IPC_NOWAIT flag, the child sleeps
             */

#ifdef UCLINUX
            if (self_exec(av[0], "d", msg_q_1) < 0) {
                tst_brkm(TBROK, cleanup, "could not self_exec");
            }
#else
            do_child();
#endif
        } else {
            TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');

            /* send a signal that must be caught to the child */
            if (kill(c_pid, SIGHUP) == -1)
                tst_brkm(TBROK, cleanup, "kill failed");

            waitpid(c_pid, NULL, 0);
        }
    }

    cleanup();

    tst_exit();
}
Beispiel #25
0
static void verify_execve(void)
{
	int i;

	for (i = 0; i < nchild; i++) {
		if (SAFE_FORK() == 0)
			do_child();
	}

	TST_CHECKPOINT_WAKE2(0, nchild);
}
Beispiel #26
0
/*
 * stat_setup() - Set up for the IPC_STAT command with shmctl().
 *		  Make things interesting by forking some children
 *		  that will either attach or inherit the shared memory.
 */
void stat_setup()
{
	void *set_shmat();
	pid_t pid;

	/*
	 * The first time through, let the children attach the memory.
	 * The second time through, attach the memory first and let
	 * the children inherit the memory.
	 */

	if (stat_time == SECOND) {
		/*
		 * use the global "set_shared" variable here so that
		 * it can be removed in the stat_func() routine.
		 */
		set_shared = set_shmat();
	}

	tst_flush();
	for (stat_i = 0; stat_i < N_ATTACH; stat_i++) {
		if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
			tst_brkm(TBROK, cleanup, "sync_pipe_create failed");

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "could not fork");
		}

		if (pid == 0) {	/* child */
#ifdef UCLINUX
			if (self_exec(argv0, "ddd", stat_i, stat_time,
				      shm_id_1) < 0) {
				tst_brkm(TBROK, cleanup, "could not self_exec");
			}
#else
			do_child();
#endif

		} else {	/* parent */
			/* save the child's pid for cleanup later */
			pid_arr[stat_i] = pid;
			if (sync_pipe_wait(sync_pipes) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_wait failed");

			if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_close failed");
		}
	}
	/* Wait 1 second to be sure all sons are in the pause function. */
	sleep(1);
}
Beispiel #27
0
void do_child_uclinux(void)
{
	struct sigaction act;

	/* Set up the signal handlers again */
	act.sa_handler = (void *)sigterm_handler;
	act.sa_flags = 0;
	(void)sigaction(SIGTERM, &act, 0);

	/* Run the normal child */
	do_child();
}
Beispiel #28
0
/**
 *  Fork/exec the specified processes
 */
static int fork_local_proc(orte_app_context_t* context,
                           orte_odls_child_t *child,
                           char **environ_copy,
                           orte_odls_job_t *jobdat)
{
    orte_iof_base_io_conf_t opts;
    int rc, p[2];
    pid_t pid;
    
    /* we do not forward io, so mark it as complete */
    child->iof_complete = true;

    /* A pipe is used to communicate between the parent and child to
       indicate whether the exec ultimately succeeded or failed.  The
       child sets the pipe to be close-on-exec; the child only ever
       writes anything to the pipe if there is an error (e.g.,
       executable not found, exec() fails, etc.).  The parent does a
       blocking read on the pipe; if the pipe closed with no data,
       then the exec() succeeded.  If the parent reads something from
       the pipe, then the child was letting us know why it failed. */
    if (pipe(p) < 0) {
        ORTE_ERROR_LOG(ORTE_ERR_SYS_LIMITS_PIPES);
        if (NULL != child) {
            child->state = ORTE_PROC_STATE_FAILED_TO_START;
            child->exit_code = ORTE_ERR_SYS_LIMITS_PIPES;
        }
        return ORTE_ERR_SYS_LIMITS_PIPES;
    }
    
    /* Fork off the child */
    pid = fork();
    if (NULL != child) {
        child->pid = pid;
    }
    
    if (pid < 0) {
        ORTE_ERROR_LOG(ORTE_ERR_SYS_LIMITS_CHILDREN);
        if (NULL != child) {
            child->state = ORTE_PROC_STATE_FAILED_TO_START;
            child->exit_code = ORTE_ERR_SYS_LIMITS_CHILDREN;
        }
        return ORTE_ERR_SYS_LIMITS_CHILDREN;
    }
    
    if (pid == 0) {
	close(p[0]);
        do_child(context, child, environ_copy, jobdat, p[1], opts);
        /* Does not return */
    } 

    close(p[1]);
    return do_parent(context, child, environ_copy, jobdat, p[0], opts);
}
Beispiel #29
0
int main(int argc, char ** argv)
{
	unsigned long size;
	long hpage_size;
	int pid, status;
	int i;
	int wait_list[MAX_PROCS];

	test_init(argc, argv);

	if (argc < 3)
		CONFIG("Usage:  %s <# procs> <# pages>", argv[0]);

	numprocs = atoi(argv[1]);
	nr_hugepages = atoi(argv[2]);

	if (numprocs > MAX_PROCS)
		CONFIG("Cannot spawn more than %d processes", MAX_PROCS);

	check_hugetlb_shm_group();

	hpage_size = check_hugepagesize();
        size = hpage_size * nr_hugepages;
	verbose_printf("Requesting %lu bytes\n", size);
	if ((shmid = shmget(2, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W )) < 0)
		FAIL("shmget(): %s", strerror(errno));

	verbose_printf("shmid: %d\n", shmid);

	verbose_printf("Spawning children:\n");
	for (i=0; i<numprocs; i++) {
		if ((pid = fork()) < 0)
			FAIL("fork(): %s", strerror(errno));

		if (pid == 0)
			do_child(i, size);

		wait_list[i] = pid;
	}

	for (i=0; i<numprocs; i++) {
		waitpid(wait_list[i], &status, 0);
		if (WEXITSTATUS(status) != 0)
			FAIL("Thread %d (pid=%d) failed", i, wait_list[i]);

		if (WIFSIGNALED(status))
			FAIL("Thread %d (pid=%d) received unhandled signal",
			     i, wait_list[i]);
	}

	PASS();
}
Beispiel #30
0
pid_t start_server(struct sockaddr_in *ssin, struct sockaddr_un *ssun)
{
	pid_t pid;

	/* set up inet socket */
	sfd = socket(PF_INET, SOCK_STREAM, 0);
	if (sfd < 0) {
		tst_brkm(TBROK|TERRNO, cleanup, "server socket failed");
		return -1;
	}
	if (bind(sfd, (struct sockaddr *)ssin, sizeof(*ssin)) < 0) {
		tst_brkm(TBROK|TERRNO, cleanup, "server bind failed");
		return -1;
	}
	if (listen(sfd, 10) < 0) {
		tst_brkm(TBROK|TERRNO, cleanup, "server listen failed");
		return -1;
	}
	/* set up UNIX-domain socket */
	ufd = socket(PF_UNIX, SOCK_STREAM, 0);
	if (ufd < 0) {
		tst_brkm(TBROK|TERRNO, cleanup, "server UD socket failed");
		return -1;
	}
	if (bind(ufd, (struct sockaddr *)ssun, sizeof(*ssun))) {
		tst_brkm(TBROK|TERRNO, cleanup, "server UD bind failed");
		return -1;
	}
	if (listen(ufd, 10) < 0) {
		tst_brkm(TBROK|TERRNO, cleanup, "server UD listen failed");
		return -1;
	}

	switch ((pid = FORK_OR_VFORK())) {
	case 0:		/* child */
#ifdef UCLINUX
		if (self_exec(argv0, "dd", sfd, ufd) < 0)
			tst_brkm(TBROK|TERRNO, cleanup, "server self_exec failed");
#else
		do_child();
#endif
		break;
	case -1:
		tst_brkm(TBROK|TERRNO, cleanup, "server fork failed");
		/* fall through */
	default:		/* parent */
		(void)close(sfd);
		(void)close(ufd);
		return pid;
	}
	 /*NOTREACHED*/ exit(1);
}