本文整理汇总了C++中pr_perror函数的典型用法代码示例。如果您正苦于以下问题:C++ pr_perror函数的具体用法?C++ pr_perror怎么用?C++ pr_perror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pr_perror函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
int ret = -1, sk_pair[2], sk, status;
char path[PATH_MAX], c;
pid_t pid;
test_init(argc, argv);
if (mount_and_add(cgname, "test") < 0)
return -1;
if (socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair)) {
pr_perror("socketpair");
goto out;
}
pid = fork();
if (pid < 0) {
pr_perror("fork failed");
goto out;
}
if (pid == 0) {
close(sk_pair[0]);
if (unshare_cgns_and_wait(sk_pair+1))
exit(1);
exit(0);
}
close(sk_pair[1]);
sk = sk_pair[0];
if ((ret = read(sk, &c, 1)) != 1) {
pr_perror("read %d", ret);
goto out;
}
test_daemon();
test_waitsig();
sprintf(path, "name=%s", cgname);
/* first check that the task is in zdtmtst:/test */
if (!pid_in_cgroup(pid, path, "/test")) {
fail("pid not in cgroup /test");
goto out;
}
/* now have the task check that it is in / */
if (write(sk, &c, 1) != 1) {
pr_perror("write");
goto out;
}
if (pid != waitpid(pid, &status, 0)) {
pr_perror("waitpid");
goto out;
}
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
fail("exit status %s\n", status);
goto out;
}
pass();
ret = 0;
out:
sprintf(path, "%s/%s/test", dirname, cgname);
rmdir(path);
sprintf(path, "%s/%s", dirname, cgname);
umount(path);
rmdir(path);
rmdir(dirname);
return ret;
}
示例2: handle_command
static void handle_command()
{
int sk = processes[current].sks[0], ret, status = 0;
struct command cmd;
ret = read(sk, &cmd, sizeof(cmd));
if (ret != sizeof(cmd)) {
pr_perror("Unable to get command");
goto err;
}
switch (cmd.cmd) {
case TEST_FORK:
{
pid_t pid;
pid = make_child(cmd.arg1, cmd.arg2);
if (pid == -1) {
status = -1;
goto err;
}
test_msg("%3d: fork(%d, %x) = %d\n",
current, cmd.arg1, cmd.arg2, pid);
processes[cmd.arg1].pid = pid;
}
break;
case TEST_WAIT:
test_msg("%3d: wait(%d) = %d\n", current,
cmd.arg1, processes[cmd.arg1].pid);
if (waitpid(processes[cmd.arg1].pid, NULL, 0) == -1) {
pr_perror("waitpid(%d)", processes[cmd.arg1].pid);
status = -1;
}
break;
case TEST_SUBREAPER:
test_msg("%3d: subreaper(%d)\n", current, cmd.arg1);
if (prctl(PR_SET_CHILD_SUBREAPER, cmd.arg1, 0, 0, 0) == -1) {
pr_perror("PR_SET_CHILD_SUBREAPER");
status = -1;
}
break;
case TEST_SETSID:
test_msg("%3d: setsid()\n", current);
if(setsid() == -1) {
pr_perror("setsid");
status = -1;
}
break;
case TEST_DIE:
test_msg("%3d: die()\n", current);
processes[current].dead = 1;
shutdown(sk, SHUT_RDWR);
exit(0);
}
ret = write(sk, &status, sizeof(status));
if (ret != sizeof(status)) {
pr_perror("Unable to answer");
goto err;
}
if (status < 0)
goto err;
return;
err:
shutdown(sk, SHUT_RDWR);
exit(1);
}
示例3: nsenter
void nsenter()
{
int argc, c;
char **argv;
get_args(&argc, &argv);
// check argv 0 to ensure that we are supposed to setns
// we use strncmp to test for a value of "nsenter" but also allows alternate implmentations
// after the setns code path to continue to use the argv 0 to determine actions to be run
// resulting in the ability to specify "nsenter-mknod", "nsenter-exec", etc...
if (strncmp(argv[0], kNsEnter, strlen(kNsEnter)) != 0) {
return;
}
#ifdef PR_SET_CHILD_SUBREAPER
if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) == -1) {
pr_perror("Failed to set child subreaper");
exit(1);
}
#endif
static const struct option longopts[] = {
{"nspid", required_argument, NULL, 'n'},
{"console", required_argument, NULL, 't'},
{NULL, 0, NULL, 0}
};
pid_t init_pid = -1;
char *init_pid_str = NULL;
char *console = NULL;
while ((c = getopt_long_only(argc, argv, "n:c:", longopts, NULL)) != -1) {
switch (c) {
case 'n':
init_pid_str = optarg;
break;
case 't':
console = optarg;
break;
}
}
if (init_pid_str == NULL) {
print_usage();
exit(1);
}
init_pid = strtol(init_pid_str, NULL, 10);
if ((init_pid == 0 && errno == EINVAL) || errno == ERANGE) {
pr_perror("Failed to parse PID from \"%s\" with output \"%d\"",
init_pid_str, init_pid);
print_usage();
exit(1);
}
argc -= 3;
argv += 3;
if (setsid() == -1) {
pr_perror("setsid failed");
exit(1);
}
// before we setns we need to dup the console
int consolefd = -1;
if (console != NULL) {
consolefd = open(console, O_RDWR);
if (consolefd < 0) {
pr_perror("Failed to open console %s", console);
exit(1);
}
}
// blocking until the parent placed the process inside correct cgroups.
unsigned char s;
if (read(3, &s, 1) != 1 || s != '1') {
pr_perror("failed to receive synchronization data from parent");
exit(1);
}
// Setns on all supported namespaces.
char ns_dir[PATH_MAX];
memset(ns_dir, 0, PATH_MAX);
snprintf(ns_dir, PATH_MAX - 1, "/proc/%d/ns/", init_pid);
int ns_dir_fd;
ns_dir_fd = open(ns_dir, O_RDONLY | O_DIRECTORY);
if (ns_dir_fd < 0) {
pr_perror("Unable to open %s", ns_dir);
exit(1);
}
char *namespaces[] = { "ipc", "uts", "net", "pid", "mnt" };
const int num = sizeof(namespaces) / sizeof(char *);
int i;
for (i = 0; i < num; i++) {
// A zombie process has links on namespaces, but they can't be opened
struct stat st;
if (fstatat(ns_dir_fd, namespaces[i], &st, AT_SYMLINK_NOFOLLOW)
== -1) {
if (errno == ENOENT)
continue;
pr_perror("Failed to stat ns file %s for ns %s",
ns_dir, namespaces[i]);
exit(1);
//.........这里部分代码省略.........
示例4: start_page_server_req
static int start_page_server_req(int sk, CriuOpts *req)
{
int ret = -1, pid, start_pipe[2];
ssize_t count;
bool success = false;
CriuResp resp = CRIU_RESP__INIT;
CriuPageServerInfo ps = CRIU_PAGE_SERVER_INFO__INIT;
struct ps_info info;
if (pipe(start_pipe)) {
pr_perror("No start pipe");
goto out;
}
pid = fork();
if (pid == 0) {
close(start_pipe[0]);
if (setup_opts_from_req(sk, req))
goto out_ch;
setproctitle("page-server --rpc --address %s --port %hu", opts.addr, opts.ps_port);
pr_debug("Starting page server\n");
pid = cr_page_server(true, start_pipe[1]);
if (pid <= 0)
goto out_ch;
info.pid = pid;
info.port = opts.ps_port;
count = write(start_pipe[1], &info, sizeof(info));
if (count != sizeof(info))
goto out_ch;
ret = 0;
out_ch:
if (ret < 0 && pid > 0)
kill(pid, SIGKILL);
close(start_pipe[1]);
exit(ret);
}
close(start_pipe[1]);
wait(&ret);
if (WIFEXITED(ret)) {
if (WEXITSTATUS(ret)) {
pr_err("Child exited with an error\n");
goto out;
}
} else {
pr_err("Child wasn't terminated normally\n");
goto out;
}
count = read(start_pipe[0], &info, sizeof(info));
close(start_pipe[0]);
if (count != sizeof(info))
goto out;
success = true;
ps.has_pid = true;
ps.pid = info.pid;
ps.has_port = true;
ps.port = info.port;
resp.ps = &ps;
pr_debug("Page server started\n");
out:
resp.type = CRIU_REQ_TYPE__PAGE_SERVER;
resp.success = success;
return send_criu_msg(sk, &resp);
}
示例5: main
int main(int argc, char **argv)
{
int pid, pipe_prep[2], pipe_goon[2], pipe_res[2];
char res;
int fd, fd2;
test_init(argc, argv);
filepath = malloc(strlen(filename) + 1);
sprintf(filepath, "/%s", filename);
pipe(pipe_prep);
pipe(pipe_goon);
pipe(pipe_res);
pid = test_fork();
if (pid != 0) {
close(pipe_prep[1]);
close(pipe_goon[0]);
close(pipe_res[1]);
res = ERR_PIPES;
read(pipe_prep[0], &res, 1);
read(pipe_prep[0], &res, 1); /* wait when pipe_prep[] will be closed */
if (res != SUCCESS) {
if (res == ERR_PIPES)
pr_perror("broken pipes");
else {
if (res & ERR_IN_FILE)
pr_perror("inside-root file fail");
if (res & ERR_ROOT)
pr_perror("chroot fail");
if (res & ERR_DIR)
pr_perror("mkdir fail");
}
return 0;
}
test_daemon();
test_waitsig();
close(pipe_goon[1]);
res = ERR_PIPES;
read(pipe_res[0], &res, 1);
if (res == SUCCESS)
pass();
else if (res == ERR_PIPES)
fail("broken pipes");
else {
if (res & ERR_IN_FILE)
fail("opened file broken");
if (res & ERR_OPEN)
fail("open in chroot fail");
if (res & ERR_FILE2)
fail("wrong file opened");
}
wait(NULL);
return 0;
}
close(pipe_prep[0]);
close(pipe_goon[1]);
close(pipe_res[0]);
if (mkdir(dirname, 0700)) {
res = ERR_DIR;
goto err_nodir;
}
if (chroot(dirname)) {
res = ERR_ROOT;
goto err_noroot;
}
fd = make_file(filepath);
if (fd < 0) {
res = ERR_IN_FILE;
goto err_nofile2;
}
res = SUCCESS;
write(pipe_prep[1], &res, 1);
close(pipe_prep[1]);
read(pipe_goon[0], &res, 1);
res = SUCCESS;
if (check_file(fd))
res |= ERR_IN_FILE;
fd2 = open(filepath, O_RDWR);
if (fd2 < 0)
res |= ERR_OPEN;
else if (check_file(fd2))
res |= ERR_FILE2;
write(pipe_res[1], &res, 1);
exit(0);
//.........这里部分代码省略.........
示例6: main
int main(int argc, char ** argv)
{
int fdm, fds, status;
task_waiter_t t;
char *slavename;
pid_t pid;
test_init(argc, argv);
task_waiter_init(&t);
fdm = open("/dev/ptmx", O_RDWR);
if (fdm == -1) {
pr_perror("Can't open a master pseudoterminal");
return 1;
}
grantpt(fdm);
unlockpt(fdm);
slavename = ptsname(fdm);
pid = test_fork();
if (pid < 0) {
pr_perror("fork() failed");
return 1;
}
if (pid == 0) {
close(fdm);
signal(SIGHUP, sighup_handler);
if (setsid() == -1)
return 1;
/* set up a controlling terminal */
fds = open(slavename, O_RDWR);
if (fds == -1) {
pr_perror("Can't open a slave pseudoterminal %s", slavename);
return 1;
}
if (ioctl(fdm, TIOCSCTTY, 1) < 0) {
pr_perror("Can't setup a controlling terminal");
return 1;
}
close(fds);
task_waiter_complete_current(&t);
test_waitsig();
if (sighup)
return 0;
return 1;
}
task_waiter_wait4(&t, pid);
test_daemon();
test_waitsig();
close(fdm);
if (kill(pid, SIGTERM) == -1) {
pr_perror("kill failed");
return 1;
}
pid = waitpid(pid, &status, 0);
if (pid < 0)
return 1;
if (WIFEXITED(status)) {
if (WEXITSTATUS(status)) {
fail("The child returned %d", WEXITSTATUS(status));
return 1;
}
} else
test_msg("The child has been killed by %d\n", WTERMSIG(status));
pass();
return 0;
}
示例7: main
int main(int argc, char **argv)
{
struct sockaddr_un addr;
unsigned int addrlen;
int srv, clnt = -1, ret, i;
char buf[1024];
struct iovec iov = {
.iov_base = &buf,
.iov_len = sizeof(buf),
};
struct msghdr hdr = {
.msg_name = &addr,
.msg_namelen = sizeof(addr),
.msg_iov = &iov,
.msg_iovlen = 1,
};
test_init(argc, argv);
srv = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
addr.sun_family = AF_UNIX;
memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV));
addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV);
if (bind(srv, &addr, addrlen)) {
fail("bind\n");
exit(1);
}
for (i = 0; i < 2; i++) {
close(clnt);
clnt = socket(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
sk_names[i][1] += i;
addr.sun_family = AF_UNIX;
memcpy(addr.sun_path, sk_names[i], sizeof(SK_NAME));
addrlen = sizeof(addr.sun_family) + sizeof(SK_NAME);
if (bind(clnt, &addr, addrlen)) {
fail("bind\n");
exit(1);
}
memcpy(addr.sun_path, SK_SRV, sizeof(SK_SRV));
addrlen = sizeof(addr.sun_family) + sizeof(SK_SRV);
if (connect(clnt, &addr, addrlen)) {
fail("connect\n");
exit(1);
}
if (send(clnt, MSG, sizeof(MSG), 0) != sizeof(MSG)) {
pr_perror("write");
return 1;
}
}
test_daemon();
test_waitsig();
for (i = 0; i < 2; i++) {
memset(addr.sun_path, 0, sizeof(addr.sun_path));
ret = recvmsg(srv, &hdr, MSG_DONTWAIT);
buf[ret > 0 ? ret : 0] = 0;
if (ret != sizeof(MSG)) {
fail("%d: %s", ret, buf);
return 1;
}
if (hdr.msg_namelen > sizeof(addr.sun_family) + 1)
pr_perror("%d, %s", hdr.msg_namelen, addr.sun_path + 1);
if (memcmp(addr.sun_path, sk_names[i], sizeof(SK_NAME))) {
fail("A sender address is mismatch");
return 1;
}
}
pass();
return 0;
}
示例8: main
int main(int argc, char ** argv)
{
int sock, acc_sock, ret;
pid_t pid;
uint32_t crc;
uint8_t buf[1000];
test_init(argc, argv);
sock = setup_srv_sock();
if (sock < 0)
exit(1);
pid = test_fork();
if (pid < 0) {
pr_perror("can't fork");
exit(1);
}
if (pid == 0) { /* child writes to the unlinked socket and returns */
close(sock);
sock = setup_clnt_sock();
if (sock < 0)
_exit(1);
test_waitsig();
crc = ~0;
datagen(buf, sizeof(buf), &crc);
if (write(sock, buf, sizeof(buf)) != sizeof(buf)) {
pr_perror("can't write to socket");
exit(errno);
}
close(sock);
exit(0);
}
acc_sock = accept(sock, NULL, NULL);
if (acc_sock < 0) {
pr_perror("can't accept() the connection on \"%s\"", filename);
goto out_kill;
}
close(sock);
sock = acc_sock;
if (unlink(filename)) {
pr_perror("can't unlink %s", filename);
goto out_kill;
}
test_daemon();
test_waitsig();
if (kill(pid, SIGTERM)) {
fail("terminating the child failed: %m\n");
goto out;
}
if (wait(&ret) != pid) {
fail("wait() returned wrong pid %d: %m\n", pid);
goto out;
}
if (WIFEXITED(ret)) {
ret = WEXITSTATUS(ret);
if (ret) {
fail("child exited with nonzero code %d (%s)\n", ret, strerror(ret));
goto out;
}
}
if (WIFSIGNALED(ret)) {
fail("child exited on unexpected signal %d\n", WTERMSIG(ret));
goto out;
}
if (read(sock, buf, sizeof(buf)) != sizeof(buf)) {
fail("can't read %s: %m\n", filename);
goto out;
}
crc = ~0;
if (datachk(buf, sizeof(buf), &crc)) {
fail("CRC mismatch\n");
goto out;
}
if (close(sock)) {
fail("close failed: %m\n");
goto out;
}
if (unlink(filename) != -1 || errno != ENOENT) {
fail("file %s should have been deleted before migration: unlink: %m\n", filename);
goto out;
}
//.........这里部分代码省略.........
示例9: handle_vma
//.........这里部分代码省略.........
vma_area->e->status |= VMA_AREA_VSYSCALL;
} else if (!strcmp(file_path, "[vdso]")) {
if (handle_vdso_vma(vma_area))
goto err;
} else if (!strcmp(file_path, "[vvar]")) {
if (handle_vvar_vma(vma_area))
goto err;
} else if (!strcmp(file_path, "[heap]")) {
vma_area->e->status |= VMA_AREA_REGULAR | VMA_AREA_HEAP;
} else {
vma_area->e->status = VMA_AREA_REGULAR;
}
/*
* Some mapping hints for restore, we save this on
* disk and restore might need to analyze it.
*/
if (vma_area->file_borrowed) {
struct vma_area *prev = prev_vfi->vma;
/*
* Pick-up flags that might be set in the branch below.
* Status is copied as-is as it should be zero here,
* and have full match with the previous.
*/
vma_area->e->flags |= (prev->e->flags & MAP_ANONYMOUS);
vma_area->e->status = prev->e->status;
vma_area->e->shmid = prev->e->shmid;
vma_area->vmst = prev->vmst;
vma_area->mnt_id = prev->mnt_id;
} else if (vma_area->vm_file_fd >= 0) {
struct stat *st_buf = vma_area->vmst;
if (S_ISREG(st_buf->st_mode))
/* regular file mapping -- supported */;
else if (S_ISCHR(st_buf->st_mode) && (st_buf->st_rdev == DEVZERO))
/* devzero mapping -- also makes sense */;
else {
pr_err("Can't handle non-regular mapping on %d's map %"PRIx64"\n", pid, vma_area->e->start);
goto err;
}
/*
* /dev/zero stands for anon-shared mapping
* otherwise it's some file mapping.
*/
if (is_anon_shmem_map(st_buf->st_dev)) {
if (!(vma_area->e->flags & MAP_SHARED))
goto err_bogus_mapping;
vma_area->e->flags |= MAP_ANONYMOUS;
vma_area->e->status |= VMA_ANON_SHARED;
vma_area->e->shmid = st_buf->st_ino;
if (!strncmp(file_path, "/SYSV", 5)) {
pr_info("path: %s\n", file_path);
vma_area->e->status |= VMA_AREA_SYSVIPC;
}
} else {
if (vma_area->e->flags & MAP_PRIVATE)
vma_area->e->status |= VMA_FILE_PRIVATE;
else
vma_area->e->status |= VMA_FILE_SHARED;
}
/*
* We cannot use the mnt_id value provided by the kernel
* for vm_file_fd if it is an AUFS file (the value is
* wrong). In such a case, fixup_aufs_vma_fd() has set
* mnt_id to -1 to mimic pre-3.15 kernels that didn't
* have mnt_id.
*/
if (vma_area->mnt_id != -1 &&
get_fd_mntid(vma_area->vm_file_fd, &vma_area->mnt_id))
return -1;
} else {
/*
* No file but mapping -- anonymous one.
*/
if (vma_area->e->flags & MAP_SHARED) {
vma_area->e->status |= VMA_ANON_SHARED;
vma_area->e->shmid = vfi->ino;
} else {
vma_area->e->status |= VMA_ANON_PRIVATE;
}
vma_area->e->flags |= MAP_ANONYMOUS;
}
return 0;
err:
return -1;
err_bogus_mapping:
pr_err("Bogus mapping 0x%"PRIx64"-0x%"PRIx64" (flags: %#x vm_file_fd: %d)\n",
vma_area->e->start, vma_area->e->end,
vma_area->e->flags, vma_area->vm_file_fd);
goto err;
err_bogus_mapfile:
pr_perror("Can't open %d's mapfile link %"PRIx64, pid, vma_area->e->start);
goto err;
}
示例10: parse_pid_status
int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
{
struct bfd f;
int done = 0;
int ret = -1;
char *str;
f.fd = open_proc(pid, "status");
if (f.fd < 0) {
pr_perror("Can't open proc status");
return -1;
}
if (bfdopenr(&f))
return -1;
while (done < 9) {
str = breadline(&f);
if (str == NULL)
break;
if (IS_ERR(str))
goto err_parse;
if (!strncmp(str, "State:", 6)) {
cr->state = str[7];
done++;
}
if (!strncmp(str, "PPid:", 5)) {
if (sscanf(str, "PPid:\t%d", &cr->ppid) != 1) {
pr_err("Unable to parse: %s\n", str);
goto err_parse;
}
done++;
}
if (!strncmp(str, "Uid:", 4)) {
if (ids_parse(str + 5, cr->uids))
goto err_parse;
done++;
}
if (!strncmp(str, "Gid:", 4)) {
if (ids_parse(str + 5, cr->gids))
goto err_parse;
done++;
}
if (!strncmp(str, "CapInh:", 7)) {
if (cap_parse(str + 8, cr->cap_inh))
goto err_parse;
done++;
}
if (!strncmp(str, "CapEff:", 7)) {
if (cap_parse(str + 8, cr->cap_eff))
goto err_parse;
done++;
}
if (!strncmp(str, "CapPrm:", 7)) {
if (cap_parse(str + 8, cr->cap_prm))
goto err_parse;
done++;
}
if (!strncmp(str, "CapBnd:", 7)) {
if (cap_parse(str + 8, cr->cap_bnd))
goto err_parse;
done++;
}
if (!strncmp(str, "Seccomp:", 8)) {
if (sscanf(str + 9, "%d", &cr->seccomp_mode) != 1) {
goto err_parse;
}
if (cr->seccomp_mode == SECCOMP_MODE_FILTER) {
pr_err("SECCOMP_MODE_FILTER not currently supported\n");
goto err_parse;
}
done++;
}
}
if (done >= 8)
ret = 0;
err_parse:
if (ret)
pr_err("Error parsing proc status file\n");
bclose(&f);
return ret;
//.........这里部分代码省略.........
示例11: vma_get_mapfile
static int vma_get_mapfile(char *fname, struct vma_area *vma, DIR *mfd,
struct vma_file_info *vfi, struct vma_file_info *prev_vfi)
{
char path[32];
if (prev_vfi->vma && vfi_equal(vfi, prev_vfi)) {
struct vma_area *prev = prev_vfi->vma;
/*
* If vfi is equal (!) and negative @vm_file_fd --
* we have nothing to borrow for sure.
*/
if (prev->vm_file_fd < 0)
return 0;
pr_debug("vma %"PRIx64" borrows vfi from previous %"PRIx64"\n",
vma->e->start, prev->e->start);
vma->vm_file_fd = prev->vm_file_fd;
if (prev->e->status & VMA_AREA_SOCKET)
vma->e->status |= VMA_AREA_SOCKET | VMA_AREA_REGULAR;
/*
* FIXME -- in theory there can be vmas that have
* dev:ino match, but live in different mount
* namespaces. However, we only borrow files for
* subsequent vmas. These are _very_ likely to
* have files from the same namespaces.
*/
vma->file_borrowed = true;
return 0;
}
/* Figure out if it's file mapping */
snprintf(path, sizeof(path), "%"PRIx64"-%"PRIx64, vma->e->start, vma->e->end);
/*
* Note that we "open" it in dumper process space
* so later we might refer to it via /proc/self/fd/vm_file_fd
* if needed.
*/
vma->vm_file_fd = openat(dirfd(mfd), path, O_RDONLY);
if (vma->vm_file_fd < 0) {
if (errno == ENOENT)
/* Just mapping w/o map_files link */
return 0;
if (errno == ENXIO) {
struct stat buf;
if (fstatat(dirfd(mfd), path, &buf, 0))
return -1;
if (S_ISSOCK(buf.st_mode)) {
pr_info("Found socket mapping @%"PRIx64"\n", vma->e->start);
vma->vm_socket_id = buf.st_ino;
vma->e->status |= VMA_AREA_SOCKET | VMA_AREA_REGULAR;
return 0;
}
if ((buf.st_mode & S_IFMT) == 0 && !strcmp(fname, AIO_FNAME)) {
/* AIO ring, let's try */
close(vma->vm_file_fd);
vma->aio_nr_req = -1;
vma->e->status = VMA_AREA_AIORING;
return 0;
}
pr_err("Unknown shit %o (%s)\n", buf.st_mode, fname);
}
return -1;
}
vma->vmst = xmalloc(sizeof(struct stat));
if (!vma->vmst)
return -1;
/*
* For AUFS support, we need to check if the symbolic link
* points to a branch. If it does, we cannot fstat() its file
* descriptor because it would return a different dev/ino than
* the real file. If fixup_aufs_vma_fd() returns positive,
* it means that it has stat()'ed using the full pathname.
* Zero return means that the symbolic link does not point to
* a branch and we can do fstat() below.
*/
if (opts.aufs) {
int ret;
ret = fixup_aufs_vma_fd(vma);
if (ret < 0)
return -1;
if (ret > 0)
return 0;
}
if (fstat(vma->vm_file_fd, vma->vmst) < 0) {
pr_perror("Failed fstat on map %"PRIx64"", vma->e->start);
return -1;
//.........这里部分代码省略.........
示例12: ns_child
int ns_child(void *_arg)
{
struct ns_exec_args *args = _arg;
int fd2;
int id1, id2;
struct stat st1, st2;
char lpath[PATH_MAX], fpath[PATH_MAX];
snprintf(fpath, sizeof(fpath), "%s/1", dirname);
if (umount(fpath)) {
pr_perror("umount");
return 1;
}
snprintf(lpath, sizeof(lpath), "%s/0/2", dirname);
snprintf(fpath, sizeof(fpath), "%s/2", dirname);
if (mkdir(fpath, 0600) < 0) {
fail("Can't make zdtm_sys");
return 1;
}
if (mount(lpath, fpath, NULL, MS_BIND, NULL)) {
pr_perror("mount");
return 1;
}
snprintf(fpath, sizeof(fpath), "%s/0", dirname);
if (umount(fpath)) {
pr_perror("umount");
return 1;
}
snprintf(fpath, sizeof(fpath), "%s/2/%s", dirname, MPTS_FILE);
fd2 = open(fpath, O_RDWR);
if (fd2 < 0) {
pr_perror("open");
return -1;
}
close(args->sync);
test_waitsig();
id1 = get_mntid(args->fd);
id2 = get_mntid(fd2);
if (id1 <0 || id2 < 0)
exit(1);
if (fstat(args->fd, &st1) || fstat(fd2, &st2)) {
pr_perror("stat");
exit(1);
}
test_msg("%d %d", id1, id2);
#ifdef ZDTM_LINK_REMAP
if (st1.st_nlink != 1) {
#else
if (st1.st_nlink != 0) {
#endif
pr_perror("Wrong number of links: %d", st1.st_nlink);
exit(1);
}
if (id1 > 0 && id1 != id2 && st1.st_ino == st2.st_ino)
exit(AWK_OK);
else
exit(AWK_FAIL);
}
int main(int argc, char **argv)
{
struct ns_exec_args args;
pid_t pid = -1;
char lpath[PATH_MAX], fpath[PATH_MAX];
char buf[256];
int p[2];
test_init(argc, argv);
if (mkdir(dirname, 0600) < 0) {
fail("Can't make zdtm_sys");
return 1;
}
if (mount("test", dirname, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}
snprintf(fpath, sizeof(fpath), "%s/0", dirname);
if (mkdir(fpath, 0600) < 0) {
fail("Can't make zdtm_sys");
return 1;
}
if (mount("test", fpath, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}
snprintf(lpath, sizeof(lpath), "%s/0/1", dirname);
//.........这里部分代码省略.........
示例13: main
int main(int argc, char **argv)
{
unsigned char buf[BUF_SIZE];
int fd, fd_s;
pid_t extpid;
uint32_t crc;
int pfd[2];
int val;
socklen_t optlen;
if (pipe(pfd)) {
pr_perror("pipe() failed");
return 1;
}
extpid = fork();
if (extpid < 0) {
pr_perror("fork() failed");
return 1;
} else if (extpid == 0) {
test_ext_init(argc, argv);
close(pfd[1]);
if (read(pfd[0], &port, sizeof(port)) != sizeof(port)) {
pr_perror("Can't read port");
return 1;
}
fd = tcp_init_client(ZDTM_FAMILY, "localhost", port);
if (fd < 0)
return 1;
#ifdef STREAM
while (1) {
if (read_data(fd, buf, BUF_SIZE)) {
pr_perror("read less then have to");
return 1;
}
if (datachk(buf, BUF_SIZE, &crc))
return 2;
datagen(buf, BUF_SIZE, &crc);
if (write_data(fd, buf, BUF_SIZE)) {
pr_perror("can't write");
return 1;
}
}
#else
if (read_data(fd, buf, BUF_SIZE)) {
pr_perror("read less then have to");
return 1;
}
if (datachk(buf, BUF_SIZE, &crc))
return 2;
datagen(buf, BUF_SIZE, &crc);
if (write_data(fd, buf, BUF_SIZE)) {
pr_perror("can't write");
return 1;
}
#endif
return 0;
}
test_init(argc, argv);
if ((fd_s = tcp_init_server(ZDTM_FAMILY, &port)) < 0) {
pr_perror("initializing server failed");
return 1;
}
close(pfd[0]);
if (write(pfd[1], &port, sizeof(port)) != sizeof(port)) {
pr_perror("Can't send port");
return 1;
}
close(pfd[1]);
/*
* parent is server of TCP connection
*/
fd = tcp_accept_server(fd_s);
if (fd < 0) {
pr_perror("can't accept client connection %m");
return 1;
}
val = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))) {
pr_perror("setsockopt");
return 1;
}
test_daemon();
#ifdef STREAM
while (test_go()) {
datagen(buf, BUF_SIZE, &crc);
if (write_data(fd, buf, BUF_SIZE)) {
pr_perror("can't write");
return 1;
//.........这里部分代码省略.........
示例14: main
int main(int argc, char **argv)
{
int ret = -1, fd, status;
char path[PATH_MAX];
pid_t pid;
if (!getenv("ZDTM_NEWNS")) {
if (mount_and_add(cgname, "test") < 0)
return -1;
if (unshare(CLONE_NEWCGROUP) < 0) {
pr_perror("unshare");
goto out;
}
}
test_init(argc, argv);
test_daemon();
test_waitsig();
sprintf(path, "name=%s", cgname);
/* first check that the task is in zdtmtst:/ */
if (!pid_in_cgroup(getpid(), path, "/")) {
fail("pid not in cgroup /");
goto out;
}
/* now check that the task is in the right place in a ns by setnsing to
* someone else's ns and looking there.
*/
pid = fork();
if (pid < 0) {
pr_perror("fork");
goto out;
}
if (pid == 0) {
sprintf(path, "/proc/%d/ns/cgroup", 1);
fd = open(path, O_RDONLY);
if (fd < 0) {
pr_perror("open");
exit(1);
}
ret = setns(fd, CLONE_NEWCGROUP);
close(fd);
if (ret < 0) {
pr_perror("setns");
exit(1);
}
sprintf(path, "name=%s", cgname);
if (!pid_in_cgroup(getppid(), path, "/test")) {
fail("pid not in cgroup %s", path);
exit(1);
}
exit(0);
}
if (pid != waitpid(pid, &status, 0)) {
pr_err("wrong pid");
goto out;
}
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
pr_err("got bad exit status %d\n", status);
goto out;
}
ret = 0;
pass();
out:
sprintf(path, "%s/%s/test", dirname, cgname);
rmdir(path);
sprintf(path, "%s/%s", dirname, cgname);
umount(path);
rmdir(path);
rmdir(dirname);
return ret;
}
示例15: main
int main(int argc, char **argv)
{
int cgfd, l, ret = 1, i;
char aux[1024], paux[1024];
FILE *cgf;
struct stat st;
test_init(argc, argv);
if (mkdir(dirname, 0700) < 0) {
pr_perror("Can't make dir");
goto out;
}
sprintf(aux, "none,name=%s", cgname);
if (mount("none", dirname, "cgroup", 0, aux)) {
pr_perror("Can't mount cgroups");
goto out_rd;
}
sprintf(paux, "%s/%s", dirname, subname);
mkdir(paux, 0600);
l = sprintf(aux, "%d", getpid());
sprintf(paux, "%s/%s/tasks", dirname, subname);
cgfd = open(paux, O_WRONLY);
if (cgfd < 0) {
pr_perror("Can't open tasks");
goto out_rs;
}
l = write(cgfd, aux, l);
close(cgfd);
if (l < 0) {
pr_perror("Can't move self to subcg");
goto out_rs;
}
for (i = 0; i < 2; i++) {
sprintf(paux, "%s/%s/%s.%d", dirname, subname, empty, i);
if (mkdir(paux, 0600)) {
pr_perror("mkdir %s", paux);
goto out_rs;
}
}
test_daemon();
test_waitsig();
cgf = fopen("/proc/self/mountinfo", "r");
if (cgf == NULL) {
fail("No mountinfo file");
goto out_rs;
}
while (fgets(paux, sizeof(paux), cgf)) {
char *s;
s = strstr(paux, cgname);
if (!s)
continue;
sscanf(paux, "%*d %*d %*d:%*d %*s %s", aux);
test_msg("found cgroup at %s\n", aux);
for (i = 0; i < 2; i++) {
ssprintf(paux, "%s/%s/%s.%d", aux, subname, empty, i);
if (stat(paux, &st)) {
fail("couldn't stat %s\n", paux);
ret = -1;
goto out_close;
}
if (!S_ISDIR(st.st_mode)) {
fail("%s is not a directory\n", paux);
ret = -1;
goto out_close;
}
}
pass();
ret = 0;
goto out_close;
}
fail("empty cgroup not found!\n");
out_close:
fclose(cgf);
out_rs:
umount(dirname);
out_rd:
rmdir(dirname);
out:
return ret;
}