Пример #1
0
/*
 * setup()
 *	performs all ONE TIME setup for this test
 */
void setup(void)
{
    /* capture signals */
    tst_sig(FORK, DEF_HANDLER, cleanup);

    /* Set up the expected error numbers for -e option */
    TEST_EXP_ENOS(exp_enos);

    /* Pause if that option was specified.
     * TEST_PAUSE contains the code to fork the test with the -i option.
     * You want to make sure you do this before you create your temporary
     * directory.
     */
    TEST_PAUSE;

    /* Create a unique temporary directory and chdir() to it. */
    tst_tmpdir();

    strcpy(name, DATA_FILE);
#if 0
    /* This doesn't work in the simulator due to floating point instructions */
    sprintf(f_name, "%s.%d", name, getpid());
#else
    /* This works fine -- no floating point instructions executed */
    strcpy(f_name, name);
    strcat(f_name, ".");
    sprintf(f_name+strlen(f_name), "%d", getpid());
#endif

    bad_addr = mmap(0, 1, PROT_NONE,
                    MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
    if (bad_addr == MAP_FAILED) {
        printf("mmap failed\n");
    }
    wr_iovec[7].iov_base = bad_addr;

}
Пример #2
0
void setup(void)
{
	struct passwd *ltpuser;
	char *bad_addr;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root(NULL);

	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
	SAFE_SETEUID(cleanup, ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	SAFE_TOUCH(cleanup, TEST_FILE1, NEW_MODE, NULL);

	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);

#if !defined(UCLINUX)
	test_cases[2].pathname = (char *)get_high_address();

	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	test_cases[3].pathname = bad_addr;
#endif

	memset(long_pathname, 'a', PATH_MAX + 1);

	SAFE_MKDIR(cleanup, TEST_DIR1, DIR_MODE);

	SAFE_TOUCH(cleanup, TEST_FILE3, FILE_MODE, NULL);

	SAFE_SYMLINK(cleanup, TEST_SYM1, TEST_SYM2);
	SAFE_SYMLINK(cleanup, TEST_SYM2, TEST_SYM1);
}
Пример #3
0
void setup(void)
{
	char tst_buff[BUF_SIZE];
	int wbytes;
	int write_len = 0;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	ltpuser = getpwnam(nobody_uid);
	if (ltpuser == NULL)
		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
	if (setuid(ltpuser->pw_uid) == -1)
		tst_brkm(TBROK | TERRNO, NULL, "setuid failed");

	TEST_PAUSE;

	tst_tmpdir();

	fildes = open(TESTFILE, O_WRONLY | O_CREAT, FILE_MODE);
	if (fildes == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "open failed");

	/* Fill the test buffer with the known data */
	memset(tst_buff, 'a', BUF_SIZE - 1);

	/* Write to the file 1k data from the buffer */
	while (write_len < FILE_SIZE) {
		if ((wbytes = write(fildes, tst_buff, sizeof(tst_buff))) <= 0)
			tst_brkm(TBROK | TERRNO, cleanup, "write failed");
		else
			write_len += wbytes;
	}

	user_id = getuid();
	group_id = getgid();

}
Пример #4
0
/*
 * void
 * setup() -  Performs setup function for the test.
 *  Creat a temporary directory and chdir to it.
 *  Creat a test file and write some data into it.
 *  Get the user/group id info. of test process.
 */
void setup()
{
	char tst_buff[BUF_SIZE];	/* data buffer */
	int wbytes;		/* no. of bytes written */
	int write_len = 0;	/* data length */

	tst_require_root(NULL);

	ltpuser = getpwnam(nobody_uid);
	if (ltpuser == NULL)
		tst_brkm(TBROK|TERRNO, NULL, "getpwnam failed");
	if (setuid(ltpuser->pw_uid) == -1)
		tst_brkm(TBROK|TERRNO, NULL, "setuid failed");

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	fildes = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
	if (fildes == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "open failed");

	memset(tst_buff, 'a', BUF_SIZE-1);

	while (write_len < FILE_SIZE) {
		if ((wbytes = write(fildes, tst_buff, sizeof(tst_buff))) <= 0)
			tst_brkm(TBROK|TERRNO, cleanup, "write failed");
		else
			write_len += wbytes;
	}

	user_id = getuid();
	group_id = getgid();

}
Пример #5
0
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 * Initialise signal set with the list that includes/excludes
 * all system-defined signals.
 * Set the signal handler to catch SIGALRM signal.
 * Get the current signal mask of test process using sigprocmask().
 */
void setup(void)
{

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/*
	 * Initialise the signal sets with the list that
	 * excludes/includes  all system-defined signals.
	 */
	if (sigemptyset(&sigset) == -1) {
		tst_brkm(TFAIL, cleanup,
			 "sigemptyset() failed, errno=%d : %s",
			 errno, strerror(errno));
	}
	if (sigfillset(&sigset2) == -1) {
		tst_brkm(TFAIL, cleanup,
			 "sigfillset() failed, errno=%d : %s",
			 errno, strerror(errno));
	}

	/* Set the signal handler function to catch the signal */
	sa_new.sa_handler = sig_handler;
	if (sigaction(SIGALRM, &sa_new, 0) == -1) {
		tst_brkm(TFAIL, cleanup,
			 "sigaction() failed, errno=%d : %s",
			 errno, strerror(errno));
	}

	/* Read the test process's current signal mask. */
	if (sigprocmask(SIG_UNBLOCK, 0, &sigset1) == -1) {
		tst_brkm(TFAIL, cleanup,
			 "sigprocmask() Failed, errno=%d : %s",
			 errno, strerror(errno));
	}
}
Пример #6
0
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 *  Create a temporary directory and change directory to it.
 *  Create a test directory under temporary directory and open it
 */
void setup()
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Switch to nobody user for correct error code collection */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}
	ltpuser = getpwnam(nobody_uid);
	if (setuid(ltpuser->pw_uid) == -1) {
		tst_resm(TINFO, "setuid failed to "
			 "to set the effective uid to %d", ltpuser->pw_uid);
		perror("setuid");
	}

	/*
	 * Pause if that option was specified
	 */
	TEST_PAUSE;

	tst_tmpdir();

	/*
	 * create a new directory and open it
	 */

	if ((r_val = mkdir(TEST_DIR, MODES)) == -1) {
		tst_brkm(TBROK, cleanup, "%s - mkdir() in main() "
			 "failed", TCID);
	}

	if ((fd = open(TEST_DIR, O_RDONLY)) == -1) {
		tst_brkm(TBROK, cleanup, "open of directory failed");
	}

}
Пример #7
0
void setup(void)
{
	struct passwd *ltpuser;
	int i;

	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
	SAFE_SETEUID(cleanup, ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
	SAFE_TOUCH(cleanup, TEST_FILE1, 0666, NULL);
	SAFE_SYMLINK(cleanup, TEST_FILE1, SYM_FILE1);
	SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE);

	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);
	SAFE_SYMLINK(cleanup, TEST_FILE2, SYM_FILE2);

	memset(longpathname, 'a', PATH_MAX + 1);

	SAFE_TOUCH(cleanup, TEST_FILE3, 0666, NULL);

	/*
	 * NOTE: the ELOOP test is written based on that the consecutive
	 * symlinks limit in kernel is hardwired to 40.
	 */
	SAFE_MKDIR(cleanup, "test_eloop", MODE_RWX);
	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
	for (i = 0; i < 43; i++)
		strcat(elooppathname, ELOOPFILE);
}
Пример #8
0
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 *  Create a temporary directory and change directory to it.
 *  Create a test file under temporary directory and write some
 *  data into it.
 */
void 
setup()
{
	/* capture signals */
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Pause if that option was specified
	 * TEST_PAUSE contains the code to fork the test with the -i option.
	 * You want to make sure you do this before you create your temporary
	 * directory.
	 */
	TEST_PAUSE;

	/* make a temp directory and cd to it */
	tst_tmpdir();

	/* Copy some data into data buffer */
	strcpy(write_buffer,  "abcdefghijklmnopqrstuvwxyz");

	/* Creat a temporary file under above directory */
	if ((fildes = open(TEMP_FILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
		tst_brkm(TBROK, cleanup,
			 "open(%s, O_RDWR | O_CREAT, %#o) Failed, errno=%d :%s",
			 TEMP_FILE, FILE_MODE, errno, strerror(errno));
		/*NOTREACHED*/
	}

	/* Write the buffer data into file */
	if (write(fildes, write_buffer, strlen(write_buffer)+1) != \
				strlen(write_buffer)+1) {
		tst_brkm(TBROK, cleanup,
			 "write() failed to write buffer data to %s",
			 TEMP_FILE);
		/*NOTREACHED*/
	}
	
}	/* End setup() */
Пример #9
0
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 *  Create a temporary directory and change directory to it.
 *  Call test specific setup functions.
 */
void setup(void)
{
	int ind;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Pause if that option was specified
	 * TEST_PAUSE contains the code to fork the test with the -i option.
	 * You want to make sure you do this before you create your temporary
	 * directory.
	 */
	TEST_PAUSE;

	/* Switch to nobody user for correct error code collection */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}
	ltpuser = getpwnam(nobody_uid);
	if (setuid(ltpuser->pw_uid) == -1)
		tst_resm(TINFO | TERRNO, "setuid(%d) failed", ltpuser->pw_uid);

	tst_tmpdir();

#if !defined(UCLINUX)
	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed");
	}
	Test_cases[3].link = bad_addr;
#endif

	/* call individual setup functions */
	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
		Test_cases[ind].setupfunc();
	}
}
Пример #10
0
/*
 * setup(void) - performs all ONE TIME setup for this test.
 * 	Exit the test program on receipt of unexpected signals.
 *	Create a temporary directory and change directory to it.
 *	Invoke individual test setup functions according to the order
 *	set in struct. definition.
 */
void setup()
{
	int ind;

	/* Capture unexpected signals */
	tst_sig(FORK, DEF_HANDLER, cleanup);

	/* Switch to nobody user for correct error code collection */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Test must be run as root");
	}
	ltpuser = getpwnam(nobody_uid);
	if (setuid(ltpuser->pw_uid) == -1) {
		tst_resm(TINFO, "setuid failed to "
			 "to set the effective uid to %d", ltpuser->pw_uid);
		perror("setuid");
	}

	TEST_PAUSE;

	/* Make a temp dir and cd to it */
	tst_tmpdir();

#if !defined(UCLINUX)
	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed");
	}
	Test_cases[2].pathname = bad_addr;
#endif

	/* call individual setup functions */
	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
		Test_cases[ind].setupfunc();
	}
}
Пример #11
0
void setup(char *argv0)
{
	char *cmd, *pwd = NULL;
	char test_path[MAXPATHLEN];

	tst_require_root(NULL);

	if (test_app[0] == '/')
		strncpy(test_path, test_app, sizeof(test_path));
	else {
		if ((pwd = get_current_dir_name()) == NULL)
			tst_brkm(TBROK|TERRNO, NULL, "getcwd failed");

		snprintf(test_path, sizeof(test_path), "%s/%s",
		    pwd, basename(test_app));

		free(pwd);
	}

	cmd = malloc(strlen(test_path) + strlen("cp -p \"") + strlen("\" .") +
	    1);
	if (cmd == NULL)
		tst_brkm(TBROK|TERRNO, NULL, "Cannot alloc command string");

	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	sprintf(cmd, "cp -p \"%s\" .", test_path);
	if (system(cmd) != 0)
		tst_brkm(TBROK, NULL, "command failed: %s", cmd);
	free(cmd);

	umask(0);

	ltpuser1 = my_getpwnam(user1name);
}
Пример #12
0
/*
 * setup()
 *	performs all ONE TIME setup for this test
 */
void setup(void)
{

	tst_sig(FORK, DEF_HANDLER, cleanup);

	if (getpwnam("nobody") == NULL) {
		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
		tst_exit();
	}

	if (getpwnam("bin") == NULL) {
		tst_brkm(TBROK, NULL, "bin must be a valid user.");
		tst_exit();
	}

	/* Check that the test process id is root */
	if (geteuid() != 0) {
		tst_brkm(TBROK, NULL, "Must be root for this test!");
		tst_exit();
	}

	root = *(getpwnam("root"));
	root_pw_uid = root.pw_uid;

	nobody = *(getpwnam("nobody"));
	nobody_pw_uid = nobody.pw_uid;

	bin = *(getpwnam("bin"));
	bin_pw_uid = bin.pw_uid;

	/* Pause if that option was specified
	 * TEST_PAUSE contains the code to fork the test with the -i option.
	 * You want to make sure you do this before you create your temporary
	 * directory.
	 */
	TEST_PAUSE;
}
Пример #13
0
void setup(void)
{
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	char *abs_path = tst_get_tmpdir();
	int p = getpid();

	/* Initialize test dir and file names */
	sprintf(pathname, "faccessattestdir%d", p);
	sprintf(testfile, "faccessattestfile%d.txt", p);
	sprintf(testfile2, "%s/faccessattestfile%d.txt", abs_path, p);
	sprintf(testfile3, "faccessattestdir%d/faccessattestfile%d.txt", p, p);

	free(abs_path);

	SAFE_MKDIR(cleanup, pathname, 0700);

	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
	fds[1] = fds[4] = fds[0];


	SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0600);
	SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);

	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);

	fds[3] = 100;
	fds[5] = AT_FDCWD;

	filenames[0] = filenames[2] = filenames[3] = filenames[4] = testfile;
	filenames[1] = testfile2;
	filenames[5] = testfile3;

	TEST_PAUSE;
}
Пример #14
0
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 *   This function installs signal handler for SIGUSR1, puts signal SIGUSR1
 *   on hold and then sends the signal SIGUSR1 to itself so that it is in
 *   pending state.
 */
void setup(void)
{
	sigset_t PendSig;	/* variable to hold pending signal */

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Install the signal handler */
	if (signal(SIGUSR1, sig_handler) == SIG_ERR) {
		tst_brkm(TBROK, cleanup, "Fails to catch the signal SIGUSR1");
	}

	/* Hold the signal SIGUSR1 */
	if (sighold(SIGUSR1) == -1) {
		tst_brkm(TBROK, cleanup,
			 "sighold failed to hold the signal SIGUSR1");
	}

	/* Send the signal SIGUSR1 to itself so that SIGUSR1 is pending */
	if (kill(getpid(), SIGUSR1) == -1) {
		tst_brkm(TBROK, cleanup,
			 "Fails to send the signal to the parent process");
	}

	/* If SIGUSR1 is not pending in the parent, fail */
	if (sigpending(&PendSig) == -1) {
		tst_brkm(TBROK, cleanup,
			 "sigpending function failed in parent");
	}

	/* Check if SIGUSR1 is pending in parent */
	if (sigismember(&PendSig, SIGUSR1) != 1) {
		tst_brkm(TBROK, cleanup,
			 "SIGUSR1 signal is not pending in parent");
	}
}
Пример #15
0
/***************************************************************
 * setup() - performs all ONE TIME setup for this test.
 ***************************************************************/
void setup()
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	sprintf(fname, "tfile_%d", getpid());
	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
		tst_brkm(TBROK, cleanup,
			 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
			 fname, errno, strerror(errno));
	}
	/* write the TCID to the file */
	if (write(fd, TCID, strlen(TCID)) == -1) {
		tst_brkm(TBROK, cleanup,
			 "write(fd, TCID, strlen(TCID))Failed, errno=%d : %s",
			 errno, strerror(errno));
	}
	close(fd);

}
Пример #16
0
/***************************************************************
 * setup() - performs all ONE TIME setup for this test.
 ***************************************************************/
void setup(void)
{
	int ind;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

#if !defined(UCLINUX)
	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed");
	}
	Test_cases[6].pathname = bad_addr;
#endif

	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
		Test_cases[ind].setupfunc();
	}

}
Пример #17
0
void setup(void)
{
	long hpage_size;

	tst_require_root(NULL);
	tst_sig(FORK, DEF_HANDLER, cleanup);
	tst_tmpdir();

	orig_hugepages = get_sys_tune("nr_hugepages");
	set_sys_tune("nr_hugepages", hugepages, 1);
	hpage_size = read_meminfo("Hugepagesize:") * 1024;

	shm_size = hpage_size * hugepages / 2;
	update_shm_size(&shm_size);
	shmkey = getipckey();
	shm_id_1 = shmget(shmkey, shm_size,
			  SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL);
	if (shm_id_1 == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "shmget");

	ltp_uid = getuserid(ltp_user);

	TEST_PAUSE;
}
Пример #18
0
/*
 * setup() - performs all ONE TIME setup for this test.
 */
void
setup()
{
	/* capture signals */
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Pause if that option was specified */
	TEST_PAUSE;

	/* make a temporary directory and cd to it */
	tst_tmpdir();

	/*
	 * create a file and use it to test whether chroot() is setting
	 * ENOTDIR if the argument is not a directory.
	 */
	(void) sprintf(fname, "tfile_%d", getpid());
	if ((fd = creat(fname, 0777)) == -1) {
		tst_brkm(TBROK, cleanup, "Failed to creat a temp file");
	}

	/*
	 * set up good_dir to test whether chroot() is setting ENOENT if the
	 * directory does not exist.
	 */
	(void)sprintf(good_dir, "%s.%d", good_dir, getpid());

	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX|MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed");
	}
#if !defined(UCLINUX)
	TC[3].dir = bad_addr;
#endif
}
Пример #19
0
/*
 * setup() - performs all one time setup for this test.
 */
void setup()
{
    int ret;

    /* set up expected error numbers */
    TEST_EXP_ENOS(exp_enos);

    /* capture the signals */
    tst_sig(NOFORK, DEF_HANDLER, cleanup);

    /* Test should be executed as root user */
    if (geteuid() != 0) {
        tst_brkm(TBROK, NULL, "Test must be run as root");
    }

    /* Keep the host name before starting the test */
    if ((ret = gethostname(hname, sizeof(hname))) < 0) {
        tst_brkm(TBROK, NULL, "gethostname() failed while"
                 " getting current host name");
    }

    /* Pause if the option was specified */
    TEST_PAUSE;
}
Пример #20
0
/*
 * setup() - performs all ONE TIME setup for this test.
 *
 *  Initialize/allocate write buffer.
 *  Call individual setup function.
 */
void setup()
{
	int i;			/* counter for setup functions */

	/* capture signals */
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* see the comment in the sighandler() function */
	/* call signal() to trap the signal generated */
	if (signal(SIGXFSZ, sighandler) == SIG_ERR) {
		tst_brkm(TBROK, cleanup, "signal() failed");
	}

	/* Pause if that option was specified */
	TEST_PAUSE;

	/* Allocate/Initialize the write buffer with known data */
	init_buffers();

	/* Call individual setup functions */
	for (i = 0; Test_cases[i].desc != NULL; i++) {
		Test_cases[i].setupfunc();
	}
}
Пример #21
0
void setup(void)
{
	int sem_q;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	while ((sem_q = semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL)) != -1) {
		sem_id_arr[num_sems++] = sem_q;
		if (num_sems == MAXIDS) {
			tst_brkm(TBROK, cleanup, "The maximum number of "
				 "semaphore ID's has been\n\t reached.  Please "
				 "increase the MAXIDS value in the test.");
		}
	}

	if (errno != ENOSPC) {
		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
			 " - errno = %d : %s", errno, strerror(errno));
	}
}
Пример #22
0
/*
 * setup() - performs all ONE TIME setup for this test.
 */
void setup()
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Create a temporary directory and make it current. */
	tst_tmpdir();

	sprintf(fname, "./tfile_%d", getpid());

	do_file_setup(fname);

#if !defined(UCLINUX)
	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED) {
		tst_brkm(TBROK, cleanup, "mmap failed");
	}
	TC[0].fd2 = bad_addr;
	TC[1].fd = bad_addr;
#endif
}
Пример #23
0
Файл: readv03.c Проект: 1587/ltp
/*
 * setup() - performs all ONE TIME setup for this test.
 */
void setup(void)
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* make a temporary directory and cd to it */
	tst_tmpdir();

	/*
	 * create a new directory and open it
	 */

	if ((r_val = mkdir(TEST_DIR, MODES)) == -1) {
		tst_brkm(TBROK, cleanup, "%s - mkdir() in main() "
			 "failed", TCID);
	}

	if ((fd = open(TEST_DIR, O_RDONLY)) == -1) {
		tst_brkm(TBROK, cleanup, "open of directory failed");
	}

}
Пример #24
0
/***************************************************************
 * setup() - performs all ONE TIME setup for this test.
 ***************************************************************/
void setup(char *path)
{
	search_path(path, subprog_path, X_OK, 1);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* create a temporary directory and go to it */
	tst_tmpdir();

	/* set up a named pipe (write side gets CLOSE-ON-EXEC) */
	if (mkfifo(FIFONAME, 0666) == -1) {
		tst_brkm(TBROK, cleanup,
			 "mkfifo of named pipe %s failed errno %d (%s)",
			 FIFONAME, errno, strerror(errno));
	}

	if ((npipe_fd = open(FIFONAME, O_RDWR, 0666)) == -1) {
		tst_brkm(TBROK, cleanup,
			 "Open of named pipe %s failed errno %d (%s)", File1,
			 errno, strerror(errno));
	}
}
Пример #25
0
void setup(void)
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root();

	ltpuser = getpwnam(nobody_uid);
	if (ltpuser == NULL)
		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
	SAFE_SETEUID(NULL, ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	/*
	 * Create a test file under temporary directory with specified
	 * mode permissios and set the ownership of the test file to the
	 * uid/gid of guest user.
	 */
	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
}
Пример #26
0
static void setup(void)
{
	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_require_root();

	tst_timer_check(CLOCK_MONOTONIC);

	/* Backup and set the lease-break-time. */
	SAFE_FILE_SCANF(NULL, PATH_LS_BRK_T, "%d", &ls_brk_t);
	SAFE_FILE_PRINTF(NULL, PATH_LS_BRK_T, "%d", 45);

	tst_tmpdir();

	switch ((type = tst_fs_type(cleanup, "."))) {
	case TST_NFS_MAGIC:
	case TST_RAMFS_MAGIC:
	case TST_TMPFS_MAGIC:
		tst_brkm(TCONF, cleanup,
			 "Cannot do fcntl(F_SETLEASE, F_WRLCK) "
			 "on %s filesystem",
			 tst_fs_type_name(type));
	default:
		break;
	}

	SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL);

	sigemptyset(&newset);
	sigaddset(&newset, SIGIO);

	if (sigprocmask(SIG_SETMASK, &newset, &oldset) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "sigprocmask() failed");

	TEST_PAUSE;
}
Пример #27
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{

    tst_sig(FORK, sighandler, cleanup);

    TEST_PAUSE;

    /*
     * Create a temporary directory and cd into it.
     * This helps to ensure that a unique msgkey is created.
     * See ../lib/libipc.c for more information.
     */
    tst_tmpdir();

    /* get an IPC resource key */
    semkey = getipckey();

    /* create a semaphore set with read and alter permissions */
    /* and PSEMS "primitive" semaphores                       */
    if ((sem_id_1 =
                semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
        tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
    }
}
Пример #28
0
/*
 * setup() - performs all ONE TIME setup for this test
 */
void
setup()
{
	/*
	 * capture signals
	 */
	tst_sig(FORK, DEF_HANDLER, cleanup);

	umask(0);

	/*
	 * Pause if that option was specified
	 */
	TEST_PAUSE;

	/*
	 * make a temp directory and cd to it
	 */
	tst_tmpdir();
	
	strcpy(fnamebuf, "fork07.");
	sprintf(pbuf, "%d", getpid());
	strcat(fnamebuf, pbuf);
}
Пример #29
0
/* setup() - performs all ONE TIME setup for this test */
void setup(void)
{
	tst_require_root(NULL);

	tim_save.modes = 0;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	/* set the HZ from sysconf */
	hz = sysconf(_SC_CLK_TCK);
	if (hz == -1) {
		tst_brkm(TBROK, NULL, "Failed to read the HZ from sysconf\n");
	}

	TEST_PAUSE;

	/* Save current parameters in tim_save */
	if ((adjtimex(&tim_save)) == -1) {
		tst_brkm(TBROK, NULL, "Failed to save current parameters");
	}
}
Пример #30
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/*
	 * Create a temporary directory and cd into it.
	 * This helps to ensure that a unique msgkey is created.
	 * See ../lib/libipc.c for more information.
	 */
	tst_tmpdir();

	msgkey = getipckey();

	/* create a message queue with read/write permissions */
	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
		tst_brkm(TBROK, cleanup, "Can't create message queue");
	}

	/* initialize the message buffer */
	init_buf(&msg_buf, MSGTYPE, MSGSIZE);
}