From ffc9388d73b0a733b92a4c65efa7f660501eb635 Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Sun, 15 Dec 2002 21:08:23 +0000
Subject: [PATCH] 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
---
 sm5/smartd.c   | 6 +++++-
 sm5/smartd.cpp | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/sm5/smartd.c b/sm5/smartd.c
index bab69402b..3d3a56df4 100644
--- a/sm5/smartd.c
+++ b/sm5/smartd.c
@@ -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");
diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp
index ab392c9c0..da8c47940 100644
--- a/sm5/smartd.cpp
+++ b/sm5/smartd.cpp
@@ -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");
-- 
GitLab