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:
Diffstat (limited to 'src/libs/zbxsysinfo/freebsd/proc.c')
-rw-r--r--src/libs/zbxsysinfo/freebsd/proc.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/src/libs/zbxsysinfo/freebsd/proc.c b/src/libs/zbxsysinfo/freebsd/proc.c
index 6733b43bdcb..dafd364bbdc 100644
--- a/src/libs/zbxsysinfo/freebsd/proc.c
+++ b/src/libs/zbxsysinfo/freebsd/proc.c
@@ -20,6 +20,7 @@
#include "common.h"
#include "sysinfo.h"
#include "zbxregexp.h"
+#include "log.h"
#if(__FreeBSD_version > 500000)
# define ZBX_COMMLEN COMMLEN
@@ -57,7 +58,8 @@ retry:
sz = (size_t)args_alloc;
if (-1 == sysctl(mib, 4, args, &sz, NULL, 0))
{
- if (errno == ENOMEM) {
+ if (errno == ENOMEM)
+ {
args_alloc *= 2;
args = zbx_realloc(args, args_alloc);
goto retry;
@@ -98,15 +100,28 @@ int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
struct passwd *usrinfo;
if (4 < request->nparam)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
+ }
procname = get_rparam(request, 0);
param = get_rparam(request, 1);
if (NULL != param && '\0' != *param)
{
- if (NULL == (usrinfo = getpwnam(param))) /* incorrect user name */
+ errno = 0;
+
+ if (NULL == (usrinfo = getpwnam(param)))
+ {
+ if (0 == errno)
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Specified user does not exist."));
+ else
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain user information: %s",
+ zbx_strerror(errno)));
+
return SYSINFO_RET_FAIL;
+ }
}
else
usrinfo = NULL;
@@ -122,7 +137,10 @@ int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
else if (0 == strcmp(param, "min"))
do_task = ZBX_DO_MIN;
else
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
return SYSINFO_RET_FAIL;
+ }
proccomm = get_rparam(request, 3);
@@ -149,12 +167,18 @@ int PROC_MEM(AGENT_REQUEST *request, AGENT_RESULT *result)
sz = 0;
if (0 != sysctl(mib, mibs, NULL, &sz, NULL, 0))
+ {
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain necessary buffer size from system: %s",
+ zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
+ }
proc = (struct kinfo_proc *)zbx_malloc(proc, sz);
if (0 != sysctl(mib, mibs, proc, &sz, NULL, 0))
{
zbx_free(proc);
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain process information: %s",
+ zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
@@ -226,15 +250,28 @@ int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
struct passwd *usrinfo;
if (4 < request->nparam)
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
+ }
procname = get_rparam(request, 0);
param = get_rparam(request, 1);
if (NULL != param && '\0' != *param)
{
- if (NULL == (usrinfo = getpwnam(param))) /* incorrect user name */
+ errno = 0;
+
+ if (NULL == (usrinfo = getpwnam(param)))
+ {
+ if (0 == errno)
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Specified user does not exist."));
+ else
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain user information: %s",
+ zbx_strerror(errno)));
+
return SYSINFO_RET_FAIL;
+ }
}
else
usrinfo = NULL;
@@ -250,7 +287,10 @@ int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
else if (0 == strcmp(param, "zomb"))
zbx_proc_stat = ZBX_PROC_STAT_ZOMB;
else
+ {
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter."));
return SYSINFO_RET_FAIL;
+ }
proccomm = get_rparam(request, 3);
@@ -275,12 +315,18 @@ int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
sz = 0;
if (0 != sysctl(mib, mibs, NULL, &sz, NULL, 0))
+ {
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain necessary buffer size from system: %s",
+ zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
+ }
proc = (struct kinfo_proc *)zbx_malloc(proc, sz);
if (0 != sysctl(mib, mibs, proc, &sz, NULL, 0))
{
zbx_free(proc);
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain process information: %s",
+ zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}