diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-06-01 14:03:38 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-06-01 14:03:38 +0000 |
| commit | a0d27d44b9fc421f058b4907e2bc4b076a343032 (patch) | |
| tree | 8f264f0a6b2736754c158fc40611d8da94d02b48 /src | |
| parent | eebf8121ea8f616317d67f04bf577e4c5bdca0d1 (diff) | |
| download | zabbix-a0d27d44b9fc421f058b4907e2bc4b076a343032.tar.gz zabbix-a0d27d44b9fc421f058b4907e2bc4b076a343032.tar.xz zabbix-a0d27d44b9fc421f058b4907e2bc4b076a343032.zip | |
- merged from branches/1.4.1 rev. 4220:4221 (Eugene) [Improvements to server stability]
git-svn-id: svn://svn.zabbix.com/trunk@4222 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
| -rw-r--r-- | src/libs/zbxcommon/regexp.c | 33 | ||||
| -rw-r--r-- | src/libs/zbxcommon/str.c | 6 | ||||
| -rw-r--r-- | src/libs/zbxdbhigh/db.c | 6 | ||||
| -rw-r--r-- | src/libs/zbxdbhigh/host.c | 2 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/common/http.c | 2 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/openbsd/diskio.c | 4 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/win32/proc.c | 4 | ||||
| -rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 2 | ||||
| -rw-r--r-- | src/zabbix_server/httppoller/httptest.c | 67 | ||||
| -rw-r--r-- | src/zabbix_server/operations.c | 8 | ||||
| -rw-r--r-- | src/zabbix_server/server.c | 21 | ||||
| -rw-r--r-- | src/zabbix_server/trapper/nodesync.c | 2 |
12 files changed, 75 insertions, 82 deletions
diff --git a/src/libs/zbxcommon/regexp.c b/src/libs/zbxcommon/regexp.c index ffcf904e..f07ad541 100644 --- a/src/libs/zbxcommon/regexp.c +++ b/src/libs/zbxcommon/regexp.c @@ -27,34 +27,25 @@ char *zbx_regexp_match(const char *string, const char *pattern, int *len) { char *c = NULL; - int status; - regex_t re; regmatch_t match; if(len) *len = 0; - - if (regcomp(&re, pattern, REG_EXTENDED | /* REG_ICASE | */ REG_NEWLINE) != 0) + if( string && string[0] ) { - return(NULL); + if ( 0 == regcomp(&re, pattern, REG_EXTENDED | /* REG_ICASE | */ REG_NEWLINE) ) + { + if( 0 == regexec(&re, string, (size_t) 1, &match, 0) ) + { /* Matched */ + c=(char *)string+match.rm_so; + if(len) *len = match.rm_eo - match.rm_so; + + } + + regfree(&re); + } } - - - status = regexec(&re, string, (size_t) 1, &match, 0); - - /* Not matched */ - if (status != 0) - { - regfree(&re); - return(NULL); - } - - c=(char *)string+match.rm_so; - if(len) *len = match.rm_eo - match.rm_so; - - regfree(&re); - return c; } diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c index d57ae64c..fcb43a90 100644 --- a/src/libs/zbxcommon/str.c +++ b/src/libs/zbxcommon/str.c @@ -298,7 +298,7 @@ char *string_replace(char *str, char *sub_str1, char *sub_str2) diff = (long)strlen(sub_str2) - len; /* allocate new memory */ - new_str = zbx_malloc((size_t)(strlen(str) + count*diff)*sizeof(char)); + new_str = zbx_malloc((size_t)(strlen(str) + count*diff + 1)*sizeof(char)); for (q=str,t=new_str,p=str; (p = strstr(p, sub_str1)); ) { @@ -310,7 +310,9 @@ char *string_replace(char *str, char *sub_str1, char *sub_str2) --t; } /* copy the tail of str */ - while ( (*t++ = *q++) ); + for( ; *q ; *t++ = *q++ ); + + *t = '\0'; return new_str; diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c index e775a652..0eac1acb 100644 --- a/src/libs/zbxdbhigh/db.c +++ b/src/libs/zbxdbhigh/db.c @@ -1421,7 +1421,7 @@ void DBvacuum(void) void DBescape_string(const char *str, char *to, int maxlen) { /* NOTE: sync changes with 'DBdyn_escape_string' */ - register int i,ptr; + register int i=0, ptr=0; #ifdef HAVE_ORACLE # define ZBX_DB_ESC_CH '\'' #else /* not HAVE_ORACLE */ @@ -1430,7 +1430,7 @@ void DBescape_string(const char *str, char *to, int maxlen) assert(to); maxlen--; - for(i=0, ptr=0; str && str[i] && ptr < maxlen; i++) + for( i=0,ptr=0; str && str[i] && ptr < maxlen; i++) { if( str[i] == '\r' ) continue; @@ -1483,7 +1483,7 @@ void DBget_item_from_db(DB_ITEM *item,DB_ROW row) ZBX_STR2UINT64(item->itemid, row[0]); /* item->itemid=atoi(row[0]); */ - zbx_snprintf(item->key, ITEM_KEY_LEN, row[1]); + zbx_snprintf(item->key, ITEM_KEY_LEN, "%s", row[1]); item->host_name=row[2]; item->port=atoi(row[3]); item->delay=atoi(row[4]); diff --git a/src/libs/zbxdbhigh/host.c b/src/libs/zbxdbhigh/host.c index b81004bb..72f3c5d7 100644 --- a/src/libs/zbxdbhigh/host.c +++ b/src/libs/zbxdbhigh/host.c @@ -2941,7 +2941,9 @@ static int DBcopy_trigger_to_host( old_expression = new_expression; new_expression = string_replace(old_expression, search, replace); + zbx_free(old_expression); + zbx_free(replace); } else { diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c index 025a9b1b..4e49e304 100644 --- a/src/libs/zbxsysinfo/common/http.c +++ b/src/libs/zbxsysinfo/common/http.c @@ -50,7 +50,7 @@ static int get_http_page(char *host, char *param, unsigned short port, char *buf { zbx_rtrim(buf, "\n\r\0"); - zbx_snprintf(buffer, max_buf_len, buf); + zbx_snprintf(buffer, max_buf_len, "%s", buf); } } } diff --git a/src/libs/zbxsysinfo/openbsd/diskio.c b/src/libs/zbxsysinfo/openbsd/diskio.c index 7a22f6d2..15c3f0db 100644 --- a/src/libs/zbxsysinfo/openbsd/diskio.c +++ b/src/libs/zbxsysinfo/openbsd/diskio.c @@ -224,7 +224,7 @@ DEV_FNCLIST if(mode[0] == '\0') { /* default parameter */ - zbx_snprintf(mode, sizeof(mode), fl[0].mode); + zbx_snprintf(mode, sizeof(mode), "%s", fl[0].mode); } for(i=0; fl[i].mode!=0; i++) @@ -281,7 +281,7 @@ DEV_FNCLIST if(mode[0] == '\0') { /* default parameter */ - zbx_snprintf(mode, sizeof(mode), fl[0].mode); + zbx_snprintf(mode, sizeof(mode), "%s", fl[0].mode); } for(i=0; fl[i].mode!=0; i++) diff --git a/src/libs/zbxsysinfo/win32/proc.c b/src/libs/zbxsysinfo/win32/proc.c index a6611375..9de1aab0 100644 --- a/src/libs/zbxsysinfo/win32/proc.c +++ b/src/libs/zbxsysinfo/win32/proc.c @@ -371,7 +371,7 @@ int PROC_INFO(const char *cmd, const char *param, unsigned flags, AGENT_RESU if(attr[0] == '\0') { /* default parameter */ - zbx_snprintf(attr, sizeof(attr), attrList[0]); + zbx_snprintf(attr, sizeof(attr), "%s", attrList[0]); } if(get_param(param, 3, type, sizeof(type)) != 0) @@ -382,7 +382,7 @@ int PROC_INFO(const char *cmd, const char *param, unsigned flags, AGENT_RESU if(type[0] == '\0') { /* default parameter */ - zbx_snprintf(type, sizeof(type), typeList[2]); + zbx_snprintf(type, sizeof(type), "%s", typeList[2]); } /* Get attribute code from string */ diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 220e9227..1dce1070 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -395,7 +395,7 @@ int main(int argc, char **argv) int main() { -#if ON +#if OFF int res, val; if(FAIL == zbx_sock_init()) diff --git a/src/zabbix_server/httppoller/httptest.c b/src/zabbix_server/httppoller/httptest.c index 9f04e110..63224ef8 100644 --- a/src/zabbix_server/httppoller/httptest.c +++ b/src/zabbix_server/httppoller/httptest.c @@ -96,13 +96,6 @@ static int process_value(zbx_uint64_t itemid, AGENT_RESULT *value) static size_t WRITEFUNCTION2( void *ptr, size_t size, size_t nmemb, void *stream) { -/* size_t s = size*nmemb + 1; - char *str_dat = calloc(1, s); - - zbx_snprintf(str_dat,s,ptr); - ZBX_LIM_PRINT("WRITEFUNCTION", s, str_dat, 65535); - zabbix_log(LOG_LEVEL_WARNING, "In WRITEFUNCTION"); -*/ size_t r_size = size*nmemb; /* First piece of data */ @@ -153,22 +146,22 @@ static void process_test_data(DB_HTTPTEST *httptest, S_ZBX_HTTPSTAT *stat) ZBX_STR2UINT64(httptestitem.itemid, row[2]); httptestitem.type=atoi(row[3]); + init_result(&value); + switch (httptestitem.type) { case ZBX_HTTPITEM_TYPE_TIME: - init_result(&value); SET_DBL_RESULT(&value, stat->test_total_time); process_value(httptestitem.itemid,&value); - free_result(&value); break; case ZBX_HTTPITEM_TYPE_LASTSTEP: - init_result(&value); SET_UI64_RESULT(&value, stat->test_last_step); process_value(httptestitem.itemid,&value); - free_result(&value); break; default: break; } + + free_result(&value); } DBfree_result(result); @@ -205,62 +198,32 @@ static void process_step_data(DB_HTTPTEST *httptest, DB_HTTPSTEP *httpstep, S_ZB ZBX_STR2UINT64(httpstepitem.itemid, row[2]); httpstepitem.type=atoi(row[3]); + init_result(&value); + switch (httpstepitem.type) { case ZBX_HTTPITEM_TYPE_RSPCODE: - init_result(&value); SET_UI64_RESULT(&value, stat->rspcode); process_value(httpstepitem.itemid,&value); - free_result(&value); break; case ZBX_HTTPITEM_TYPE_TIME: - init_result(&value); SET_DBL_RESULT(&value, stat->total_time); process_value(httpstepitem.itemid,&value); - free_result(&value); break; case ZBX_HTTPITEM_TYPE_SPEED: - init_result(&value); SET_DBL_RESULT(&value, stat->speed_download); process_value(httpstepitem.itemid,&value); - free_result(&value); break; default: break; } + + free_result(&value); } DBfree_result(result); zabbix_log(LOG_LEVEL_DEBUG, "End process_step_data()"); CHECK_MEMORY("process_step_data", "end"); - -/* DB_RESULT result; - DB_ROW row; - char server_esc[MAX_STRING_LEN]; - char key_esc[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_WARNING, "In process_httptest(httptestid:" ZBX_FS_UI64 ")", stat->httptestid); - - DBescape_string(server, server_esc, MAX_STRING_LEN); - DBescape_string(key, key_esc, MAX_STRING_LEN); - - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, LOCAL_NODE("h.hostid")); - - row=DBfetch(result); - DBget_item_from_db(&item,row); - - if(set_result_type(&agent, item.value_type, value) == SUCCEED) - { - process_new_value(&item,&agent); - update_triggers(item.itemid); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", value, item.key, item.host ); - zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", value, item.key, item.host ); - } - - DBfree_result(result);*/ } /****************************************************************************** @@ -313,37 +276,43 @@ static void process_httptest(DB_HTTPTEST *httptest) { zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_COOKIEFILE [%s]", curl_easy_strerror(err)); + (void)curl_easy_cleanup(easyhandle); return; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, httptest->agent))) { zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_USERAGENT [%s]", curl_easy_strerror(err)); + (void)curl_easy_cleanup(easyhandle); return; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_FOLLOWLOCATION, 1))) { zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_FOLLOWLOCATION [%s]", curl_easy_strerror(err)); + (void)curl_easy_cleanup(easyhandle); return; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_WRITEFUNCTION ,WRITEFUNCTION2))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_WRITEFUNCTION [%s]", curl_easy_strerror(err)); + (void)curl_easy_cleanup(easyhandle); return; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_HEADERFUNCTION ,HEADERFUNCTION2))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_WRITEFUNCTION [%s]", curl_easy_strerror(err)); + (void)curl_easy_cleanup(easyhandle); return; } /* Process self-signed certificates. Do not verify certificate. */ if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_SSL_VERIFYPEER , 0))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_SSL_VERIFYPEER [%s]", curl_easy_strerror(err)); + (void)curl_easy_cleanup(easyhandle); return; } @@ -417,7 +386,7 @@ static void process_httptest(DB_HTTPTEST *httptest) } else { - if(zbx_regexp_match(page.data,httpstep.required,NULL) == NULL) + if(httpstep.required[0]!='\0' && zbx_regexp_match(page.data,httpstep.required,NULL) == NULL) { zabbix_log(LOG_LEVEL_DEBUG, "Page didn't match [%s]", httpstep.required); err_str = strdup("Page didn't match"); diff --git a/src/zabbix_server/operations.c b/src/zabbix_server/operations.c index 91004a44..44f5da6a 100644 --- a/src/zabbix_server/operations.c +++ b/src/zabbix_server/operations.c @@ -725,12 +725,16 @@ void op_template_add(DB_EVENT *event, DB_ACTION *action, DB_OPERATION *operation if(!row || DBis_null(row[0]) == SUCCEED) { hosttemplateid = DBget_maxid("hosts_templates","hosttemplateid"); + DBexecute("begin;"); + DBexecute("insert into hosts_templates (hosttemplateid,hostid,templateid) values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ")", hosttemplateid, hostid, templateid); DBsync_host_with_template(hostid, templateid); + + DBexecute("commit;"); } DBfree_result(result); } @@ -786,12 +790,16 @@ void op_template_del(DB_EVENT *event, DB_ACTION *action, DB_OPERATION *operation if( (row = DBfetch(result)) ) { + DBexecute("begin;"); + DBdelete_template_elements(hostid, templateid, 0 /* not a unlink mode */); DBexecute("delete from hosts_templates where " "hostid=" ZBX_FS_UI64 " and templateid=" ZBX_FS_UI64, hostid, templateid); + + DBexecute("commit;"); } DBfree_result(result); } diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index e7352e7d..8499f2bd 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -233,10 +233,31 @@ void init_config(void) void test() { + zbx_uint64_t + hosttemplateid = 0, + hostid = __UINT64_C(10050), + templateid = __UINT64_C(10001); + zabbix_set_log_level(LOG_LEVEL_DEBUG); printf("-= Test Started =-\n\n"); + DBconnect(ZBX_DB_CONNECT_EXIT); + + DBexecute("begin;"); + + hosttemplateid = DBget_maxid("hosts_templates","hosttemplateid"); + + DBexecute("insert into hosts_templates (hosttemplateid,hostid,templateid) values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ")", + hosttemplateid, + hostid, + templateid); + + DBsync_host_with_template(hostid, templateid); + + DBexecute("rollback;"); + + DBclose(); printf("\n-= Test completed =-\n"); } diff --git a/src/zabbix_server/trapper/nodesync.c b/src/zabbix_server/trapper/nodesync.c index 0705edd6..cf7438f1 100644 --- a/src/zabbix_server/trapper/nodesync.c +++ b/src/zabbix_server/trapper/nodesync.c @@ -133,7 +133,7 @@ static int process_record(int nodeid, char *record) fieldname); zbx_strlcat(fields_update,tmp,sizeof(fields)); - zbx_snprintf(tmp,sizeof(tmp),"NULL,", value); + zbx_snprintf(tmp,sizeof(tmp),"NULL,"); } else { |
