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 57d77eab32

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>
This commit is contained in:
Xavier Chantry 2009-03-15 15:42:35 +01:00 committed by Dan McGee
parent 687f04ab46
commit 36863b968f
1 changed files with 3 additions and 0 deletions

View File

@ -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) {