Ejemplo n.º 1
0
Archivo: shmctl02.c Proyecto: 1587/ltp
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{
	key_t shmkey2;

	tst_require_root();

	/* Switch to nobody user for correct error code collection */
	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");
	}

	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();

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

	/* create a shared memory segment without read or write permissions */
	if ((shm_id_1 = shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL)) == -1) {
		tst_brkm(TBROK, cleanup, "couldn't create shared memory "
			 "segment #1 in setup()");
	}

	/* Get an new IPC resource key. */
	shmkey2 = getipckey();

	/* create a shared memory segment with read and write permissions */
	if ((shm_id_2 = shmget(shmkey2, SHM_SIZE, IPC_CREAT | IPC_EXCL |
			       SHM_RW)) == -1) {
		tst_brkm(TBROK, cleanup, "couldn't create shared memory "
			 "segment #2 in setup()");
	}
}
Ejemplo n.º 2
0
static void setup(void)
{
	if ((tst_kvercmp(2, 6, 16)) < 0)
		tst_brkm(TCONF, NULL, "This test needs kernel 2.6.16 or newer");

	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to acquire device");

	TEST_PAUSE;

	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");

	SAFE_TOUCH(cleanup, TEST_FILE, 0644, NULL);

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

	SAFE_TOUCH(cleanup, TEST_EXIST, 0644, NULL);

	SAFE_SYMLINK(cleanup, TEST_ELOOP, "test_file_eloop2");
	SAFE_SYMLINK(cleanup, "test_file_eloop2", TEST_ELOOP);

	SAFE_MKDIR(cleanup, "./tmp", DIR_MODE);
	SAFE_TOUCH(cleanup, TEST_EACCES, 0666, NULL);

	tst_mkfs(cleanup, device, fs_type, NULL);
	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);

	if (mount(device, "mntpoint", fs_type, 0, NULL) < 0) {
		tst_brkm(TBROK | TERRNO, cleanup,
			 "mount device:%s failed", device);
	}
	mount_flag = 1;

	max_hardlinks = tst_fs_fill_hardlinks(cleanup, "emlink_dir");
}
Ejemplo n.º 3
0
static void setup(void)
{
	tst_require_root(NULL);
	uid = geteuid();
	ncpus = tst_ncpus_max();

	/* Current mask */
	mask = CPU_ALLOC(ncpus);
	if (mask == NULL)
		tst_brkm(TBROK | TERRNO, cleanup, "CPU_ALLOC(%ld) failed",
			ncpus);
	mask_size = CPU_ALLOC_SIZE(ncpus);
	if (sched_getaffinity(0, mask_size, mask) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "sched_getaffinity() failed");

	/* Mask with one more cpu than available on the system */
	emask = CPU_ALLOC(ncpus + 1);
	if (emask == NULL)
		tst_brkm(TBROK | TERRNO, cleanup, "CPU_ALLOC(%ld) failed",
			ncpus + 1);
	emask_size = CPU_ALLOC_SIZE(ncpus + 1);
	CPU_ZERO_S(emask_size, emask);
	CPU_SET_S(ncpus, emask_size, emask);

	privileged_pid = tst_fork();
	if (privileged_pid == 0) {
		pause();

		exit(0);
	} else if (privileged_pid < 0) {
		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
	}

	/* Dropping the root privileges */
	ltpuser = getpwnam(nobody_uid);
	if (ltpuser == NULL)
		tst_brkm(TBROK | TERRNO, cleanup,
			"getpwnam failed for user id %s", nobody_uid);

	SAFE_SETEUID(cleanup, ltpuser->pw_uid);

	/* this pid is not used by the OS */
	free_pid = tst_get_unused_pid(cleanup);
}
Ejemplo n.º 4
0
static void setup(void)
{
	int i;
	struct passwd *ltpuser;
	const char *fs_type;

	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to acquire device");

	tst_mkfs(cleanup, device, fs_type, NULL);

	TEST_PAUSE;

	/* mount a read-only file system for EROFS test */
	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
	if (mount(device, MNT_POINT, fs_type, MS_RDONLY, NULL) < 0) {
		tst_brkm(TBROK | TERRNO, cleanup,
			 "mount device:%s failed", device);
	}
	mount_flag = 1;

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

	SAFE_MKDIR(cleanup, DIR_TEMP, DIR_TEMP_MODE);

	/*
	 * NOTE: the ELOOP test is written based on that the consecutive
	 * symlinks limits in kernel is hardwired to 40.
	 */
	SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
	for (i = 0; i < 43; i++)
		strcat(elooppathname, ELOPFILE);
}
Ejemplo n.º 5
0
Archivo: chown03.c Proyecto: 1587/ltp
/*
 * 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 close it
 *  Change the group ownership on testfile.
 */
void setup(void)
{
	int fd;			/* file handler for testfile */

	TEST_PAUSE;

	tst_require_root();

	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	ltpuser = getpwnam(nobody_uid);
	if (ltpuser == NULL)
		tst_brkm(TBROK | TERRNO, NULL, "getpwnam(\"nobody\") failed");
	if (setegid(ltpuser->pw_gid) == -1)
		tst_brkm(TBROK | TERRNO, NULL, "setegid(%d) failed",
			 ltpuser->pw_gid);
	if (seteuid(ltpuser->pw_uid) == -1)
		tst_brkm(TBROK | TERRNO, NULL, "seteuid(%d) failed",
			 ltpuser->pw_uid);

	/* Create a test file under temporary directory */
	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1)
		tst_brkm(TBROK | TERRNO, cleanup,
			 "open(%s, O_RDWR|O_CREAT, %o) failed", TESTFILE,
			 FILE_MODE);

	if (seteuid(0) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "seteuid(0) failed");

	if (fchown(fd, -1, 0) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "fchown failed");

	if (fchmod(fd, NEW_PERMS) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "fchmod failed");

	if (seteuid(ltpuser->pw_uid) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "seteuid to nobody failed");

	if (close(fd) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "closing %s failed",
			 TESTFILE);
}
Ejemplo n.º 6
0
int main(int ac, char **av)
{
	int lc, i;
	char *msg;

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

	setup();

	TEST_EXP_ENOS(exp_enos);

	/*
	 * FIXME (garrcoop): this should really test out whether or not the
	 * process's mappable address space is indeed accessible by the
	 * current user, instead of needing to be run by root all the time.
	 */
	tst_require_root(NULL);

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

		Tst_count = 0;

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

			if (TC[i].setupfunc != NULL)
				TC[i].setupfunc(TC[i].len);

			TEST(mlock(*(TC[i].addr), TC[i].len));

			/* I'm confused -- given the description above this
			 * should fail as designed, but this application
			 * */
			if (TEST_RETURN == -1)
				tst_resm(TFAIL|TTERRNO, "mlock failed");
			else
				tst_resm(TPASS, "mlock passed");
		}
	}

	cleanup();

	tst_exit();
}
Ejemplo n.º 7
0
/*
 * setup() - performs all ONE TIME setup for this test.
 */
void setup()
{
	char *cur_dir = NULL;

	tst_require_root(NULL);

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

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	/* get the current directory for the first test */
	if ((cur_dir = getcwd(cur_dir, 0)) == NULL) {
		tst_brkm(TBROK | TERRNO, cleanup, "getcwd failed");
	}

	strncpy(good_dir, cur_dir, NSIZE);

	/* create a file that will be used in test #3 */
	if ((fileHandle = creat("file1", MODE1)) == -1) {
		tst_brkm(TBROK, cleanup, "couldn't create a test file");
	}
#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 | TERRNO, cleanup, "mmap failed");
	}
	TC[4].fname = bad_addr;
#endif

	/* create a directory that will be used in test #6 */
	if (mkdir("dir6", MODE2) == -1) {
		tst_brkm(TBROK, cleanup, "couldn't creat a test directory");
	}
}
Ejemplo n.º 8
0
static void setup(void)
{
	int fd;
	unsigned int i;
	tst_require_root(NULL);

	for (i = 0; i < ARRAY_SIZE(cdrv); ++i) {
		fd = open(cdrv[i].file, O_RDWR);
		if (fd == -1)
			continue;

		id = i;
		close(fd);
		break;
	}

	if (id == -1)
		tst_brkm(TCONF, NULL, "overclock not supported");

	tst_resm(TINFO, "found '%s' driver, sysfs knob '%s'",
		cdrv[id].name, cdrv[id].file);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	SAFE_FILE_SCANF(NULL, cdrv[i].file, "%d", &boost_value);

	/* change cpu0 scaling governor */
	SAFE_FILE_SCANF(NULL, governor, "%s", governor_name);
	SAFE_FILE_PRINTF(cleanup, governor, "%s", "performance");

	/* use only cpu0 */
	cpu_set_t set;
	CPU_ZERO(&set);
	CPU_SET(0, &set);
	if (sched_setaffinity(0, sizeof(cpu_set_t), &set) < 0)
		tst_brkm(TBROK | TERRNO, cleanup, "failed to set CPU0");

	struct sched_param params;
	params.sched_priority = sched_get_priority_max(SCHED_FIFO);
	if (sched_setscheduler(getpid(), SCHED_FIFO, &params)) {
		tst_resm(TWARN | TERRNO,
			"failed to set FIFO sched with max priority");
	}
}
Ejemplo n.º 9
0
/*
 * void
 * 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 iividual test setup functions according to the order
 *	set in struct. definition.
 */
void setup(void)
{
	int i;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	test_home = get_current_dir_name();

	tst_require_root(NULL);

	TEST_PAUSE;

	tst_tmpdir();

	tst_mkfs(NULL, device, fstype, NULL);

	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);

	/*
	 * mount a read-only file system for test EROFS
	 */
	if (mount(device, MNT_POINT, fstype, MS_RDONLY, NULL) < 0) {
		tst_brkm(TBROK | TERRNO, cleanup,
			 "mount device:%s failed", device);
	}
	mount_flag = 1;

	bad_addr = mmap(0, 1, PROT_NONE,
			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
	if (bad_addr == MAP_FAILED)
		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
	test_cases[3].pathname = bad_addr;

	for (i = 0; i < TST_TOTAL; i++)
		if (test_cases[i].setupfunc != NULL)
			test_cases[i].setupfunc();

	/*
	 * create two symbolic links who point to each other for
	 * test ELOOP.
	 */
	SAFE_SYMLINK(cleanup, "test_file4", "test_file5");
	SAFE_SYMLINK(cleanup, "test_file5", "test_file4");
}
Ejemplo n.º 10
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{
	key_t msgkey2;

	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

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

	TEST_PAUSE;

	/* Switch to nobody user for correct error code collection */
	ltpuser = getpwnam(nobody_uid);
	if (setuid(ltpuser->pw_uid) == -1)
		tst_resm(TINFO, "setuid(%d) failed", ltpuser->pw_uid);

	/*
	 * 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();

	/* Get an new IPC resource key. */
	msgkey2 = getipckey();

	/* now we have a key, so let's create a message queue */
	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
		tst_brkm(TBROK | TERRNO, cleanup,
			 "Can't create message queue #1");
	}

	/* now let's create another message queue with read & write access */
	if ((msg_q_2 =
	     msgget(msgkey2, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR)) == -1) {
		tst_brkm(TBROK | TERRNO, cleanup,
			 "Can't create message queue #2");
	}
}
Ejemplo n.º 11
0
void setup()
{
	int fd;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	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(TINFO|TERRNO, NULL, "setuid failed");

	TEST_PAUSE;

	tst_tmpdir();

	if (mkdir(TESTDIR, DIR_MODE) < 0)
		tst_brkm(TBROK|TERRNO, cleanup, "mkdir(%s, %#o) failed",
			 TESTDIR, DIR_MODE);

	if (chmod(TESTDIR, DIR_MODE) < 0)
		tst_brkm(TBROK|TERRNO, cleanup, "chmod(%s, %#o) failed",
			 TESTDIR, DIR_MODE);

	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
	if (fd == -1)
		tst_brkm(TBROK|TERRNO, cleanup,
			 "open(%s, O_RDWR|O_CREAT, %#o) failed",
			 TESTFILE, FILE_MODE);

	if (close(fd) == -1)
		tst_brkm(TBROK|TERRNO, cleanup,
			 "close(%s) failed",
			 TESTFILE);

	if (chmod(TESTFILE, 0) < 0)
		tst_brkm(TBROK|TERRNO, cleanup,
			 "chmod(%s, 0) failed",
			 TESTFILE);
}
Ejemplo n.º 12
0
Archivo: mknodat02.c Proyecto: kraj/ltp
static void setup(void)
{
	int i;
	const char *fs_type;

	if (tst_kvercmp(2, 6, 16) < 0) {
		tst_brkm(TCONF, NULL, "This test can only run on kernels "
			 "that are 2.6.16 and higher");
	}

	tst_require_root();

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to acquire device");

	tst_mkfs(cleanup, device, fs_type, NULL, NULL);

	TEST_PAUSE;

	/*
	 * mount a read-only file system for EROFS test
	 */
	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL);
	mount_flag = 1;
	dir_fd = SAFE_OPEN(cleanup, MNT_POINT, O_DIRECTORY);

	/*
	 * NOTE: the ELOOP test is written based on that the consecutive
	 * symlinks limits in kernel is hardwired to 40.
	 */
	SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
	for (i = 0; i < 43; i++)
		strcat(elooppathname, ELOPFILE);
}
Ejemplo n.º 13
0
static void setup(void)
{
	int i;

	tst_require_root(NULL);
	tst_sig(FORK, 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(TINFO | TERRNO, NULL, "setuid failed");

	TEST_PAUSE;
	tst_tmpdir();

	for (i = 0; i < TST_TOTAL; i++)
		test_cases[i].setupfunc();
}
Ejemplo n.º 14
0
/*
 * setup() - performs all ONE TIME setup for this test
 */
void setup(void)
{
	tst_require_root();

	ltpuser = getpwnam(nobody_uid);

	UID16_CHECK(ltpuser->pw_uid, "setresuid", cleanup)

	tst_tmpdir();

	sprintf(testfile, "setresuid04file%d.tst", getpid());

	/* Create test file */
	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;
}
Ejemplo n.º 15
0
/*
 * setup() - performs all ONE TIME setup for this test
 */
void setup(void)
{
	tst_require_root(NULL);

	ltpuser = getpwnam(nobody_uid);

	tst_tmpdir();

	sprintf(testfile, "setresuid04file%d.tst", getpid());

	/* Create test file */
	fd = open(testfile, O_CREAT | O_RDWR, 0644);
	if (fd < 0)
		tst_brkm(TBROK, cleanup, "cannot creat test file");

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;
}
Ejemplo n.º 16
0
Archivo: ksm03.c Proyecto: CSRedRat/ltp
void setup(void)
{
	tst_require_root();

	if (tst_kvercmp(2, 6, 32) < 0)
		tst_brkm(TCONF, NULL, "2.6.32 or greater kernel required");
	if (access(PATH_KSM, F_OK) == -1)
		tst_brkm(TCONF, NULL, "KSM configuration is not enabled");

	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
		SAFE_FILE_SCANF(NULL, PATH_KSM "merge_across_nodes",
				"%d", &merge_across_nodes);
		SAFE_FILE_PRINTF(NULL, PATH_KSM "merge_across_nodes", "1");
	}

	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
	tst_sig(FORK, DEF_HANDLER, NULL);
	TEST_PAUSE;
}
Ejemplo n.º 17
0
Archivo: ioperm02.c Proyecto: kraj/ltp
/* setup() - performs all ONE TIME setup for this test */
void setup(void)
{
	tst_require_root();

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Check if "nobody" user id exists */
	if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
		tst_brkm(TBROK, NULL, "\"nobody\" user id doesn't exist");
	}

	/*
	 * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed
	 * from kernel 2.6.8 to permit 16-bits (65536) ioperm
	 *
	 * Ricky Ng-Adam, [email protected]
	 * */
	test_cases = malloc(sizeof(struct test_cases_t) * 2);
	test_cases[0].num = NUM_BYTES;
	test_cases[0].turn_on = TURN_ON;
	test_cases[0].desc = "Invalid I/O address";
	test_cases[0].exp_errno = EINVAL;
	test_cases[1].num = NUM_BYTES;
	test_cases[1].turn_on = TURN_ON;
	test_cases[1].desc = "Non super-user";
	test_cases[1].exp_errno = EPERM;
	if ((tst_kvercmp(2, 6, 8) < 0) || (tst_kvercmp(2, 6, 9) == 0)) {
		/*try invalid ioperm on 1022, 1023, 1024 */
		test_cases[0].from = (IO_BITMAP_BITS - NUM_BYTES) + 1;

		/*try get valid ioperm on 1021, 1022, 1023 */
		test_cases[1].from = IO_BITMAP_BITS - NUM_BYTES;
	} else {
		/*try invalid ioperm on 65534, 65535, 65536 */
		test_cases[0].from = (IO_BITMAP_BITS_16 - NUM_BYTES) + 1;

		/*try valid ioperm on 65533, 65534, 65535 */
		test_cases[1].from = IO_BITMAP_BITS_16 - NUM_BYTES;
	}

	TEST_PAUSE;

}
Ejemplo n.º 18
0
void setup(void)
{
	long hpage_size;

	tst_require_root();
	check_hugepage();
	tst_sig(FORK, sighandler, 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(cleanup);

	TEST_PAUSE;
}
Ejemplo n.º 19
0
static void setup(void)
{
	tst_require_root();

	tst_sig(FORK, DEF_HANDLER, NULL);

	ltpuser = getpwnam("nobody");
	if (ltpuser == NULL)
		tst_brkm(TBROK, NULL, "getpwnam(\"nobody\") failed");

	SAFE_SETGID(NULL, ltpuser->pw_gid);
	SAFE_SETUID(NULL, ltpuser->pw_uid);

	root = get_group_by_name("root");
	ltpgroup = get_group_by_gid(ltpuser->pw_gid);
	bin = get_group_by_name("bin");

	TEST_PAUSE;
}
Ejemplo n.º 20
0
void setup(void)
{
	int fd;

	tst_require_root(NULL);

	tst_sig(FORK, DEF_HANDLER, cleanup);
	TEST_PAUSE;

	fd = open(SYSFS_OVER, O_RDONLY);
	if (fd == -1)
		tst_brkm(TBROK|TERRNO, NULL, "open");
	if (read(fd, &overcommit, 1) != 1)
		tst_brkm(TBROK|TERRNO, NULL, "read");
	close(fd);

	mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW);
	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
}
Ejemplo n.º 21
0
/*
 * setup()
 *	performs all ONE TIME setup for this test
 */
void setup(void)
{
	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	/* Check for nobody_uid user id */
	if ((ltpuser = getpwnam("nobody")) == NULL) {
		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
	}

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

	/* Pause if that option was specified
	 * TEST_PAUSE contains the code to fork the test with the -c option.
	 */
	TEST_PAUSE;
}
Ejemplo n.º 22
0
void setup(void)
{
	char *cur_dir = NULL;

	tst_require_root(NULL);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	if ((cur_dir = getcwd(cur_dir, 0)) == NULL)
		tst_brkm(TBROK | TERRNO, cleanup, "getcwd failed");

	sprintf(good_dir, "%s.%d", cur_dir, getpid());

	ltpuser1 = my_getpwnam(user1name);
}
Ejemplo n.º 23
0
void setup()
{
	int fd;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root(NULL);

	TEST_PAUSE;

	tst_tmpdir();

	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "opening %s failed",
			 TESTFILE);
	if (close(fd) == -1)
		tst_brkm(TBROK, cleanup, "closing %s failed", TESTFILE);

}
Ejemplo n.º 24
0
static void setup(void)
{
	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_require_root(NULL);

	tst_tmpdir();

	switch ((fs_type = tst_fs_type(cleanup, "."))) {
	case TST_NFS_MAGIC:
	case TST_TMPFS_MAGIC:
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapon on a file on %s filesystem",
			 tst_fs_type_name(fs_type));
	break;
	}

	TEST_PAUSE;
}
Ejemplo n.º 25
0
static void setup(void)
{
	tst_require_root();

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

	tst_tmpdir();

	sprintf(testfile, "setreuid07file%d.tst", getpid());

	/* Create test file */
	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;
}
Ejemplo n.º 26
0
void setup(void)
{
	long hpage_size;
	char buf[BUFSIZ];

	tst_require_root(NULL);
	tst_sig(NOFORK, 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;

	read_file(PATH_SHMMNI, buf);
	orig_shmmni = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX);
	snprintf(buf, BUFSIZ, "%ld", hugepages / 2);
	write_file(PATH_SHMMNI, buf);

	/*
	 * Use a while loop to create the maximum number of memory segments.
	 * If the loop exceeds MAXIDS, then break the test and cleanup.
	 */
	num_shms = 0;
	shm_id_1 = shmget(IPC_PRIVATE, shm_size,
			  SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
	while (shm_id_1 != -1) {
		shm_id_arr[num_shms++] = shm_id_1;
		if (num_shms == MAXIDS)
			tst_brkm(TBROK, cleanup, "The maximum number of "
				 "shared memory ID's has been reached. "
				 "Please increase the MAXIDS value in "
				 "the test.");
		shm_id_1 = shmget(IPC_PRIVATE, shm_size,
				  SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
	}
	if (errno != ENOSPC)
		tst_brkm(TBROK | TERRNO, cleanup, "shmget #setup");

	TEST_PAUSE;
}
Ejemplo n.º 27
0
Archivo: execve02.c Proyecto: 1587/ltp
static void setup(void)
{
	char path[PATH_MAX];
	struct passwd *pwd;

	tst_require_root();

	if (tst_get_path(TEST_APP, path, sizeof(path))) {
		tst_brkm(TBROK, NULL,
		         "Couldn't found "TEST_APP" binary in $PATH");
	}

	tst_tmpdir();

	SAFE_CP(tst_rmdir, path, ".");
	SAFE_CHMOD(cleanup, TEST_APP, 0700);

	pwd = SAFE_GETPWNAM(tst_rmdir, USER_NAME);
	nobody_uid = pwd->pw_uid;
}
Ejemplo n.º 28
0
Archivo: mkdir04.c Proyecto: Nan619/ltp
/*
 * setup() - performs all ONE TIME setup for this test.
 */
void setup(void)
{
	struct passwd *pw;

	tst_require_root();

	pw = SAFE_GETPWNAM(NULL, "nobody");
	nobody_uid = pw->pw_uid;
	pw = SAFE_GETPWNAM(NULL, "bin");
	bin_uid = pw->pw_uid;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

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

	umask(0);
}
Ejemplo n.º 29
0
Archivo: chmod04.c Proyecto: kraj/ltp
/*
 * void
 * setup() - performs all ONE TIME setup for this test.
 *  Create a temporary directory and cd to it.
 *  Create another test directory under temporary directory.
 */
void setup(void)
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root();
	ltpuser = getpwnam(nobody_uid);
	if (setuid(ltpuser->pw_uid) == -1)
		tst_resm(TINFO | TERRNO, "setuid(%u) failed", ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	/*
	 * Create a test directory under temporary directory with specified
	 * mode permissios.
	 */
	SAFE_MKDIR(cleanup, TESTDIR, DIR_MODE);
}
Ejemplo n.º 30
0
static void setup(void)
{

	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_require_root(NULL);
	tst_mkfs(NULL, device, fstype, NULL);

	tst_tmpdir();

	if (mkdir(mntpoint, DIR_MODE)) {
		tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; "
			 "errno = %d: %s", mntpoint, DIR_MODE, errno,
			 strerror(errno));
	}

	TEST_EXP_ENOS(exp_enos);

	TEST_PAUSE;
}