diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-12-21 10:01:27 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-12-21 10:01:27 +0000 |
| commit | bbde600decc1970f1507828fce5ba22c0948519b (patch) | |
| tree | 03f9dd5aadd4c8f938d554b4a02d8fbae405dcac /src/libs | |
| parent | 738cd691cc0d40e97db910ae0453014b6c703efc (diff) | |
| download | zabbix-bbde600decc1970f1507828fce5ba22c0948519b.tar.gz zabbix-bbde600decc1970f1507828fce5ba22c0948519b.tar.xz zabbix-bbde600decc1970f1507828fce5ba22c0948519b.zip | |
- fixed printing of stdout/stderr (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3622 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs')
| -rw-r--r-- | src/libs/zbxnix/daemon.c | 24 | ||||
| -rw-r--r-- | src/libs/zbxsys/threads.c | 27 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/common/common.c | 4 |
3 files changed, 43 insertions, 12 deletions
diff --git a/src/libs/zbxnix/daemon.c b/src/libs/zbxnix/daemon.c index 74b80030..3b111be1 100644 --- a/src/libs/zbxnix/daemon.c +++ b/src/libs/zbxnix/daemon.c @@ -21,6 +21,7 @@ #include "daemon.h" #include "pid.h" +#include "cfg.h" #include "log.h" char *APP_PID_FILE = NULL; @@ -116,7 +117,7 @@ int daemon_start(int allow_root) } - if( (pid = fork()) != 0 ) + if( (pid = zbx_fork()) != 0 ) { exit( 0 ); } @@ -125,7 +126,7 @@ int daemon_start(int allow_root) signal( SIGHUP, SIG_IGN ); - if( (pid = fork()) !=0 ) + if( (pid = zbx_fork()) !=0 ) { exit( 0 ); } @@ -133,14 +134,19 @@ int daemon_start(int allow_root) chdir("/"); umask(0002); - for(i=0; i<MAXFD; i++) - { - /* Do not close stderr */ - if(i == fileno(stderr)) continue; //TODO!!! redirection; - /* Do not close stdout */ - if(i == fileno(stdout)) continue; //TODO!!! redirestion; + for(i=0; i<MAXFD; i++) close(i); + + open("/dev/null", O_RDONLY); /* stdin */ - close(i); + if(CONFIG_LOG_FILE) + { + fopen(CONFIG_LOG_FILE, "a+"); /* stdout */ + fopen(CONFIG_LOG_FILE, "a+"); /* stderr */ + } + else + { + open("/dev/null", O_RDWR); /* stdout */ + open("/dev/null", O_RDWR); /* stderr */ } #ifdef HAVE_SYS_RESOURCE_SETPRIORITY diff --git a/src/libs/zbxsys/threads.c b/src/libs/zbxsys/threads.c index 6501d5e1..c659d4aa 100644 --- a/src/libs/zbxsys/threads.c +++ b/src/libs/zbxsys/threads.c @@ -24,6 +24,31 @@ /****************************************************************************** * * + * Function: zbx_fork * + * * + * Purpose: Flush stdout and stderr before forking * + * * + * Parameters: * + * * + * Return value: same as system fork function * + * * + * Author: Eugene Grigorjev * + * * + * Comments: * + * Use this function instead of system fork function! * + * * + ******************************************************************************/ +#if !defined(_WINDOWS) +int zbx_fork() +{ + fflush(stdout); + fflush(stderr); + return fork(); +} +#endif + +/****************************************************************************** + * * * Function: zbx_thread_start * * * * Purpose: Start the handled function as "thread" * @@ -56,7 +81,7 @@ ZBX_THREAD_HANDLE zbx_thread_start(ZBX_THREAD_ENTRY_POINTER(handler), void *args #else /* not _WINDOWS */ - thread = fork(); + thread = zbx_fork(); if(thread == 0) /* child process */ { diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c index 5ad3aa65..d38d1499 100644 --- a/src/libs/zbxsysinfo/common/common.c +++ b/src/libs/zbxsysinfo/common/common.c @@ -1401,14 +1401,14 @@ int RUN_COMMAND(const char *cmd, const char *param, unsigned flags, AGENT_RESULT #else /* not _WINDOWS */ - pid = fork(); /* run new thread 1 */ + pid = zbx_fork(); /* run new thread 1 */ switch(pid) { case -1: zabbix_log(LOG_LEVEL_WARNING, "fork failed for command '%s'",command); return SYSINFO_RET_FAIL; case 0: - pid = fork(); /* run new tread 2 to replace by command */ + pid = zbx_fork(); /* run new tread 2 to replace by command */ switch(pid) { case -1: |
