staticint __child(int sk, int memfd)
{ int ret; char buf;
/* *Ensurewedon'tleavearoundabunchoforphanedchildrenifour *testsfail.
*/
ret = prctl(PR_SET_PDEATHSIG, SIGKILL); if (ret) {
fprintf(stderr, "%s: Child could not set DEATHSIG\n",
strerror(errno)); return -1;
}
ret = send(sk, &memfd, sizeof(memfd), 0); if (ret != sizeof(memfd)) {
fprintf(stderr, "%s: Child failed to send fd number\n",
strerror(errno)); return -1;
}
/* *Thefixturesetupiscompletedatthispoint.Thetestswillrun. * *Thisblockingrecvenablestheparenttomessagethechild. *Eitherwewillread'P'offofthesk,indicatingthatweneed *todisableptrace,orwewillreada0,indicatingthattheother *sidehasclosedthesk.Thisoccursduringfixtureteardowntime, *indicatingthatthechildshouldexit.
*/ while ((ret = recv(sk, &buf, sizeof(buf), 0)) > 0) { if (buf == 'P') {
ret = prctl(PR_SET_DUMPABLE, 0); if (ret < 0) {
fprintf(stderr, "%s: Child failed to disable ptrace\n",
strerror(errno)); return -1;
}
} else {
fprintf(stderr, "Child received unknown command %c\n",
buf); return -1;
}
ret = send(sk, &buf, sizeof(buf), 0); if (ret != 1) {
fprintf(stderr, "%s: Child failed to ack\n",
strerror(errno)); return -1;
}
} if (ret < 0) {
fprintf(stderr, "%s: Child failed to read from socket\n",
strerror(errno)); return -1;
}
return0;
}
staticint child(int sk)
{ int memfd, ret;
memfd = sys_memfd_create("test", 0); if (memfd < 0) {
fprintf(stderr, "%s: Child could not create memfd\n",
strerror(errno));
ret = -1;
} else {
ret = __child(sk, memfd);
close(memfd);
}
close(sk); return ret;
}
FIXTURE(child)
{ /* *remote_fdisthenumberoftheFDwhichwearetryingtoretrieve *fromthechild.
*/ int remote_fd; /* pid points to the child which we are fetching FDs from */
pid_t pid; /* pidfd is the pidfd of the child */ int pidfd; /* *skisoursideofthesocketpairusedtocommunicatewiththechild. *Whenitisclosed,thechildwillexit.
*/ int sk; bool ignore_child_result;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.