File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 2222#include <string.h>
2323#include <time.h>
2424#include <ctype.h>
25+ #ifdef FLB_HAVE_FORK
26+ #include <unistd.h>
27+ #endif
2528
2629#include <sys/types.h>
2730#include <sys/stat.h>
@@ -177,6 +180,7 @@ void flb_utils_warn_c(const char *msg)
177180/* Run current process in background mode */
178181int flb_utils_set_daemon (struct flb_config * config )
179182{
183+ int fd ;
180184 pid_t pid ;
181185
182186 if ((pid = fork ()) < 0 ){
@@ -202,8 +206,15 @@ int flb_utils_set_daemon(struct flb_config *config)
202206 /* Our last STDOUT messages */
203207 flb_info ("switching to background mode (PID=%ld)" , (long ) getpid ());
204208
205- fclose (stderr );
206- fclose (stdout );
209+ /* Redirect stdin, stdout, stderr to `/dev/null`. */
210+ fd = open ("/dev/null" , O_RDWR );
211+ if (fd != -1 ) {
212+ dup2 (fd , STDIN_FILENO );
213+ dup2 (fd , STDOUT_FILENO );
214+ dup2 (fd , STDERR_FILENO );
215+ if (fd > 2 )
216+ close (fd );
217+ }
207218
208219 return 0 ;
209220}
You can’t perform that action at this time.
0 commit comments