summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-02-19 12:07:46 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-02-19 12:07:46 +0000
commitbbadd78fb2a0ef624b1503f647157f58e93ab474 (patch)
treee8b09916e091a9882e858e3d6170e96514d17ba6
parent46e7eba7e031f101a82973caae71c2a0c1882cca (diff)
downloadzabbix-bbadd78fb2a0ef624b1503f647157f58e93ab474.tar.gz
zabbix-bbadd78fb2a0ef624b1503f647157f58e93ab474.tar.xz
zabbix-bbadd78fb2a0ef624b1503f647157f58e93ab474.zip
- tested and fixed jabber messager (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3836 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--frontends/php/items.php4
-rw-r--r--include/cfg.h6
-rw-r--r--include/db.h2
-rw-r--r--include/mutexs.h4
-rw-r--r--include/zbxplugin.h6
-rw-r--r--src/libs/zbxcommon/misc.c1
-rw-r--r--src/libs/zbxcommon/str.c2
-rw-r--r--src/libs/zbxcomms/comms.c6
-rw-r--r--src/libs/zbxdb/db.c82
-rw-r--r--src/libs/zbxdbhigh/db.c17
-rw-r--r--src/libs/zbxjabber/jabber.c17
-rw-r--r--src/libs/zbxlog/log.c4
-rw-r--r--src/libs/zbxnet/security.c11
-rw-r--r--src/libs/zbxnix/daemon.c3
-rw-r--r--src/libs/zbxsys/mutexs.c15
-rw-r--r--src/libs/zbxsysinfo/common/common.c12
-rw-r--r--src/zabbix_agent/diskdevices.c2
-rwxr-xr-xsrc/zabbix_agent/eventlog.c30
-rw-r--r--src/zabbix_agent/interfaces.c2
-rw-r--r--src/zabbix_agent/zbxconf.c2
-rw-r--r--src/zabbix_sender/zabbix_sender.c6
-rw-r--r--src/zabbix_server/actions.c4
-rw-r--r--src/zabbix_server/alerter/alerter.c1
-rw-r--r--src/zabbix_server/functions.c3
-rw-r--r--src/zabbix_server/httppoller/httptest.c6
-rw-r--r--src/zabbix_server/server.c10
-rw-r--r--src/zabbix_server/trapper/active.c4
-rw-r--r--src/zabbix_server/trapper/trapper.c16
28 files changed, 153 insertions, 125 deletions
diff --git a/frontends/php/items.php b/frontends/php/items.php
index ac3125f5..78f2d338 100644
--- a/frontends/php/items.php
+++ b/frontends/php/items.php
@@ -526,7 +526,7 @@ include_once "include/page_header.php";
{
echo BR;
insert_copy_elements_to_forms("group_itemid");
- } elseif (!(isset($_REQUEST["form"]) && ($_REQUEST["form"]==S_CREATE_ITEM || $_REQUEST["form"]=="update"))) {
+ } elseif (!isset($_REQUEST["form"]) || !in_array($_REQUEST["form"],array(S_CREATE_ITEM,"update","clone"))) {
echo BR;
// Table HEADER
$form = new CForm();
@@ -824,7 +824,7 @@ include_once "include/page_header.php";
}
- if(isset($_REQUEST["form"]) && ($_REQUEST["form"]==S_CREATE_ITEM || $_REQUEST["form"]=="update" ||
+ if(isset($_REQUEST["form"]) && (in_array($_REQUEST["form"],array(S_CREATE_ITEM,"update","clone")) ||
($_REQUEST["form"]=="mass_update" && isset($_REQUEST['group_itemid']))))
{
// FORM
diff --git a/include/cfg.h b/include/cfg.h
index 965f7dbe..c8d008d4 100644
--- a/include/cfg.h
+++ b/include/cfg.h
@@ -26,9 +26,9 @@
#define PARM_OPT 0
#define PARM_MAND 1
-//
-// Application flags
-//
+/*
+ * Application flags
+ */
#define AF_STANDALONE 0x0001
#define AF_USE_EVENT_LOG 0x0002
diff --git a/include/db.h b/include/db.h
index 2e08f680..bc66d860 100644
--- a/include/db.h
+++ b/include/db.h
@@ -263,7 +263,7 @@ DB_TRIGGER
char *comments;
int status;
int value;
-// int prevvalue;
+/* int prevvalue; */
int priority;
};
diff --git a/include/mutexs.h b/include/mutexs.h
index d8d51ab8..fdd804fc 100644
--- a/include/mutexs.h
+++ b/include/mutexs.h
@@ -50,7 +50,9 @@
#endif /* _WINDOWS */
-int zbx_mutex_create(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name);
+#define zbx_mutex_create(mutex, name) zbx_mutex_create_ext(mutex, name, 0)
+#define zbx_mutex_create_force(mutex, name) zbx_mutex_create_ext(mutex, name, 1)
+int zbx_mutex_create_ext(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name, unsigned char forced);
int zbx_mutex_lock(ZBX_MUTEX *mutex);
int zbx_mutex_unlock(ZBX_MUTEX *mutex);
int zbx_mutex_destroy(ZBX_MUTEX *mutex);
diff --git a/include/zbxplugin.h b/include/zbxplugin.h
index cf8998af..e61516e7 100644
--- a/include/zbxplugin.h
+++ b/include/zbxplugin.h
@@ -43,13 +43,13 @@ typedef struct
struct zbx_plugin_list
{
- struct zbx_plugin_list *next; // Pointer to next element in a chain
+ struct zbx_plugin_list *next; /* Pointer to next element in a chain */
- ZBX_MODULE hModule; // DLL module handle
+ ZBX_MODULE hModule; /* DLL module handle */
int runned;
int (__zabbix_api * init)(char *,ZBX_PLUGIN_ARGS **);
void (__zabbix_api * shutdown)(void);
- ZBX_PLUGIN_ARGS *args; // List of subagent's commands
+ ZBX_PLUGIN_ARGS *args; /* List of subagent's commands */
};
typedef struct zbx_plugin_list ZBX_PLUGIN_LIST;
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index 97b26565..53503a07 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -224,7 +224,6 @@ int calculate_item_nextcheck(int itemid, int item_type, int delay, char *delay_f
******************************************************************************/
int check_time_period(const char *period, time_t now)
{
- //time_t now;
char tmp[MAX_STRING_LEN];
char *s;
int d1,d2,h1,h2,m1,m2;
diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c
index 65886297..5e808587 100644
--- a/src/libs/zbxcommon/str.c
+++ b/src/libs/zbxcommon/str.c
@@ -133,7 +133,7 @@ int find_char(char *str,char c)
* Author: Eugene Grigorjev *
* *
******************************************************************************/
-//#define ZBX_STDERR_FILE "zbx_errors.log"
+/* #define ZBX_STDERR_FILE "zbx_errors.log" */
void zbx_error(const char *fmt, ...)
{
diff --git a/src/libs/zbxcomms/comms.c b/src/libs/zbxcomms/comms.c
index 3bd18b46..b6998a4c 100644
--- a/src/libs/zbxcomms/comms.c
+++ b/src/libs/zbxcomms/comms.c
@@ -80,7 +80,7 @@ int zbx_tcp_connect(zbx_sock_t *s, char *ip, int port)
if(NULL == (hp = zbx_gethost(ip)))
{
-// zabbix_log( LOG_LEVEL_WARNING, "Cannot resolve [%s]", ip);
+/* zabbix_log( LOG_LEVEL_WARNING, "Cannot resolve [%s]", ip); */
return FAIL;
}
@@ -91,7 +91,7 @@ int zbx_tcp_connect(zbx_sock_t *s, char *ip, int port)
s->socket = socket(AF_INET,SOCK_STREAM,0);
if(s->socket == -1)
{
-// zabbix_log( LOG_LEVEL_WARNING, "Cannot create socket [%s:%d] [%s]", ip, port ,strerror(errno));
+/* zabbix_log( LOG_LEVEL_WARNING, "Cannot create socket [%s:%d] [%s]", ip, port ,strerror(errno)); */
return FAIL;
}
@@ -101,7 +101,7 @@ int zbx_tcp_connect(zbx_sock_t *s, char *ip, int port)
if( connect(s->socket,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
{
-// zabbix_log( LOG_LEVEL_WARNING, "Cannot connect to [%s:%d] [%s]", ip, port, strerror(errno));
+/* zabbix_log( LOG_LEVEL_WARNING, "Cannot connect to [%s:%d] [%s]", ip, port, strerror(errno)); */
zbx_tcp_close(s);
return FAIL;
}
diff --git a/src/libs/zbxdb/db.c b/src/libs/zbxdb/db.c
index 6e8afb01..dd0ee138 100644
--- a/src/libs/zbxdb/db.c
+++ b/src/libs/zbxdb/db.c
@@ -35,16 +35,16 @@
#ifdef HAVE_SQLITE3
int sqlite_transaction_started = 0;
- sqlite3 *sqlite;
+ sqlite3 *conn = NULL;
PHP_MUTEX sqlite_access;
#endif
#ifdef HAVE_MYSQL
- MYSQL mysql;
+ MYSQL *conn = NULL;
#endif
#ifdef HAVE_POSTGRESQL
- PGconn *conn;
+ PGconn *conn = NULL;
#endif
#ifdef HAVE_ORACLE
@@ -54,18 +54,20 @@
void zbx_db_close(void)
{
#ifdef HAVE_MYSQL
- mysql_close(&mysql);
+ mysql_close(conn);
+ conn = NULL;
#endif
#ifdef HAVE_POSTGRESQL
PQfinish(conn);
+ conn = NULL
#endif
#ifdef HAVE_ORACLE
sqlo_finish(oracle);
#endif
#ifdef HAVE_SQLITE3
sqlite_transaction_started = 0;
- sqlite3_close(sqlite);
-
+ sqlite3_close(conn);
+ conn = NULL;
php_sem_remove(&sqlite_access);
#endif
}
@@ -82,40 +84,40 @@ int zbx_db_connect(char *host, char *user, char *password, char *dbname, char *d
/* zabbix_log(LOG_LEVEL_ERR, "[%s] [%s] [%s]\n",dbname, dbuser, dbpassword ); */
#ifdef HAVE_MYSQL
/* For MySQL >3.22.00 */
- /* if( ! mysql_connect( &mysql, NULL, dbuser, dbpassword ) )*/
+ /* if( ! mysql_connect( conn, NULL, dbuser, dbpassword ) )*/
- mysql_init(&mysql);
+ conn = mysql_init(NULL);
- if( ! mysql_real_connect( &mysql, host, user, password, dbname, port, dbsocket,0 ) )
+ if( ! mysql_real_connect( conn, host, user, password, dbname, port, dbsocket,0 ) )
{
zabbix_log(LOG_LEVEL_ERR, "Failed to connect to database: Error: %s [%d]",
- mysql_error(&mysql), mysql_errno(&mysql));
+ mysql_error(conn), mysql_errno(conn));
ret = ZBX_DB_FAIL;
}
if(ZBX_DB_OK == ret)
{
- if( mysql_select_db( &mysql, dbname ) != 0 )
+ if( mysql_select_db( conn, dbname ) != 0 )
{
zabbix_log(LOG_LEVEL_ERR, "Failed to select database: Error: %s [%d]",
- mysql_error(&mysql), mysql_errno(&mysql));
+ mysql_error(conn), mysql_errno(conn));
ret = ZBX_DB_FAIL;
}
}
if(ZBX_DB_OK == ret)
{
- if(mysql_autocommit(&mysql, 1) != 0)
+ if(mysql_autocommit(conn, 1) != 0)
{
zabbix_log(LOG_LEVEL_ERR, "Failed to set autocommit to 1: Error: %s [%d]",
- mysql_error(&mysql), mysql_errno(&mysql));
+ mysql_error(conn), mysql_errno(conn));
ret = ZBX_DB_FAIL;
}
}
if(ZBX_DB_FAIL == ret)
{
- switch(mysql_errno(&mysql)) {
+ switch(mysql_errno(conn)) {
case CR_SERVER_GONE_ERROR:
case CR_CONNECTION_ERROR:
ret = ZBX_DB_DOWN;
@@ -160,18 +162,18 @@ int zbx_db_connect(char *host, char *user, char *password, char *dbname, char *d
#ifdef HAVE_SQLITE3
int res;
- res = sqlite3_open(name, &sqlite);
+ res = sqlite3_open(name, &conn);
/* check to see that the backend connection was successfully made */
if(res)
{
- zabbix_log(LOG_LEVEL_ERR, "Can't open database [%s]: %s\n", name, sqlite3_errmsg(sqlite));
+ zabbix_log(LOG_LEVEL_ERR, "Can't open database [%s]: %s\n", name, sqlite3_errmsg(conn));
DBclose();
exit(FAIL);
}
/* Do not return SQLITE_BUSY immediately, wait for N ms */
- sqlite3_busy_timeout(sqlite, 60*1000);
+ sqlite3_busy_timeout(conn, 60*1000);
if(ZBX_MUTEX_ERROR == php_sem_get(&sqlite_access, name))
{
@@ -348,13 +350,21 @@ int zbx_db_vexecute(const char *fmt, va_list args)
zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s", sql);
#ifdef HAVE_MYSQL
- if(mysql_query(&mysql,sql) != 0)
+ if(!conn)
{
- ret = (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)?ZBX_DB_DOWN:ZBX_DB_FAIL;
+ zabbix_log( LOG_LEVEL_ERR, "Query executing require connection to database!");
+ ret = ZBX_DB_FAIL;
}
else
{
- ret = (int)mysql_affected_rows(&mysql);
+ if(mysql_query(conn,sql) != 0)
+ {
+ ret = (mysql_errno(conn) == CR_SERVER_GONE_ERROR)?ZBX_DB_DOWN:ZBX_DB_FAIL;
+ }
+ else
+ {
+ ret = (int)mysql_affected_rows(conn);
+ }
}
#endif
#ifdef HAVE_POSTGRESQL
@@ -398,7 +408,7 @@ int zbx_db_vexecute(const char *fmt, va_list args)
}
lbl_exec:
- if(SQLITE_OK != (ret = sqlite3_exec(sqlite, sql, NULL, 0, &error)))
+ if(SQLITE_OK != (ret = sqlite3_exec(conn, sql, NULL, 0, &error)))
{
if(ret == SQLITE_BUSY) goto lbl_exec; /* attention deadlock!!! */
@@ -474,6 +484,8 @@ void SQ_DBfree_result(DB_RESULT result)
DB_ROW zbx_db_fetch(DB_RESULT result)
{
#ifdef HAVE_MYSQL
+ if(!result) return NULL;
+
return mysql_fetch_row(result);
#endif
#ifdef HAVE_POSTGRESQL
@@ -543,6 +555,8 @@ DB_ROW zbx_db_fetch(DB_RESULT result)
return &(result->data[result->curow * result->ncolumn]);
#endif
+
+ return NULL;
}
/*
@@ -573,15 +587,23 @@ DB_RESULT zbx_db_vselect(const char *fmt, va_list args)
zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s", sql);
#ifdef HAVE_MYSQL
- if(mysql_query(&mysql,sql) != 0)
+ if(!conn)
{
- zabbix_log( LOG_LEVEL_ERR, "Query::%s",sql);
- zabbix_log(LOG_LEVEL_ERR, "Query failed:%s [%d]", mysql_error(&mysql), mysql_errno(&mysql) );
- result = (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)?(DB_RESULT)ZBX_DB_DOWN:(DB_RESULT)ZBX_DB_FAIL;
+ zabbix_log( LOG_LEVEL_ERR, "Query executing require connection to database!");
+ result = NULL;
}
else
{
- result = mysql_store_result(&mysql);
+ if(mysql_query(conn,sql) != 0)
+ {
+ zabbix_log( LOG_LEVEL_ERR, "Query::%s",sql);
+ zabbix_log(LOG_LEVEL_ERR, "Query failed:%s [%d]", mysql_error(conn), mysql_errno(conn) );
+ result = (mysql_errno(conn) == CR_SERVER_GONE_ERROR)?(DB_RESULT)ZBX_DB_DOWN:(DB_RESULT)ZBX_DB_FAIL;
+ }
+ else
+ {
+ result = mysql_store_result(conn);
+ }
}
#endif
#ifdef HAVE_POSTGRESQL
@@ -628,7 +650,7 @@ DB_RESULT zbx_db_vselect(const char *fmt, va_list args)
result->curow = 0;
lbl_get_table:
- if(SQLITE_OK != (ret = sqlite3_get_table(sqlite,sql,&result->data,&result->nrow, &result->ncolumn, &error)))
+ if(SQLITE_OK != (ret = sqlite3_get_table(conn,sql,&result->data,&result->nrow, &result->ncolumn, &error)))
{
if(ret == SQLITE_BUSY) goto lbl_get_table; /* attention deadlock!!! */
@@ -666,7 +688,7 @@ zbx_uint64_t zbx_db_insert_id(int exec_result, const char *table, const char *fi
if(exec_result == FAIL) return 0;
- return mysql_insert_id(&mysql);
+ return mysql_insert_id(conn);
#endif
#ifdef HAVE_POSTGRESQL
@@ -712,7 +734,7 @@ zbx_uint64_t zbx_db_insert_id(int exec_result, const char *table, const char *fi
return id;
#endif
#ifdef HAVE_SQLITE3
- return (zbx_uint64_t)sqlite3_last_insert_rowid(sqlite);
+ return (zbx_uint64_t)sqlite3_last_insert_rowid(conn);
#endif
}
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index b73d718b..458a7520 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -35,6 +35,7 @@
#include "common.h"
#include "actions.h"
#include "events.h"
+#include "threads.h"
void DBclose(void)
{
@@ -48,17 +49,13 @@ void DBclose(void)
*/
void DBconnect(int flag)
{
- int i;
-
- int loop = 0;
+ int err;
- while(loop == 0)
- {
- i = zbx_db_connect(CONFIG_DBHOST, CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBNAME, CONFIG_DBSOCKET, CONFIG_DBPORT);
+ do {
+ err = zbx_db_connect(CONFIG_DBHOST, CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBNAME, CONFIG_DBSOCKET, CONFIG_DBPORT);
- switch(i) {
+ switch(err) {
case ZBX_DB_OK:
- loop = 1;
break;
case ZBX_DB_DOWN:
if(flag == ZBX_DB_CONNECT_EXIT)
@@ -68,13 +65,13 @@ void DBconnect(int flag)
else
{
zabbix_log(LOG_LEVEL_WARNING, "Database is down. Reconnecting in 10 seconds");
- sleep(10);
+ zbx_sleep(10);
}
break;
default:
exit(FAIL);
}
- }
+ } while(ZBX_DB_OK != err);
}
/******************************************************************************
diff --git a/src/libs/zbxjabber/jabber.c b/src/libs/zbxjabber/jabber.c
index ba13a592..d29b589c 100644
--- a/src/libs/zbxjabber/jabber.c
+++ b/src/libs/zbxjabber/jabber.c
@@ -62,14 +62,14 @@ typedef struct jabber_session {
static jabber_session_p jsess = NULL;
-int on_result (jabber_session_p sess, ikspak *pak)
+static int on_result (jabber_session_p sess, ikspak *pak)
{
zabbix_log (LOG_LEVEL_DEBUG, "JABBER: ready");
sess->status = JABBER_READY;
return IKS_FILTER_EAT;
}
-int disconnect_jabber()
+static int disconnect_jabber()
{
zabbix_log(LOG_LEVEL_INFORMATION, "JABBER: disconnecting");
iks_disconnect(jsess->prs);
@@ -79,7 +79,7 @@ int disconnect_jabber()
return SUCCEED;
}
-int on_stream (jabber_session_p sess, int type, iks *node)
+static int on_stream (jabber_session_p sess, int type, iks *node)
{
iks *x = NULL;
ikspak *pak = NULL;
@@ -154,13 +154,13 @@ int on_stream (jabber_session_p sess, int type, iks *node)
return IKS_OK;
}
-int on_error (void *user_data, ikspak *pak)
+static int on_error (void *user_data, ikspak *pak)
{
zabbix_log (LOG_LEVEL_WARNING, "JABBER: authorization failed");
return IKS_FILTER_EAT;
}
-void on_log (jabber_session_p sess, const char *data, size_t size, int is_incoming)
+static void on_log (jabber_session_p sess, const char *data, size_t size, int is_incoming)
{
char msg[16] = "";
if (iks_is_secure (sess->prs)) strcat(msg, "Sec");
@@ -168,7 +168,7 @@ void on_log (jabber_session_p sess, const char *data, size_t size, int is_incomi
zabbix_log(LOG_LEVEL_DEBUG, "%s [%s]\n", msg, data);
}
-void j_setup_filter (jabber_session_p sess)
+static void j_setup_filter (jabber_session_p sess)
{
if (sess->my_filter) iks_filter_delete (sess->my_filter);
sess->my_filter = iks_filter_new ();
@@ -184,7 +184,7 @@ void j_setup_filter (jabber_session_p sess)
IKS_RULE_DONE);
}
-int connect_jabber(char *jabber_id, char *password, int use_sasl, char *error, int len)
+static int connect_jabber(char *jabber_id, char *password, int use_sasl, char *error, int len)
{
char *buf = NULL;
@@ -274,7 +274,8 @@ int send_jabber(char *username, char *passwd, char *sendto, char *message, char
zabbix_log( LOG_LEVEL_DEBUG, "JABBER: sending message");
if (NULL == jsess || jsess->status == JABBER_DISCONNECTED || jsess->status == JABBER_ERROR) {
- connect_jabber(username, passwd, 1, error, max_error_len);
+ if (SUCCEED != connect_jabber(username, passwd, 1, error, max_error_len))
+ return FAIL;
}
if ( NULL == (x = iks_new ("message")) ||
diff --git a/src/libs/zbxlog/log.c b/src/libs/zbxlog/log.c
index 0be91741..3fdb06cd 100644
--- a/src/libs/zbxlog/log.c
+++ b/src/libs/zbxlog/log.c
@@ -104,7 +104,7 @@ int zabbix_open_log(int type, int level, const char *filename)
return FAIL;
}
- if(ZBX_MUTEX_ERROR == zbx_mutex_create(&log_file_access, ZBX_MUTEX_LOG))
+ if(ZBX_MUTEX_ERROR == zbx_mutex_create_force(&log_file_access, ZBX_MUTEX_LOG))
{
zbx_error("Unable to create mutex for log file");
return FAIL;
@@ -124,7 +124,7 @@ int zabbix_open_log(int type, int level, const char *filename)
{
/* Not supported logging type */
- if(ZBX_MUTEX_ERROR == zbx_mutex_create(&log_file_access, ZBX_MUTEX_LOG))
+ if(ZBX_MUTEX_ERROR == zbx_mutex_create_force(&log_file_access, ZBX_MUTEX_LOG))
{
zbx_error("Unable to create mutex for log file");
return FAIL;
diff --git a/src/libs/zbxnet/security.c b/src/libs/zbxnet/security.c
index 4a4376d6..9f66a4d1 100644
--- a/src/libs/zbxnet/security.c
+++ b/src/libs/zbxnet/security.c
@@ -17,17 +17,6 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-
-//#include <sys/types.h>
-//#include <sys/socket.h>
-//#include <netinet/in.h>
-//#include <arpa/inet.h>
-//#include <netdb.h>
-
-//#include <string.h>
-
-//#include <errno.h>
-
#include "common.h"
#include "zbxsock.h"
#include "log.h"
diff --git a/src/libs/zbxnix/daemon.c b/src/libs/zbxnix/daemon.c
index 9063605f..3a3deb9d 100644
--- a/src/libs/zbxnix/daemon.c
+++ b/src/libs/zbxnix/daemon.c
@@ -20,6 +20,7 @@
#include "common.h"
#include "daemon.h"
+#include "mutexs.h"
#include "pid.h"
#include "cfg.h"
#include "log.h"
@@ -147,7 +148,7 @@ int daemon_start(int allow_root)
#endif /* HAVE_SYS_RESOURCE_SETPRIORITY */
-//------------------------------------------------
+/*------------------------------------------------*/
if( FAIL == create_pid_file(APP_PID_FILE))
{
diff --git a/src/libs/zbxsys/mutexs.c b/src/libs/zbxsys/mutexs.c
index c392e38d..292c1032 100644
--- a/src/libs/zbxsys/mutexs.c
+++ b/src/libs/zbxsys/mutexs.c
@@ -47,21 +47,23 @@
/******************************************************************************
* *
- * Function: zbx_mutex_create *
+ * Function: zbx_mutex_create_ext *
* *
* Purpose: Create the mutex *
* *
* Parameters: mutex - handle of mutex *
+ * name - name of mutex (index for nix system) *
+ * forced - remove mutex if exist (only for nix) *
* *
* Return value: If the function succeeds, the return ZBX_MUTEX_OK, *
* ZBX_MUTEX_ERROR on an error *
* *
* Author: Eugene Grigorjev *
* *
- * Comments: *
+ * Comments: you can use alias 'zbx_mutex_create' and 'zbx_mutex_create_force'*
* *
******************************************************************************/
-int zbx_mutex_create(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name)
+int zbx_mutex_create_ext(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name, unsigned char forced)
{
#if defined(_WINDOWS)
@@ -89,11 +91,11 @@ int zbx_mutex_create(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name)
}
}
+lbl_create:
if ( -1 != (ZBX_SEM_LIST_ID = semget(sem_key, ZBX_MUTEX_COUNT, IPC_CREAT | IPC_EXCL | 0666 /* 0022 */)) )
{
/* set default semaphore value */
semopts.val = 1;
-
for ( i = 0; i < ZBX_MUTEX_COUNT; i++ )
{
if(-1 == semctl(ZBX_SEM_LIST_ID, i, SETVAL, semopts))
@@ -110,6 +112,11 @@ int zbx_mutex_create(ZBX_MUTEX *mutex, ZBX_MUTEX_NAME name)
{
ZBX_SEM_LIST_ID = semget(sem_key, ZBX_MUTEX_COUNT, 0666 /* 0022 */);
semopts.buf = &seminfo;
+
+ if(forced) {
+ semctl(ZBX_SEM_LIST_ID, 0, IPC_RMID, 0);
+ goto lbl_create;
+ }
/* wait for initialization */
for ( i = 0; i < ZBX_MUTEX_MAX_TRIES; i++)
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index f72a7fd0..684d2964 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -941,7 +941,7 @@ int getPROC2(char *file, char *param, int fieldno, unsigned flags, int type, AGE
return SYSINFO_RET_FAIL;
}
- // find line
+ /* find line */
found = 0;
while ( fgets(buf, MAX_STRING_LEN, f) != NULL )
{
@@ -954,8 +954,8 @@ int getPROC2(char *file, char *param, int fieldno, unsigned flags, int type, AGE
if (!found) return SYSINFO_RET_FAIL;
- // find field
- res = (char *)strtok(buf, " "); // btime field1 field2
+ /* find field */
+ res = (char *)strtok(buf, " "); /* btime field1 field2 */
for(i=1; i<=fieldno; i++)
{
res = (char *)strtok(NULL," ");
@@ -968,7 +968,7 @@ int getPROC2(char *file, char *param, int fieldno, unsigned flags, int type, AGE
return SYSINFO_RET_FAIL;
}
- // convert field to right type
+ /* convert field to right type */
switch (type)
{
case AR_UINT64:
@@ -1272,7 +1272,7 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
{
zabbix_log(LOG_LEVEL_DEBUG, "Unable to create process: '%s' [%s]", command, strerror_from_system(GetLastError()));
- // Remove temporary file
+ /* Remove temporary file */
CloseHandle(hOutput);
DeleteFile(szTempFile);
@@ -1292,7 +1292,7 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
cmd_result[len] = '\0';
- // Remove temporary file
+ /* Remove temporary file */
CloseHandle(hOutput);
DeleteFile(szTempFile);
diff --git a/src/zabbix_agent/diskdevices.c b/src/zabbix_agent/diskdevices.c
index ffa758b1..eb60ef8f 100644
--- a/src/zabbix_agent/diskdevices.c
+++ b/src/zabbix_agent/diskdevices.c
@@ -31,7 +31,7 @@ void collect_stats_diskdevices(ZBX_DISKDEVICES_DATA *pdiskdevices)
#if OFF && (!defined(_WINDOWS) || (defined(TODO) && defined(_WINDOWS)))
-//TODO!!! Make same as cpustat.c
+/*TODO!!! Make same as cpustat.c */
#include <netdb.h>
diff --git a/src/zabbix_agent/eventlog.c b/src/zabbix_agent/eventlog.c
index 51afe002..dd0a8267 100755
--- a/src/zabbix_agent/eventlog.c
+++ b/src/zabbix_agent/eventlog.c
@@ -27,7 +27,7 @@
#define MAX_INSERT_STRS 64
#define MAX_MSG_LENGTH 1024
-// open event logger and return number of records
+/* open event logger and return number of records */
static long zbx_open_eventlog(
char *source,
HANDLE *eventlog_handle,
@@ -42,17 +42,17 @@ static long zbx_open_eventlog(
*eventlog_handle = 0;
*pNumRecords = 0;
- eventlog_handle = OpenEventLog(NULL, source); // open log file
+ eventlog_handle = OpenEventLog(NULL, source); /* open log file */
if (!eventlog_handle) return GetLastError();
- GetNumberOfEventLogRecords(eventlog_handle,(unsigned long*)pNumRecords); // get number of records
+ GetNumberOfEventLogRecords(eventlog_handle,(unsigned long*)pNumRecords); /* get number of records */
GetOldestEventLogRecord(eventlog_handle,(unsigned long*)pLatestRecord);
return(0);
}
-// close event logger
+/* close event logger */
static long zbx_close_eventlog(HANDLE eventlog_handle)
{
if (eventlog_handle) CloseEventLog(eventlog_handle);
@@ -60,7 +60,7 @@ static long zbx_close_eventlog(HANDLE eventlog_handle)
return(0);
}
-// get Nth error from event log. 1 is the first.
+/* get Nth error from event log. 1 is the first. */
static long zbx_get_eventlog_message(
char *source,
HANDLE eventlog_handle,
@@ -83,9 +83,9 @@ static long zbx_get_eventlog_message(
DWORD Type;
HINSTANCE hLib = NULL; /* handle to the messagetable DLL */
char *pCh = NULL, *pFile = NULL, *pNextFile = NULL;
- char *aInsertStrs[MAX_INSERT_STRS]; // array of pointers to insert
+ char *aInsertStrs[MAX_INSERT_STRS]; /* array of pointers to insert */
long i;
- LPTSTR msgBuf = NULL; // hold text of the error message that we
+ LPTSTR msgBuf = NULL; /* hold text of the error message that we */
long err = 0;
if (!eventlog_handle) return(0);
@@ -104,16 +104,16 @@ static long zbx_get_eventlog_message(
return GetLastError();
}
- pELR = (EVENTLOGRECORD*)bBuffer; // point to data
+ pELR = (EVENTLOGRECORD*)bBuffer; /* point to data */
- *pTime = (double)pELR->TimeGenerated; // return double timestamp
- *pType = pELR->EventType; // return event type
- *pCategory = pELR->EventCategory; // return category
- *timestamp = pELR->TimeGenerated; // return timestamp
+ *pTime = (double)pELR->TimeGenerated; /* return double timestamp */
+ *pType = pELR->EventType; /* return event type */
+ *pCategory = pELR->EventCategory; /* return category */
+ *timestamp = pELR->TimeGenerated; /* return timestamp */
- strcpy(pSource,((char*)pELR + sizeof(EVENTLOGRECORD)));// copy source name
+ strcpy(pSource,((char*)pELR + sizeof(EVENTLOGRECORD)));/* copy source name */
-// Get path to message dll
+/* Get path to message dll */
strcpy(temp,"SYSTEM\\CurrentControlSet\\Services\\EventLog\\");
strcat(temp,source);
strcat(temp,"\\");
@@ -177,7 +177,7 @@ static long zbx_get_eventlog_message(
if(msgBuf)
{
- strcpy(pMessage,msgBuf); // copy message
+ strcpy(pMessage,msgBuf); /* copy message */
err = 0;
/* Free the buffer that FormatMessage allocated for us. */
diff --git a/src/zabbix_agent/interfaces.c b/src/zabbix_agent/interfaces.c
index e2d72b4a..eb34a43c 100644
--- a/src/zabbix_agent/interfaces.c
+++ b/src/zabbix_agent/interfaces.c
@@ -31,7 +31,7 @@ void collect_stats_interfaces(ZBX_INTERFACES_DATA *pinterfaces)
#if OFF && (!defined(_WINDOWS) || (defined(TODO) && defined(_WINDOWS)))
-//TODO!!! Make same as cpustat.c
+/*TODO!!! Make same as cpustat.c*/
#include <netdb.h>
diff --git a/src/zabbix_agent/zbxconf.c b/src/zabbix_agent/zbxconf.c
index 4640dcab..a74acf7d 100644
--- a/src/zabbix_agent/zbxconf.c
+++ b/src/zabbix_agent/zbxconf.c
@@ -86,7 +86,7 @@ void load_config(int exit_on_error)
{"EnableRemoteCommands",&CONFIG_ENABLE_REMOTE_COMMANDS, 0,TYPE_INT, PARM_OPT,0,1},
{"AllowRoot", &CONFIG_ALLOW_ROOT, 0,TYPE_INT, PARM_OPT,0,1},
-// {"PerfCounter", &CONFIG_PERF_COUNTER, 0, TYPE_STRING,PARM_OPT,0,0},
+/* {"PerfCounter", &CONFIG_PERF_COUNTER, 0, TYPE_STRING,PARM_OPT,0,0}, */
{"LogUnresolvedSymbols",&CONFIG_LOG_UNRES_SYMB, 0, TYPE_STRING,PARM_OPT,0,1},
diff --git a/src/zabbix_sender/zabbix_sender.c b/src/zabbix_sender/zabbix_sender.c
index e0dd611e..6d2ae83f 100644
--- a/src/zabbix_sender/zabbix_sender.c
+++ b/src/zabbix_sender/zabbix_sender.c
@@ -145,7 +145,7 @@ int main(int argc, char **argv)
{
int ret=SUCCEED;
char line[MAX_STRING_LEN];
- char port_str[MAX_STRING_LEN]="10051"; // default value
+ char port_str[MAX_STRING_LEN]="10051"; /* default value */
char zabbix_server[MAX_STRING_LEN]="";
char server[MAX_STRING_LEN]="";
char key[MAX_STRING_LEN]="";
@@ -188,7 +188,7 @@ int main(int argc, char **argv)
alarm(SENDER_TIMEOUT);
- //printf("Run with options: z=%s, p=%s, s=%s, k=%s, o=%s\n", zabbix_server, port_str, server, key, value);
+ /*printf("Run with options: z=%s, p=%s, s=%s, k=%s, o=%s\n", zabbix_server, port_str, server, key, value);*/
ret = send_value(zabbix_server, atoi(port_str), server, key, value,"0");
alarm(0);
@@ -221,7 +221,7 @@ int main(int argc, char **argv)
strscpy(key,s);
s=(char *)strtok(NULL," ");
strscpy(value,s);
- //printf("Run with options from file(%s): z=%s, s=%s, p=%s, k=%s, o=%s\n", input_file, zabbix_server, server, port_str, key, value);
+ /*printf("Run with options from file(%s): z=%s, s=%s, p=%s, k=%s, o=%s\n", input_file, zabbix_server, server, port_str, key, value);*/
ret = send_value(zabbix_server,atoi(port_str),server,key,value,"0");
alarm(0);
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index 1e9758c4..df743254 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -89,12 +89,12 @@ static void send_to_user_medias(DB_EVENT *event,DB_ACTION *action, zbx_uint64_t
zabbix_log( LOG_LEVEL_DEBUG, "Trigger severity [%d] Media severity [%d] Period [%s]",event->trigger_priority, media.severity, media.period);
if(((1<<event->trigger_priority)&media.severity)==0)
{
- zabbix_log( LOG_LEVEL_DEBUG, "Won't send message");
+ zabbix_log( LOG_LEVEL_DEBUG, "Won't send message (severity)");
continue;
}
if(check_time_period(media.period, (time_t)NULL) == 0)
{
- zabbix_log( LOG_LEVEL_DEBUG, "Won't send message");
+ zabbix_log( LOG_LEVEL_DEBUG, "Won't send message (period)");
continue;
}
diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c
index f8358c19..367a8c34 100644
--- a/src/zabbix_server/alerter/alerter.c
+++ b/src/zabbix_server/alerter/alerter.c
@@ -205,7 +205,6 @@ int main_alerter_loop()
now = time(NULL);
-/* zbx_snprintf(sql,sizeof(sql),"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path from alerts a,media_type mt where a.status=0 and a.retries<3 and a.mediatypeid=mt.mediatypeid order by a.clock"); */
result = DBselect("select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem,mt.username,mt.passwd from alerts a,media_type mt where a.status=%d and a.retries<3 and (a.repeats<a.maxrepeats or a.maxrepeats=0) and a.nextcheck<=%d and a.mediatypeid=mt.mediatypeid and " ZBX_COND_NODEID " order by a.clock", ALERT_STATUS_NOT_SENT, now, LOCAL_NODE("mt.mediatypeid"));
while((row=DBfetch(result)))
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index 1dde2fd0..3f8a1af3 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -89,7 +89,7 @@ void update_functions(DB_ITEM *item)
function.function=row[0];
function.parameter=row[1];
ZBX_STR2UINT64(function.itemid,row[2]);
-// function.itemid=atoi(row[2]);
+/* function.itemid=atoi(row[2]); */
lastvalue=row[3];
zabbix_log( LOG_LEVEL_DEBUG, "ItemId:" ZBX_FS_UI64 " Evaluating %s(%d)",
@@ -154,7 +154,6 @@ void update_services_rec(zbx_uint64_t serviceid)
while((row=DBfetch(result)))
{
ZBX_STR2UINT64(serviceupid,row[0]);
-// serviceupid=atoi(row[0]);
algorithm=atoi(row[1]);
if(SERVICE_ALGORITHM_NONE == algorithm)
{
diff --git a/src/zabbix_server/httppoller/httptest.c b/src/zabbix_server/httppoller/httptest.c
index 7ebdf8c7..99341108 100644
--- a/src/zabbix_server/httppoller/httptest.c
+++ b/src/zabbix_server/httppoller/httptest.c
@@ -104,8 +104,10 @@ static size_t WRITEFUNCTION2( void *ptr, size_t size, size_t nmemb, void *stream
static size_t HEADERFUNCTION2( void *ptr, size_t size, size_t nmemb, void *stream)
{
-// ZBX_LIM_PRINT("HEADERFUNCTION", size*nmemb, ptr, 300);
-// zabbix_log(LOG_LEVEL_WARNING, "In HEADERFUNCTION");
+/*
+ ZBX_LIM_PRINT("HEADERFUNCTION", size*nmemb, ptr, 300);
+ zabbix_log(LOG_LEVEL_WARNING, "In HEADERFUNCTION");
+*/
return size*nmemb;
}
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index e3327163..ad19f3b6 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -333,8 +333,16 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp)
void test()
{
+ char error[MAX_STRING_LEN];
+
printf("-= Test Started =-\n");
+ printf("send_jabber result '%i'\n",
+ send_jabber("zabbix@xmpp.ru", "zabbixthebest", "zabbix@xmpp.ru", "test from ZABBIX server", error, sizeof(error))
+ );
+
+ printf("send_jabber error: '%s'\n", error);
+
printf("\n-= Test completed =-\n");
}
#endif /* TEST */
@@ -454,6 +462,8 @@ int main(int argc, char **argv)
zabbix_log( LOG_LEVEL_WARNING, "Starting zabbix_server. ZABBIX %s.", ZABBIX_VERSION);
test();
+
+ zbx_on_exit();
return 0;
#endif /* TEST */
diff --git a/src/zabbix_server/trapper/active.c b/src/zabbix_server/trapper/active.c
index 465785c5..1993f2d2 100644
--- a/src/zabbix_server/trapper/active.c
+++ b/src/zabbix_server/trapper/active.c
@@ -74,7 +74,7 @@ int send_list_of_active_checks(zbx_sock_t *sock, char *host)
{
zbx_snprintf(s,sizeof(s),"%s:%s:%s\n",row[0],row[1],row[2]);
zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s);
-// if( write(sockfd,s,strlen(s)) == -1 )
+/* if( write(sockfd,s,strlen(s)) == -1 ) */
if( zbx_tcp_send(sock,s) != SUCCEED )
{
zabbix_log( LOG_LEVEL_WARNING, "Error while sending list of active checks");
@@ -86,7 +86,7 @@ int send_list_of_active_checks(zbx_sock_t *sock, char *host)
zbx_snprintf(s,sizeof(s),"%s\n","ZBX_EOF");
zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s);
-// if( write(sockfd,s,strlen(s)) == -1 )
+/* if( write(sockfd,s,strlen(s)) == -1 ) */
if( zbx_tcp_send(sock,s) != SUCCEED )
{
zabbix_log( LOG_LEVEL_WARNING, "Error while sending list of active checks");
diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c
index e97c3a00..62673d24 100644
--- a/src/zabbix_server/trapper/trapper.c
+++ b/src/zabbix_server/trapper/trapper.c
@@ -106,12 +106,12 @@ int process_trap(zbx_sock_t *sock,char *s, int max_len)
/* Node data exchange? */
if(strncmp(s,"Data",4) == 0)
{
-// zabbix_log( LOG_LEVEL_WARNING, "Node data received [len:%d]", strlen(s));
+/* zabbix_log( LOG_LEVEL_WARNING, "Node data received [len:%d]", strlen(s)); */
if(node_sync(s) == SUCCEED)
{
zbx_snprintf(result,sizeof(result),"OK\n");
if( zbx_tcp_send(sock,result) != SUCCEED)
-// if( write(sockfd,result,strlen(result)) == -1)
+/* if( write(sockfd,result,strlen(result)) == -1) */
{
zabbix_log( LOG_LEVEL_WARNING, "Error sending confirmation to node");
zabbix_syslog("Trapper: error sending confirmation to node");
@@ -122,11 +122,11 @@ int process_trap(zbx_sock_t *sock,char *s, int max_len)
/* Slave node events? */
if(strncmp(s,"Events",6) == 0)
{
-// zabbix_log( LOG_LEVEL_WARNING, "Slave node events received [len:%d]", strlen(s));
+/* zabbix_log( LOG_LEVEL_WARNING, "Slave node events received [len:%d]", strlen(s)); */
if(node_events(s) == SUCCEED)
{
zbx_snprintf(result,sizeof(result),"OK\n");
-// if( write(sockfd,result,strlen(result)) == -1)
+/* if( write(sockfd,result,strlen(result)) == -1) */
if( zbx_tcp_send(sock,result) != SUCCEED)
{
zabbix_log( LOG_LEVEL_WARNING, "Error sending confirmation to node");
@@ -138,11 +138,11 @@ int process_trap(zbx_sock_t *sock,char *s, int max_len)
/* Slave node history ? */
if(strncmp(s,"History",7) == 0)
{
-// zabbix_log( LOG_LEVEL_WARNING, "Slave node history received [len:%d]", strlen(s));
+/* zabbix_log( LOG_LEVEL_WARNING, "Slave node history received [len:%d]", strlen(s)); */
if(node_history(s) == SUCCEED)
{
zbx_snprintf(result,sizeof(result),"OK\n");
-// if( write(sockfd,result,strlen(result)) == -1)
+/* if( write(sockfd,result,strlen(result)) == -1) */
if( zbx_tcp_send(sock,result) != SUCCEED)
{
zabbix_log( LOG_LEVEL_WARNING, "Error sending confirmation to node]");
@@ -206,10 +206,10 @@ int process_trap(zbx_sock_t *sock,char *s, int max_len)
{
zbx_snprintf(result,sizeof(result),"NOT OK");
}
-// zabbix_log( LOG_LEVEL_WARNING, "Sending back [%s]", result);
+/* zabbix_log( LOG_LEVEL_WARNING, "Sending back [%s]", result); */
zabbix_log( LOG_LEVEL_DEBUG, "Length [%d]", strlen(result));
if( zbx_tcp_send(sock,result) != SUCCEED)
-// if( write(sockfd,result,strlen(result)) == -1)
+/* if( write(sockfd,result,strlen(result)) == -1) */
{
zabbix_log( LOG_LEVEL_WARNING, "Error sending result back");
zabbix_syslog("Trapper: error sending result back");