PERFORCE change 164582 for review
Robert Watson
rwatson at FreeBSD.org
Wed Jun 17 14:16:36 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164582
Change 164582 by rwatson at rwatson_freebsd_capabilities on 2009/06/17 14:16:06
Simplify.
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/fdrpc/Makefile#2 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/fdrpc/fdrpc.c#3 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/fdrpc/Makefile#2 (text+ko) ====
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/fdrpc/fdrpc.c#3 (text+ko) ====
@@ -45,6 +45,11 @@
#include <stdlib.h>
#include <unistd.h>
+/*
+ * This test program creates a sandbox, passes it a file descriptor by RPC,
+ * and then expects it back in the reply.
+ */
+
#define FDRPC_SANDBOX "./fdrpc"
int
@@ -64,10 +69,7 @@
&lcsp) < 0)
err(-1, "lch_start %s", FDRPC_SANDBOX);
- /*
- * Send a file descriptor to the sandbox, then get it back.
- */
- ch = 'X';
+ ch = 'X'; /* RPC data. */
fdcount = 1;
fd_send = STDIN_FILENO;
iov.iov_base = &ch;
@@ -89,7 +91,7 @@
int
cap_main(int argc, char *argv[])
{
- int fdarray[2], fdcount;
+ int fd, fdcount;
struct lc_host *lchp;
struct iovec iov;
uint32_t opno, seqno;
@@ -100,23 +102,24 @@
err(-1, "lcs_get");
while (1) {
- fdcount = 2;
-
+ fdcount = 1;
if (lcs_recvrpc_rights(lchp, &opno, &seqno, &buffer, &len,
- fdarray, &fdcount) < 0) {
+ &fd, &fdcount) < 0) {
if (errno == EPIPE)
exit(-1);
else
err(-1, "lcs_recvrpc_rights");
}
+ if (opno != 0)
+ errx(-1, "lcs_recvrpc_rights: opno %d", opno);
if (fdcount != 1)
errx(-1, "lcs_recvrpc_rights: fdcount %d", fdcount);
iov.iov_len = len;
iov.iov_base = buffer;
- if (lcs_sendrpc_rights(lchp, opno, seqno, &iov, 1, fdarray,
+ if (lcs_sendrpc_rights(lchp, opno, seqno, &iov, 1, &fd,
fdcount) < 0)
err(-1, "lcs_sendrpc_rights");
- close(fdarray[0]);
+ close(fd);
free(buffer);
}
}
More information about the p4-projects
mailing list