summaryrefslogtreecommitdiffstats
path: root/src/zabbix_agent/logfiles.c
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-25 12:02:22 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-25 12:02:22 +0000
commit80312add3bb092cd15615d8c0ed715628e747164 (patch)
tree70be5fe6c3897686a3d1fe7ff77a80123baa4cf1 /src/zabbix_agent/logfiles.c
parent94e492c52f83dbfa3ffa15b96bdabe19aee0d600 (diff)
downloadzabbix-80312add3bb092cd15615d8c0ed715628e747164.tar.gz
zabbix-80312add3bb092cd15615d8c0ed715628e747164.tar.xz
zabbix-80312add3bb092cd15615d8c0ed715628e747164.zip
- merged rev. 4357:4358 branches/1.4.1/ (Eugene) [fixed and improved log monitoring]
git-svn-id: svn://svn.zabbix.com/trunk@4359 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_agent/logfiles.c')
-rw-r--r--src/zabbix_agent/logfiles.c88
1 files changed, 55 insertions, 33 deletions
diff --git a/src/zabbix_agent/logfiles.c b/src/zabbix_agent/logfiles.c
index 9ae00bed..ec3b49df 100644
--- a/src/zabbix_agent/logfiles.c
+++ b/src/zabbix_agent/logfiles.c
@@ -22,6 +22,27 @@
#include "log.h"
#include "logfiles.h"
+/******************************************************************************
+ * *
+ * Function: process_log *
+ * *
+ * Purpose: Get message from logfile *
+ * *
+ * Parameters: filename - logfile name *
+ * lastlogsize - offset for message *
+ * value - pointer for logged message *
+ * *
+ * Return value: returns SUCCEED on succesfull reading, *
+ * FAIL on other cases *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * This function allocate memory for 'value', because use zbx_free. *
+ * Return SUCCEED and NULL value if end of file received. *
+ * *
+ * *
+ ******************************************************************************/
int process_log(
char *filename,
long *lastlogsize,
@@ -30,6 +51,7 @@ int process_log(
{
FILE *f = NULL;
struct stat buf;
+ int ret = FAIL;
assert(filename);
assert(lastlogsize);
@@ -38,47 +60,47 @@ int process_log(
zabbix_log( LOG_LEVEL_DEBUG, "In process log (%s,%li)", filename, *lastlogsize);
/* Handling of file shrinking */
- if(stat(filename,&buf) == 0)
+ if( 0 != stat(filename,&buf) )
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
+ }
+ else
{
if(buf.st_size<*lastlogsize)
{
*lastlogsize=0;
}
- }
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
- *value = strdup("ZBX_NOTSUPPORTED\n");
- return 1;
- }
- if(NULL == (f = fopen(filename,"r") ))
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
- *value = strdup("ZBX_NOTSUPPORTED\n");
- return 1;
- }
-
- if(-1 == fseek(f,*lastlogsize,SEEK_SET))
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot set postition to [%li] for [%s] [%s]", *lastlogsize, filename, strerror(errno));
- *value = strdup("ZBX_NOTSUPPORTED\n");
- zbx_fclose(f);
- return 1;
- }
+ if(NULL == (f = fopen(filename,"r") ))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
+ }
+ else
+ {
+ if(-1 == fseek(f,*lastlogsize,SEEK_SET))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot set postition to [%li] for [%s] [%s]", *lastlogsize, filename, strerror(errno));
+ }
+ else
+ {
+ *value = zbx_malloc(*value, MAX_BUF_LEN);
+ memset(*value, 0, MAX_BUF_LEN);
- *value = zbx_malloc(*value, MAX_BUF_LEN);
- memset(*value, 0, MAX_BUF_LEN);
+ if(NULL == fgets(*value, MAX_BUF_LEN-1, f))
+ {
+ /* EOF */
+ zbx_free(*value);
+ }
+ else
+ {
+ *lastlogsize += (long)strlen(*value);
+ }
- if(NULL == fgets(*value, MAX_BUF_LEN-1, f))
- {
- /* EOF */
- zbx_fclose(f);
- return 1;
+ ret = SUCCEED;
+ }
+ zbx_fclose(f);
+ }
}
- zbx_fclose(f);
-
- *lastlogsize += (long)strlen(*value);
- return 0;
+ return ret;
}