Source
xxxxxxxxxx
if (1 == invalid_user) /* handle 0 for non-existent user after all parameters have been parsed and validated */
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/* Enable wide (64-bit) interfaces for narrow (32-bit) applications (see pstat(2) for details). */
/* Without this on some HP-UX systems you can get runtime error when calling pstat_getproc(): */
/* Value too large to be stored in data type */
static int check_procstate(struct pst_status pst, int zbx_proc_stat)
{
if (ZBX_PROC_STAT_ALL == zbx_proc_stat)
return SUCCEED;
switch (zbx_proc_stat)
{
case ZBX_PROC_STAT_RUN:
return PS_RUN == pst.pst_stat ? SUCCEED : FAIL;
case ZBX_PROC_STAT_SLEEP:
return PS_SLEEP == pst.pst_stat ? SUCCEED : FAIL;
case ZBX_PROC_STAT_ZOMB:
return PS_ZOMBIE == pst.pst_stat ? SUCCEED : FAIL;
}
return FAIL;
}
int PROC_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
{
char *procname, *proccomm, *param;
struct passwd *usrinfo;
int proccount = 0, invalid_user = 0, zbx_proc_stat, count, idx = 0;
struct pst_status pst[ZBX_BURST];
if (4 < request->nparam)
{
SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters."));
return SYSINFO_RET_FAIL;
}
procname = get_rparam(request, 0);
if (NULL != procname && '\0' == *procname)
procname = NULL;
param = get_rparam(request, 1);
if (NULL != param && '\0' != *param)
{
errno = 0;
if (NULL == (usrinfo = getpwnam(param)))
{
if (0 != errno)
{
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain user information: %s",
zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
invalid_user = 1;
}
}
else
usrinfo = NULL;
param = get_rparam(request, 2);
if (NULL == param || '\0' == *param || 0 == strcmp(param, "all"))