本文整理汇总了C++中SAFE_OPEN函数的典型用法代码示例。如果您正苦于以下问题:C++ SAFE_OPEN函数的具体用法?C++ SAFE_OPEN怎么用?C++ SAFE_OPEN使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SAFE_OPEN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup(void)
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
tst_tmpdir();
/* Initialize test dir and file names */
char *abs_path = tst_get_tmpdir();
int p = getpid();
sprintf(pathname, "fchmodattestdir%d", p);
sprintf(testfile, "fchmodattest%d.txt", p);
sprintf(testfile2, "%s/fchmodattest%d.txt", abs_path, p);
sprintf(testfile3, "fchmodattestdir%d/fchmodattest%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;
}
示例2: splice_test
static void splice_test(void)
{
int pipes[2];
int ret;
fd_in = SAFE_OPEN(cleanup, TESTFILE1, O_RDONLY);
SAFE_PIPE(cleanup, pipes);
fd_out = SAFE_OPEN(cleanup, TESTFILE2, O_WRONLY | O_CREAT | O_TRUNC, 0666);
ret = splice(fd_in, NULL, pipes[1], NULL, TEST_BLOCK_SIZE, 0);
if (ret < 0)
tst_brkm(TBROK | TERRNO, cleanup, "splice(fd_in, pipe) failed");
ret = splice(pipes[0], NULL, fd_out, NULL, TEST_BLOCK_SIZE, 0);
if (ret < 0)
tst_brkm(TBROK | TERRNO, cleanup, "splice(pipe, fd_out) failed");
close(fd_in);
close(fd_out);
close(pipes[0]);
close(pipes[1]);
fd_out = 0;
fd_in = 0;
check_file();
}
示例3: verify_fcntl
static void verify_fcntl(int i)
{
fd1 = SAFE_OPEN(cleanup, "file", test_cases[i].fd1_flag);
fd2 = SAFE_OPEN(cleanup, "file", test_cases[i].fd2_flag);
TEST(fcntl(fd1, F_SETLEASE, F_WRLCK));
if (TEST_RETURN == 0) {
tst_resm(TFAIL, "fcntl(F_SETLEASE, F_WRLCK) "
"succeeded unexpectedly");
} else {
if (TEST_ERRNO == EBUSY || TEST_ERRNO == EAGAIN) {
tst_resm(TPASS | TTERRNO,
"fcntl(F_SETLEASE, F_WRLCK) "
"failed as expected");
} else {
tst_resm(TFAIL | TTERRNO,
"fcntl(F_SETLEASE, F_WRLCK) "
"failed unexpectedly, "
"expected errno is EBUSY or EAGAIN");
}
}
SAFE_CLOSE(cleanup, fd1);
fd1 = 0;
SAFE_CLOSE(cleanup, fd2);
fd2 = 0;
}
示例4: setup
void setup(void)
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
tst_tmpdir();
char *abs_path = tst_get_tmpdir();
SAFE_ASPRINTF(cleanup, &testfile3, "%s/fstatattestfile3.txt", abs_path);
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] =
filenames[5] = testfile;
filenames[1] = testfile3;
TEST_PAUSE;
}
示例5: setup
static void setup(void)
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
tst_tmpdir();
fd2 = SAFE_OPEN(cleanup, ".", O_DIRECTORY);
SAFE_FILE_PRINTF(cleanup, "test_file", "A");
fd3 = SAFE_OPEN(cleanup, "test_file", O_RDWR);
#if !defined(UCLINUX)
outside_buf = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
#endif
addr4 = SAFE_MEMALIGN(cleanup, getpagesize(), (4096 * 10));
addr5 = addr4 + 1;
fs_type = tst_fs_type(cleanup, ".");
if (fs_type != TST_TMPFS_MAGIC)
fd4 = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_DIRECT);
}
示例6: setup
void setup(void)
{
if ((tst_kvercmp(2, 6, 17)) < 0) {
tst_brkm(TCONF, cleanup, "This test can only run on kernels "
"that are 2.6.17 or higher");
}
TEST_PAUSE;
tst_sig(FORK, DEF_HANDLER, cleanup);
tst_tmpdir();
SAFE_FILE_PRINTF(cleanup, TEST_FILE, STR);
rdfd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY);
wrfd = SAFE_OPEN(cleanup, TEST_FILE2,
O_WRONLY | O_CREAT, 0644);
appendfd = SAFE_OPEN(cleanup, TEST_FILE3,
O_RDWR | O_CREAT | O_APPEND, 0644);
SAFE_PIPE(cleanup, pipes);
SAFE_WRITE(cleanup, 1, pipes[1], STR, sizeof(STR) - 1);
}
示例7: setup
static void setup(void)
{
char *tmpdir;
if (tst_kvercmp(2, 6, 16) < 0)
tst_brkm(TCONF, NULL, "This test needs kernel 2.6.16 or newer");
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
tst_tmpdir();
/* Initialize test dir and file names */
tmpdir = tst_get_tmpdir();
sprintf(testfilepath, PATHNAME"/mknodattestfile%d", getpid());
sprintf(testfile, "mknodattestfile%d", getpid());
sprintf(testfile2, "mknodattestfile2%d", getpid());
sprintf(testfile3, "%s/mknodattestfile3%d", tmpdir, getpid());
free(tmpdir);
SAFE_MKDIR(cleanup, PATHNAME, 0700);
dir_fd = SAFE_OPEN(cleanup, PATHNAME, O_DIRECTORY);
fd = SAFE_OPEN(cleanup, testfile2, O_CREAT | O_RDWR, 0600);
}
示例8: setup
static void setup(void)
{
fd[0] = SAFE_OPEN("testfile1", O_RDWR | O_CREAT, 0644);
fd[1] = SAFE_OPEN("testfile2", O_RDWR | O_CREAT, 0644);
SAFE_FSETXATTR(fd[1], SECURITY_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);
}
示例9: setup
static void setup(void)
{
fd1 = SAFE_OPEN("file1", O_RDWR | O_CREAT, 0644);
SAFE_FTRUNCATE(fd1, getpagesize());
fd2 = SAFE_OPEN("file2", O_WRONLY | O_CREAT, 0644);
fd4 = SAFE_OPEN(".", O_RDONLY);
SAFE_PIPE(fd5);
}
示例10: setup
static void setup(void)
{
fd1 = SAFE_OPEN("file1", O_RDWR | O_CREAT, 0644);
SAFE_FTRUNCATE(fd1, getpagesize());
fd2 = SAFE_OPEN("file2", O_RDONLY | O_CREAT, 0644);
SAFE_PIPE(fd4);
wr_iovec3[0].iov_base = tst_get_bad_addr(NULL);
}
示例11: main
int main(int argc, char *argv[])
{
pid_t cpid2;
char path[BUFSIZ];
int lc;
int fd;
tst_parse_opts(argc, argv, NULL, NULL);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
parentuid = geteuid();
parentgid = getegid();
cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
(void *)child_fn1, NULL);
if (cpid1 < 0)
tst_brkm(TBROK | TERRNO, cleanup,
"cpid1 clone failed");
cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
(void *)child_fn2, NULL);
if (cpid2 < 0)
tst_brkm(TBROK | TERRNO, cleanup,
"cpid2 clone failed");
if (setgroupstag == false) {
sprintf(path, "/proc/%d/setgroups", cpid1);
fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
SAFE_WRITE(cleanup, 1, fd, "deny", 4);
SAFE_CLOSE(cleanup, fd);
sprintf(path, "/proc/%d/setgroups", cpid2);
fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
SAFE_WRITE(cleanup, 1, fd, "deny", 4);
SAFE_CLOSE(cleanup, fd);
}
updatemap(cpid1, UID_MAP, CHILD1UID, parentuid, cleanup);
updatemap(cpid2, UID_MAP, CHILD2UID, parentuid, cleanup);
updatemap(cpid1, GID_MAP, CHILD1GID, parentuid, cleanup);
updatemap(cpid2, GID_MAP, CHILD2GID, parentuid, cleanup);
TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 1);
tst_record_childstatus(cleanup, cpid1);
tst_record_childstatus(cleanup, cpid2);
}
cleanup();
tst_exit();
}
示例12: mylinkat_test
static void mylinkat_test(struct test_struct *desc)
{
int fd;
TEST(mylinkat
(*desc->oldfd, desc->oldfn, *desc->newfd, desc->newfn,
desc->flags));
if (TEST_ERRNO == desc->expected_errno) {
if (STD_FUNCTIONAL_TEST) {
if (TEST_RETURN == 0 && desc->referencefn1 != NULL) {
int tnum = rand(), vnum = ~tnum;
fd = SAFE_OPEN(cleanup, desc->referencefn1,
O_RDWR);
SAFE_WRITE(cleanup, 1, fd, &tnum, sizeof(tnum));
SAFE_CLOSE(cleanup, fd);
fd = SAFE_OPEN(cleanup, desc->referencefn2,
O_RDONLY);
SAFE_READ(cleanup, 1, fd, &vnum, sizeof(vnum));
SAFE_CLOSE(cleanup, fd);
if (tnum == vnum)
tst_resm(TPASS,
"linkat is functionality correct");
else {
tst_resm(TFAIL,
"The link file's content isn't "
"as same as the original file's "
"although linkat returned 0");
}
} else {
if (TEST_RETURN == 0)
tst_resm(TPASS,
"linkat succeeded as expected");
else
tst_resm(TPASS | TTERRNO,
"linkat failed as expected");
}
} else
tst_resm(TPASS, "Test passed");
} else {
if (TEST_RETURN == 0)
tst_resm(TFAIL, "linkat succeeded unexpectedly");
else
tst_resm(TFAIL | TTERRNO,
"linkat failed unexpectedly; expected %d - %s",
desc->expected_errno,
strerror(desc->expected_errno));
}
}
示例13: main
int main(int argc, char *argv[])
{
int status;
int lc;
int childpid;
int parentuid;
int parentgid;
char path[BUFSIZ];
char content[BUFSIZ];
int fd;
tst_parse_opts(argc, argv, NULL, NULL);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
childpid = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
(void *)child_fn1, NULL);
if (childpid < 0)
tst_brkm(TFAIL | TERRNO, cleanup, "clone failed");
parentuid = geteuid();
parentgid = getegid();
sprintf(path, "/proc/%d/uid_map", childpid);
sprintf(content, "100 %d 1", parentuid);
fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
SAFE_CLOSE(cleanup, fd);
sprintf(path, "/proc/%d/gid_map", childpid);
sprintf(content, "100 %d 1", parentgid);
fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
SAFE_CLOSE(cleanup, fd);
TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
if (waitpid(childpid, &status, 0) < 0)
tst_brkm(TBROK | TERRNO, cleanup, "waitpid failed");
if (WIFSIGNALED(status)) {
tst_resm(TFAIL, "child was killed with signal = %d",
WTERMSIG(status));
} else if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
tst_resm(TFAIL, "child exited abnormally");
else
tst_resm(TPASS, "the uid and the gid are right inside "
"the container");
}
cleanup();
tst_exit();
}
示例14: setup
static void setup(void)
{
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
tst_tmpdir();
memset(buf, 0x42, sizeof(buf));
fd = SAFE_OPEN(cleanup, "data_file", O_WRONLY | O_CREAT, 0666);
SAFE_WRITE(cleanup, 1, fd, buf, sizeof(buf));
SAFE_CLOSE(cleanup, fd);
fd = SAFE_OPEN(cleanup, "data_file", O_RDONLY);
}
示例15: setup
static void setup(void)
{
char cur_dir_path[512];
check_execveat();
SAFE_MKDIR(TESTDIR, 0777);
SAFE_CP(TEST_APP, TEST_REL_APP);
SAFE_GETCWD(cur_dir_path, sizeof(cur_dir_path));
sprintf(app_abs_path, "%s/%s", cur_dir_path, TEST_REL_APP);
fd1 = SAFE_OPEN(TESTDIR, O_DIRECTORY);
fd4 = SAFE_OPEN(TEST_REL_APP, O_PATH);
}