Esempio n. 1
0
File: grub.c Progetto: jgraef/meinOS
/**
 * Gets grub modules
 *  @return List of grub modules
 */
pid_t *init_get_grub_modules() {
  size_t i;
  pid_t child;
  pid_t *children = NULL;

  for (i=0;(child = getchild(i))!=-1;i++) {
    children = realloc(children,(i+1)*sizeof(pid_t));
    children[i] = child;
  }
  children = realloc(children,(i+1)*sizeof(pid_t));
  children[i] = 0;

  return children;
}
Esempio n. 2
0
anbool bt_contains2(bt* tree, void* data, compare_func_2 compare, void* token) {
    bt_node *n;
    int cmp;
    int dir;

    if (!tree->root)
        return FALSE;

    dir = 0;
    for (n = tree->root; !isleaf(n); n = getchild(n, dir)) {
        cmp = compare(data, first_element(n->branch.children[1]), token);
        if (cmp == 0)
            return TRUE;
        dir = (cmp > 0);
    }
    return bt_leaf_contains(tree, &n->leaf, data, compare, token);
}
Esempio n. 3
0
int runtest(void)
{
	int i, j;
	int count, child, status;
	char tmpdir[MAXPATHLEN];

	/* Create permanent directories with holes in directory structure */

	for (j = 0; j < nfiles; j++) {
		sprintf(tmpdir, DIR_NAME, j);
		TEST(mkdir(tmpdir, MODE_RWX));

		if (TEST_RETURN < 0) {
			tst_brkm(TFAIL, cleanup,
				 "Error creating permanent directories, ERRNO = %d",
				 TEST_ERRNO);
		}
		if ((j % NCHILD) != 0) {
			if (rmdir(tmpdir) < 0) {
				tst_brkm(TFAIL, cleanup,
					 "Error removing directory, ERRNO = %d",
					 errno);
			}
		}
	}

	parent_pid = getpid();

	/* allocate space for list of child pid's */

	if ((pidlist = malloc((child_groups * NCHILD) * sizeof(int))) ==
	    NULL) {
		tst_brkm(TWARN, NULL,
			 "\tMalloc failed (may be OK if under stress)");
	}

	child_count = 0;
	for (j = 0; j < child_groups; j++) {
		for (i = 0; i < NCHILD; i++) {
			getchild(j, i, child_count);
			child_count++;
		}
	}

	/* If signal already received, skip to cleanup */

	if (!sigchld && !sigterm) {
		if (test_time) {
			/* To get out of sleep if signal caught */
			if (!setjmp(env_buf)) {
				jump++;
				sleep(test_time);
			}
		} else {
			pause();
		}
	}

	/* Reset signals since we are about to clean-up and to avoid
	 * problem with wait call *               $
	 * */

	if (signal(SIGTERM, SIG_IGN) == SIG_ERR) {
		tst_brkm(TFAIL, cleanup,
			 "Error resetting SIGTERM signal, ERRNO = %d", errno);
	}
	if (signal(SIGCLD, SIG_DFL) == SIG_ERR) {
		tst_brkm(TFAIL, cleanup,
			 "Error resetting SIGCLD signal, ERRNO = %d", errno);
	}

	if (test_time) {
		sleep(test_time);
	}

	/* Clean up children */
	massmurder();
	/*
	 * Watch children finish and show returns.
	 */

	count = 0;
	while (1) {
		if ((child = wait(&status)) > 0) {
			if (status != 0) {
				tst_brkm(TWARN,
					 NULL,
					 "\tChild{%d} exited status = %0x",
					 child, status);
			}
			count++;
		} else {
			if (errno != EINTR) {
				break;
			}
			tst_resm(TINFO, "\tSignal detected during wait");
		}
	}

	/*
	 * Make sure correct number of children exited.
	 */

	if (count != child_count) {
		tst_resm(TWARN, "\tWrong number of children waited on!");
		tst_brkm(TWARN, NULL, "\tSaw %d, expected %d", count,
			 NCHILD);
	}

	/* Check for core file in test directory. */

	if (access("core", 0) == 0) {
		tst_brkm(TWARN, NULL, "\tCore file found in test directory.");
	}

	/* Remove expected files */

	for (j = 0; j < nfiles; j += NCHILD) {
		sprintf(tmpdir, DIR_NAME, j);
		if (rmdir(tmpdir) < 0) {
			tst_brkm(TWARN,
				 NULL,
				 "\tError removing expected directory, ERRNO = %d",
				 errno);
		}
	}

	tst_resm(TPASS, "PASS");

	return 0;
}