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 #ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES
27 	int	mib[2], len;
28 	int	maxfiles;
29 
30 	mib[0] = CTL_KERN;
31 	mib[1] = KERN_MAXFILES;
32 
33 	len = sizeof(maxfiles);
34 
35 	if (0 != sysctl(mib, 2, &maxfiles, (size_t *)&len, NULL, 0))
36 	{
37 		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
38 		return SYSINFO_RET_FAIL;
39 	}
40 
41      	SET_UI64_RESULT(result, maxfiles);
42 
43 	return SYSINFO_RET_OK;
44 #else
45 	SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"kern.maxfiles\" system"
46 			" parameter."));
47 	return SYSINFO_RET_FAIL;
48 #endif
49 }
50 
KERNEL_MAXPROC(AGENT_REQUEST * request,AGENT_RESULT * result)51 int	KERNEL_MAXPROC(AGENT_REQUEST *request, AGENT_RESULT *result)
52 {
53 #ifdef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC
54 	int	mib[2], len;
55 	int	maxproc;
56 
57 	mib[0] = CTL_KERN;
58 	mib[1] = KERN_MAXPROC;
59 
60 	len = sizeof(maxproc);
61 
62 	if (0 != sysctl(mib, 2, &maxproc, (size_t *)&len, NULL, 0))
63 	{
64 		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
65 		return SYSINFO_RET_FAIL;
66 	}
67 
68      	SET_UI64_RESULT(result, maxproc);
69 	return SYSINFO_RET_OK;
70 #else
71 	SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"kern.maxproc\" system"
72 			" parameter."));
73 	return SYSINFO_RET_FAIL;
74 #endif
75 }
76