From nobody Tue Nov 30 02:16:42 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CFD8818B1C47; Tue, 30 Nov 2021 02:16:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J35SW0sM8z4VdP; Tue, 30 Nov 2021 02:16:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CCC915BAA; Tue, 30 Nov 2021 02:16:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AU2GgDj008282; Tue, 30 Nov 2021 02:16:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AU2GgX8008281; Tue, 30 Nov 2021 02:16:42 GMT (envelope-from git) Date: Tue, 30 Nov 2021 02:16:42 GMT Message-Id: <202111300216.1AU2GgX8008281@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: f16ec9c6e36f - main - Add tests for posix_spawn_file_actions_add{chdir,fchdir}_np(3) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f16ec9c6e36f1d481468e7301d6f3b857db17561 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638238603; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=g6vJUcgVxptmfWD/BETzPso4pxCR++EDCdgDFTcL2wc=; b=VONZWdFziB3ehYIfSgCl8+WWD2Udah3dDSlzow3g2cluUzprOWccBO+N1QZyIoMy2SgmES xrz+zS9Dxpds8Yj79kbjsh0BxrWq3G+n8jxlNNJ2V7WFCah+VN8kot7dgQOC1T/j2JE1sI 7Ex960hd3bTsLXrVX6hselijgfOC+1OrnQCuB0fwGBiM0ARzznhTZA7jZglL8UhCkL80Av FXz4qgbN6Px18sfkauXMKkr1jOFKUE1n/8BEoILdNWhnuDRrkp7gzlQzhi2nYg9L9CMYoX 3lyPoYkY70pjl0zDwkmsm83Qqs+Elgp8neQQY/fOMZAn9pYVPqfrMrZ+rcsczg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638238603; a=rsa-sha256; cv=none; b=pm0tZgJLeZF4JrFez/4wKU4VjZFL28AciBR14HIwGSnSLHKnKfrDPQ9DYJvFA6yPeqN3j3 vmkmPWz/0FNVwAdx2W7bbJ5Swrx+pFKxU9ZuGQJcoW7L3TQnoAXnkCGh8L2PvvPnUdCfZb scShnQttlLc8zXFQzGjqvcoBDkDD9MzpcNdxtemQYEdJdKpw69mFRbjih3cxvegNqoK3cx 6ECkWvsIq0ePLuIETIZrkzYAwbJFkJsuBsk2YTGrB4kG/01JRtv/2PiZYPBya8Iu8lcBQG DBfNvW3DOAZbkQe/65o2WpKoV3GL9lBG03qkcBzyXKTAcA9R3DA73zbXy3Be6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f16ec9c6e36f1d481468e7301d6f3b857db17561 commit f16ec9c6e36f1d481468e7301d6f3b857db17561 Author: Konstantin Belousov AuthorDate: 2021-11-28 00:55:26 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-30 01:43:54 +0000 Add tests for posix_spawn_file_actions_add{chdir,fchdir}_np(3) Reviewed by: kevans, ngie (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33143 --- .../lib/libc/gen/posix_spawn/t_fileactions.c | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c index b3d364207fbb..ce2078eae98e 100644 --- a/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c +++ b/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c @@ -385,6 +385,79 @@ ATF_TC_BODY(t_spawn_empty_fileactions, tc) ATF_REQUIRE(insize == outsize); } +static const char bin_pwd[] = "/bin/pwd"; + +static void +t_spawn_chdir_impl(bool chdir) +{ + int status, err, tmpdir_fd; + pid_t pid; + char * const args[2] = { __UNCONST("pwd"), NULL }; + posix_spawn_file_actions_t fa; + FILE *f; + char read_pwd[128]; + size_t ss; + static const char tmp_path[] = "/tmp"; + + unlink(TESTFILE); + + posix_spawn_file_actions_init(&fa); + posix_spawn_file_actions_addopen(&fa, fileno(stdout), + TESTFILE, O_WRONLY | O_CREAT, 0600); + if (chdir) { + ATF_REQUIRE(posix_spawn_file_actions_addchdir_np(&fa, + tmp_path) == 0); + } else { + tmpdir_fd = open(tmp_path, O_DIRECTORY | O_RDONLY); + ATF_REQUIRE(tmpdir_fd > 0); + ATF_REQUIRE(posix_spawn_file_actions_addfchdir_np(&fa, + tmpdir_fd) == 0); + } + err = posix_spawn(&pid, bin_pwd, &fa, NULL, args, NULL); + posix_spawn_file_actions_destroy(&fa); + if (!chdir) + close(tmpdir_fd); + + ATF_REQUIRE(err == 0); + waitpid(pid, &status, 0); + ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); + + f = fopen(TESTFILE, "r"); + ATF_REQUIRE(f != NULL); + ss = fread(read_pwd, 1, sizeof(read_pwd), f); + fclose(f); + ATF_REQUIRE(ss == strlen(tmp_path) + 1); + ATF_REQUIRE(strncmp(read_pwd, tmp_path, strlen(tmp_path)) == 0); +} + +ATF_TC(t_spawn_chdir); + +ATF_TC_HEAD(t_spawn_chdir, tc) +{ + atf_tc_set_md_var(tc, "descr", + "posix_spawn changes directory for the spawned program"); + atf_tc_set_md_var(tc, "require.progs", bin_pwd); +} + +ATF_TC_BODY(t_spawn_chdir, tc) +{ + t_spawn_chdir_impl(true); +} + +ATF_TC(t_spawn_fchdir); + +ATF_TC_HEAD(t_spawn_fchdir, tc) +{ + atf_tc_set_md_var(tc, "descr", + "posix_spawn changes directory for the spawned program"); + atf_tc_set_md_var(tc, "require.progs", bin_pwd); +} + +ATF_TC_BODY(t_spawn_fchdir, tc) +{ + t_spawn_chdir_impl(false); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_spawn_fileactions); @@ -395,6 +468,8 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, t_spawn_reopen); ATF_TP_ADD_TC(tp, t_spawn_openmode); ATF_TP_ADD_TC(tp, t_spawn_empty_fileactions); + ATF_TP_ADD_TC(tp, t_spawn_chdir); + ATF_TP_ADD_TC(tp, t_spawn_fchdir); return atf_no_error(); }