Skip to content
Snippets Groups Projects
Commit ffc9388d authored by ballen4705's avatar ballen4705
Browse files

I have been reading W. Richard Stevens "Advanced Programming in the UNIX Environment".

We need to flush all buffered IO streams before fork(), else both parent and child end
up with copies and will eventually flush them, resulting in two copies.


git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@375 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent b7f2be7e
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@
// CVS ID strings
extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.c,v 1.86 2002/12/15 16:54:29 ballen4705 Exp $"
const char *CVSid6="$Id: smartd.c,v 1.87 2002/12/15 21:08:23 ballen4705 Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc.
......@@ -256,6 +256,10 @@ int daemon_init(void){
pid_t pid;
int i;
// flush all buffered streams. Else we might get two copies of open
// streams since both parent and child get copies of the buffers.
fflush(NULL);
if ((pid=fork()) < 0) {
// unable to fork!
printout(LOG_CRIT,"smartd unable to fork daemon process!\n");
......
......@@ -50,7 +50,7 @@
// CVS ID strings
extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.cpp,v 1.86 2002/12/15 16:54:29 ballen4705 Exp $"
const char *CVSid6="$Id: smartd.cpp,v 1.87 2002/12/15 21:08:23 ballen4705 Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc.
......@@ -256,6 +256,10 @@ int daemon_init(void){
pid_t pid;
int i;
// flush all buffered streams. Else we might get two copies of open
// streams since both parent and child get copies of the buffers.
fflush(NULL);
if ((pid=fork()) < 0) {
// unable to fork!
printout(LOG_CRIT,"smartd unable to fork daemon process!\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment