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 | |
| 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')
| -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 | ||||
| -rw-r--r-- | src/zabbix_server/alerter/alerter.c | 2 | ||||
| -rw-r--r-- | src/zabbix_server/server.c | 5 | ||||
| -rw-r--r-- | src/zabbix_server/trapper/trapper.c | 2 |
6 files changed, 48 insertions, 16 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: diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c index 75c4622a..27c555d4 100644 --- a/src/zabbix_server/alerter/alerter.c +++ b/src/zabbix_server/alerter/alerter.c @@ -105,7 +105,7 @@ static int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, /* if(-1 == execl("/home/zabbix/bin/lmt.sh","lmt.sh",alert->sendto,alert->subject,alert->message,(char *)0))*/ - pid=fork(); + pid = zbx_fork(); if(0 != pid) { waitpid(pid,NULL,0); diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 0e5d7463..1367d744 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -337,7 +337,7 @@ void test() for(k = 0; k < 10; k++) { - switch(fork()) + switch( zbx_fork() ) { case -1: SDI("FORK - FAIL"); exit(1); break; case 0: @@ -501,6 +501,7 @@ int main(int argc, char **argv) } zabbix_log( LOG_LEVEL_WARNING, "Starting zabbix_server. ZABBIX %s.", ZABBIX_VERSION); + test(); return 0; #endif /* TEST */ @@ -578,7 +579,7 @@ int MAIN_ZABBIX_ENTRY(void) for(i=1; i<=CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS+CONFIG_ALERTER_FORKS+CONFIG_HOUSEKEEPER_FORKS+CONFIG_TIMER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS+CONFIG_NODEWATCHER_FORKS; i++) { - if((pid = fork()) == 0) + if((pid = zbx_fork()) == 0) { server_num = i; break; diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index a0ffc4ee..278a1213 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -344,7 +344,7 @@ pid_t child_trapper_make(int i,int listenfd, int addrlen) { pid_t pid; - if((pid = fork()) >0) + if((pid = zbx_fork()) >0) { return (pid); } |
