这篇教程C++ tst_require_root函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中tst_require_root函数的典型用法代码示例。如果您正苦于以下问题:C++ tst_require_root函数的具体用法?C++ tst_require_root怎么用?C++ tst_require_root使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了tst_require_root函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: setup/* * 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()"); }}
开发者ID:1587,项目名称:ltp,代码行数:47,
示例2: setupstatic 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");}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:44,
示例3: setupstatic 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);}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:44,
示例4: setupstatic 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);}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:44,
示例5: setup/* * 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);}
开发者ID:1587,项目名称:ltp,代码行数:51,
示例6: mainint 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();}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:44,
示例7: setup/* * 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"); }}
开发者ID:Altiscale,项目名称:sig-core-t_ltp,代码行数:47,
示例8: setupstatic 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, ¶ms)) { tst_resm(TWARN | TERRNO, "failed to set FIFO sched with max priority"); }}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:44,
示例9: setup/* * 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");}
开发者ID:ArnoldWu,项目名称:ltp,代码行数:52,
示例10: setup/* * 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"); }}
开发者ID:MohdVara,项目名称:ltp,代码行数:46,
示例11: setupvoid 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);}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:43,
示例12: setupstatic 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);}
开发者ID:kraj,项目名称:ltp,代码行数:43,
示例13: setupstatic 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();}
开发者ID:MohdVara,项目名称:ltp,代码行数:19,
示例14: setup/* * 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;}
开发者ID:kraj,项目名称:ltp,代码行数:22,
示例15: setup/* * 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;}
开发者ID:Altiscale,项目名称:sig-core-t_ltp,代码行数:22,
示例16: setupvoid 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;}
开发者ID:CSRedRat,项目名称:ltp,代码行数:19,
示例17: setup/* 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 C++ tst_res函数代码示例 C++ tst_parse_opts函数代码示例
|