summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-03-15 15:42:35 +0100
committerDan McGee <dan@archlinux.org>2009-03-15 11:40:49 -0500
commit36863b968f562840461e60be4ed23abf635d6008 (patch)
treedff86c5d35d856979d7475604c748a3ef2f3b0e8
parent687f04ab4699440e3d8b371454b26039b6eb2772 (diff)
downloadpacman-36863b968f562840461e60be4ed23abf635d6008.tar.xz
runscriptlet : Flush open fds before fork() to avoid cloning buffers
This is a bug I noticed 2 years ago : http://www.nabble.com/Re%3A-logging-output-crazy-to11437357.html#a11479679 I thought I fixed it with 57d77eab32c01cd7572a11f76480a3724d09c029 But the bug was still here. Reading man fork, this part caught my attention: * The child inherits copies of the parent's set of open file descriptors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent. This means that the two descriptors share open file status flags, current file offset, and signal-driven I/O attributes (see the description of F_SETOWN and F_SETSIG in fcntl(2)). Since the open file descriptors are inherited, it is probably a good idea to flush them before forking. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/trans.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 4b831193..ae01e3fa 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -511,6 +511,9 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
}
_alpm_log(PM_LOG_DEBUG, "%s\n", cmdline);
+ /* Flush open fds before fork() to avoid cloning buffers */
+ fflush(NULL);
+
/* fork- parent and child each have seperate code blocks below */
pid = fork();
if(pid == -1) {