From nobody Tue Dec 07 00:27:40 2021 X-Original-To: dev-commits-src-all@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 190FE18D3D42; Tue, 7 Dec 2021 00:27:42 +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 4J7LjS3Sqlz4SJy; Tue, 7 Dec 2021 00:27:40 +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 477AE15FAB; Tue, 7 Dec 2021 00:27:40 +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 1B70Redl021486; Tue, 7 Dec 2021 00:27:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B70Reeh021485; Tue, 7 Dec 2021 00:27:40 GMT (envelope-from git) Date: Tue, 7 Dec 2021 00:27:40 GMT Message-Id: <202112070027.1B70Reeh021485@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: c5f46d7306f5 - stable/13 - Add tests for posix_spawn_file_actions_add{chdir,fchdir}_np(3) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: c5f46d7306f527aa4014d9d2d0e07e65527f6522 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638836861; 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=KmshEfoIm2y0WtXdRFxtYeZNXFwP5i8Wo+DKFMUQt+Q=; b=WeSswJK09l95ReGaFyK9YjqJq58nvKdoux1xgnRSYqyqJ7adQkpcX3fXqzWAkVWNP6TE9d f2C38FZ5zy0yVOr+rdEdDNVjT/AvQFDv2pKqmt1+yTwIOVjlqaHVJcqeckItAbYwIX7nO6 rgDf/2W94dUcxhiNYhyqIAJh6HA+GEmjZAGDFWR1blEAVlfH0Bx+04dDUNdaoasKWCRlMu nFrwDSU3D2J4GQ/diOyBLCajwSDcrVvzKxcoZCnSNfy74xkjcHAG79tGWd5LganXSpMjUq GhoEkOqE+h/CZubKJiyavTG1oT1fSgK82mI7cJYdQ3wYM67KgNrfLl3nbXZWQg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638836861; a=rsa-sha256; cv=none; b=aD4R8ij5FyztaLUdgfkUurlLguUeB4tA3WBkeec9t+iLcGvwOPIbYp8O17jB68RTDhCXzP AzRzu/puPJVhYFJzfICb9K46ZJfms1XOnlWPZJsv55peFPFPq4s9fJ8DVARdqE9DUIQXKw 2VPWHo0eblJacTTCWilMT04oq0/t2Wzz7m7M3818bFibFGr+1zC9sS5ljHfpIKxU7Bn9K0 pU81cFlSZ/KOwale9y1Kd8E4l7O8UTfj09CMDaBHRYreC6Fcgw8fqJmYOHQKv15/ULe3p0 a6ABT2FnQsnzX6JdthrwZ+vVwZUgmIFuPiWerZurodQWA8CGd+wXdRIGGxl7zA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c5f46d7306f527aa4014d9d2d0e07e65527f6522 commit c5f46d7306f527aa4014d9d2d0e07e65527f6522 Author: Konstantin Belousov AuthorDate: 2021-11-28 00:55:26 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-07 00:25:56 +0000 Add tests for posix_spawn_file_actions_add{chdir,fchdir}_np(3) (cherry picked from commit f16ec9c6e36f1d481468e7301d6f3b857db17561) --- .../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(); }