1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 **/
19 
20 #include "common.h"
21 #include "sysinfo.h"
22 #include "log.h"
23 
KERNEL_MAXFILES(AGENT_REQUEST * request,AGENT_RESULT * result)24 int	KERNEL_MAXFILES(AGENT_REQUEST *request, AGENT_RESULT *result)
25 {
26 	int	mib[] = {CTL_KERN, KERN_MAXFILES}, maxfiles;
27 	size_t	len = sizeof(maxfiles);
28 
29 	if (0 != sysctl(mib, 2, &maxfiles, &len, NULL, 0))
30 	{
31 		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
32 		return SYSINFO_RET_FAIL;
33 	}
34 
35 	SET_UI64_RESULT(result, maxfiles);
36 
37 	return SYSINFO_RET_OK;
38 }
39 
KERNEL_MAXPROC(AGENT_REQUEST * request,AGENT_RESULT * result)40 int	KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
41 {
42 	int	mib[] = {CTL_KERN, KERN_MAXPROC}, maxproc;
43 	size_t	len = sizeof(maxproc);
44 
45 	if (0 != sysctl(mib, 2, &maxproc, &len, NULL, 0))
46 	{
47 		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
48 		return SYSINFO_RET_FAIL;
49 	}
50 
51 	SET_UI64_RESULT(result, maxproc);
52 
53 	return SYSINFO_RET_OK;
54 }
55