3
** Copyright (C) 2000-2005 SIA Zabbix
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
24
static int getPROC2(char *file, char *param, int fieldno, unsigned flags, int type, AGENT_RESULT *result)
29
char buf[MAX_STRING_LEN];
35
if (NULL == (f = fopen(file,"r")))
37
return SYSINFO_RET_FAIL;
42
while ( fgets(buf, MAX_STRING_LEN, f) != NULL )
44
if (strncmp(buf, "btime", 5) == 0)
51
if (!found) return SYSINFO_RET_FAIL;
54
res = (char *)strtok(buf, " "); /* btime field1 field2 */
55
for(i=1; i<=fieldno; i++)
57
res = (char *)strtok(NULL," ");
64
return SYSINFO_RET_FAIL;
67
/* convert field to right type */
71
sscanf(res, "%lu", &uValue);
72
SET_UI64_RESULT(result, uValue);
75
sscanf(res, "%lf", &fValue);
76
SET_DBL_RESULT(result, fValue);
78
case AR_STRING: default:
79
SET_STR_RESULT(result, buf);
83
return SYSINFO_RET_OK;
86
int SYSTEM_BOOTTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
92
return getPROC2("/proc/stat", "btime", 1, flags, AR_UINT64, result);