Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--include/threads.h6
-rw-r--r--include/zbxexec.h3
-rw-r--r--src/libs/zbxexec/execute.c322
-rw-r--r--src/libs/zbxicmpping/icmpping.c10
-rw-r--r--src/libs/zbxlog/log.c36
-rw-r--r--src/libs/zbxmedia/jabber.c10
-rw-r--r--src/libs/zbxnix/daemon.c154
-rw-r--r--src/libs/zbxsys/threads.c14
-rw-r--r--src/libs/zbxsysinfo/aix/cpu.c2
-rw-r--r--src/libs/zbxsysinfo/common/common.c96
-rw-r--r--src/libs/zbxsysinfo/osf/swap.c2
-rw-r--r--src/libs/zbxsysinfo/osx/swap.c2
-rw-r--r--src/zabbix_agent/cpustat.c10
-rw-r--r--src/zabbix_agent/listener.c4
-rw-r--r--src/zabbix_agent/listener.h2
-rw-r--r--src/zabbix_agent/stats.c4
-rw-r--r--src/zabbix_agent/zabbix_agent.c6
-rw-r--r--src/zabbix_agent/zabbix_agentd.c2
-rw-r--r--src/zabbix_proxy/proxy.c6
-rw-r--r--src/zabbix_server/alerter/alerter.c33
-rw-r--r--src/zabbix_server/server.c6
-rw-r--r--src/zabbix_server/trapper/nodehistory.c2
23 files changed, 389 insertions, 344 deletions
diff --git a/ChangeLog b/ChangeLog
index e0412a8ba4a..5fddd54f018 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -167,6 +167,7 @@ New features:
--------------------------------------------------------------------------------
Changes for 1.8.6rc1
+ - [ZBX-3519] fixed unterminated processes when system.run[,wait] times out and added proper output handling for system.run[,nowait] on UNIX (rudolfs)
- [ZBX-3768] fixed 'uptime' and 's' units as according to the documentation (Sasha)
- [ZBX-3490] added support for LVM devices and full path to devices to vfs.dev.read and vfs.dev.write; thanks to Takanori Suzuki (dimir, sasha)
- [ZBX-3862] fixed broken popups in frontend in Internet Explorer 7 (KB)
diff --git a/include/threads.h b/include/threads.h
index 0e46b26fdaf..82d4019b371 100644
--- a/include/threads.h
+++ b/include/threads.h
@@ -43,7 +43,7 @@
#define zbx_thread_kill(h) TerminateThread(h, SUCCEED);
-#else /* not _WINDOWS */
+#else /* not _WINDOWS */
int zbx_fork();
@@ -66,7 +66,7 @@
#define zbx_thread_kill(h) kill(h, SIGTERM);
-#endif /* _WINDOWS */
+#endif /* _WINDOWS */
typedef struct
{
@@ -80,4 +80,4 @@ int zbx_thread_wait(ZBX_THREAD_HANDLE thread);
/* zbx_thread_exit(status) -- declared as define !!! */
long int zbx_get_thread_id();
-#endif /* ZABBIX_THREADS_H */
+#endif /* ZABBIX_THREADS_H */
diff --git a/include/zbxexec.h b/include/zbxexec.h
index d870eff04d3..46bb0047c9c 100644
--- a/include/zbxexec.h
+++ b/include/zbxexec.h
@@ -21,5 +21,6 @@
#define ZABBIX_ZBXEXEC_H
int zbx_execute(const char *command, char **buffer, char *error, size_t max_error_len, int timeout);
+int zbx_execute_nowait(const char *command);
-#endif /* ZABBIX_ZBXEXEC_H */
+#endif
diff --git a/src/libs/zbxexec/execute.c b/src/libs/zbxexec/execute.c
index 487f06fda9d..ae54cbf416d 100644
--- a/src/libs/zbxexec/execute.c
+++ b/src/libs/zbxexec/execute.c
@@ -36,8 +36,6 @@
* *
* Author: Alexander Vladishev *
* *
- * Comments: *
- * *
******************************************************************************/
static int zbx_get_timediff_ms(struct _timeb *time1, struct _timeb *time2)
{
@@ -67,8 +65,6 @@ static int zbx_get_timediff_ms(struct _timeb *time1, struct _timeb *time2)
* *
* Author: Alexander Vladishev *
* *
- * Comments: *
- * *
******************************************************************************/
static int zbx_read_from_pipe(HANDLE hRead, char **buf, size_t buf_size, int timeout_ms)
{
@@ -94,13 +90,13 @@ static int zbx_read_from_pipe(HANDLE hRead, char **buf, size_t buf_size, int tim
if (zbx_get_timediff_ms(&start_time, &current_time) >= timeout_ms)
return TIMEOUT_ERROR;
- Sleep(20);
+ Sleep(20); /* milliseconds */
}
return SUCCEED;
}
-#else /* not _WINDOWS */
+#else /* not _WINDOWS */
/******************************************************************************
* *
@@ -118,8 +114,6 @@ static int zbx_read_from_pipe(HANDLE hRead, char **buf, size_t buf_size, int tim
* *
* Author: Alexander Vladishev *
* *
- * Comments: *
- * *
******************************************************************************/
static int zbx_popen(pid_t *pid, const char *command)
{
@@ -138,7 +132,7 @@ static int zbx_popen(pid_t *pid, const char *command)
return -1;
}
- if (*pid > 0) /* parent process */
+ if (0 != *pid) /* parent process */
{
close(fd[1]);
@@ -152,11 +146,21 @@ static int zbx_popen(pid_t *pid, const char *command)
dup2(fd[1], STDOUT_FILENO);
close(fd[1]);
- zabbix_log(LOG_LEVEL_DEBUG, "%s() executing script", __function_name);
+ /* set the child as the process group leader, otherwise orphans may be left after timeout */
+ if (-1 == setpgid(0, 0))
+ {
+ zabbix_log(LOG_LEVEL_ERR, "%s(): failed to create a process group: %s",
+ __function_name, zbx_strerror(errno));
+ exit(0);
+ }
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s(): executing script", __function_name);
execl("/bin/sh", "sh", "-c", command, NULL);
- zabbix_log(LOG_LEVEL_DEBUG, "%s() cannot execute script [%s]: %s", __function_name, command, zbx_strerror(errno));
- exit(FAIL);
+
+ /* execl() returns only when an error occurs */
+ zabbix_log(LOG_LEVEL_WARNING, "execl() failed for [%s]: %s", command, zbx_strerror(errno));
+ exit(0);
}
/******************************************************************************
@@ -172,8 +176,6 @@ static int zbx_popen(pid_t *pid, const char *command)
* *
* Author: Alexander Vladishev *
* *
- * Comments: *
- * *
******************************************************************************/
static int zbx_waitpid(pid_t pid)
{
@@ -233,41 +235,37 @@ exit:
* error - [OUT] error string if function fails *
* max_error_len - [IN] length of error buffer *
* *
- * Return value: SUCCEED if processed successfully, FAIL - otherwise *
+ * Return value: SUCCEED if processed successfully, TIMEOUT_ERROR if *
+ * timeout occurred or FAIL otherwise *
* *
* Author: Alexander Vladishev *
* *
- * Comments: *
- * *
******************************************************************************/
int zbx_execute(const char *command, char **buffer, char *error, size_t max_error_len, int timeout)
{
+ char *p = NULL;
+ size_t buf_size = MAX_BUFFER_LEN;
+ int ret = FAIL;
#ifdef _WINDOWS
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ SECURITY_ATTRIBUTES sa;
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits;
+ HANDLE job = NULL, hWrite = NULL, hRead = NULL;
+ char *cmd = NULL;
+ LPTSTR wcmd = NULL;
+ struct _timeb start_time, current_time;
+#else
+ pid_t pid;
+ int fd;
+#endif
- STARTUPINFO si = {0};
- PROCESS_INFORMATION pi = {0};
- SECURITY_ATTRIBUTES sa;
- HANDLE hWrite = NULL, hRead = NULL;
- char *cmd = NULL;
- LPTSTR wcmd = NULL;
- struct _timeb start_time, current_time;
-
-#else /* not _WINDOWS */
-
- pid_t pid;
- int fd;
-
-#endif /* _WINDOWS */
-
- char *p = NULL;
- size_t buf_size = MAX_BUFFER_LEN;
- int ret = SUCCEED;
-
- assert(timeout);
+ *error = '\0';
if (NULL != buffer)
{
- *buffer = p = zbx_realloc(*buffer, buf_size);
+ p = zbx_realloc(*buffer, buf_size);
+ *buffer = p;
buf_size--; /* '\0' */
}
@@ -281,9 +279,31 @@ int zbx_execute(const char *command, char **buffer, char *error, size_t max_erro
/* create a pipe for the child process's STDOUT */
if (0 == CreatePipe(&hRead, &hWrite, &sa, 0))
{
- zbx_snprintf(error, max_error_len, "unable to create pipe: %s", strerror_from_system(GetLastError()));
- ret = FAIL;
- goto lbl_exit;
+ zbx_snprintf(error, max_error_len, "unable to create a pipe: %s", strerror_from_system(GetLastError()));
+ goto close;
+ }
+
+ /* create a new job where the script will be executed */
+ if (0 == (job = CreateJobObject(&sa, NULL)))
+ {
+ zbx_snprintf(error, max_error_len, "unable to create a job: %s", strerror_from_system(GetLastError()));
+ goto close;
+ }
+
+ /* get the current job limits */
+ if (0 == QueryInformationJobObject(job, JobObjectExtendedLimitInformation, &limits, sizeof(limits), 0))
+ {
+ zbx_snprintf(error, max_error_len, "unable to query job info: %s", strerror_from_system(GetLastError()));
+ goto close;
+ }
+
+ /* set job limits to kill all child processes when terminating the job */
+ limits.BasicLimitInformation.LimitFlags &= ~JOB_OBJECT_LIMIT_BREAKAWAY_OK;
+ limits.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+ if (0 == SetInformationJobObject(job, JobObjectExtendedLimitInformation, &limits, sizeof(limits)))
+ {
+ zbx_snprintf(error, max_error_len, "unable to set job info: %s", strerror_from_system(GetLastError()));
+ goto close;
}
/* fill in process startup info structure */
@@ -294,68 +314,75 @@ int zbx_execute(const char *command, char **buffer, char *error, size_t max_erro
si.hStdOutput = hWrite;
si.hStdError = hWrite;
+ /* use cmd command to support scripts */
cmd = zbx_dsprintf(cmd, "cmd /C \"%s\"", command);
wcmd = zbx_utf8_to_unicode(cmd);
- /* create new process */
- if (0 == CreateProcess(NULL, wcmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
+ /* create the new process */
+ if (0 == CreateProcess(NULL, wcmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, &pi))
{
- zbx_snprintf(error, max_error_len, "unable to create process: '%s': %s",
+ zbx_snprintf(error, max_error_len, "unable to create process [%s]: %s",
cmd, strerror_from_system(GetLastError()));
- ret = FAIL;
- goto lbl_exit;
+ goto close;
}
CloseHandle(hWrite);
hWrite = NULL;
+ /* assign the new process to the created job */
+ if (0 == AssignProcessToJobObject(job, pi.hProcess))
+ {
+ zbx_snprintf(error, max_error_len, "unable to assign process [%s] to a job: %s",
+ cmd, strerror_from_system(GetLastError()));
+ if (0 == TerminateProcess(pi.hProcess, 0))
+ {
+ zabbix_log(LOG_LEVEL_ERR, "failed to terminate [%s]: %s",
+ cmd, strerror_from_system(GetLastError()));
+ }
+ }
+ else if (-1 == ResumeThread(pi.hThread))
+ {
+ zbx_snprintf(error, max_error_len, "unable to assign process [%s] to a job: %s",
+ cmd, strerror_from_system(GetLastError()));
+ }
+ else
+ ret = SUCCEED;
+
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+
+ if (FAIL == ret)
+ goto close;
+
_ftime(&start_time);
timeout *= 1000;
- if (NULL != buffer)
- {
- if (SUCCEED == (ret = zbx_read_from_pipe(hRead, &p, buf_size, timeout)))
- *p = '\0';
- }
+ if (NULL != buffer && SUCCEED == (ret = zbx_read_from_pipe(hRead, &p, buf_size, timeout)))
+ *p = '\0';
if (TIMEOUT_ERROR != ret)
{
_ftime(&current_time);
- if (0 < (timeout -= zbx_get_timediff_ms(&start_time, &current_time)))
+ if (0 < (timeout -= zbx_get_timediff_ms(&start_time, &current_time)) &&
+ WAIT_TIMEOUT == WaitForSingleObject(pi.hProcess, timeout))
{
- if (WAIT_TIMEOUT == WaitForSingleObject(pi.hProcess, timeout))
- ret = TIMEOUT_ERROR;
+ ret = TIMEOUT_ERROR;
}
}
-
- /* wait for child process to exit */
- if (TIMEOUT_ERROR == ret)
+close:
+ if (NULL != job)
{
- zbx_strlcpy(error, "Timeout while executing a shell script", max_error_len);
- ret = FAIL;
+ /* terminate the child process and it's childs */
+ if (0 == TerminateJobObject(job, 0))
+ zabbix_log(LOG_LEVEL_ERR, "failed to terminate job [%s]: %s", cmd, strerror_from_system(GetLastError()));
+ CloseHandle(job);
}
- /* terminate child process */
- TerminateProcess(pi.hProcess, 0);
-
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
-
- CloseHandle(hRead);
- hRead = NULL;
-
-lbl_exit:
if (NULL != hWrite)
- {
CloseHandle(hWrite);
- hWrite = NULL;
- }
if (NULL != hRead)
- {
CloseHandle(hRead);
- hRead = NULL;
- }
zbx_free(cmd);
zbx_free(wcmd);
@@ -382,44 +409,145 @@ lbl_exit:
close(fd);
- if (-1 == rc)
+ if (-1 == rc || -1 == zbx_waitpid(pid))
{
if (EINTR == errno)
- zbx_strlcpy(error, "timeout while executing a shell script", max_error_len);
+ ret = TIMEOUT_ERROR;
else
- zbx_strlcpy(error, zbx_strerror(errno), max_error_len);
+ zbx_snprintf(error, max_error_len, "zbx_waitpid() failed: %s", zbx_strerror(errno));
+
+ /* kill the whole process group, pid must be the leader */
+ if (-1 == kill(-pid, SIGTERM))
+ zabbix_log(LOG_LEVEL_ERR, "failed to kill [%s]: %s", command, zbx_strerror(errno));
- kill(pid, SIGTERM);
zbx_waitpid(pid);
- ret = FAIL;
}
else
- {
- if (-1 == zbx_waitpid(pid))
- {
- if (EINTR == errno)
- zbx_strlcpy(error, "timeout while executing a shell script", max_error_len);
- else
- zbx_strlcpy(error, zbx_strerror(errno), max_error_len);
-
- kill(pid, SIGTERM);
- zbx_waitpid(pid);
- ret = FAIL;
- }
- }
+ ret = SUCCEED;
}
else
- {
zbx_strlcpy(error, zbx_strerror(errno), max_error_len);
- ret = FAIL;
- }
alarm(0);
#endif /* _WINDOWS */
- if (FAIL == ret && NULL != buffer)
+ if (TIMEOUT_ERROR == ret)
+ zbx_strlcpy(error, "timeout while executing a shell script", max_error_len);
+ else if ('\0' != *error)
+ zabbix_log(LOG_LEVEL_WARNING, "%s", error);
+
+ if (SUCCEED != ret && NULL != buffer)
zbx_free(*buffer);
return ret;
}
+
+/******************************************************************************
+ * *
+ * Function: zbx_execute_nowait *
+ * *
+ * Purpose: this function executes a script in the background and *
+ * suppresses the std output *
+ * *
+ * Parameters: command - [IN] command for execution *
+ * *
+ * Author: Rudolfs Kreicbergs *
+ * *
+ ******************************************************************************/
+int zbx_execute_nowait(const char *command)
+{
+#ifdef _WINDOWS
+ const char *__function_name = "zbx_execute_nowait";
+
+ char *full_command;
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ LPTSTR wcommand;
+
+ full_command = zbx_dsprintf(NULL, "cmd /C \"%s\"", command);
+ wcommand = zbx_utf8_to_unicode(full_command);
+
+ /* fill in process startup info structure */
+ memset(&si, 0, sizeof(si));
+ si.cb = sizeof(si);
+ GetStartupInfo(&si);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "%s(): executing [%s]", __function_name, full_command);
+
+ if (0 == CreateProcess(
+ NULL, /* no module name (use command line) */
+ wcommand, /* name of app to launch */
+ NULL, /* default process security attributes */
+ NULL, /* default thread security attributes */
+ FALSE, /* do not inherit handles from the parent */
+ 0, /* normal priority */
+ NULL, /* use the same environment as the parent */
+ NULL, /* launch in the current directory */
+ &si, /* startup information */
+ &pi)) /* process information stored upon return */
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "failed to create process for [%s]: %s",
+ full_command, strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+
+ zbx_free(wcommand);
+ zbx_free(full_command);
+
+ return SUCCEED;
+
+#else /* not _WINDOWS */
+ pid_t pid;
+
+ /* use a double fork for running the command in background */
+ if (-1 == (pid = zbx_fork()))
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "first fork() failed for executing [%s]: %s",
+ command, zbx_strerror(errno));
+ return FAIL;
+ }
+ else if (0 != pid)
+ {
+ waitpid(pid, NULL, 0);
+ return SUCCEED;
+ }
+
+ /* This is the child process. Now create a grand child process which */
+ /* will be replaced by execl() with the actual command to be executed. */
+
+ pid = zbx_fork();
+
+ switch (pid)
+ {
+ case -1:
+ zabbix_log(LOG_LEVEL_WARNING, "second fork() failed for executing [%s]: %s",
+ command, zbx_strerror(errno));
+ break;
+ case 0:
+ /* this is the grand child process */
+
+ /* suppress the output of the executed script, otherwise */
+ /* the output might get written to a logfile or elsewhere */
+ redirect_std(NULL);
+
+ /* replace the process with actual command to be executed */
+ execl("/bin/sh", "sh", "-c", command, NULL);
+
+ /* execl() returns only when an error occurs */
+ zabbix_log(LOG_LEVEL_WARNING, "execl() failed for [%s]: %s", command, zbx_strerror(errno));
+ break;
+ default:
+ /* this is the child process, exit to complete the double fork */
+
+ waitpid(pid, NULL, WNOHANG);
+ break;
+ }
+
+ /* always exit, parent has already returned */
+ exit(0);
+#endif
+}
diff --git a/src/libs/zbxicmpping/icmpping.c b/src/libs/zbxicmpping/icmpping.c
index b26bfd0e160..d5d65d3e334 100644
--- a/src/libs/zbxicmpping/icmpping.c
+++ b/src/libs/zbxicmpping/icmpping.c
@@ -27,7 +27,7 @@ extern char *CONFIG_SOURCE_IP;
extern char *CONFIG_FPING_LOCATION;
#ifdef HAVE_IPV6
extern char *CONFIG_FPING6_LOCATION;
-#endif /* HAVE_IPV6 */
+#endif
extern char *CONFIG_TMPDIR;
/* official fping does not support source IP address */
@@ -38,7 +38,7 @@ static const char *source_ip_option = NULL;
#ifdef HAVE_IPV6
static unsigned char source_ip6_checked = 0;
static const char *source_ip6_option = NULL;
-#endif /* HAVE_IPV6 */
+#endif
static void get_source_ip_option(const char *fping, const char **option, unsigned char *checked)
{
@@ -101,10 +101,10 @@ static int process_ping(ZBX_FPING_HOST *hosts, int hosts_count, int count, int i
if (-1 == access(CONFIG_FPING_LOCATION, F_OK | X_OK))
{
-#ifndef HAVE_IPV6
+#if !defined(HAVE_IPV6)
zbx_snprintf(error, max_error_len, "%s: %s", CONFIG_FPING_LOCATION, zbx_strerror(errno));
return ret;
-#endif /* HAVE_IPV6 */
+#endif
}
else
{
@@ -120,7 +120,7 @@ static int process_ping(ZBX_FPING_HOST *hosts, int hosts_count, int count, int i
return ret;
}
}
-#endif /* HAVE_IPV6 */
+#endif
}
#ifdef HAVE_IPV6
diff --git a/src/libs/zbxlog/log.c b/src/libs/zbxlog/log.c
index 275f77356e3..3e395885876 100644
--- a/src/libs/zbxlog/log.c
+++ b/src/libs/zbxlog/log.c
@@ -39,29 +39,30 @@ static int log_level = LOG_LEVEL_WARNING;
#define ZBX_MESSAGE_BUF_SIZE 1024
#if !defined(_WINDOWS)
-void redirect_std(const char *filename)
+void redirect_std(const char *filename)
{
- int fd;
- const char default_file[] = "/dev/null";
- const char *out_file = default_file;
- int open_flags = O_WRONLY;
+ int fd;
+ const char default_file[] = "/dev/null";
+ const char *out_file = default_file;
+ int open_flags = O_WRONLY;
- close(fileno(stdin));
- open(default_file, O_RDONLY); /* stdin, normally fd==0 */
+ close(STDIN_FILENO);
+ open(default_file, O_RDONLY); /* stdin, normally fd==0 */
- if ( filename && *filename)
+ if (NULL != filename && '\0' != *filename)
{
out_file = filename;
open_flags |= O_CREAT | O_APPEND;
}
- if ( -1 != (fd = open(out_file, open_flags, 0666)) )
+ if (-1 != (fd = open(out_file, open_flags, 0666)))
{
- if (-1 == dup2(fd, fileno(stderr)))
+ if (-1 == dup2(fd, STDERR_FILENO))
zbx_error("cannot redirect stderr to [%s]", filename);
- if (-1 == dup2(fd, fileno(stdout)))
+ if (-1 == dup2(fd, STDOUT_FILENO))
zbx_error("cannot redirect stdout to [%s]", filename);
+
close(fd);
}
else
@@ -82,14 +83,10 @@ int zabbix_open_log(int type, int level, const char *filename)
log_level = level;
if (LOG_LEVEL_EMPTY == level)
- {
return SUCCEED;
- }
if (LOG_TYPE_FILE == type && NULL == filename)
- {
type = LOG_TYPE_SYSLOG;
- }
if (LOG_TYPE_SYSLOG == type)
{
@@ -241,11 +238,11 @@ void __zbx_zabbix_log(int level, const char *fmt, ...)
milliseconds
);
- va_start(args,fmt);
- vfprintf(log_file,fmt, args);
+ va_start(args, fmt);
+ vfprintf(log_file, fmt, args);
va_end(args);
- fprintf(log_file,"\n");
+ fprintf(log_file, "\n");
zbx_fclose(log_file);
if (0 != CONFIG_LOG_FILE_SIZE && 0 == stat(log_filename, &buf))
@@ -296,8 +293,7 @@ void __zbx_zabbix_log(int level, const char *fmt, ...)
break;
}
- zbx_wsnprintf(thread_id, sizeof(thread_id)/sizeof(wchar_t), TEXT("[%li]: "),
- zbx_get_thread_id());
+ zbx_wsnprintf(thread_id, sizeof(thread_id) / sizeof(wchar_t), TEXT("[%li]: "), zbx_get_thread_id());
strings[0] = thread_id;
strings[1] = zbx_utf8_to_unicode(message);
diff --git a/src/libs/zbxmedia/jabber.c b/src/libs/zbxmedia/jabber.c
index ee6da430556..8d982cd67d7 100644
--- a/src/libs/zbxmedia/jabber.c
+++ b/src/libs/zbxmedia/jabber.c
@@ -425,12 +425,20 @@ static void on_log(jabber_session_p sess, const char *data, size_t size, int is_
* Author: Eugene Grigorjev *
* *
******************************************************************************/
+static void tes(int *tes)
+{
+ return;
+}
+
static int connect_jabber(const char *jabber_id, const char *password, int use_sasl, int port)
{
const char *__function_name = "connect_jabber";
char *buf = NULL;
char real_server[MAX_STRING_LEN];
- int real_port = 0, iks_error, timeout, ret = FAIL;
+ int real_port = 0, iks_error, timeout, ret = FAIL, test;
+
+ tes(&test);
+ printf("%d",test);
zabbix_log(LOG_LEVEL_DEBUG, "%s: In %s() jabber_id:'%s'", __module_name, __function_name, jabber_id);
diff --git a/src/libs/zbxnix/daemon.c b/src/libs/zbxnix/daemon.c
index d1e0cb6ed10..4bdc0fadba8 100644
--- a/src/libs/zbxnix/daemon.c
+++ b/src/libs/zbxnix/daemon.c
@@ -26,10 +26,10 @@
#include "fatal.h"
-char *CONFIG_PID_FILE = NULL;
+char *CONFIG_PID_FILE = NULL;
static int parent = 0;
-static int parent_pid = (-1);
+static int parent_pid = -1;
static int exiting = 0;
#define CHECKED_FIELD(siginfo, field) (NULL == siginfo ? -1 : siginfo->field)
@@ -38,58 +38,64 @@ static int exiting = 0;
static void child_signal_handler(int sig, siginfo_t *siginfo, void *context)
{
if (NULL == siginfo)
- zabbix_log(LOG_LEVEL_DEBUG, "Received [signal:%d(%s)] with NULL siginfo.",
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "received [signal:%d(%s)] with NULL siginfo",
sig, get_signal_name(sig));
+ }
+
if (NULL == context)
- zabbix_log(LOG_LEVEL_DEBUG, "Received [signal:%d(%s)] with NULL context.",
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "received [signal:%d(%s)] with NULL context",
sig, get_signal_name(sig));
+ }
switch (sig)
{
- case SIGALRM:
- zabbix_log(LOG_LEVEL_DEBUG, "Timeout while answering request");
- break;
- case SIGILL:
- case SIGFPE:
- case SIGSEGV:
- case SIGBUS:
- zabbix_log(LOG_LEVEL_CRIT, "Got signal [signal:%d(%s),reason:%d,refaddr:%p]. Crashing ...",
- sig, get_signal_name(sig),
- CHECKED_FIELD(siginfo, si_code),
- CHECKED_FIELD_TYPE(siginfo, si_addr, void *));
- print_fatal_info(sig, siginfo, context);
- exit(FAIL);
- break;
- case SIGQUIT:
- case SIGINT:
- case SIGTERM:
- zabbix_log(parent_pid == CHECKED_FIELD(siginfo, si_pid) ? LOG_LEVEL_DEBUG : LOG_LEVEL_WARNING,
- "Got signal [signal:%d(%s),sender_pid:%d,sender_uid:%d,reason:%d]. Exiting ...",
- sig, get_signal_name(sig),
- CHECKED_FIELD(siginfo, si_pid),
- CHECKED_FIELD(siginfo, si_uid),
- CHECKED_FIELD(siginfo, si_code));
- if (1 == parent)
- {
- if (0 == exiting)
+ case SIGALRM:
+ zabbix_log(LOG_LEVEL_DEBUG, "timeout while answering request");
+ break;
+ case SIGILL:
+ case SIGFPE:
+ case SIGSEGV:
+ case SIGBUS:
+ zabbix_log(LOG_LEVEL_CRIT, "Got signal [signal:%d(%s),reason:%d,refaddr:%p]. Crashing ...",
+ sig, get_signal_name(sig),
+ CHECKED_FIELD(siginfo, si_code),
+ CHECKED_FIELD_TYPE(siginfo, si_addr, void *));
+ print_fatal_info(sig, siginfo, context);
+ exit(FAIL);
+ break;
+ case SIGQUIT:
+ case SIGINT:
+ case SIGTERM:
+ zabbix_log(parent_pid == CHECKED_FIELD(siginfo, si_pid) ? LOG_LEVEL_DEBUG : LOG_LEVEL_WARNING,
+ "Got signal [signal:%d(%s),sender_pid:%d,sender_uid:%d,reason:%d]. Exiting ...",
+ sig, get_signal_name(sig),
+ CHECKED_FIELD(siginfo, si_pid),
+ CHECKED_FIELD(siginfo, si_uid),
+ CHECKED_FIELD(siginfo, si_code));
+
+ if (1 == parent)
{
- exiting = 1;
- zbx_on_exit();
+ if (0 == exiting)
+ {
+ exiting = 1;
+ zbx_on_exit();
+ }
}
- }
- else
- exit(FAIL);
- break;
- case SIGPIPE:
- zabbix_log(LOG_LEVEL_DEBUG, "Got signal [signal:%d(%s),sender_pid:%d]. Ignoring ...",
- sig, get_signal_name(sig),
- CHECKED_FIELD(siginfo, si_pid));
- break;
- default:
- zabbix_log(LOG_LEVEL_WARNING, "Got signal [signal:%d(%s),sender_pid:%d,sender_uid:%d]. Ignoring ...",
- sig, get_signal_name(sig),
- CHECKED_FIELD(siginfo, si_pid),
- CHECKED_FIELD(siginfo, si_uid));
+ else
+ exit(FAIL);
+ break;
+ case SIGPIPE:
+ zabbix_log(LOG_LEVEL_DEBUG, "Got signal [signal:%d(%s),sender_pid:%d]. Ignoring ...",
+ sig, get_signal_name(sig),
+ CHECKED_FIELD(siginfo, si_pid));
+ break;
+ default:
+ zabbix_log(LOG_LEVEL_WARNING, "Got signal [signal:%d(%s),sender_pid:%d,sender_uid:%d]. Ignoring ...",
+ sig, get_signal_name(sig),
+ CHECKED_FIELD(siginfo, si_pid),
+ CHECKED_FIELD(siginfo, si_uid));
}
}
@@ -97,33 +103,33 @@ static void parent_signal_handler(int sig, siginfo_t *siginfo, void *context)
{
switch (sig)
{
- case SIGCHLD:
- if (1 == parent)
- {
- if (0 == exiting)
+ case SIGCHLD:
+ if (1 == parent)
{
- int i, found = 0;
- extern int threads_num;
- extern pid_t *threads;
+ if (0 == exiting)
+ {
+ int i, found = 0;
+ extern int threads_num;
+ extern pid_t *threads;
- for (i = 1; i < threads_num && !found; i++)
- found = (threads[i] == CHECKED_FIELD(siginfo, si_pid));
-
- if (!found) /* we should not worry too much about non-Zabbix child */
- return; /* processes, like watchdog alert scripts, terminating */
-
- zabbix_log(LOG_LEVEL_CRIT, "One child process died (PID:%d,exitcode/signal:%d). Exiting ...",
- CHECKED_FIELD(siginfo, si_pid),
- CHECKED_FIELD(siginfo, si_status));
- exiting = 1;
- zbx_on_exit();
+ for (i = 1; i < threads_num && !found; i++)
+ found = (threads[i] == CHECKED_FIELD(siginfo, si_pid));
+
+ if (0 == found) /* we should not worry too much about non-Zabbix child */
+ return; /* processes, like watchdog alert scripts, terminating */
+
+ zabbix_log(LOG_LEVEL_CRIT, "One child process died (PID:%d,exitcode/signal:%d). Exiting ...",
+ CHECKED_FIELD(siginfo, si_pid),
+ CHECKED_FIELD(siginfo, si_status));
+ exiting = 1;
+ zbx_on_exit();
+ }
}
- }
- else
- exit(FAIL);
- break;
- default:
- child_signal_handler(sig, siginfo, context);
+ else
+ exit(FAIL);
+ break;
+ default:
+ child_signal_handler(sig, siginfo, context);
}
}
@@ -135,8 +141,6 @@ static void parent_signal_handler(int sig, siginfo_t *siginfo, void *context)
* *
* Parameters: allow_root - allow root permission for application *
* *
- * Return value: *
- * *
* Author: Alexei Vladishev *
* *
* Comments: it doesn't allow running under 'root' if allow_root is zero *
@@ -149,7 +153,7 @@ int daemon_start(int allow_root)
struct sigaction phan;
char user[7] = "zabbix";
- if (0 == allow_root && (0 == getuid() || 0 == getgid())) /* running as root? */
+ if (0 == allow_root && (0 == getuid() || 0 == getgid())) /* running as root? */
{
pwd = getpwnam(user);
@@ -252,12 +256,12 @@ void set_parent_signal_handler()
{
struct sigaction phan;
- parent = 1; /* signalize signal handler that this process is a PARENT process */
+ parent = 1; /* signalize signal handler that this process is a PARENT process */
phan.sa_sigaction = parent_signal_handler;
sigemptyset(&phan.sa_mask);
phan.sa_flags = SA_SIGINFO;
- sigaction(SIGCHLD, &phan, NULL); /* for parent only, to avoid problems with EXECUTE_INT/DBL/STR and others */
+ sigaction(SIGCHLD, &phan, NULL); /* for parent only, to avoid problems with EXECUTE_INT/DBL/STR and others */
}
void set_child_signal_handler()
diff --git a/src/libs/zbxsys/threads.c b/src/libs/zbxsys/threads.c
index 9ce82189fcf..8ce1f859587 100644
--- a/src/libs/zbxsys/threads.c
+++ b/src/libs/zbxsys/threads.c
@@ -38,7 +38,7 @@
* Use this function instead of system fork function! *
* *
******************************************************************************/
-#ifndef _WINDOWS
+#if !defined(_WINDOWS)
int zbx_fork()
{
fflush(stdout);
@@ -69,19 +69,18 @@ ZBX_THREAD_HANDLE zbx_thread_start(ZBX_THREAD_ENTRY_POINTER(handler), zbx_thread
ZBX_THREAD_HANDLE thread = ZBX_THREAD_HANDLE_NULL;
#ifdef _WINDOWS
-
unsigned thrdaddr;
/* NOTE: _beginthreadex returns 0 on failure, rather than 1 */
if (0 == (thread = (ZBX_THREAD_HANDLE)_beginthreadex(NULL, 0, handler, thread_args, 0, &thrdaddr)))
{
- zbx_error("Error on thread creation. [%s]", strerror_from_system(GetLastError()));
+ zbx_error("failed to create a thread: %s", strerror_from_system(GetLastError()));
thread = (ZBX_THREAD_HANDLE)ZBX_THREAD_ERROR;
}
-#else /* not _WINDOWS */
+#else
- if (0 == (thread = zbx_fork())) /* child process */
+ if (0 == (thread = zbx_fork())) /* child process */
{
(*handler)(thread_args);
@@ -92,11 +91,10 @@ ZBX_THREAD_HANDLE zbx_thread_start(ZBX_THREAD_ENTRY_POINTER(handler), zbx_thread
}
else if (-1 == thread)
{
- zbx_error("Error on thread creation.");
+ zbx_error("failed to fork: %s", zbx_strerror(errno));
thread = (ZBX_THREAD_HANDLE)ZBX_THREAD_ERROR;
}
-
-#endif /* _WINDOWS */
+#endif
return thread;
}
diff --git a/src/libs/zbxsysinfo/aix/cpu.c b/src/libs/zbxsysinfo/aix/cpu.c
index e834a69a2b2..a03c9d4de63 100644
--- a/src/libs/zbxsysinfo/aix/cpu.c
+++ b/src/libs/zbxsysinfo/aix/cpu.c
@@ -100,7 +100,7 @@ static int get_cpuload(double *load1, double *load5, double *load15)
{
#if defined(HAVE_LIBPERFSTAT)
perfstat_cpu_total_t ps_cpu_total;
-#ifndef SBITS
+#if !defined(SBITS)
# define SBITS 16
#endif
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index 4274bb2e682..75e61191309 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -21,7 +21,6 @@
#include "sysinfo.h"
#include "log.h"
-#include "threads.h"
#include "file.h"
#include "http.h"
@@ -176,12 +175,12 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
zbx_rtrim(cmd_result, ZBX_WHITESPACE);
- if ('\0' == *cmd_result) /* we got whitespace only */
- goto lbl_exit;
-
zabbix_log(LOG_LEVEL_DEBUG, "Run remote command [%s] Result [%d] [%.20s]...",
param, strlen(cmd_result), cmd_result);
+ if ('\0' == *cmd_result) /* we got whitespace only */
+ goto lbl_exit;
+
SET_TEXT_RESULT(result, zbx_strdup(NULL, cmd_result));
ret = SYSINFO_RET_OK;
@@ -227,16 +226,6 @@ static int SYSTEM_RUN(const char *cmd, const char *param, unsigned flags, AGENT_
{
char command[MAX_STRING_LEN], flag[9];
-#ifdef _WINDOWS
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- char full_command[MAX_STRING_LEN];
- LPTSTR wcommand;
- int ret = SYSINFO_RET_FAIL;
-#else
- pid_t pid;
-#endif
-
if (1 != CONFIG_ENABLE_REMOTE_COMMANDS && 0 == (flags & PROCESS_LOCAL_COMMAND))
return SYSINFO_RET_FAIL;
@@ -259,87 +248,10 @@ static int SYSTEM_RUN(const char *cmd, const char *param, unsigned flags, AGENT_
if ('\0' == *flag || 0 == strcmp(flag, "wait")) /* default parameter */
return EXECUTE_STR(cmd, command, flags, result);
- else if (0 != strcmp(flag, "nowait"))
+ else if (0 != strcmp(flag, "nowait") || SUCCEED != zbx_execute_nowait(command))
return SYSINFO_RET_FAIL;
-#ifdef _WINDOWS
-
- zbx_snprintf(full_command, sizeof(full_command), "cmd /C \"%s\"", command);
-
- GetStartupInfo(&si);
-
- zabbix_log(LOG_LEVEL_DEBUG, "Executing full command '%s'", full_command);
-
- wcommand = zbx_utf8_to_unicode(full_command);
-
- if (!CreateProcess(
- NULL, /* no module name (use command line) */
- wcommand, /* name of app to launch */
- NULL, /* default process security attributes */
- NULL, /* default thread security attributes */
- FALSE, /* do not inherit handles from the parent */
- 0, /* normal priority */
- NULL, /* use the same environment as the parent */
- NULL, /* launch in the current directory */
- &si, /* startup information */
- &pi)) /* process information stored upon return */
- {
- zabbix_log(LOG_LEVEL_DEBUG, "Creation of the process failed");
- goto lbl_exit;
- }
-
- ret = SYSINFO_RET_OK;
-
- SET_UI64_RESULT(result, 1);
-lbl_exit:
- zbx_free(wcommand);
-
- return ret;
-
-#else /* not _WINDOWS */
-
- 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 = zbx_fork(); /* run new thread 2 to replace by command */
- switch(pid)
- {
- case -1:
- zabbix_log(LOG_LEVEL_WARNING, "fork2 failed for '%s'", command);
- return SYSINFO_RET_FAIL;
- case 0:
- /*
- * DON'T REMOVE SLEEP
- * sleep needed to return server result as "1"
- * then we can run "execl"
- * otherwise command print result into socket with STDOUT id
- */
- sleep(3);
- /**/
-
- /* replace thread 2 by the execution of command */
- if (execl("/bin/sh", "sh", "-c", command, (char *)0))
- zabbix_log(LOG_LEVEL_WARNING, "execl failed for command '%s'", command);
-
- /* in a normal case the program will never reach this point */
- exit(0);
- default:
- waitpid(pid, NULL, WNOHANG); /* NO WAIT can be used for thread 2 closing */
- exit(0); /* close thread 1 and transmit thread 2 to system (solve zombie state) */
- break;
- }
- default:
- waitpid(pid, NULL, 0); /* wait thread 1 closing */
- break;
- }
-
SET_UI64_RESULT(result, 1);
return SYSINFO_RET_OK;
-
-#endif /* _WINDOWS */
}
diff --git a/src/libs/zbxsysinfo/osf/swap.c b/src/libs/zbxsysinfo/osf/swap.c
index dcc64b07b2e..42df08703de 100644
--- a/src/libs/zbxsysinfo/osf/swap.c
+++ b/src/libs/zbxsysinfo/osf/swap.c
@@ -21,7 +21,7 @@
#include "sysinfo.h"
/* Solaris. */
-#ifndef HAVE_SYSINFO_FREESWAP
+#if !defined(HAVE_SYSINFO_FREESWAP)
#ifdef HAVE_SYS_SWAP_SWAPTABLE
static void get_swapinfo(double *total, double *fr)
{
diff --git a/src/libs/zbxsysinfo/osx/swap.c b/src/libs/zbxsysinfo/osx/swap.c
index a4dcce6eaa7..538642e393e 100644
--- a/src/libs/zbxsysinfo/osx/swap.c
+++ b/src/libs/zbxsysinfo/osx/swap.c
@@ -21,7 +21,7 @@
#include "sysinfo.h"
/* Solaris. */
-#ifndef HAVE_SYSINFO_FREESWAP
+#if !defined(HAVE_SYSINFO_FREESWAP)
#ifdef HAVE_SYS_SWAP_SWAPTABLE
static void get_swapinfo(double *total, double *fr)
{
diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c
index f1a62c4f238..0a650c8a00d 100644
--- a/src/zabbix_agent/cpustat.c
+++ b/src/zabbix_agent/cpustat.c
@@ -23,7 +23,7 @@
#include "mutexs.h"
#include "log.h"
-#ifndef _WINDOWS
+#if !defined(_WINDOWS)
# define LOCK_CPUSTATS zbx_mutex_lock(&cpustats_lock)
# define UNLOCK_CPUSTATS zbx_mutex_unlock(&cpustats_lock)
static ZBX_MUTEX cpustats_lock;
@@ -33,7 +33,7 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
{
const char *__function_name = "init_cpu_collector";
int ret = FAIL;
-#ifdef _WINDOWS
+#ifdef _WINDOWS
TCHAR cpu[8];
char counterPath[PDH_MAX_COUNTER_PATH];
PDH_COUNTER_PATH_ELEMENTS cpe;
@@ -107,14 +107,14 @@ void free_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
remove_perf_counter(pcpus->cpu_counter[i]);
pcpus->cpu_counter[i] = NULL;
}
-#else /* not _WINDOWS */
+#else
zbx_mutex_destroy(&cpustats_lock);
-#endif /* _WINDOWS */
+#endif
zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
}
-#ifndef _WINDOWS
+#if !defined(_WINDOWS)
static void update_cpu_counters(ZBX_SINGLE_CPU_STAT_DATA *cpu, zbx_uint64_t *counter)
{
diff --git a/src/zabbix_agent/listener.c b/src/zabbix_agent/listener.c
index 32b9ce323c7..b33ea83e6ba 100644
--- a/src/zabbix_agent/listener.c
+++ b/src/zabbix_agent/listener.c
@@ -29,9 +29,9 @@
#if defined(ZABBIX_SERVICE)
# include "service.h"
-#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */
+#elif defined(ZABBIX_DAEMON)
# include "daemon.h"
-#endif /* ZABBIX_DAEMON */
+#endif
static void process_listener(zbx_sock_t *s)
{
diff --git a/src/zabbix_agent/listener.h b/src/zabbix_agent/listener.h
index d31af98788c..4a60629b625 100644
--- a/src/zabbix_agent/listener.h
+++ b/src/zabbix_agent/listener.h
@@ -24,4 +24,4 @@
ZBX_THREAD_ENTRY(listener_thread, pSock);
-#endif /* ZABBIX_LISTENER_H */
+#endif
diff --git a/src/zabbix_agent/stats.c b/src/zabbix_agent/stats.c
index 8ba3d2018aa..cc15b7277f1 100644
--- a/src/zabbix_agent/stats.c
+++ b/src/zabbix_agent/stats.c
@@ -33,7 +33,7 @@
ZBX_COLLECTOR_DATA *collector = NULL;
-#ifndef _WINDOWS
+#if !defined(_WINDOWS)
static int shm_id;
#endif
@@ -143,7 +143,7 @@ void init_collector_data()
{
int cpu_count;
size_t sz, sz_cpu;
-#ifndef _WINDOWS
+#if !defined(_WINDOWS)
key_t shm_key;
#endif
diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c
index 45794c3a081..934492de9fa 100644
--- a/src/zabbix_agent/zabbix_agent.c
+++ b/src/zabbix_agent/zabbix_agent.c
@@ -29,7 +29,7 @@
const char *progname = NULL;
const char title_message[] = "Zabbix Agent";
const char usage_message[] = "[-Vhp] [-c <file>] [-t <item>]";
-#ifndef HAVE_GETOPT_LONG
+#if !defined(HAVE_GETOPT_LONG)
const char *help_message[] = {
"Options:",
" -c <file> absolute path to the configuration file",
@@ -37,7 +37,7 @@ const char *help_message[] = {
" -V display version number",
" -p print supported items and exit",
" -t <item> test specified item and exit",
- 0 /* end of text */
+ NULL /* end of text */
};
#else
const char *help_message[] = {
@@ -47,7 +47,7 @@ const char *help_message[] = {
" -V --version display version number",
" -p --print print supported items and exit",
" -t --test <item> test specified item and exit",
- 0 /* end of text */
+ NULL /* end of text */
};
#endif
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index f0dfd106185..f72ea9aaddb 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -521,7 +521,7 @@ void zbx_on_exit()
if (NULL != threads)
{
int i;
-#ifndef _WINDOWS
+#if !defined(_WINDOWS)
sigset_t set;
/* ignore SIGCHLD signals in order for zbx_sleep() to work */
diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c
index 488bc523a00..cc4b8f74a7c 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -51,13 +51,13 @@ const char *progname = NULL;
const char title_message[] = "Zabbix Proxy";
const char usage_message[] = "[-hV] [-c <file>]";
-#ifndef HAVE_GETOPT_LONG
+#if !defined(HAVE_GETOPT_LONG)
const char *help_message[] = {
"Options:",
" -c <file> absolute path to the configuration file",
" -h give this help",
" -V display version number",
- 0 /* end of text */
+ NULL /* end of text */
};
#else
const char *help_message[] = {
@@ -65,7 +65,7 @@ const char *help_message[] = {
" -c --config <file> absolute path to the configuration file",
" -h --help give this help",
" -V --version display version number",
- 0 /* end of text */
+ NULL /* end of text */
};
#endif
diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c
index 992b6e1bac9..f0416ff6ef3 100644
--- a/src/zabbix_server/alerter/alerter.c
+++ b/src/zabbix_server/alerter/alerter.c
@@ -85,8 +85,11 @@ int execute_action(DB_ALERT *alert, DB_MEDIATYPE *mediatype, char *error, int ma
}
else if (MEDIA_TYPE_EXEC == mediatype->type)
{
- pid = zbx_fork();
- if (0 != pid)
+ if (-1 == (pid = zbx_fork()))
+ {
+ zabbix_log(LOG_LEVEL_ERR, "%s(): failed to fork(): %s", __function_name, zbx_strerror(errno));
+ }
+ else if (0 != pid)
{
waitpid(pid, NULL, 0);
res = SUCCEED;
@@ -98,26 +101,20 @@ int execute_action(DB_ALERT *alert, DB_MEDIATYPE *mediatype, char *error, int ma
zabbix_log(LOG_LEVEL_DEBUG, "before executing [%s]", full_path);
- if (-1 == execl(full_path, mediatype->exec_path, alert->sendto,
- alert->subject, alert->message, (char *)NULL))
- {
- zabbix_log(LOG_LEVEL_ERR, "error executing [%s]: %s", full_path, zbx_strerror(errno));
- zabbix_syslog("error executing [%s]: %s", full_path, zbx_strerror(errno));
- exit(FAIL);
- }
- else
- THIS_SHOULD_NEVER_HAPPEN;
+ execl(full_path, mediatype->exec_path, alert->sendto,
+ alert->subject, alert->message, (char *)NULL);
+
+ /* execl() returns only when an error occurs */
+ zabbix_log(LOG_LEVEL_ERR, "error executing [%s]: %s", full_path, zbx_strerror(errno));
+ zabbix_syslog("error executing [%s]: %s", full_path, zbx_strerror(errno));
+ exit(0);
}
}
else
{
- zabbix_log(LOG_LEVEL_ERR, "unsupported media type [%d] for alert ID [" ZBX_FS_UI64 "]",
- mediatype->type, alert->alertid);
- zabbix_syslog("unsupported media type [%d] for alert ID [" ZBX_FS_UI64 "]",
- mediatype->type, alert->alertid);
- zbx_snprintf(error, max_error_len, "unsupported media type [%d]",
- mediatype->type);
- res = FAIL;
+ zbx_snprintf(error, max_error_len, "unsupported media type [%d]", mediatype->type);
+ zabbix_log(LOG_LEVEL_ERR, "alert ID [" ZBX_FS_UI64 "]: %s", alert->alertid, error);
+ zabbix_syslog("alert ID [" ZBX_FS_UI64 "]: %s", alert->alertid, error);
}
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(res));
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 04623ae6880..f2376cda9d6 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -55,14 +55,14 @@ const char *progname = NULL;
const char title_message[] = "Zabbix Server";
const char usage_message[] = "[-hV] [-c <file>] [-n <nodeid>]";
-#ifndef HAVE_GETOPT_LONG
+#if !defined(HAVE_GETOPT_LONG)
const char *help_message[] = {
"Options:",
" -c <file> absolute path to the configuration file",
" -h give this help",
" -n <nodeid> convert database data to new nodeid",
" -V display version number",
- 0 /* end of text */
+ NULL /* end of text */
};
#else
const char *help_message[] = {
@@ -71,7 +71,7 @@ const char *help_message[] = {
" -h --help give this help",
" -n --new-nodeid <nodeid> convert database data to new nodeid",
" -V --version display version number",
- 0 /* end of text */
+ NULL /* end of text */
};
#endif
diff --git a/src/zabbix_server/trapper/nodehistory.c b/src/zabbix_server/trapper/nodehistory.c
index 89999cc1aab..e4b438c88f9 100644
--- a/src/zabbix_server/trapper/nodehistory.c
+++ b/src/zabbix_server/trapper/nodehistory.c
@@ -279,7 +279,7 @@ static int process_record(char **sql, int *sql_allocated, int *sql_offset, int s
#endif
}
-#ifndef HAVE_MULTIROW_INSERT
+#if !defined(HAVE_MULTIROW_INSERT)
begin_history_sql(sql, sql_allocated, sql_offset, table);
#endif