Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix @sample not working anymore
Baptiste Daroussin committed 6 years ago
commit 4cbe4573c8f5534e402651828f7140d39a315066
parent e0242b9
1 file changed +13 -2
modified libpkg/scripts.c
@@ -35,6 +35,7 @@

#include <assert.h>
#include <errno.h>
+
#include <fcntl.h>
#include <paths.h>
#include <spawn.h>
#include <stdlib.h>
@@ -59,6 +60,7 @@ pkg_script_run(struct pkg * const pkg, pkg_script type)
	const char *argv[4];
	char **ep;
	int ret = EPKG_OK;
+
	int fd = -1;
	int stdin_pipe[2] = {-1, -1};
	posix_spawn_file_actions_t action;
	bool use_pipe = 0;
@@ -157,8 +159,15 @@ pkg_script_run(struct pkg * const pkg, pkg_script type)

				use_pipe = 1;
			} else {
-
				posix_spawn_file_actions_addclose(&action,
-
				    STDIN_FILENO);
+
				fd = open("/dev/null", O_RDWR);
+
				if (fd < 0) {
+
					pkg_errno("Cannot open %s", "/dev/null");
+
					ret = EPKG_FATAL;
+
					posix_spawn_file_actions_destroy(&action);
+
					goto cleanup;
+
				}
+
				posix_spawn_file_actions_adddup2(&action,
+
				    fd, STDIN_FILENO);

				argv[0] = _PATH_BSHELL;
				argv[1] = "-c";
@@ -178,6 +187,8 @@ pkg_script_run(struct pkg * const pkg, pkg_script type)
			}
			posix_spawn_file_actions_destroy(&action);

+
			if (fd != -1)
+
				close(fd);
			if (use_pipe) {
				script_cmd_p = utstring_body(script_cmd);
				script_cmd_len = utstring_len(script_cmd);