Ejemplo n.º 1
0
Archivo: fork01.c Proyecto: 1587/ltp
int main(int ac, char **av)
{
	int lc;
	int fails;
	int kid_status, wait_status;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		TEST(fork());
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "fork() Failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
			tst_resm(TBROK, "unable to continue");
		}
		if (TEST_RETURN == 0) {
			/* child */
			child_pid();
			exit(KIDEXIT);
		} else {
			/* parent */
			tst_resm(TPASS, "fork() returned %ld",
				 TEST_RETURN);
			/* wait for the child to complete */
			wait_status = waitpid(TEST_RETURN, &kid_status, 0);

			if (wait_status == TEST_RETURN) {
				if (kid_status != KIDEXIT << 8) {
					tst_resm(TBROK,
						 "incorrect child status returned on wait(): %d",
						 kid_status);
					fails++;
				}
			} else {
				tst_resm(TBROK,
					 "wait() for child status failed with %d errno: %d : %s",
					 wait_status, errno,
					 strerror(errno));
				fails++;
			}
			if (fails == 0) {
				/* verification tests */
				parent_pid();
			}
		}		/* TEST_RETURN */
	}

	cleanup();
	tst_exit();
}
Ejemplo n.º 2
0
Archivo: semctl01.c Proyecto: 1587/ltp
/*
 * pid_setup() - set up for the GETPID command with semctl()
 */
static void pid_setup(void)
{
	int pid;

	/*
	 * Fork a child to do a semop that will pass.
	 */
	pid = FORK_OR_VFORK();
	if (pid == -1)
		tst_brkm(TBROK, cleanup, "fork failed in pid_setup()");

	if (pid == 0) {		/* child */
#ifdef UCLINUX
		if (self_exec(argv0, "nd", 1, sem_id_1) < 0)
			tst_brkm(TBROK, cleanup, "self_exec failed "
				 "in pid_setup()");
#else
		child_pid();
#endif
	} else {
		pid_arr[SEM2] = pid;
		TST_PROCESS_STATE_WAIT(cleanup, pid, 'Z');
	}
}
Ejemplo n.º 3
0
int
main(int ac, char **av)
{
    int lc;		/* loop counter */
    char *msg;		/* message returned from parse_opts */
    int fails;
    int kid_status, wait_status; 
    
    /***************************************************************
     * parse standard options
     ***************************************************************/
    if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
	tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
    setup();

    /* set the expected errnos... */
    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
    for (lc=0; TEST_LOOPING(lc); lc++) {

      /* reset Tst_count in case we are looping. */
      Tst_count=0;
      fails = 0;
      
      /* 
       * Call fork(2)
       */
      TEST(fork());
      
      /* check return code */
      if ( TEST_RETURN == -1 ) {
	TEST_ERROR_LOG(TEST_ERRNO);
	if ( STD_FUNCTIONAL_TEST ) {
	  tst_resm(TFAIL, "fork() Failed, errno=%d : %s",
		   TEST_ERRNO, strerror(TEST_ERRNO));
	  tst_resm(TBROK,"unable to continue");
	}
      } 
      if (TEST_RETURN == 0) {
	/* child */
	if ( STD_FUNCTIONAL_TEST ) {
	  child_pid();
	}
	exit(KIDEXIT);
      } else {
	/* parent */
	if ( STD_FUNCTIONAL_TEST ) {
	  tst_resm(TPASS, "fork() returned %d", TEST_RETURN);
	}
	/* wait for the child to complete */
	wait_status = waitpid(TEST_RETURN, &kid_status, 0);
	if ( STD_FUNCTIONAL_TEST ) {
	  if (wait_status == TEST_RETURN) {
	    if (kid_status != KIDEXIT << 8) {
	      tst_resm(TBROK,
		       "incorrect child status returned on wait(): %d", 
		       kid_status);
	      fails++;
	    }
	  }
	  else {
	    tst_resm(TBROK, 
		     "wait() for child status failed with %d errno: %d : %s", 
		     wait_status,errno,strerror(errno));
	    fails++;
	  }
	  if (fails == 0 ) {
	    /* verification tests */
	    parent_pid();
	  }
	}	 	  /* STD_FUNCTIONAL_TEST */
      }  /* TEST_RETURN */
    }	/* End for TEST_LOOPING */
    
    /***************************************************************
     * cleanup and exit
     ***************************************************************/
    cleanup();

    return 0;
}	/* End main */