Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 May 2019 17:00:09 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r502342 - head/ports-mgmt/pkg-devel/files
Message-ID:  <201905231700.x4NH092a015804@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Thu May 23 17:00:09 2019
New Revision: 502342
URL: https://svnweb.freebsd.org/changeset/ports/502342

Log:
  Add a patch to not close stding but actually use /dev/null
  When running scripts

Added:
  head/ports-mgmt/pkg-devel/files/patch-better-stdin-handling   (contents, props changed)

Added: head/ports-mgmt/pkg-devel/files/patch-better-stdin-handling
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/ports-mgmt/pkg-devel/files/patch-better-stdin-handling	Thu May 23 17:00:09 2019	(r502342)
@@ -0,0 +1,47 @@
+diff --git libpkg/scripts.c libpkg/scripts.c
+index 04667af1..489b46d7 100644
+--- libpkg/scripts.c
++++ 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905231700.x4NH092a015804>