Date: Thu, 28 Jan 2010 13:50:41 GMT From: Jonathan Anderson <jona@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 173835 for review Message-ID: <201001281350.o0SDofKY056199@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=173835 Change 173835 by jona@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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001281350.o0SDofKY056199>