PERFORCE change 173835 for review
Jonathan Anderson
jona at FreeBSD.org
Thu Jan 28 13:50:41 UTC 2010
http://p4web.freebsd.org/chv.cgi?CH=173835
Change 173835 by jona at jona-belle-freebsd8 on 2010/01/28 13:49:55
Create -> MMAP -> Copy -> Read works
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/fdlist/fdlist.c#2 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/fdlist/fdlist.c#2 (text+ko) ====
@@ -83,8 +83,41 @@
int shmfd = shm_open(SHM_ANON, O_RDWR, 0600);
if (shmfd < 0)
err(-1, "Error opening shared memory");
- else
- printf("Opened POSIX shared memory @ FD %i\n", shmfd);
+
+ int size = lc_fdlist_size(fds);
+ if (ftruncate(shmfd, size) < 0)
+ err(-1, "Error truncating shmfd");
+
+ void *shm = mmap(NULL, size, PROT_READ | PROT_WRITE,
+ MAP_NOSYNC | MAP_SHARED, shmfd, 0);
+
+ if (shm == MAP_FAILED)
+ err(-1, "Error mmap'ing shared memory");
+
+
+ memcpy(shm, fds, lc_fdlist_size(fds));
+
+
+ struct lc_fdlist *copy = (struct lc_fdlist*) shm;
+
+ pos = 0;
+ for (int i = 0; i < 20; i++) {
+ char *name;
+ int value;
+
+ lc_fdlist_lookup(copy, "org.freebsd.Capsicum", "testjunk",
+ &name, &value, &pos);
+
+ if (strcmp("garbage", name))
+ warnx("i=%i\tGot '%s' instead of 'garbage'", i, name);
+
+ if (value != 50 + i)
+ warnx("i=%i\tGot 'FD' %i instead of %i", i, value, 50 + i);
+ }
+
+
+ printf("OK\n");
+
return 0;
}
More information about the p4-projects
mailing list