From 36863b968f562840461e60be4ed23abf635d6008 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sun, 15 Mar 2009 15:42:35 +0100 Subject: 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 Signed-off-by: Dan McGee --- lib/libalpm/trans.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') 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) { -- cgit v1.2.3-70-g09d2