Module Name: src Committed By: pooka Date: Tue Feb 15 15:54:56 UTC 2011
Modified Files: src/tests/lib/librumpclient: h_exec.c t_exec.sh Log Message: test FD_CLOEXEC To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/librumpclient/h_exec.c \ src/tests/lib/librumpclient/t_exec.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/librumpclient/h_exec.c diff -u src/tests/lib/librumpclient/h_exec.c:1.1 src/tests/lib/librumpclient/h_exec.c:1.2 --- src/tests/lib/librumpclient/h_exec.c:1.1 Tue Feb 15 15:16:46 2011 +++ src/tests/lib/librumpclient/h_exec.c Tue Feb 15 15:54:56 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: h_exec.c,v 1.1 2011/02/15 15:16:46 pooka Exp $ */ +/* $NetBSD: h_exec.c,v 1.2 2011/02/15 15:54:56 pooka Exp $ */ /* * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -56,10 +56,10 @@ if (argc > 1) { if (strcmp(argv[1], "_didexec") == 0) { daemon(0, 0); /* detach-me-notnot ergo detach */ - s1 = atoi(argv[2]); + s2 = atoi(argv[2]); slen = sizeof(sin); /* see below */ - accept(s1, (struct sockaddr *)&sin, &slen); + accept(s2, (struct sockaddr *)&sin, &slen); } } @@ -92,11 +92,18 @@ * "pause()", but conveniently gets rid of this helper * since we were called with RUMPCLIENT_RETRYCONN_DIE set */ - accept(s1, (struct sockaddr *)&sin, &slen); + accept(s2, (struct sockaddr *)&sin, &slen); + } + + if (argc == 3 && strcmp(argv[2], "cloexec1") == 0) { + if (fcntl(s1, F_SETFD, FD_CLOEXEC) == -1) { + fprintf(stderr, "repomies jumalauta %d!\n", errno); + err(1, "cloexec failed"); + } } /* omstart! */ - sprintf(buf, "%d", s1); + sprintf(buf, "%d", s2); if (execl(argv[1], "h_ution", "_didexec", buf, NULL) == -1) err(1, "exec"); } Index: src/tests/lib/librumpclient/t_exec.sh diff -u src/tests/lib/librumpclient/t_exec.sh:1.1 src/tests/lib/librumpclient/t_exec.sh:1.2 --- src/tests/lib/librumpclient/t_exec.sh:1.1 Tue Feb 15 15:16:46 2011 +++ src/tests/lib/librumpclient/t_exec.sh Tue Feb 15 15:54:56 2011 @@ -1,4 +1,4 @@ -# $NetBSD: t_exec.sh,v 1.1 2011/02/15 15:16:46 pooka Exp $ +# $NetBSD: t_exec.sh,v 1.2 2011/02/15 15:54:56 pooka Exp $ # # Copyright (c) 2011 The NetBSD Foundation, Inc. # All rights reserved. @@ -77,9 +77,33 @@ rump.halt } +atf_test_case cloexec cleanup +cloexec_head() +{ + atf_set "descr" "check that FD_CLOEXEC works" +} + +cloexec_body() +{ + + atf_check -s exit:0 ${rumpsrv} ${RUMP_SERVER} + atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \ + $(atf_get_srcdir)/h_exec $(atf_get_srcdir)/h_ution cloexec1 + atf_check -s exit:0 -o save:sstat.out rump.sockstat + atf_check -s exit:0 -o inline:'2\n' sed -n '$=' sstat.out + atf_check -s exit:0 -o match:'^root.*h_ution.*tcp.*\*\.2345' \ + sed -n 2p sstat.out +} + +cloexec_cleanup() +{ + rump.halt +} + atf_init_test_cases() { atf_add_test_case noexec atf_add_test_case exec + atf_add_test_case cloexec }