Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
FreeBSD's /bin/sh does not allow redirecting to FD > 9
Baptiste Daroussin committed 6 years ago
commit 74368a8f38b8bb7f23a2aa8b0a69db080deee30b
parent 5f91af0
2 files changed +8 -10
modified libpkg/scripts.c
@@ -59,7 +59,7 @@ pkg_script_run(struct pkg * const pkg, pkg_script type, bool upgrade)
	pid_t pid;
	const char *script_cmd_p;
	const char *argv[4];
-
	char **ep, *buf;
+
	char **ep;
	int ret = EPKG_OK;
	int fd = -1;
	int stdin_pipe[2] = {-1, -1};
@@ -154,10 +154,10 @@ pkg_script_run(struct pkg * const pkg, pkg_script type, bool upgrade)
				goto cleanup;
			}

-
			asprintf(&buf, "%d", cur_pipe[1]);
-
			setenv("PKG_MSGFD", buf, 1);
-
			free(buf);
+
			setenv("PKG_MSGFD", "4", 1);

+
			posix_spawn_file_actions_adddup2(&action, cur_pipe[1], 4);
+
			posix_spawn_file_actions_addclose(&action, cur_pipe[0]);
			if (utstring_len(script_cmd) > argmax) {
				if (pipe(stdin_pipe) < 0) {
					ret = EPKG_FATAL;
modified tests/frontend/shellscript.sh
@@ -40,7 +40,7 @@ message_body() {
scripts: {
  post-install: <<EOS
	echo this is post install1
-
	echo this is a message >\&\${PKG_MSGFD}
+
	echo this is a message >&\${PKG_MSGFD}
	echo this is post install2
EOS
}
@@ -67,7 +67,6 @@ upgrade_body() {
scripts: {
  post-install: <<EOS
if [ -n "\${PKG_UPGRADE+x}" ]; then
-
	echo "upgrade:\${PKG_UPGRADE}"
	echo "upgrade:\${PKG_UPGRADE}">&\${PKG_MSGFD}
fi
EOS
@@ -83,7 +82,7 @@ EOF
	mkdir -p ${TMPDIR}/target
	atf_check \
		-e empty \
-
		-o empty \
+
		-o ignore \
		-s exit:0 \
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz

@@ -92,8 +91,7 @@ EOF
scripts: {
  post-install: <<EOS
if [ -n "\${PKG_UPGRADE+x}" ]; then
-
	echo "upgrade:\${PKG_UPGRADE}">\&\${PKG_MSGFD}
-
	echo this is a message >\&\${PKG_MSGFD}
+
	echo "upgrade:\${PKG_UPGRADE}">&\${PKG_MSGFD}
fi
EOS
}
@@ -125,7 +123,7 @@ local: {
EOF
	atf_check \
		-e empty \
-
		-o match:"upgrade:1" \
+
		-o match:"upgrade:true" \
		-s exit:0 \
		pkg -o REPOS_DIR="${TMPDIR}/reposconf" -r ${TMPDIR}/target upgrade -y
}