Date: Sun, 18 Jan 2009 17:43:40 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 156339 for review Message-ID: <200901181743.n0IHheOR003229@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=156339 Change 156339 by rwatson@rwatson_freebsd_capabilities on 2009/01/18 17:42:55 Check fstat() mode on process descriptors in regression test. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#2 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#2 (text+ko) ==== @@ -30,11 +30,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#1 $ + * $P4: //depot/projects/trustedbsd/capabilities/src/tools/regression/procdesc/procdesc_test.c#2 $ */ #include <sys/types.h> #include <sys/procdesc.h> +#include <sys/stat.h> #include <err.h> #include <fcntl.h> @@ -54,25 +55,37 @@ int main(int argc, char *argv[]) { - pid_t pid; + struct stat sb; + pid_t pid, realpid; int fd; printf("1. pdfork() and allow to exit before close().\n"); - pid = pdfork(&fd); - if (pid < 0) + realpid = pdfork(&fd); + if (realpid < 0) err(-1, "pdfork"); - if (pid == 0) { + if (realpid == 0) { if (execve(sleep_argv[0], sleep_argv, environ) < 0) err(-1, "%s", sleep_argv[0]); } else { if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid before sleep: %d\n", pid); + if (pid != realpid) + errx(-1, "pdfork pid %d pdgetpid pid %d", realpid, + pid); + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != (S_IFREG | S_IRWXU)) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("before sleep: pid %d mode 0%05o\n", pid, sb.st_mode); sleep(10); if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid after sleep: %d\n", pid); + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != S_IFREG) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("after sleep: pid %d mode %05o\n", pid, sb.st_mode); close(fd); } @@ -87,11 +100,19 @@ } else { if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid before sleep: %d\n", pid); + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != (S_IFREG | S_IRWXU)) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("before sleep: pid %d mode %05o\n", pid, sb.st_mode); sleep(2); if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid after sleep: %d\n", pid); + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != (S_IFREG | S_IRWXU)) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("after sleep: pid %d mode %05o\n", pid, sb.st_mode); close(fd); } @@ -106,20 +127,29 @@ } else { if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid before sleep: %d\n", pid); + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != (S_IFREG | S_IRWXU)) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("before sleep: pid %d mode %05o\n", pid, sb.st_mode); sleep(2); if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid after sleep: %d\n", pid); - + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != (S_IFREG | S_IRWXU)) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("after sleep: pid %d mode %05o\n", pid, sb.st_mode); if (pdkill(fd, SIGKILL) < 0) err(-1, "pdkill"); - sleep(1); if (pdgetpid(fd, &pid) < 0) err(-1, "pdgetpid"); - printf("pid after kill: %d\n", pid); - + if (fstat(fd, &sb) < 0) + err(-1, "fstat"); + if (sb.st_mode != S_IFREG) + errx(-1, "stat mode 0%05o", sb.st_mode); + printf("after kill: pid %d mode %05o\n", pid, sb.st_mode); close(fd); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200901181743.n0IHheOR003229>