summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbuild/win32/include/config.h382
-rwxr-xr-xbuild/win32/project/zabbix_agentd.dep874
-rwxr-xr-xbuild/win32/project/zabbix_agentd.dsp2920
-rwxr-xr-xbuild/win32/project/zabbix_agentd.dsw29
-rwxr-xr-xbuild/win32/project/zabbix_agentd.mak1365
-rw-r--r--configure.in11
-rwxr-xr-xdo68
-rw-r--r--frontends/php/include/db.inc.php2
-rwxr-xr-xinclude/alias.h40
-rw-r--r--include/base64.h26
-rw-r--r--include/cfg.h15
-rw-r--r--include/common.h184
-rwxr-xr-xinclude/daemon.h49
-rwxr-xr-xinclude/gnuregex.h501
-rw-r--r--include/log.h7
-rwxr-xr-xinclude/mutexs.h44
-rwxr-xr-xinclude/perfmon.h58
-rw-r--r--include/pid.h7
-rwxr-xr-xinclude/service.h55
-rw-r--r--include/sysinc.h64
-rw-r--r--include/sysinfo.h8
-rwxr-xr-xinclude/threads.h68
-rwxr-xr-xinclude/zbxgetopt.h102
-rwxr-xr-xinclude/zbxplugin.h61
-rwxr-xr-xinclude/zbxsecurity.h27
-rwxr-xr-xinclude/zbxsock.h72
-rwxr-xr-xinclude/zbxtypes.h57
-rw-r--r--misc/conf/zabbix_agentd.conf5
-rw-r--r--src/alphacode/poller/poller.c2
-rwxr-xr-xsrc/alphacode/poller/snmp.c2
-rw-r--r--src/libs/Makefile.am4
-rw-r--r--src/libs/zbxcommon/Makefile.am2
-rwxr-xr-xsrc/libs/zbxcommon/alias.c128
-rw-r--r--src/libs/zbxcommon/comms.c25
-rwxr-xr-xsrc/libs/zbxcommon/gnuregex.c4941
-rw-r--r--src/libs/zbxcommon/misc.c82
-rw-r--r--src/libs/zbxcommon/regexp.c50
-rw-r--r--src/libs/zbxcommon/str.c102
-rw-r--r--src/libs/zbxcommon/xml.c26
-rwxr-xr-xsrc/libs/zbxcommon/zbxgetopt.c676
-rw-r--r--src/libs/zbxconf/cfg.c165
-rw-r--r--src/libs/zbxcrypto/Makefile.am2
-rw-r--r--src/libs/zbxcrypto/base64.c274
-rw-r--r--src/libs/zbxcrypto/md5.c3
-rw-r--r--src/libs/zbxdbhigh/Makefile.am2
-rw-r--r--src/libs/zbxdbhigh/action.c4
-rw-r--r--src/libs/zbxdbhigh/db.c152
-rw-r--r--src/libs/zbxdbhigh/graph.c16
-rw-r--r--src/libs/zbxdbhigh/host.c18
-rw-r--r--src/libs/zbxdbhigh/item.c12
-rw-r--r--src/libs/zbxdbhigh/trigger.c30
-rw-r--r--src/libs/zbxemail/email.c66
-rw-r--r--src/libs/zbxlog/log.c325
-rw-r--r--src/libs/zbxnet/Makefile.am2
-rw-r--r--src/libs/zbxnet/security.c68
-rwxr-xr-xsrc/libs/zbxnet/zbxsock.c111
-rwxr-xr-xsrc/libs/zbxnix/Makefile.am3
-rwxr-xr-xsrc/libs/zbxnix/daemon.c194
-rwxr-xr-xsrc/libs/zbxnix/pid.c65
-rw-r--r--src/libs/zbxplugin/Makefile.am4
-rwxr-xr-xsrc/libs/zbxplugin/zbxplugin.c33
-rw-r--r--src/libs/zbxsms/sms.c16
-rwxr-xr-xsrc/libs/zbxsys/Makefile.am3
-rwxr-xr-xsrc/libs/zbxsys/mutexs.c227
-rwxr-xr-xsrc/libs/zbxsys/threads.c138
-rw-r--r--src/libs/zbxsysinfo/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/aix/AIX_new.c2
-rw-r--r--src/libs/zbxsysinfo/aix/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/aix/aix.c211
-rw-r--r--src/libs/zbxsysinfo/aix/cpu.c10
-rw-r--r--src/libs/zbxsysinfo/aix/diskio.c32
-rw-r--r--src/libs/zbxsysinfo/aix/diskspace.c2
-rw-r--r--src/libs/zbxsysinfo/aix/inodes.c2
-rw-r--r--src/libs/zbxsysinfo/aix/memory.c11
-rw-r--r--src/libs/zbxsysinfo/aix/proc.c8
-rw-r--r--src/libs/zbxsysinfo/aix/sensors.c7
-rw-r--r--src/libs/zbxsysinfo/aix/swap.c10
-rw-r--r--src/libs/zbxsysinfo/common/common.c443
-rw-r--r--src/libs/zbxsysinfo/common/file.c139
-rw-r--r--src/libs/zbxsysinfo/common/http.c97
-rw-r--r--src/libs/zbxsysinfo/common/ntp.c78
-rw-r--r--src/libs/zbxsysinfo/common/system.c22
-rw-r--r--src/libs/zbxsysinfo/freebsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/freebsd/cpu.c20
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskio.c44
-rw-r--r--src/libs/zbxsysinfo/freebsd/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/freebsd/freebsd.c211
-rw-r--r--src/libs/zbxsysinfo/freebsd/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/freebsd/memory.c15
-rw-r--r--src/libs/zbxsysinfo/freebsd/proc.c43
-rw-r--r--src/libs/zbxsysinfo/freebsd/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/freebsd/swap.c10
-rw-r--r--src/libs/zbxsysinfo/hpux/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/hpux/cpu.c24
-rw-r--r--src/libs/zbxsysinfo/hpux/diskio.c44
-rw-r--r--src/libs/zbxsysinfo/hpux/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/hpux/hpux.c211
-rw-r--r--src/libs/zbxsysinfo/hpux/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/hpux/memory.c10
-rw-r--r--src/libs/zbxsysinfo/hpux/proc.c44
-rw-r--r--src/libs/zbxsysinfo/hpux/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/hpux/swap.c10
-rw-r--r--src/libs/zbxsysinfo/linux/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/linux/cpu.c27
-rw-r--r--src/libs/zbxsysinfo/linux/diskio.c17
-rw-r--r--src/libs/zbxsysinfo/linux/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/linux/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/linux/kernel.c5
-rw-r--r--src/libs/zbxsysinfo/linux/linux.c209
-rw-r--r--src/libs/zbxsysinfo/linux/memory.c9
-rw-r--r--src/libs/zbxsysinfo/linux/net.c45
-rw-r--r--src/libs/zbxsysinfo/linux/proc.c36
-rw-r--r--src/libs/zbxsysinfo/linux/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/linux/swap.c8
-rw-r--r--src/libs/zbxsysinfo/netbsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/netbsd/cpu.c24
-rw-r--r--src/libs/zbxsysinfo/netbsd/diskio.c38
-rw-r--r--src/libs/zbxsysinfo/netbsd/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/netbsd/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/netbsd/memory.c7
-rw-r--r--src/libs/zbxsysinfo/netbsd/netbsd.c215
-rw-r--r--src/libs/zbxsysinfo/netbsd/proc.c14
-rw-r--r--src/libs/zbxsysinfo/netbsd/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/netbsd/swap.c10
-rw-r--r--src/libs/zbxsysinfo/openbsd/Makefile.am2
-rwxr-xr-xsrc/libs/zbxsysinfo/openbsd/OpenBSD3.7.c2
-rw-r--r--src/libs/zbxsysinfo/openbsd/cpu.c18
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskio.c12
-rw-r--r--src/libs/zbxsysinfo/openbsd/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/openbsd/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/openbsd/memory.c4
-rw-r--r--src/libs/zbxsysinfo/openbsd/net.c90
-rw-r--r--src/libs/zbxsysinfo/openbsd/openbsd.c214
-rw-r--r--src/libs/zbxsysinfo/openbsd/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/openbsd/swap.c26
-rw-r--r--src/libs/zbxsysinfo/osf/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/osf/cpu.c36
-rw-r--r--src/libs/zbxsysinfo/osf/diskio.c44
-rw-r--r--src/libs/zbxsysinfo/osf/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/osf/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/osf/memory.c8
-rw-r--r--src/libs/zbxsysinfo/osf/osf.c209
-rw-r--r--src/libs/zbxsysinfo/osf/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/osf/swap.c10
-rw-r--r--src/libs/zbxsysinfo/osx/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/osx/cpu.c22
-rw-r--r--src/libs/zbxsysinfo/osx/diskio.c42
-rw-r--r--src/libs/zbxsysinfo/osx/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/osx/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/osx/memory.c10
-rw-r--r--src/libs/zbxsysinfo/osx/osx.c211
-rw-r--r--src/libs/zbxsysinfo/osx/proc.c14
-rw-r--r--src/libs/zbxsysinfo/osx/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/osx/swap.c10
-rw-r--r--src/libs/zbxsysinfo/solaris/Makefile.am2
-rwxr-xr-xsrc/libs/zbxsysinfo/solaris/SunOS5.9.c8
-rw-r--r--src/libs/zbxsysinfo/solaris/cpu.c18
-rw-r--r--src/libs/zbxsysinfo/solaris/diskio.c17
-rw-r--r--src/libs/zbxsysinfo/solaris/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/solaris/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/solaris/memory.c2
-rw-r--r--src/libs/zbxsysinfo/solaris/net.c106
-rw-r--r--src/libs/zbxsysinfo/solaris/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/solaris/solaris.c215
-rw-r--r--src/libs/zbxsysinfo/solaris/swap.c30
-rw-r--r--src/libs/zbxsysinfo/unknown/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/unknown/cpu.c24
-rw-r--r--src/libs/zbxsysinfo/unknown/diskio.c42
-rw-r--r--src/libs/zbxsysinfo/unknown/diskspace.c6
-rw-r--r--src/libs/zbxsysinfo/unknown/inodes.c6
-rw-r--r--src/libs/zbxsysinfo/unknown/memory.c9
-rw-r--r--src/libs/zbxsysinfo/unknown/proc.c14
-rw-r--r--src/libs/zbxsysinfo/unknown/sensors.c5
-rw-r--r--src/libs/zbxsysinfo/unknown/swap.c10
-rw-r--r--src/libs/zbxsysinfo/unknown/unknown.c211
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/cpu.c209
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/diskio.c94
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/diskspace.c34
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/inodes.c35
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/kernel.c48
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/memory.c34
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/net.c70
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/proc.c163
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/sensors.c36
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/swap.c64
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/system_w32.c141
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/uptime.c32
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/win32.c79
-rwxr-xr-xsrc/libs/zbxwin32/perfmon.c75
-rwxr-xr-xsrc/libs/zbxwin32/service.c441
-rw-r--r--src/zabbix_agent/Makefile.am16
-rw-r--r--src/zabbix_agent/active.c651
-rw-r--r--src/zabbix_agent/active.h17
-rw-r--r--src/zabbix_agent/cpustat.c639
-rw-r--r--src/zabbix_agent/cpustat.h92
-rw-r--r--src/zabbix_agent/diskdevices.c40
-rw-r--r--src/zabbix_agent/diskdevices.h25
-rw-r--r--src/zabbix_agent/interfaces.c34
-rw-r--r--src/zabbix_agent/interfaces.h21
-rwxr-xr-xsrc/zabbix_agent/listener.c156
-rwxr-xr-xsrc/zabbix_agent/listener.h27
-rw-r--r--src/zabbix_agent/logfiles.c35
-rwxr-xr-xsrc/zabbix_agent/messages.mc17
-rwxr-xr-xsrc/zabbix_agent/resources.rc82
-rw-r--r--src/zabbix_agent/stats.c214
-rw-r--r--src/zabbix_agent/stats.h27
-rw-r--r--src/zabbix_agent/zabbix_agent.c88
-rw-r--r--src/zabbix_agent/zabbix_agentd.c793
-rwxr-xr-xsrc/zabbix_agent/zbxconf.c168
-rwxr-xr-xsrc/zabbix_agent/zbxconf.h38
-rwxr-xr-xsrc/zabbix_agent_win32/active.cpp12
-rw-r--r--src/zabbix_get/Makefile.am2
-rw-r--r--src/zabbix_get/zabbix_get.c8
-rw-r--r--src/zabbix_sender/Makefile.am2
-rw-r--r--src/zabbix_sender/zabbix_sender.c4
-rw-r--r--src/zabbix_server/Makefile.am9
-rw-r--r--src/zabbix_server/actions.c26
-rw-r--r--src/zabbix_server/alerter/alerter.c58
-rw-r--r--src/zabbix_server/evalfunc.c68
-rw-r--r--src/zabbix_server/expression.c34
-rw-r--r--src/zabbix_server/functions.c64
-rw-r--r--src/zabbix_server/housekeeper/housekeeper.c72
-rw-r--r--src/zabbix_server/pinger/pinger.c29
-rw-r--r--src/zabbix_server/poller/checks_agent.c32
-rw-r--r--src/zabbix_server/poller/checks_aggregate.c14
-rw-r--r--src/zabbix_server/poller/checks_internal.c2
-rw-r--r--src/zabbix_server/poller/checks_simple.c32
-rw-r--r--src/zabbix_server/poller/checks_snmp.c50
-rw-r--r--src/zabbix_server/poller/poller.c49
-rw-r--r--src/zabbix_server/poller/poller.h2
-rw-r--r--src/zabbix_server/server.c321
-rw-r--r--src/zabbix_server/timer/timer.c17
-rw-r--r--src/zabbix_server/trapper/active.c6
-rw-r--r--src/zabbix_server/trapper/autoregister.c2
-rw-r--r--src/zabbix_server/trapper/trapper.c23
-rw-r--r--src/zabbix_server/zlog.c2
-rw-r--r--src/zabbix_snmptrapper/zabbix_snmptrapper.c4
237 files changed, 19602 insertions, 5438 deletions
diff --git a/build/win32/include/config.h b/build/win32/include/config.h
new file mode 100755
index 00000000..c6565abd
--- /dev/null
+++ b/build/win32/include/config.h
@@ -0,0 +1,382 @@
+/* include/config.h. Generated by configure. */
+/* include/config.h.in. Generated from configure.in by autoheader. */
+
+/* Define to os name for code managing */
+#define ARCH "windows"
+
+//#define WIN32_LEAN_AND_MEAN
+
+/* Define to 1 if you have the <windows.h> header file. */
+#define HAVE_WINDOWS_H 1
+
+/* Define to 1 if you have the <winsock2.h> header file. */
+//#define HAVE_WINSOCK2_H 1
+
+/* Define to 1 if you have the <conio.h> header file. */
+#define HAVE_CONIO_H 1
+
+/* Define to 1 if you have the <process.h> header file. */
+#define HAVE_PROCESS_H 1
+
+/* Define to 1 if you have the <pdh.h> header file. */
+#define HAVE_PDH_H 1
+
+/* Define to 1 if you have the <psapi.h> header file. */
+#define HAVE_PSAPI_H 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+//#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the <arpa/nameser.h> header file. */
+//#define HAVE_ARPA_NAMESER_H 1
+
+/* Define to 1 if you have the `asprintf' function. */
+//#define HAVE_ASPRINTF 1
+
+/* Define to 1 if you have the <assert.h> header file. */
+//#define HAVE_ASSERT_H 1
+
+/* Define to 1 if you have the `atoll' function. */
+//#define HAVE_ATOLL 1
+
+/* Define to 1 if you have the <ctype.h> header file. */
+//#define HAVE_CTYPE_H 1
+
+/* Define to 1 if you have the <dirent.h> header file. */
+//#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+//#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+//#define HAVE_FCNTL_H 1
+
+/* Define to 1 if function 'seteuid' and 'setegid' exist. */
+//#define HAVE_FUNCTION_SETEUID 1
+
+/* Define to 1 if function 'setproctitle' exist. */
+/* #undef HAVE_FUNCTION_SETPROCTITLE */
+
+/* Define to 1 if 'KERN_BOOTTIME' exist. */
+/* #undef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME */
+
+/* Define to 1 if 'KERN_MAXFILES' exist. */
+/* #undef HAVE_FUNCTION_SYSCTL_KERN_MAXFILES */
+
+/* Define to 1 if 'KERN_MAXPROC' exist. */
+/* #undef HAVE_FUNCTION_SYSCTL_KERN_MAXPROC */
+
+/* Define to 1 if you have the `getloadavg' function. */
+//#define HAVE_GETLOADAVG 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+//#define HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
+//#define HAVE_GETOPT_LONG 1
+
+/* Define to 1 if you have the `hstrerror' function. */
+//#define HAVE_HSTRERROR 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+//#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <knlist.h> header file. */
+/* #undef HAVE_KNLIST_H */
+
+/* Define to 1 if you have the <kstat.h> header file. */
+/* #undef HAVE_KSTAT_H */
+
+/* Define to 1 if you have the <kvm.h> header file. */
+/* #undef HAVE_KVM_H */
+
+/* Define to 1 if LDAP should be enabled. */
+//#define HAVE_LDAP 1
+
+/* Define to 1 if you have the <ldap.h> header file. */
+//#define HAVE_LDAP_H 1
+
+/* Define to 1 if you have the `kstat' library (-lkstat). */
+/* #undef HAVE_LIBKSTAT */
+
+/* Define to 1 if you have the `kvm' library (-lkvm). */
+/* #undef HAVE_LIBKVM */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+//#define HAVE_LIBNSL 1
+
+/* Define to 1 if you have the `resolv' library (-lresolv). */
+//#define HAVE_LIBRESOLV 1
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Define to 1 if you have the <linux/kernel.h> header file. */
+//#define HAVE_LINUX_KERNEL_H 1
+
+/* Define to 1 if you have the <mach/host_info.h> header file. */
+/* #undef HAVE_MACH_HOST_INFO_H */
+
+/* Define to 1 if you have the <mach/mach_host.h> header file. */
+/* #undef HAVE_MACH_MACH_HOST_H */
+
+/* Define to 1 if you have the <memory.h> header file. */
+//#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <mtent.h> header file. */
+/* #undef HAVE_MTENT_H */
+
+/* Define to 1 if MySQL should be enabled. */
+//#define HAVE_MYSQL 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+//#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+//#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if NETSNMP should be enabled. */
+//#define HAVE_NETSNMP 1
+
+/* Define to 1 if you have the <net/if.h> header file. */
+//#define HAVE_NET_IF_H 1
+
+/* Define to 1 if you have the <nlist.h> header file. */
+/* #undef HAVE_NLIST_H */
+
+/* Define to 1 if Oracle should be enabled. */
+/* #undef HAVE_ORACLE */
+
+/* Define to 1 if PostgreSQL should be enabled. */
+/* #undef HAVE_PGSQL */
+
+/* Define to 1 if '/proc' file system should be used. */
+//#define HAVE_PROC 1
+
+/* Define to 1 if you have the <procinfo.h> header file. */
+/* #undef HAVE_PROCINFO_H */
+
+/* Define to 1 if file '/proc/0/psinfo' should be used. */
+/* #undef HAVE_PROC_0_PSINFO */
+
+/* Define to 1 if file '/proc/1/status' should be used. */
+//#define HAVE_PROC_1_STATUS 1
+
+/* Define to 1 if file '/proc/loadavg' should be used. */
+//#define HAVE_PROC_LOADAVG 1
+
+/* Define to 1 if file /proc/net/dev' should be used. */
+//#define HAVE_PROC_NET_DEV 1
+
+/* Define to 1 if file '/proc/stat' should be used. */
+//#define HAVE_PROC_STAT 1
+
+/* Define to 1 if you have the <pwd.h> header file. */
+//#define HAVE_PWD_H 1
+
+/* Define to 1 if you have the <resolv.h> header file. */
+//#define HAVE_RESOLV_H 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+//#define HAVE_SIGNAL_H 1
+
+/* Define to 1 if SNMP should be enabled. */
+//#define HAVE_SNMP 1
+
+/* Define to 1 if you have the `snprintf' function. */
+//#define HAVE_SNPRINTF 1
+
+/* Define to 1 if you have the `socket' function. */
+//#define HAVE_SOCKET 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+//#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+//#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+//#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+//#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strtod' function. */
+//#define HAVE_STRTOD 1
+
+/* Define to 1 if 'sysinfo.bufferram' exist. */
+//#define HAVE_SYSINFO_BUFFERRAM 1
+
+/* Define to 1 if 'sysinfo.freeram' exist. */
+//#define HAVE_SYSINFO_FREERAM 1
+
+/* Define to 1 if 'sysinfo.freeswap' exist. */
+//#define HAVE_SYSINFO_FREESWAP 1
+
+/* Define to 1 if 'sysinfo.mem_unit' exist. */
+//#define HAVE_SYSINFO_MEM_UNIT 1
+
+/* Define to 1 if 'sysinfo.procs' exist. */
+//#define HAVE_SYSINFO_PROCS 1
+
+/* Define to 1 if 'sysinfo.sharedram' exist. */
+//#define HAVE_SYSINFO_SHAREDRAM 1
+
+/* Define to 1 if 'sysinfo.totalram' exist. */
+//#define HAVE_SYSINFO_TOTALRAM 1
+
+/* Define to 1 if 'sysinfo.totalswap' exist. */
+//#define HAVE_SYSINFO_TOTALSWAP 1
+
+/* Define to 1 if 'sysinfo.uptime' exist. */
+//#define HAVE_SYSINFO_UPTIME 1
+
+/* Define to 1 if you have the <syslog.h> header file. */
+//#define HAVE_SYSLOG_H 1
+
+/* Define to 1 if you have the <sys/disk.h> header file. */
+/* #undef HAVE_SYS_DISK_H */
+
+/* Define to 1 if you have the <sys/dkstat.h> header file. */
+/* #undef HAVE_SYS_DKSTAT_H */
+
+/* Define to 1 if you have the <sys/dk.h> header file. */
+/* #undef HAVE_SYS_DK_H */
+
+/* Define to 1 if you have the <sys/loadavg.h> header file. */
+/* #undef HAVE_SYS_LOADAVG_H */
+
+/* Define to 1 if you have the <sys/mount.h> header file. */
+//#define HAVE_SYS_MOUNT_H 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+//#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/procfs.h> header file. */
+//#define HAVE_SYS_PROCFS_H 1
+
+/* Define to 1 if you have the <sys/proc.h> header file. */
+/* #undef HAVE_SYS_PROC_H */
+
+/* Define to 1 if you have the <sys/pstat.h> header file. */
+/* #undef HAVE_SYS_PSTAT_H */
+
+/* Define to 1 if function 'setpriority' exist. */
+//#define HAVE_SYS_RESOURCE_SETPRIORITY 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+//#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/statvfs.h> header file. */
+//#define HAVE_SYS_STATVFS_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/swap.h> header file. */
+//#define HAVE_SYS_SWAP_H 1
+
+/* Define to 1 if struct 'swaptable' exist. */
+/* #undef HAVE_SYS_SWAP_SWAPTABLE */
+
+/* Define to 1 if you have the <sys/syscall.h> header file. */
+//#define HAVE_SYS_SYSCALL_H 1
+
+/* Define to 1 if you have the <sys/sysctl.h> header file. */
+//#define HAVE_SYS_SYSCTL_H 1
+
+/* Define to 1 if you have the <sys/sysinfo.h> header file. */
+//#define HAVE_SYS_SYSINFO_H 1
+
+/* Define to 1 if you have the <math.h> header file. */
+#define HAVE_MATH_H 1
+
+/* Define to 1 if you have the <sys/sysmacros.h> header file. */
+//#define HAVE_SYS_SYSMACROS_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+//#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/var.h> header file. */
+/* #undef HAVE_SYS_VAR_H */
+
+/* Define to 1 if you have the <sys/vfs.h> header file. */
+//#define HAVE_SYS_VFS_H 1
+
+/* Define to 1 if you have the <sys/vmmeter.h> header file. */
+/* #undef HAVE_SYS_VMMETER_H */
+
+/* Define to 1 if struct 'vmtotal' exist . */
+/* #undef HAVE_SYS_VMMETER_VMTOTAL */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if UCDSNMP should be enabled. */
+/* #undef HAVE_UCDSNMP */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+//#define HAVE_UNISTD_H 1
+
+/* Define to 1 if function 'sysconf' exist. */
+//#define HAVE_UNISTD_SYSCONF 1
+
+/* Define to 1 if you have the `vasprintf' function. */
+//#define HAVE_VASPRINTF 1
+
+/* Define to 1 if you have the <vm/vm_param.h> header file. */
+/* #undef HAVE_VM_VM_PARAM_H */
+
+/* Define to 1 if you have the `vsnprintf' function. */
+//#define HAVE_VSNPRINTF 1
+
+/* Define to 1 if function '__va_copy' exist. */
+//#define HAVE___VA_COPY 1
+
+/* Define to 1 if you're using Linux 2.4.x */
+/* #undef KERNEL_2_4 */
+
+/* Define to 1 if you're using Linux 2.6.x */
+//#define KERNEL_2_6 1
+
+/* Name of package */
+//#define PACKAGE "zabbix"
+
+/* Define to the address where bug reports for this package should be sent. */
+//#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+//#define PACKAGE_NAME ""
+
+/* Define to the full name and version of this package. */
+//#define PACKAGE_STRING ""
+
+/* Define to the one symbol short name of this package. */
+//#define PACKAGE_TARNAME ""
+
+/* Define to the version of this package. */
+//#define PACKAGE_VERSION ""
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+//#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+//#define STDC_HEADERS 1
+
+/* Version number of package */
+//#define VERSION "1.1patch1"
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define socklen_t type */
+/* #undef socklen_t */
diff --git a/build/win32/project/zabbix_agentd.dep b/build/win32/project/zabbix_agentd.dep
new file mode 100755
index 00000000..4ab42b1b
--- /dev/null
+++ b/build/win32/project/zabbix_agentd.dep
@@ -0,0 +1,874 @@
+# Microsoft Developer Studio Generated Dependency File, included by zabbix_agentd.mak
+
+..\..\..\src\libs\zbxcommon\alias.c : \
+ "..\..\..\include\alias.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\comms.c : \
+ "..\..\..\include\base64.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\gnuregex.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\gnuregex.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\misc.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\regexp.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\gnuregex.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\str.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\xml.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcommon\zbxgetopt.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxgetopt.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxlog\log.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\mutexs.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\messages.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcrypto\base64.c : \
+ "..\..\..\include\base64.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxcrypto\md5.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\md5.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxnet\security.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxnet\zbxsock.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxconf\cfg.c : \
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\common\common.c : \
+ "..\..\..\include\alias.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\md5.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\common\file.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\common\http.c : \
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\common\ntp.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\common\system.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\cpu.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\cpustat.h"\
+ "..\..\..\src\zabbix_agent\diskdevices.h"\
+ "..\..\..\src\zabbix_agent\interfaces.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\diskio.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\diskspace.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\inodes.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\kernel.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\memory.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\net.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\proc.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\sensors.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\md5.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\swap.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\md5.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\system_w32.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\uptime.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsysinfo\win32\win32.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxwin32\perfmon.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\perfmon.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxwin32\service.c : \
+ "..\..\..\include\alias.h"\
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\perfmon.h"\
+ "..\..\..\include\service.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\zbxconf.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsys\mutexs.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\mutexs.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxsys\threads.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\libs\zbxplugin\zbxplugin.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxplugin.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\active.c : \
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\service.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\active.h"\
+ "..\..\..\src\zabbix_agent\logfiles.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\cpustat.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\perfmon.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\cpustat.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\diskdevices.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\diskdevices.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\interfaces.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\interfaces.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\listener.c : \
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\service.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxsecurity.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\cpustat.h"\
+ "..\..\..\src\zabbix_agent\diskdevices.h"\
+ "..\..\..\src\zabbix_agent\interfaces.h"\
+ "..\..\..\src\zabbix_agent\listener.h"\
+ "..\..\..\src\zabbix_agent\zbxconf.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\logfiles.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\logfiles.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\stats.c : \
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\mutexs.h"\
+ "..\..\..\include\service.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\cpustat.h"\
+ "..\..\..\src\zabbix_agent\diskdevices.h"\
+ "..\..\..\src\zabbix_agent\interfaces.h"\
+ "..\..\..\src\zabbix_agent\zbxconf.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\zabbix_agentd.c : \
+ "..\..\..\include\alias.h"\
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\mutexs.h"\
+ "..\..\..\include\pid.h"\
+ "..\..\..\include\service.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\threads.h"\
+ "..\..\..\include\zbxgetopt.h"\
+ "..\..\..\include\zbxsock.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\active.h"\
+ "..\..\..\src\zabbix_agent\cpustat.h"\
+ "..\..\..\src\zabbix_agent\diskdevices.h"\
+ "..\..\..\src\zabbix_agent\interfaces.h"\
+ "..\..\..\src\zabbix_agent\listener.h"\
+ "..\..\..\src\zabbix_agent\zabbix_agent.h"\
+ "..\..\..\src\zabbix_agent\zbxconf.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+..\..\..\src\zabbix_agent\zbxconf.c : \
+ "..\..\..\include\alias.h"\
+ "..\..\..\include\cfg.h"\
+ "..\..\..\include\common.h"\
+ "..\..\..\include\log.h"\
+ "..\..\..\include\sysinc.h"\
+ "..\..\..\include\sysinfo.h"\
+ "..\..\..\include\zbxplugin.h"\
+ "..\..\..\include\zbxtypes.h"\
+ "..\..\..\src\zabbix_agent\zbxconf.h"\
+ "..\include\config.h"\
+ "c:\program files\microsoft platform sdk\include\basetsd.h"\
+ "c:\program files\microsoft platform sdk\include\guiddef.h"\
+ "c:\program files\microsoft platform sdk\include\propidl.h"\
+ "c:\program files\microsoft platform sdk\include\psapi.h"\
+ "c:\program files\microsoft platform sdk\include\reason.h"\
+ "c:\program files\microsoft platform sdk\include\specstrings.h"\
+ "c:\program files\microsoft platform sdk\include\stralign.h"\
+ "c:\program files\microsoft platform sdk\include\tvout.h"\
+ "c:\program files\microsoft platform sdk\include\winefs.h"\
+
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+..\..\..\src\zabbix_agent\resources.rc : \
+ "..\..\..\src\zabbix_agent\MSG00001.bin"\
+
diff --git a/build/win32/project/zabbix_agentd.dsp b/build/win32/project/zabbix_agentd.dsp
new file mode 100755
index 00000000..6457ce6b
--- /dev/null
+++ b/build/win32/project/zabbix_agentd.dsp
@@ -0,0 +1,2920 @@
+# Microsoft Developer Studio Project File - Name="zabbix_agentd" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=zabbix_agentd - Win32 Test
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "zabbix_agentd.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "zabbix_agentd.mak" CFG="zabbix_agentd - Win32 Test"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "zabbix_agentd - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "zabbix_agentd - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "zabbix_agentd - Win32 TODO" (based on "Win32 (x86) Console Application")
+!MESSAGE "zabbix_agentd - Win32 Test" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "NDEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "ZABBIX_SERVICE" /FR /YX /FD /c
+# ADD BASE RSC /l 0x419 /d "NDEBUG"
+# ADD RSC /l 0x409 /fo"Release/zabbixw32.res" /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "ZABBIX_SERVICE" /FR /YX /FD /GZ /c
+# ADD BASE RSC /l 0x419 /d "_DEBUG"
+# ADD RSC /l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "zabbix_agentd___Win32_TODO"
+# PROP BASE Intermediate_Dir "zabbix_agentd___Win32_TODO"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "TODO"
+# PROP Intermediate_Dir "TODO"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /D "_DEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "TODO" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "ZABBIX_SERVICE" /FR /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+# ADD RSC /l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "zabbix_agentd___Win32_Test"
+# PROP BASE Intermediate_Dir "zabbix_agentd___Win32_Test"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Test"
+# PROP Intermediate_Dir "Test"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "ZABBIX_TEST" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "ZABBIX_SERVICE" /FR /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+# ADD RSC /l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "zabbix_agentd - Win32 Release"
+# Name "zabbix_agentd - Win32 Debug"
+# Name "zabbix_agentd - Win32 TODO"
+# Name "zabbix_agentd - Win32 Test"
+# Begin Group "src"
+
+# PROP Default_Filter ""
+# Begin Group "libs"
+
+# PROP Default_Filter ""
+# Begin Group "zbxcommon"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\alias.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\comms.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\gnuregex.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\misc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\regexp.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\str.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\xml.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcommon\zbxgetopt.c
+# End Source File
+# End Group
+# Begin Group "zbxlog"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxlog\log.c
+# End Source File
+# End Group
+# Begin Group "zbxcrypto"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcrypto\base64.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxcrypto\md5.c
+# End Source File
+# End Group
+# Begin Group "zbxnet"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxnet\security.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxnet\zbxsock.c
+# End Source File
+# End Group
+# Begin Group "zbxconf"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxconf\cfg.c
+# End Source File
+# End Group
+# Begin Group "zbxsysinfo"
+
+# PROP Default_Filter ""
+# Begin Group "aix"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\aix.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\AIX_new.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\aix\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "freebsd"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\freebsd.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\freebsd\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "hpux"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\hpux.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\hpux\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "linux"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\linux.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\linux\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "netbsd"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\netbsd.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\netbsd\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "openbsd"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\openbsd.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\OpenBSD3.7.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\openbsd\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "osf"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\osf.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osf\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "osx"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\osx.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\osx\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "solaris"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\solaris.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\SunOS5.9.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\solaris\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "unknown"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\cpu.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\diskio.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\diskspace.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\inodes.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\kernel.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\memory.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\net.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\proc.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\sensors.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\swap.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\unknown.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\unknown\uptime.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "win32"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\cpu.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\diskio.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\diskspace.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\inodes.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\kernel.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\memory.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\net.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\proc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\sensors.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\swap.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\system_w32.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\uptime.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\win32.c
+# End Source File
+# End Group
+# Begin Group "common"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\common.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\file.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\http.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\ntp.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\system.c
+# End Source File
+# End Group
+# End Group
+# Begin Group "zbxwin32"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxwin32\perfmon.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# ADD CPP /W4
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxwin32\service.c
+# End Source File
+# End Group
+# Begin Group "zbxnix"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxnix\daemon.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+# PROP BASE Exclude_From_Build 1
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+# PROP BASE Exclude_From_Build 1
+# PROP Exclude_From_Build 1
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxnix\pid.c
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+# PROP BASE Exclude_From_Build 1
+# PROP Exclude_From_Build 1
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "zbxsys"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsys\mutexs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxsys\threads.c
+# End Source File
+# End Group
+# Begin Group "zbxplugin"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\src\libs\zbxplugin\zbxplugin.c
+# End Source File
+# End Group
+# End Group
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\active.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\active.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\cpustat.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\cpustat.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\diskdevices.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\diskdevices.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\interfaces.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\interfaces.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\listener.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\listener.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\logfiles.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\logfiles.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\stats.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\stats.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\zabbix_agentd.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\zbxconf.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\zbxconf.h
+# End Source File
+# End Group
+# Begin Group "inlcude"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\include\alias.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\base64.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\cfg.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\common.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\include\config.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\daemon.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\db.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\email.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\gnuregex.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\log.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\md5.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\mutexs.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\perfmon.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\pid.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\service.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\sms.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\sysinc.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\sysinfo.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\threads.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\zbxgetopt.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\zbxplugin.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\zbxsecurity.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\zbxsock.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\zbxtypes.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\include\zlog.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\messages.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\messages.mc
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+# Begin Custom Build - Message Compiling...
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+BuildCmds= \
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName) \
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc \
+
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# Begin Custom Build - Message Compiling...
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+BuildCmds= \
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName) \
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc \
+
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+# Begin Custom Build - Message Compiling...
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+BuildCmds= \
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName) \
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc \
+
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+# Begin Custom Build - Message Compiling...
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+BuildCmds= \
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName) \
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc \
+
+
+"$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\resource.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\src\zabbix_agent\resources.rc
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Resource Compiling...
+IntDir=.\Release
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\resources.rc
+InputName=resources
+
+"$(IntDir)\$(InputName).res" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rc /l 0x409 /fo"$(INTDIR)\$(InputName).res" /i $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+# PROP Ignore_Default_Tool 1
+USERDEP__RESOU="Msg00001.bin"
+# Begin Custom Build - Resource Compiling...
+IntDir=.\Debug
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\resources.rc
+InputName=resources
+
+"$(IntDir)\$(InputName).res" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rc /l 0x409 /fo"$(INTDIR)\$(InputName).res" /i $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Resource Compiling...
+IntDir=.\TODO
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\resources.rc
+InputName=resources
+
+"$(IntDir)\$(InputName).res" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rc /l 0x409 /fo"$(INTDIR)\$(InputName).res" /i $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+# PROP Ignore_Default_Tool 1
+# Begin Custom Build - Resource Compiling...
+IntDir=.\Test
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\resources.rc
+InputName=resources
+
+"$(IntDir)\$(InputName).res" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rc /l 0x409 /fo"$(INTDIR)\$(InputName).res" /i $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Group
+# Begin Group "Package Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\configure.in
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\do
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\go
+# End Source File
+# End Group
+# Begin Group "Documentation"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=..\..\..\AUTHORS
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\ChangeLog
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\COPYING
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\FAQ
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\INSTALL
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\NEWS
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\README
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\TODO
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/build/win32/project/zabbix_agentd.dsw b/build/win32/project/zabbix_agentd.dsw
new file mode 100755
index 00000000..6355edae
--- /dev/null
+++ b/build/win32/project/zabbix_agentd.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "zabbix_agentd"=.\zabbix_agentd.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/build/win32/project/zabbix_agentd.mak b/build/win32/project/zabbix_agentd.mak
new file mode 100755
index 00000000..c330d098
--- /dev/null
+++ b/build/win32/project/zabbix_agentd.mak
@@ -0,0 +1,1365 @@
+# Microsoft Developer Studio Generated NMAKE File, Based on zabbix_agentd.dsp
+!IF "$(CFG)" == ""
+CFG=zabbix_agentd - Win32 Test
+!MESSAGE No configuration specified. Defaulting to zabbix_agentd - Win32 Test.
+!ENDIF
+
+!IF "$(CFG)" != "zabbix_agentd - Win32 Release" && "$(CFG)" != "zabbix_agentd - Win32 Debug" && "$(CFG)" != "zabbix_agentd - Win32 TODO" && "$(CFG)" != "zabbix_agentd - Win32 Test"
+!MESSAGE Invalid configuration "$(CFG)" specified.
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "zabbix_agentd.mak" CFG="zabbix_agentd - Win32 Test"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "zabbix_agentd - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "zabbix_agentd - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "zabbix_agentd - Win32 TODO" (based on "Win32 (x86) Console Application")
+!MESSAGE "zabbix_agentd - Win32 Test" (based on "Win32 (x86) Console Application")
+!MESSAGE
+!ERROR An invalid configuration is specified.
+!ENDIF
+
+!IF "$(OS)" == "Windows_NT"
+NULL=
+!ELSE
+NULL=nul
+!ENDIF
+
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+OUTDIR=.\Release
+INTDIR=.\Release
+# Begin Custom Macros
+OutDir=.\Release
+# End Custom Macros
+
+ALL : ".\Msg00001.bin" ".\messages.h" "$(OUTDIR)\zabbix_agentd.exe" "$(OUTDIR)\zabbix_agentd.bsc"
+
+
+CLEAN :
+ -@erase "$(INTDIR)\active.obj"
+ -@erase "$(INTDIR)\active.sbr"
+ -@erase "$(INTDIR)\alias.obj"
+ -@erase "$(INTDIR)\alias.sbr"
+ -@erase "$(INTDIR)\base64.obj"
+ -@erase "$(INTDIR)\base64.sbr"
+ -@erase "$(INTDIR)\cfg.obj"
+ -@erase "$(INTDIR)\cfg.sbr"
+ -@erase "$(INTDIR)\common.obj"
+ -@erase "$(INTDIR)\common.sbr"
+ -@erase "$(INTDIR)\comms.obj"
+ -@erase "$(INTDIR)\comms.sbr"
+ -@erase "$(INTDIR)\cpu.obj"
+ -@erase "$(INTDIR)\cpu.sbr"
+ -@erase "$(INTDIR)\cpustat.obj"
+ -@erase "$(INTDIR)\cpustat.sbr"
+ -@erase "$(INTDIR)\diskdevices.obj"
+ -@erase "$(INTDIR)\diskdevices.sbr"
+ -@erase "$(INTDIR)\diskio.obj"
+ -@erase "$(INTDIR)\diskio.sbr"
+ -@erase "$(INTDIR)\diskspace.obj"
+ -@erase "$(INTDIR)\diskspace.sbr"
+ -@erase "$(INTDIR)\file.obj"
+ -@erase "$(INTDIR)\file.sbr"
+ -@erase "$(INTDIR)\gnuregex.obj"
+ -@erase "$(INTDIR)\gnuregex.sbr"
+ -@erase "$(INTDIR)\http.obj"
+ -@erase "$(INTDIR)\http.sbr"
+ -@erase "$(INTDIR)\inodes.obj"
+ -@erase "$(INTDIR)\inodes.sbr"
+ -@erase "$(INTDIR)\interfaces.obj"
+ -@erase "$(INTDIR)\interfaces.sbr"
+ -@erase "$(INTDIR)\kernel.obj"
+ -@erase "$(INTDIR)\kernel.sbr"
+ -@erase "$(INTDIR)\listener.obj"
+ -@erase "$(INTDIR)\listener.sbr"
+ -@erase "$(INTDIR)\log.obj"
+ -@erase "$(INTDIR)\log.sbr"
+ -@erase "$(INTDIR)\logfiles.obj"
+ -@erase "$(INTDIR)\logfiles.sbr"
+ -@erase "$(INTDIR)\md5.obj"
+ -@erase "$(INTDIR)\md5.sbr"
+ -@erase "$(INTDIR)\memory.obj"
+ -@erase "$(INTDIR)\memory.sbr"
+ -@erase "$(INTDIR)\misc.obj"
+ -@erase "$(INTDIR)\misc.sbr"
+ -@erase "$(INTDIR)\mutexs.obj"
+ -@erase "$(INTDIR)\mutexs.sbr"
+ -@erase "$(INTDIR)\net.obj"
+ -@erase "$(INTDIR)\net.sbr"
+ -@erase "$(INTDIR)\ntp.obj"
+ -@erase "$(INTDIR)\ntp.sbr"
+ -@erase "$(INTDIR)\perfmon.obj"
+ -@erase "$(INTDIR)\perfmon.sbr"
+ -@erase "$(INTDIR)\proc.obj"
+ -@erase "$(INTDIR)\proc.sbr"
+ -@erase "$(INTDIR)\regexp.obj"
+ -@erase "$(INTDIR)\regexp.sbr"
+ -@erase "$(INTDIR)\security.obj"
+ -@erase "$(INTDIR)\security.sbr"
+ -@erase "$(INTDIR)\sensors.obj"
+ -@erase "$(INTDIR)\sensors.sbr"
+ -@erase "$(INTDIR)\service.obj"
+ -@erase "$(INTDIR)\service.sbr"
+ -@erase "$(INTDIR)\stats.obj"
+ -@erase "$(INTDIR)\stats.sbr"
+ -@erase "$(INTDIR)\str.obj"
+ -@erase "$(INTDIR)\str.sbr"
+ -@erase "$(INTDIR)\swap.obj"
+ -@erase "$(INTDIR)\swap.sbr"
+ -@erase "$(INTDIR)\system.obj"
+ -@erase "$(INTDIR)\system.sbr"
+ -@erase "$(INTDIR)\system_w32.obj"
+ -@erase "$(INTDIR)\system_w32.sbr"
+ -@erase "$(INTDIR)\threads.obj"
+ -@erase "$(INTDIR)\threads.sbr"
+ -@erase "$(INTDIR)\uptime.obj"
+ -@erase "$(INTDIR)\uptime.sbr"
+ -@erase "$(INTDIR)\vc60.idb"
+ -@erase "$(INTDIR)\win32.obj"
+ -@erase "$(INTDIR)\win32.sbr"
+ -@erase "$(INTDIR)\xml.obj"
+ -@erase "$(INTDIR)\xml.sbr"
+ -@erase "$(INTDIR)\zabbix_agentd.obj"
+ -@erase "$(INTDIR)\zabbix_agentd.sbr"
+ -@erase "$(INTDIR)\zabbixw32.res"
+ -@erase "$(INTDIR)\zbxconf.obj"
+ -@erase "$(INTDIR)\zbxconf.sbr"
+ -@erase "$(INTDIR)\zbxgetopt.obj"
+ -@erase "$(INTDIR)\zbxgetopt.sbr"
+ -@erase "$(INTDIR)\zbxplugin.obj"
+ -@erase "$(INTDIR)\zbxplugin.sbr"
+ -@erase "$(INTDIR)\zbxsock.obj"
+ -@erase "$(INTDIR)\zbxsock.sbr"
+ -@erase "$(OUTDIR)\zabbix_agentd.bsc"
+ -@erase "$(OUTDIR)\zabbix_agentd.exe"
+ -@erase "messages.h"
+ -@erase "Msg00001.bin"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+CPP_PROJ=/nologo /MT /W3 /GX /O2 /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "NDEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\zabbix_agentd.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
+RSC_PROJ=/l 0x409 /fo"$(INTDIR)\zabbixw32.res" /d "NDEBUG"
+BSC32=bscmake.exe
+BSC32_FLAGS=/nologo /o"$(OUTDIR)\zabbix_agentd.bsc"
+BSC32_SBRS= \
+ "$(INTDIR)\alias.sbr" \
+ "$(INTDIR)\comms.sbr" \
+ "$(INTDIR)\gnuregex.sbr" \
+ "$(INTDIR)\misc.sbr" \
+ "$(INTDIR)\regexp.sbr" \
+ "$(INTDIR)\str.sbr" \
+ "$(INTDIR)\xml.sbr" \
+ "$(INTDIR)\zbxgetopt.sbr" \
+ "$(INTDIR)\log.sbr" \
+ "$(INTDIR)\base64.sbr" \
+ "$(INTDIR)\md5.sbr" \
+ "$(INTDIR)\security.sbr" \
+ "$(INTDIR)\zbxsock.sbr" \
+ "$(INTDIR)\cfg.sbr" \
+ "$(INTDIR)\common.sbr" \
+ "$(INTDIR)\file.sbr" \
+ "$(INTDIR)\http.sbr" \
+ "$(INTDIR)\ntp.sbr" \
+ "$(INTDIR)\system.sbr" \
+ "$(INTDIR)\cpu.sbr" \
+ "$(INTDIR)\diskio.sbr" \
+ "$(INTDIR)\diskspace.sbr" \
+ "$(INTDIR)\inodes.sbr" \
+ "$(INTDIR)\kernel.sbr" \
+ "$(INTDIR)\memory.sbr" \
+ "$(INTDIR)\net.sbr" \
+ "$(INTDIR)\proc.sbr" \
+ "$(INTDIR)\sensors.sbr" \
+ "$(INTDIR)\swap.sbr" \
+ "$(INTDIR)\system_w32.sbr" \
+ "$(INTDIR)\uptime.sbr" \
+ "$(INTDIR)\win32.sbr" \
+ "$(INTDIR)\perfmon.sbr" \
+ "$(INTDIR)\service.sbr" \
+ "$(INTDIR)\mutexs.sbr" \
+ "$(INTDIR)\threads.sbr" \
+ "$(INTDIR)\zbxplugin.sbr" \
+ "$(INTDIR)\active.sbr" \
+ "$(INTDIR)\cpustat.sbr" \
+ "$(INTDIR)\diskdevices.sbr" \
+ "$(INTDIR)\interfaces.sbr" \
+ "$(INTDIR)\listener.sbr" \
+ "$(INTDIR)\logfiles.sbr" \
+ "$(INTDIR)\stats.sbr" \
+ "$(INTDIR)\zabbix_agentd.sbr" \
+ "$(INTDIR)\zbxconf.sbr"
+
+"$(OUTDIR)\zabbix_agentd.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
+ $(BSC32) @<<
+ $(BSC32_FLAGS) $(BSC32_SBRS)
+<<
+
+LINK32=link.exe
+LINK32_FLAGS=ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\zabbix_agentd.pdb" /machine:I386 /out:"$(OUTDIR)\zabbix_agentd.exe"
+LINK32_OBJS= \
+ "$(INTDIR)\alias.obj" \
+ "$(INTDIR)\comms.obj" \
+ "$(INTDIR)\gnuregex.obj" \
+ "$(INTDIR)\misc.obj" \
+ "$(INTDIR)\regexp.obj" \
+ "$(INTDIR)\str.obj" \
+ "$(INTDIR)\xml.obj" \
+ "$(INTDIR)\zbxgetopt.obj" \
+ "$(INTDIR)\log.obj" \
+ "$(INTDIR)\base64.obj" \
+ "$(INTDIR)\md5.obj" \
+ "$(INTDIR)\security.obj" \
+ "$(INTDIR)\zbxsock.obj" \
+ "$(INTDIR)\cfg.obj" \
+ "$(INTDIR)\common.obj" \
+ "$(INTDIR)\file.obj" \
+ "$(INTDIR)\http.obj" \
+ "$(INTDIR)\ntp.obj" \
+ "$(INTDIR)\system.obj" \
+ "$(INTDIR)\cpu.obj" \
+ "$(INTDIR)\diskio.obj" \
+ "$(INTDIR)\diskspace.obj" \
+ "$(INTDIR)\inodes.obj" \
+ "$(INTDIR)\kernel.obj" \
+ "$(INTDIR)\memory.obj" \
+ "$(INTDIR)\net.obj" \
+ "$(INTDIR)\proc.obj" \
+ "$(INTDIR)\sensors.obj" \
+ "$(INTDIR)\swap.obj" \
+ "$(INTDIR)\system_w32.obj" \
+ "$(INTDIR)\uptime.obj" \
+ "$(INTDIR)\win32.obj" \
+ "$(INTDIR)\perfmon.obj" \
+ "$(INTDIR)\service.obj" \
+ "$(INTDIR)\mutexs.obj" \
+ "$(INTDIR)\threads.obj" \
+ "$(INTDIR)\zbxplugin.obj" \
+ "$(INTDIR)\active.obj" \
+ "$(INTDIR)\cpustat.obj" \
+ "$(INTDIR)\diskdevices.obj" \
+ "$(INTDIR)\interfaces.obj" \
+ "$(INTDIR)\listener.obj" \
+ "$(INTDIR)\logfiles.obj" \
+ "$(INTDIR)\stats.obj" \
+ "$(INTDIR)\zabbix_agentd.obj" \
+ "$(INTDIR)\zbxconf.obj" \
+ "$(INTDIR)\zabbixw32.res"
+
+"$(OUTDIR)\zabbix_agentd.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+OUTDIR=.\Debug
+INTDIR=.\Debug
+# Begin Custom Macros
+OutDir=.\Debug
+# End Custom Macros
+
+ALL : ".\Msg00001.bin" ".\messages.h" "$(OUTDIR)\zabbix_agentd.exe" "$(OUTDIR)\zabbix_agentd.bsc"
+
+
+CLEAN :
+ -@erase "$(INTDIR)\active.obj"
+ -@erase "$(INTDIR)\active.sbr"
+ -@erase "$(INTDIR)\alias.obj"
+ -@erase "$(INTDIR)\alias.sbr"
+ -@erase "$(INTDIR)\base64.obj"
+ -@erase "$(INTDIR)\base64.sbr"
+ -@erase "$(INTDIR)\cfg.obj"
+ -@erase "$(INTDIR)\cfg.sbr"
+ -@erase "$(INTDIR)\common.obj"
+ -@erase "$(INTDIR)\common.sbr"
+ -@erase "$(INTDIR)\comms.obj"
+ -@erase "$(INTDIR)\comms.sbr"
+ -@erase "$(INTDIR)\cpu.obj"
+ -@erase "$(INTDIR)\cpu.sbr"
+ -@erase "$(INTDIR)\cpustat.obj"
+ -@erase "$(INTDIR)\cpustat.sbr"
+ -@erase "$(INTDIR)\diskdevices.obj"
+ -@erase "$(INTDIR)\diskdevices.sbr"
+ -@erase "$(INTDIR)\diskio.obj"
+ -@erase "$(INTDIR)\diskio.sbr"
+ -@erase "$(INTDIR)\diskspace.obj"
+ -@erase "$(INTDIR)\diskspace.sbr"
+ -@erase "$(INTDIR)\file.obj"
+ -@erase "$(INTDIR)\file.sbr"
+ -@erase "$(INTDIR)\gnuregex.obj"
+ -@erase "$(INTDIR)\gnuregex.sbr"
+ -@erase "$(INTDIR)\http.obj"
+ -@erase "$(INTDIR)\http.sbr"
+ -@erase "$(INTDIR)\inodes.obj"
+ -@erase "$(INTDIR)\inodes.sbr"
+ -@erase "$(INTDIR)\interfaces.obj"
+ -@erase "$(INTDIR)\interfaces.sbr"
+ -@erase "$(INTDIR)\kernel.obj"
+ -@erase "$(INTDIR)\kernel.sbr"
+ -@erase "$(INTDIR)\listener.obj"
+ -@erase "$(INTDIR)\listener.sbr"
+ -@erase "$(INTDIR)\log.obj"
+ -@erase "$(INTDIR)\log.sbr"
+ -@erase "$(INTDIR)\logfiles.obj"
+ -@erase "$(INTDIR)\logfiles.sbr"
+ -@erase "$(INTDIR)\md5.obj"
+ -@erase "$(INTDIR)\md5.sbr"
+ -@erase "$(INTDIR)\memory.obj"
+ -@erase "$(INTDIR)\memory.sbr"
+ -@erase "$(INTDIR)\misc.obj"
+ -@erase "$(INTDIR)\misc.sbr"
+ -@erase "$(INTDIR)\mutexs.obj"
+ -@erase "$(INTDIR)\mutexs.sbr"
+ -@erase "$(INTDIR)\net.obj"
+ -@erase "$(INTDIR)\net.sbr"
+ -@erase "$(INTDIR)\ntp.obj"
+ -@erase "$(INTDIR)\ntp.sbr"
+ -@erase "$(INTDIR)\perfmon.obj"
+ -@erase "$(INTDIR)\perfmon.sbr"
+ -@erase "$(INTDIR)\proc.obj"
+ -@erase "$(INTDIR)\proc.sbr"
+ -@erase "$(INTDIR)\regexp.obj"
+ -@erase "$(INTDIR)\regexp.sbr"
+ -@erase "$(INTDIR)\security.obj"
+ -@erase "$(INTDIR)\security.sbr"
+ -@erase "$(INTDIR)\sensors.obj"
+ -@erase "$(INTDIR)\sensors.sbr"
+ -@erase "$(INTDIR)\service.obj"
+ -@erase "$(INTDIR)\service.sbr"
+ -@erase "$(INTDIR)\stats.obj"
+ -@erase "$(INTDIR)\stats.sbr"
+ -@erase "$(INTDIR)\str.obj"
+ -@erase "$(INTDIR)\str.sbr"
+ -@erase "$(INTDIR)\swap.obj"
+ -@erase "$(INTDIR)\swap.sbr"
+ -@erase "$(INTDIR)\system.obj"
+ -@erase "$(INTDIR)\system.sbr"
+ -@erase "$(INTDIR)\system_w32.obj"
+ -@erase "$(INTDIR)\system_w32.sbr"
+ -@erase "$(INTDIR)\threads.obj"
+ -@erase "$(INTDIR)\threads.sbr"
+ -@erase "$(INTDIR)\uptime.obj"
+ -@erase "$(INTDIR)\uptime.sbr"
+ -@erase "$(INTDIR)\vc60.idb"
+ -@erase "$(INTDIR)\vc60.pdb"
+ -@erase "$(INTDIR)\win32.obj"
+ -@erase "$(INTDIR)\win32.sbr"
+ -@erase "$(INTDIR)\xml.obj"
+ -@erase "$(INTDIR)\xml.sbr"
+ -@erase "$(INTDIR)\zabbix_agentd.obj"
+ -@erase "$(INTDIR)\zabbix_agentd.sbr"
+ -@erase "$(INTDIR)\zabbixw32.res"
+ -@erase "$(INTDIR)\zbxconf.obj"
+ -@erase "$(INTDIR)\zbxconf.sbr"
+ -@erase "$(INTDIR)\zbxgetopt.obj"
+ -@erase "$(INTDIR)\zbxgetopt.sbr"
+ -@erase "$(INTDIR)\zbxplugin.obj"
+ -@erase "$(INTDIR)\zbxplugin.sbr"
+ -@erase "$(INTDIR)\zbxsock.obj"
+ -@erase "$(INTDIR)\zbxsock.sbr"
+ -@erase "$(OUTDIR)\zabbix_agentd.bsc"
+ -@erase "$(OUTDIR)\zabbix_agentd.exe"
+ -@erase "$(OUTDIR)\zabbix_agentd.ilk"
+ -@erase "$(OUTDIR)\zabbix_agentd.pdb"
+ -@erase "messages.h"
+ -@erase "Msg00001.bin"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\zabbix_agentd.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
+RSC_PROJ=/l 0x409 /fo"$(INTDIR)\zabbixw32.res" /d "_DEBUG"
+BSC32=bscmake.exe
+BSC32_FLAGS=/nologo /o"$(OUTDIR)\zabbix_agentd.bsc"
+BSC32_SBRS= \
+ "$(INTDIR)\alias.sbr" \
+ "$(INTDIR)\comms.sbr" \
+ "$(INTDIR)\gnuregex.sbr" \
+ "$(INTDIR)\misc.sbr" \
+ "$(INTDIR)\regexp.sbr" \
+ "$(INTDIR)\str.sbr" \
+ "$(INTDIR)\xml.sbr" \
+ "$(INTDIR)\zbxgetopt.sbr" \
+ "$(INTDIR)\log.sbr" \
+ "$(INTDIR)\base64.sbr" \
+ "$(INTDIR)\md5.sbr" \
+ "$(INTDIR)\security.sbr" \
+ "$(INTDIR)\zbxsock.sbr" \
+ "$(INTDIR)\cfg.sbr" \
+ "$(INTDIR)\common.sbr" \
+ "$(INTDIR)\file.sbr" \
+ "$(INTDIR)\http.sbr" \
+ "$(INTDIR)\ntp.sbr" \
+ "$(INTDIR)\system.sbr" \
+ "$(INTDIR)\cpu.sbr" \
+ "$(INTDIR)\diskio.sbr" \
+ "$(INTDIR)\diskspace.sbr" \
+ "$(INTDIR)\inodes.sbr" \
+ "$(INTDIR)\kernel.sbr" \
+ "$(INTDIR)\memory.sbr" \
+ "$(INTDIR)\net.sbr" \
+ "$(INTDIR)\proc.sbr" \
+ "$(INTDIR)\sensors.sbr" \
+ "$(INTDIR)\swap.sbr" \
+ "$(INTDIR)\system_w32.sbr" \
+ "$(INTDIR)\uptime.sbr" \
+ "$(INTDIR)\win32.sbr" \
+ "$(INTDIR)\perfmon.sbr" \
+ "$(INTDIR)\service.sbr" \
+ "$(INTDIR)\mutexs.sbr" \
+ "$(INTDIR)\threads.sbr" \
+ "$(INTDIR)\zbxplugin.sbr" \
+ "$(INTDIR)\active.sbr" \
+ "$(INTDIR)\cpustat.sbr" \
+ "$(INTDIR)\diskdevices.sbr" \
+ "$(INTDIR)\interfaces.sbr" \
+ "$(INTDIR)\listener.sbr" \
+ "$(INTDIR)\logfiles.sbr" \
+ "$(INTDIR)\stats.sbr" \
+ "$(INTDIR)\zabbix_agentd.sbr" \
+ "$(INTDIR)\zbxconf.sbr"
+
+"$(OUTDIR)\zabbix_agentd.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
+ $(BSC32) @<<
+ $(BSC32_FLAGS) $(BSC32_SBRS)
+<<
+
+LINK32=link.exe
+LINK32_FLAGS=ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\zabbix_agentd.pdb" /debug /machine:I386 /out:"$(OUTDIR)\zabbix_agentd.exe" /pdbtype:sept
+LINK32_OBJS= \
+ "$(INTDIR)\alias.obj" \
+ "$(INTDIR)\comms.obj" \
+ "$(INTDIR)\gnuregex.obj" \
+ "$(INTDIR)\misc.obj" \
+ "$(INTDIR)\regexp.obj" \
+ "$(INTDIR)\str.obj" \
+ "$(INTDIR)\xml.obj" \
+ "$(INTDIR)\zbxgetopt.obj" \
+ "$(INTDIR)\log.obj" \
+ "$(INTDIR)\base64.obj" \
+ "$(INTDIR)\md5.obj" \
+ "$(INTDIR)\security.obj" \
+ "$(INTDIR)\zbxsock.obj" \
+ "$(INTDIR)\cfg.obj" \
+ "$(INTDIR)\common.obj" \
+ "$(INTDIR)\file.obj" \
+ "$(INTDIR)\http.obj" \
+ "$(INTDIR)\ntp.obj" \
+ "$(INTDIR)\system.obj" \
+ "$(INTDIR)\cpu.obj" \
+ "$(INTDIR)\diskio.obj" \
+ "$(INTDIR)\diskspace.obj" \
+ "$(INTDIR)\inodes.obj" \
+ "$(INTDIR)\kernel.obj" \
+ "$(INTDIR)\memory.obj" \
+ "$(INTDIR)\net.obj" \
+ "$(INTDIR)\proc.obj" \
+ "$(INTDIR)\sensors.obj" \
+ "$(INTDIR)\swap.obj" \
+ "$(INTDIR)\system_w32.obj" \
+ "$(INTDIR)\uptime.obj" \
+ "$(INTDIR)\win32.obj" \
+ "$(INTDIR)\perfmon.obj" \
+ "$(INTDIR)\service.obj" \
+ "$(INTDIR)\mutexs.obj" \
+ "$(INTDIR)\threads.obj" \
+ "$(INTDIR)\zbxplugin.obj" \
+ "$(INTDIR)\active.obj" \
+ "$(INTDIR)\cpustat.obj" \
+ "$(INTDIR)\diskdevices.obj" \
+ "$(INTDIR)\interfaces.obj" \
+ "$(INTDIR)\listener.obj" \
+ "$(INTDIR)\logfiles.obj" \
+ "$(INTDIR)\stats.obj" \
+ "$(INTDIR)\zabbix_agentd.obj" \
+ "$(INTDIR)\zbxconf.obj" \
+ "$(INTDIR)\zabbixw32.res"
+
+"$(OUTDIR)\zabbix_agentd.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+OUTDIR=.\TODO
+INTDIR=.\TODO
+# Begin Custom Macros
+OutDir=.\TODO
+# End Custom Macros
+
+ALL : ".\Msg00001.bin" ".\messages.h" "$(OUTDIR)\zabbix_agentd.exe" "$(OUTDIR)\zabbix_agentd.bsc"
+
+
+CLEAN :
+ -@erase "$(INTDIR)\active.obj"
+ -@erase "$(INTDIR)\active.sbr"
+ -@erase "$(INTDIR)\alias.obj"
+ -@erase "$(INTDIR)\alias.sbr"
+ -@erase "$(INTDIR)\base64.obj"
+ -@erase "$(INTDIR)\base64.sbr"
+ -@erase "$(INTDIR)\cfg.obj"
+ -@erase "$(INTDIR)\cfg.sbr"
+ -@erase "$(INTDIR)\common.obj"
+ -@erase "$(INTDIR)\common.sbr"
+ -@erase "$(INTDIR)\comms.obj"
+ -@erase "$(INTDIR)\comms.sbr"
+ -@erase "$(INTDIR)\cpu.obj"
+ -@erase "$(INTDIR)\cpu.sbr"
+ -@erase "$(INTDIR)\cpustat.obj"
+ -@erase "$(INTDIR)\cpustat.sbr"
+ -@erase "$(INTDIR)\diskdevices.obj"
+ -@erase "$(INTDIR)\diskdevices.sbr"
+ -@erase "$(INTDIR)\diskio.obj"
+ -@erase "$(INTDIR)\diskio.sbr"
+ -@erase "$(INTDIR)\diskspace.obj"
+ -@erase "$(INTDIR)\diskspace.sbr"
+ -@erase "$(INTDIR)\file.obj"
+ -@erase "$(INTDIR)\file.sbr"
+ -@erase "$(INTDIR)\gnuregex.obj"
+ -@erase "$(INTDIR)\gnuregex.sbr"
+ -@erase "$(INTDIR)\http.obj"
+ -@erase "$(INTDIR)\http.sbr"
+ -@erase "$(INTDIR)\inodes.obj"
+ -@erase "$(INTDIR)\inodes.sbr"
+ -@erase "$(INTDIR)\interfaces.obj"
+ -@erase "$(INTDIR)\interfaces.sbr"
+ -@erase "$(INTDIR)\kernel.obj"
+ -@erase "$(INTDIR)\kernel.sbr"
+ -@erase "$(INTDIR)\listener.obj"
+ -@erase "$(INTDIR)\listener.sbr"
+ -@erase "$(INTDIR)\log.obj"
+ -@erase "$(INTDIR)\log.sbr"
+ -@erase "$(INTDIR)\logfiles.obj"
+ -@erase "$(INTDIR)\logfiles.sbr"
+ -@erase "$(INTDIR)\md5.obj"
+ -@erase "$(INTDIR)\md5.sbr"
+ -@erase "$(INTDIR)\memory.obj"
+ -@erase "$(INTDIR)\memory.sbr"
+ -@erase "$(INTDIR)\misc.obj"
+ -@erase "$(INTDIR)\misc.sbr"
+ -@erase "$(INTDIR)\mutexs.obj"
+ -@erase "$(INTDIR)\mutexs.sbr"
+ -@erase "$(INTDIR)\net.obj"
+ -@erase "$(INTDIR)\net.sbr"
+ -@erase "$(INTDIR)\ntp.obj"
+ -@erase "$(INTDIR)\ntp.sbr"
+ -@erase "$(INTDIR)\perfmon.obj"
+ -@erase "$(INTDIR)\perfmon.sbr"
+ -@erase "$(INTDIR)\proc.obj"
+ -@erase "$(INTDIR)\proc.sbr"
+ -@erase "$(INTDIR)\regexp.obj"
+ -@erase "$(INTDIR)\regexp.sbr"
+ -@erase "$(INTDIR)\security.obj"
+ -@erase "$(INTDIR)\security.sbr"
+ -@erase "$(INTDIR)\sensors.obj"
+ -@erase "$(INTDIR)\sensors.sbr"
+ -@erase "$(INTDIR)\service.obj"
+ -@erase "$(INTDIR)\service.sbr"
+ -@erase "$(INTDIR)\stats.obj"
+ -@erase "$(INTDIR)\stats.sbr"
+ -@erase "$(INTDIR)\str.obj"
+ -@erase "$(INTDIR)\str.sbr"
+ -@erase "$(INTDIR)\swap.obj"
+ -@erase "$(INTDIR)\swap.sbr"
+ -@erase "$(INTDIR)\system.obj"
+ -@erase "$(INTDIR)\system.sbr"
+ -@erase "$(INTDIR)\system_w32.obj"
+ -@erase "$(INTDIR)\system_w32.sbr"
+ -@erase "$(INTDIR)\threads.obj"
+ -@erase "$(INTDIR)\threads.sbr"
+ -@erase "$(INTDIR)\uptime.obj"
+ -@erase "$(INTDIR)\uptime.sbr"
+ -@erase "$(INTDIR)\vc60.idb"
+ -@erase "$(INTDIR)\vc60.pdb"
+ -@erase "$(INTDIR)\win32.obj"
+ -@erase "$(INTDIR)\win32.sbr"
+ -@erase "$(INTDIR)\xml.obj"
+ -@erase "$(INTDIR)\xml.sbr"
+ -@erase "$(INTDIR)\zabbix_agentd.obj"
+ -@erase "$(INTDIR)\zabbix_agentd.sbr"
+ -@erase "$(INTDIR)\zbxconf.obj"
+ -@erase "$(INTDIR)\zbxconf.sbr"
+ -@erase "$(INTDIR)\zbxgetopt.obj"
+ -@erase "$(INTDIR)\zbxgetopt.sbr"
+ -@erase "$(INTDIR)\zbxplugin.obj"
+ -@erase "$(INTDIR)\zbxplugin.sbr"
+ -@erase "$(INTDIR)\zbxsock.obj"
+ -@erase "$(INTDIR)\zbxsock.sbr"
+ -@erase "$(OUTDIR)\zabbix_agentd.bsc"
+ -@erase "$(OUTDIR)\zabbix_agentd.exe"
+ -@erase "$(OUTDIR)\zabbix_agentd.ilk"
+ -@erase "$(OUTDIR)\zabbix_agentd.pdb"
+ -@erase ".\Debug\zabbixw32.res"
+ -@erase "messages.h"
+ -@erase "Msg00001.bin"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "TODO" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\zabbix_agentd.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
+RSC_PROJ=/l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+BSC32=bscmake.exe
+BSC32_FLAGS=/nologo /o"$(OUTDIR)\zabbix_agentd.bsc"
+BSC32_SBRS= \
+ "$(INTDIR)\alias.sbr" \
+ "$(INTDIR)\comms.sbr" \
+ "$(INTDIR)\gnuregex.sbr" \
+ "$(INTDIR)\misc.sbr" \
+ "$(INTDIR)\regexp.sbr" \
+ "$(INTDIR)\str.sbr" \
+ "$(INTDIR)\xml.sbr" \
+ "$(INTDIR)\zbxgetopt.sbr" \
+ "$(INTDIR)\log.sbr" \
+ "$(INTDIR)\base64.sbr" \
+ "$(INTDIR)\md5.sbr" \
+ "$(INTDIR)\security.sbr" \
+ "$(INTDIR)\zbxsock.sbr" \
+ "$(INTDIR)\cfg.sbr" \
+ "$(INTDIR)\common.sbr" \
+ "$(INTDIR)\file.sbr" \
+ "$(INTDIR)\http.sbr" \
+ "$(INTDIR)\ntp.sbr" \
+ "$(INTDIR)\system.sbr" \
+ "$(INTDIR)\cpu.sbr" \
+ "$(INTDIR)\diskio.sbr" \
+ "$(INTDIR)\diskspace.sbr" \
+ "$(INTDIR)\inodes.sbr" \
+ "$(INTDIR)\kernel.sbr" \
+ "$(INTDIR)\memory.sbr" \
+ "$(INTDIR)\net.sbr" \
+ "$(INTDIR)\proc.sbr" \
+ "$(INTDIR)\sensors.sbr" \
+ "$(INTDIR)\swap.sbr" \
+ "$(INTDIR)\system_w32.sbr" \
+ "$(INTDIR)\uptime.sbr" \
+ "$(INTDIR)\win32.sbr" \
+ "$(INTDIR)\perfmon.sbr" \
+ "$(INTDIR)\service.sbr" \
+ "$(INTDIR)\mutexs.sbr" \
+ "$(INTDIR)\threads.sbr" \
+ "$(INTDIR)\zbxplugin.sbr" \
+ "$(INTDIR)\active.sbr" \
+ "$(INTDIR)\cpustat.sbr" \
+ "$(INTDIR)\diskdevices.sbr" \
+ "$(INTDIR)\interfaces.sbr" \
+ "$(INTDIR)\listener.sbr" \
+ "$(INTDIR)\logfiles.sbr" \
+ "$(INTDIR)\stats.sbr" \
+ "$(INTDIR)\zabbix_agentd.sbr" \
+ "$(INTDIR)\zbxconf.sbr"
+
+"$(OUTDIR)\zabbix_agentd.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
+ $(BSC32) @<<
+ $(BSC32_FLAGS) $(BSC32_SBRS)
+<<
+
+LINK32=link.exe
+LINK32_FLAGS=ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\zabbix_agentd.pdb" /debug /machine:I386 /out:"$(OUTDIR)\zabbix_agentd.exe" /pdbtype:sept
+LINK32_OBJS= \
+ "$(INTDIR)\alias.obj" \
+ "$(INTDIR)\comms.obj" \
+ "$(INTDIR)\gnuregex.obj" \
+ "$(INTDIR)\misc.obj" \
+ "$(INTDIR)\regexp.obj" \
+ "$(INTDIR)\str.obj" \
+ "$(INTDIR)\xml.obj" \
+ "$(INTDIR)\zbxgetopt.obj" \
+ "$(INTDIR)\log.obj" \
+ "$(INTDIR)\base64.obj" \
+ "$(INTDIR)\md5.obj" \
+ "$(INTDIR)\security.obj" \
+ "$(INTDIR)\zbxsock.obj" \
+ "$(INTDIR)\cfg.obj" \
+ "$(INTDIR)\common.obj" \
+ "$(INTDIR)\file.obj" \
+ "$(INTDIR)\http.obj" \
+ "$(INTDIR)\ntp.obj" \
+ "$(INTDIR)\system.obj" \
+ "$(INTDIR)\cpu.obj" \
+ "$(INTDIR)\diskio.obj" \
+ "$(INTDIR)\diskspace.obj" \
+ "$(INTDIR)\inodes.obj" \
+ "$(INTDIR)\kernel.obj" \
+ "$(INTDIR)\memory.obj" \
+ "$(INTDIR)\net.obj" \
+ "$(INTDIR)\proc.obj" \
+ "$(INTDIR)\sensors.obj" \
+ "$(INTDIR)\swap.obj" \
+ "$(INTDIR)\system_w32.obj" \
+ "$(INTDIR)\uptime.obj" \
+ "$(INTDIR)\win32.obj" \
+ "$(INTDIR)\perfmon.obj" \
+ "$(INTDIR)\service.obj" \
+ "$(INTDIR)\mutexs.obj" \
+ "$(INTDIR)\threads.obj" \
+ "$(INTDIR)\zbxplugin.obj" \
+ "$(INTDIR)\active.obj" \
+ "$(INTDIR)\cpustat.obj" \
+ "$(INTDIR)\diskdevices.obj" \
+ "$(INTDIR)\interfaces.obj" \
+ "$(INTDIR)\listener.obj" \
+ "$(INTDIR)\logfiles.obj" \
+ "$(INTDIR)\stats.obj" \
+ "$(INTDIR)\zabbix_agentd.obj" \
+ "$(INTDIR)\zbxconf.obj" \
+ ".\Debug\zabbixw32.res"
+
+"$(OUTDIR)\zabbix_agentd.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+OUTDIR=.\Test
+INTDIR=.\Test
+# Begin Custom Macros
+OutDir=.\Test
+# End Custom Macros
+
+ALL : ".\Msg00001.bin" ".\messages.h" "$(OUTDIR)\zabbix_agentd.exe" "$(OUTDIR)\zabbix_agentd.bsc"
+
+
+CLEAN :
+ -@erase "$(INTDIR)\active.obj"
+ -@erase "$(INTDIR)\active.sbr"
+ -@erase "$(INTDIR)\alias.obj"
+ -@erase "$(INTDIR)\alias.sbr"
+ -@erase "$(INTDIR)\base64.obj"
+ -@erase "$(INTDIR)\base64.sbr"
+ -@erase "$(INTDIR)\cfg.obj"
+ -@erase "$(INTDIR)\cfg.sbr"
+ -@erase "$(INTDIR)\common.obj"
+ -@erase "$(INTDIR)\common.sbr"
+ -@erase "$(INTDIR)\comms.obj"
+ -@erase "$(INTDIR)\comms.sbr"
+ -@erase "$(INTDIR)\cpu.obj"
+ -@erase "$(INTDIR)\cpu.sbr"
+ -@erase "$(INTDIR)\cpustat.obj"
+ -@erase "$(INTDIR)\cpustat.sbr"
+ -@erase "$(INTDIR)\diskdevices.obj"
+ -@erase "$(INTDIR)\diskdevices.sbr"
+ -@erase "$(INTDIR)\diskio.obj"
+ -@erase "$(INTDIR)\diskio.sbr"
+ -@erase "$(INTDIR)\diskspace.obj"
+ -@erase "$(INTDIR)\diskspace.sbr"
+ -@erase "$(INTDIR)\file.obj"
+ -@erase "$(INTDIR)\file.sbr"
+ -@erase "$(INTDIR)\gnuregex.obj"
+ -@erase "$(INTDIR)\gnuregex.sbr"
+ -@erase "$(INTDIR)\http.obj"
+ -@erase "$(INTDIR)\http.sbr"
+ -@erase "$(INTDIR)\inodes.obj"
+ -@erase "$(INTDIR)\inodes.sbr"
+ -@erase "$(INTDIR)\interfaces.obj"
+ -@erase "$(INTDIR)\interfaces.sbr"
+ -@erase "$(INTDIR)\kernel.obj"
+ -@erase "$(INTDIR)\kernel.sbr"
+ -@erase "$(INTDIR)\listener.obj"
+ -@erase "$(INTDIR)\listener.sbr"
+ -@erase "$(INTDIR)\log.obj"
+ -@erase "$(INTDIR)\log.sbr"
+ -@erase "$(INTDIR)\logfiles.obj"
+ -@erase "$(INTDIR)\logfiles.sbr"
+ -@erase "$(INTDIR)\md5.obj"
+ -@erase "$(INTDIR)\md5.sbr"
+ -@erase "$(INTDIR)\memory.obj"
+ -@erase "$(INTDIR)\memory.sbr"
+ -@erase "$(INTDIR)\misc.obj"
+ -@erase "$(INTDIR)\misc.sbr"
+ -@erase "$(INTDIR)\mutexs.obj"
+ -@erase "$(INTDIR)\mutexs.sbr"
+ -@erase "$(INTDIR)\net.obj"
+ -@erase "$(INTDIR)\net.sbr"
+ -@erase "$(INTDIR)\ntp.obj"
+ -@erase "$(INTDIR)\ntp.sbr"
+ -@erase "$(INTDIR)\perfmon.obj"
+ -@erase "$(INTDIR)\perfmon.sbr"
+ -@erase "$(INTDIR)\proc.obj"
+ -@erase "$(INTDIR)\proc.sbr"
+ -@erase "$(INTDIR)\regexp.obj"
+ -@erase "$(INTDIR)\regexp.sbr"
+ -@erase "$(INTDIR)\security.obj"
+ -@erase "$(INTDIR)\security.sbr"
+ -@erase "$(INTDIR)\sensors.obj"
+ -@erase "$(INTDIR)\sensors.sbr"
+ -@erase "$(INTDIR)\service.obj"
+ -@erase "$(INTDIR)\service.sbr"
+ -@erase "$(INTDIR)\stats.obj"
+ -@erase "$(INTDIR)\stats.sbr"
+ -@erase "$(INTDIR)\str.obj"
+ -@erase "$(INTDIR)\str.sbr"
+ -@erase "$(INTDIR)\swap.obj"
+ -@erase "$(INTDIR)\swap.sbr"
+ -@erase "$(INTDIR)\system.obj"
+ -@erase "$(INTDIR)\system.sbr"
+ -@erase "$(INTDIR)\system_w32.obj"
+ -@erase "$(INTDIR)\system_w32.sbr"
+ -@erase "$(INTDIR)\threads.obj"
+ -@erase "$(INTDIR)\threads.sbr"
+ -@erase "$(INTDIR)\uptime.obj"
+ -@erase "$(INTDIR)\uptime.sbr"
+ -@erase "$(INTDIR)\vc60.idb"
+ -@erase "$(INTDIR)\vc60.pdb"
+ -@erase "$(INTDIR)\win32.obj"
+ -@erase "$(INTDIR)\win32.sbr"
+ -@erase "$(INTDIR)\xml.obj"
+ -@erase "$(INTDIR)\xml.sbr"
+ -@erase "$(INTDIR)\zabbix_agentd.obj"
+ -@erase "$(INTDIR)\zabbix_agentd.sbr"
+ -@erase "$(INTDIR)\zbxconf.obj"
+ -@erase "$(INTDIR)\zbxconf.sbr"
+ -@erase "$(INTDIR)\zbxgetopt.obj"
+ -@erase "$(INTDIR)\zbxgetopt.sbr"
+ -@erase "$(INTDIR)\zbxplugin.obj"
+ -@erase "$(INTDIR)\zbxplugin.sbr"
+ -@erase "$(INTDIR)\zbxsock.obj"
+ -@erase "$(INTDIR)\zbxsock.sbr"
+ -@erase "$(OUTDIR)\zabbix_agentd.bsc"
+ -@erase "$(OUTDIR)\zabbix_agentd.exe"
+ -@erase "$(OUTDIR)\zabbix_agentd.ilk"
+ -@erase "$(OUTDIR)\zabbix_agentd.pdb"
+ -@erase ".\Debug\zabbixw32.res"
+ -@erase "messages.h"
+ -@erase "Msg00001.bin"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I "../include/" /I "../../../include/" /I "../../../src/zabbix_agent" /D "_DEBUG" /D "HAVE_ASSERT_H" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "ZABBIX_TEST" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\zabbix_agentd.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
+RSC_PROJ=/l 0x409 /fo"Debug/zabbixw32.res" /d "_DEBUG"
+BSC32=bscmake.exe
+BSC32_FLAGS=/nologo /o"$(OUTDIR)\zabbix_agentd.bsc"
+BSC32_SBRS= \
+ "$(INTDIR)\alias.sbr" \
+ "$(INTDIR)\comms.sbr" \
+ "$(INTDIR)\gnuregex.sbr" \
+ "$(INTDIR)\misc.sbr" \
+ "$(INTDIR)\regexp.sbr" \
+ "$(INTDIR)\str.sbr" \
+ "$(INTDIR)\xml.sbr" \
+ "$(INTDIR)\zbxgetopt.sbr" \
+ "$(INTDIR)\log.sbr" \
+ "$(INTDIR)\base64.sbr" \
+ "$(INTDIR)\md5.sbr" \
+ "$(INTDIR)\security.sbr" \
+ "$(INTDIR)\zbxsock.sbr" \
+ "$(INTDIR)\cfg.sbr" \
+ "$(INTDIR)\common.sbr" \
+ "$(INTDIR)\file.sbr" \
+ "$(INTDIR)\http.sbr" \
+ "$(INTDIR)\ntp.sbr" \
+ "$(INTDIR)\system.sbr" \
+ "$(INTDIR)\cpu.sbr" \
+ "$(INTDIR)\diskio.sbr" \
+ "$(INTDIR)\diskspace.sbr" \
+ "$(INTDIR)\inodes.sbr" \
+ "$(INTDIR)\kernel.sbr" \
+ "$(INTDIR)\memory.sbr" \
+ "$(INTDIR)\net.sbr" \
+ "$(INTDIR)\proc.sbr" \
+ "$(INTDIR)\sensors.sbr" \
+ "$(INTDIR)\swap.sbr" \
+ "$(INTDIR)\system_w32.sbr" \
+ "$(INTDIR)\uptime.sbr" \
+ "$(INTDIR)\win32.sbr" \
+ "$(INTDIR)\perfmon.sbr" \
+ "$(INTDIR)\service.sbr" \
+ "$(INTDIR)\mutexs.sbr" \
+ "$(INTDIR)\threads.sbr" \
+ "$(INTDIR)\zbxplugin.sbr" \
+ "$(INTDIR)\active.sbr" \
+ "$(INTDIR)\cpustat.sbr" \
+ "$(INTDIR)\diskdevices.sbr" \
+ "$(INTDIR)\interfaces.sbr" \
+ "$(INTDIR)\listener.sbr" \
+ "$(INTDIR)\logfiles.sbr" \
+ "$(INTDIR)\stats.sbr" \
+ "$(INTDIR)\zabbix_agentd.sbr" \
+ "$(INTDIR)\zbxconf.sbr"
+
+"$(OUTDIR)\zabbix_agentd.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
+ $(BSC32) @<<
+ $(BSC32_FLAGS) $(BSC32_SBRS)
+<<
+
+LINK32=link.exe
+LINK32_FLAGS=ws2_32.lib pdh.lib psapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\zabbix_agentd.pdb" /debug /machine:I386 /out:"$(OUTDIR)\zabbix_agentd.exe" /pdbtype:sept
+LINK32_OBJS= \
+ "$(INTDIR)\alias.obj" \
+ "$(INTDIR)\comms.obj" \
+ "$(INTDIR)\gnuregex.obj" \
+ "$(INTDIR)\misc.obj" \
+ "$(INTDIR)\regexp.obj" \
+ "$(INTDIR)\str.obj" \
+ "$(INTDIR)\xml.obj" \
+ "$(INTDIR)\zbxgetopt.obj" \
+ "$(INTDIR)\log.obj" \
+ "$(INTDIR)\base64.obj" \
+ "$(INTDIR)\md5.obj" \
+ "$(INTDIR)\security.obj" \
+ "$(INTDIR)\zbxsock.obj" \
+ "$(INTDIR)\cfg.obj" \
+ "$(INTDIR)\common.obj" \
+ "$(INTDIR)\file.obj" \
+ "$(INTDIR)\http.obj" \
+ "$(INTDIR)\ntp.obj" \
+ "$(INTDIR)\system.obj" \
+ "$(INTDIR)\cpu.obj" \
+ "$(INTDIR)\diskio.obj" \
+ "$(INTDIR)\diskspace.obj" \
+ "$(INTDIR)\inodes.obj" \
+ "$(INTDIR)\kernel.obj" \
+ "$(INTDIR)\memory.obj" \
+ "$(INTDIR)\net.obj" \
+ "$(INTDIR)\proc.obj" \
+ "$(INTDIR)\sensors.obj" \
+ "$(INTDIR)\swap.obj" \
+ "$(INTDIR)\system_w32.obj" \
+ "$(INTDIR)\uptime.obj" \
+ "$(INTDIR)\win32.obj" \
+ "$(INTDIR)\perfmon.obj" \
+ "$(INTDIR)\service.obj" \
+ "$(INTDIR)\mutexs.obj" \
+ "$(INTDIR)\threads.obj" \
+ "$(INTDIR)\zbxplugin.obj" \
+ "$(INTDIR)\active.obj" \
+ "$(INTDIR)\cpustat.obj" \
+ "$(INTDIR)\diskdevices.obj" \
+ "$(INTDIR)\interfaces.obj" \
+ "$(INTDIR)\listener.obj" \
+ "$(INTDIR)\logfiles.obj" \
+ "$(INTDIR)\stats.obj" \
+ "$(INTDIR)\zabbix_agentd.obj" \
+ "$(INTDIR)\zbxconf.obj" \
+ ".\Debug\zabbixw32.res"
+
+"$(OUTDIR)\zabbix_agentd.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ENDIF
+
+.c{$(INTDIR)}.obj::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cpp{$(INTDIR)}.obj::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cxx{$(INTDIR)}.obj::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.c{$(INTDIR)}.sbr::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cpp{$(INTDIR)}.sbr::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cxx{$(INTDIR)}.sbr::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+
+!IF "$(NO_EXTERNAL_DEPS)" != "1"
+!IF EXISTS("zabbix_agentd.dep")
+!INCLUDE "zabbix_agentd.dep"
+!ELSE
+!MESSAGE Warning: cannot find "zabbix_agentd.dep"
+!ENDIF
+!ENDIF
+
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release" || "$(CFG)" == "zabbix_agentd - Win32 Debug" || "$(CFG)" == "zabbix_agentd - Win32 TODO" || "$(CFG)" == "zabbix_agentd - Win32 Test"
+SOURCE=..\..\..\src\libs\zbxcommon\alias.c
+
+"$(INTDIR)\alias.obj" "$(INTDIR)\alias.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\comms.c
+
+"$(INTDIR)\comms.obj" "$(INTDIR)\comms.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\gnuregex.c
+
+"$(INTDIR)\gnuregex.obj" "$(INTDIR)\gnuregex.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\misc.c
+
+"$(INTDIR)\misc.obj" "$(INTDIR)\misc.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\regexp.c
+
+"$(INTDIR)\regexp.obj" "$(INTDIR)\regexp.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\str.c
+
+"$(INTDIR)\str.obj" "$(INTDIR)\str.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\xml.c
+
+"$(INTDIR)\xml.obj" "$(INTDIR)\xml.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcommon\zbxgetopt.c
+
+"$(INTDIR)\zbxgetopt.obj" "$(INTDIR)\zbxgetopt.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxlog\log.c
+
+"$(INTDIR)\log.obj" "$(INTDIR)\log.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcrypto\base64.c
+
+"$(INTDIR)\base64.obj" "$(INTDIR)\base64.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxcrypto\md5.c
+
+"$(INTDIR)\md5.obj" "$(INTDIR)\md5.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxnet\security.c
+
+"$(INTDIR)\security.obj" "$(INTDIR)\security.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxnet\zbxsock.c
+
+"$(INTDIR)\zbxsock.obj" "$(INTDIR)\zbxsock.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxconf\cfg.c
+
+"$(INTDIR)\cfg.obj" "$(INTDIR)\cfg.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\common.c
+
+"$(INTDIR)\common.obj" "$(INTDIR)\common.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\file.c
+
+"$(INTDIR)\file.obj" "$(INTDIR)\file.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\http.c
+
+"$(INTDIR)\http.obj" "$(INTDIR)\http.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\ntp.c
+
+"$(INTDIR)\ntp.obj" "$(INTDIR)\ntp.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\common\system.c
+
+"$(INTDIR)\system.obj" "$(INTDIR)\system.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\cpu.c
+
+"$(INTDIR)\cpu.obj" "$(INTDIR)\cpu.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\diskio.c
+
+"$(INTDIR)\diskio.obj" "$(INTDIR)\diskio.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\diskspace.c
+
+"$(INTDIR)\diskspace.obj" "$(INTDIR)\diskspace.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\inodes.c
+
+"$(INTDIR)\inodes.obj" "$(INTDIR)\inodes.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\kernel.c
+
+"$(INTDIR)\kernel.obj" "$(INTDIR)\kernel.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\memory.c
+
+"$(INTDIR)\memory.obj" "$(INTDIR)\memory.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\net.c
+
+"$(INTDIR)\net.obj" "$(INTDIR)\net.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\proc.c
+
+"$(INTDIR)\proc.obj" "$(INTDIR)\proc.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\sensors.c
+
+"$(INTDIR)\sensors.obj" "$(INTDIR)\sensors.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\swap.c
+
+"$(INTDIR)\swap.obj" "$(INTDIR)\swap.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\system_w32.c
+
+"$(INTDIR)\system_w32.obj" "$(INTDIR)\system_w32.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\uptime.c
+
+"$(INTDIR)\uptime.obj" "$(INTDIR)\uptime.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsysinfo\win32\win32.c
+
+"$(INTDIR)\win32.obj" "$(INTDIR)\win32.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxwin32\perfmon.c
+
+"$(INTDIR)\perfmon.obj" "$(INTDIR)\perfmon.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxwin32\service.c
+
+"$(INTDIR)\service.obj" "$(INTDIR)\service.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxnix\daemon.c
+SOURCE=..\..\..\src\libs\zbxnix\pid.c
+SOURCE=..\..\..\src\libs\zbxsys\mutexs.c
+
+"$(INTDIR)\mutexs.obj" "$(INTDIR)\mutexs.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxsys\threads.c
+
+"$(INTDIR)\threads.obj" "$(INTDIR)\threads.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\libs\zbxplugin\zbxplugin.c
+
+"$(INTDIR)\zbxplugin.obj" "$(INTDIR)\zbxplugin.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\active.c
+
+"$(INTDIR)\active.obj" "$(INTDIR)\active.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\cpustat.c
+
+"$(INTDIR)\cpustat.obj" "$(INTDIR)\cpustat.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\diskdevices.c
+
+"$(INTDIR)\diskdevices.obj" "$(INTDIR)\diskdevices.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\interfaces.c
+
+"$(INTDIR)\interfaces.obj" "$(INTDIR)\interfaces.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\listener.c
+
+"$(INTDIR)\listener.obj" "$(INTDIR)\listener.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\logfiles.c
+
+"$(INTDIR)\logfiles.obj" "$(INTDIR)\logfiles.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\stats.c
+
+"$(INTDIR)\stats.obj" "$(INTDIR)\stats.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\zabbix_agentd.c
+
+"$(INTDIR)\zabbix_agentd.obj" "$(INTDIR)\zabbix_agentd.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\zbxconf.c
+
+"$(INTDIR)\zbxconf.obj" "$(INTDIR)\zbxconf.sbr" : $(SOURCE) "$(INTDIR)"
+ $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+SOURCE=..\..\..\src\zabbix_agent\messages.mc
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+".\messages.h" ".\Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ <<tempfile.bat
+ @echo off
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName)
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+<<
+
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+".\messages.h" ".\Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ <<tempfile.bat
+ @echo off
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName)
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+<<
+
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+".\messages.h" ".\Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ <<tempfile.bat
+ @echo off
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName)
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+<<
+
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+ProjDir=.
+InputPath=..\..\..\src\zabbix_agent\messages.mc
+InputName=messages
+
+".\messages.h" ".\Msg00001.bin" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ <<tempfile.bat
+ @echo off
+ mc -s -U -h $(ProjDir)\..\..\..\src\zabbix_agent\ -r $(ProjDir)\..\..\..\src\zabbix_agent\ $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName)
+ del $(ProjDir)\..\..\..\src\zabbix_agent\$(InputName).rc
+<<
+
+
+!ENDIF
+
+SOURCE=..\..\..\src\zabbix_agent\resources.rc
+
+!IF "$(CFG)" == "zabbix_agentd - Win32 Release"
+
+
+"$(INTDIR)\zabbixw32.res" : $(SOURCE) "$(INTDIR)"
+ $(RSC) /l 0x409 /fo"$(INTDIR)\zabbixw32.res" /i "\Eugene\zabbix\src\zabbix_agent" /d "NDEBUG" $(SOURCE)
+
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Debug"
+
+
+"$(INTDIR)\zabbixw32.res" : $(SOURCE) "$(INTDIR)"
+ $(RSC) /l 0x409 /fo"$(INTDIR)\zabbixw32.res" /i "\Eugene\zabbix\src\zabbix_agent" /d "_DEBUG" $(SOURCE)
+
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 TODO"
+
+
+".\Debug\zabbixw32.res" : $(SOURCE) "$(INTDIR)"
+ $(RSC) /l 0x409 /fo"Debug/zabbixw32.res" /i "\Eugene\zabbix\src\zabbix_agent" /d "_DEBUG" $(SOURCE)
+
+
+!ELSEIF "$(CFG)" == "zabbix_agentd - Win32 Test"
+
+
+".\Debug\zabbixw32.res" : $(SOURCE) "$(INTDIR)"
+ $(RSC) /l 0x409 /fo"Debug/zabbixw32.res" /i "\Eugene\zabbix\src\zabbix_agent" /d "_DEBUG" $(SOURCE)
+
+
+!ENDIF
+
+
+!ENDIF
+
diff --git a/configure.in b/configure.in
index c382afa4..cb45e241 100644
--- a/configure.in
+++ b/configure.in
@@ -37,7 +37,7 @@ dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(stdio.h stdlib.h string.h unistd.h netdb.h signal.h \
syslog.h time.h errno.h sys/types.h sys/stat.h netinet/in.h \
- sys/socket.h dirent.h ctype.h \
+ math.h sys/socket.h dirent.h ctype.h \
mtent.h fcntl.h sys/param.h sys/mount.h arpa/inet.h \
sys/vfs.h sys/pstat.h sys/sysinfo.h sys/statvfs.h \
sys/socket.h sys/loadavg.h netinet/in.h arpa/inet.h \
@@ -45,7 +45,9 @@ AC_CHECK_HEADERS(stdio.h stdlib.h string.h unistd.h netdb.h signal.h \
sys/time.h kstat.h sys/syscall.h sys/sysmacros.h sys/procfs.h \
stdint.h mach/host_info.h mach/mach_host.h knlist.h pwd.h sys/proc.h \
sys/var.h resolv.h arpa/nameser.h assert.h sys/dkstat.h sys/disk.h \
- nlist.h net/if.h kvm.h linux/kernel.h ldap.h getopt.h procinfo.h sys/dk.h)
+ nlist.h net/if.h kvm.h linux/kernel.h ldap.h getopt.h procinfo.h sys/dk.h \
+ sys/resource.h pthread.h windows.h process.h conio.h sys/wait.h regex.h \
+ stdarg.h winsock2.h pdh.h psapi.h sys/sem.h sys/ipc.h sys/shm.h )
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@@ -969,7 +971,7 @@ dnl AC_SUBST(CONFIG_HOST_UNKNOWN)
AC_SUBST(ARCH)
AC_OUTPUT(Makefile src/Makefile src/libs/Makefile src/libs/zbxlog/Makefile src/libs/zbxcrypto/Makefile \
- src/libs/zbxpid/Makefile src/libs/zbxnet/Makefile src/libs/zbxconf/Makefile src/zabbix_sender/Makefile \
+ src/libs/zbxnet/Makefile src/libs/zbxconf/Makefile src/zabbix_sender/Makefile \
src/libs/zbxdbhigh/Makefile src/libs/zbxemail/Makefile src/libs/zbxsysinfo/Makefile src/libs/zbxsms/Makefile \
src/zabbix_server/pinger/Makefile src/zabbix_agent/Makefile \
src/zabbix_server/housekeeper/Makefile src/zabbix_server/alerter/Makefile src/zabbix_server/Makefile \
@@ -977,7 +979,8 @@ AC_OUTPUT(Makefile src/Makefile src/libs/Makefile src/libs/zbxlog/Makefile src/l
src/zabbix_get/Makefile src/libs/zbxcommon/Makefile src/libs/zbxsysinfo/linux/Makefile \
src/libs/zbxsysinfo/aix/Makefile src/libs/zbxsysinfo/freebsd/Makefile src/libs/zbxsysinfo/hpux/Makefile \
src/libs/zbxsysinfo/openbsd/Makefile src/libs/zbxsysinfo/osx/Makefile src/libs/zbxsysinfo/solaris/Makefile \
- src/libs/zbxsysinfo/osf/Makefile src/libs/zbxsysinfo/netbsd/Makefile src/libs/zbxsysinfo/unknown/Makefile)
+ src/libs/zbxsysinfo/osf/Makefile src/libs/zbxsysinfo/netbsd/Makefile src/libs/zbxsysinfo/unknown/Makefile \
+ src/libs/zbxnix/Makefile src/libs/zbxplugin/Makefile src/libs/zbxsys/Makefile)
echo "
diff --git a/do b/do
index ae5d5f14..fc7f189e 100755
--- a/do
+++ b/do
@@ -7,6 +7,7 @@
# Eugene Grigorjev
#
+win2nix="no"
premake="no"
copy="no"
tgz="no"
@@ -23,24 +24,25 @@ def="--enable-agent --enable-server --with-mysql --with-ldap --with-net-snmp"
for cmd
do
case "$cmd" in
- copy ) copy="yes"; noparam=1;;
- cpy ) copy="yes"; noparam=1;;
- pre ) premake="yes"; noparam=1;;
- premake ) premake="yes"; noparam=1;;
- conf ) configure="yes"; noparam=1;;
- config ) configure="yes"; noparam=1;;
- configure ) configure="yes"; noparam=1;;
- make ) domake="yes"; noparam=1;;
- test ) dotest="yes"; noparam=1;;
- tar ) tgz="yes"; noparam=1;;
- nocat ) docat="no"; noparam=1;;
- cat ) docat="yes"; noparam=1;;
- def ) config_param="$config_param $def";;
- --enable-* ) config_param="$config_param $cmd";;
- --with-* ) config_param="$config_param $cmd";;
- --prefix=* ) config_param="$config_param $cmd";;
- help ) help="yes";;
- h ) help="yes";;
+ win2nix ) win2nix="yes"; noparam=1;;
+ copy ) copy="yes"; noparam=1;;
+ cpy ) copy="yes"; noparam=1;;
+ pre ) premake="yes"; noparam=1;;
+ premake ) premake="yes"; noparam=1;;
+ conf ) configure="yes"; noparam=1;;
+ config ) configure="yes"; noparam=1;;
+ configure ) configure="yes"; noparam=1;;
+ make ) domake="yes"; noparam=1;;
+ test ) dotest="yes"; noparam=1;;
+ tar ) tgz="yes"; noparam=1;;
+ nocat ) docat="no"; noparam=1;;
+ cat ) docat="yes"; noparam=1;;
+ def ) config_param="$config_param $def";;
+ --enable-* ) config_param="$config_param $cmd";;
+ --with-* ) config_param="$config_param $cmd";;
+ --prefix=* ) config_param="$config_param $cmd";;
+ help ) help="yes";;
+ h ) help="yes";;
* )
echo "$0: ERROR: uncnown parameter \"$cmd\"";
help="yes";
@@ -50,9 +52,23 @@ if [ "$help" = "yes" ] || [ $noparam = 0 ]
then
echo
echo "Usage:"
- echo " $0 [copy|cpy] [premake|pre] [configure|config|conf] [def] [make] [test] [tar] [cat] [nocat] [--enable-*] [--with-*]"
- echo
- echo " def = $def"
+ echo " $0 [commands] [options]"
+ echo
+ echo " Commands:"
+ echo " [win2nix] - convers win EOL [\\r\\n] to nix EOL [\\r]"
+ echo " [copy|cpy] - copy automake files"
+ echo " [premake|pre] - make configuration file"
+ echo " [configure|config|conf] - configure make files"
+ echo " [make] - make applications"
+ echo " [test] - test applications"
+ echo " [tar] - create ../zabbix.tar.gz of this folder"
+ echo
+ echo " Options:"
+ echo " [def] - default configuration \"$def\""
+ echo " [cat] - cat WARRNING file at the end (defaut - ON)"
+ echo " [nocat] - do not cat WARRNING file"
+ echo " [--enable-*] - option for configuration"
+ echo " [--with-*] - option for configuration"
echo
echo "Examples:"
echo " $0 conf def make test - compyle, test, and sow report"
@@ -64,7 +80,8 @@ fi
if [ "$copy" = "yes" ] || [ $premake = "yes" ] ||
[ $configure = "yes" ] || [ $domake = "yes" ] ||
- [ $dotest = "yes" ] || [ $tgz = "yes" ]
+ [ $dotest = "yes" ] || [ $tgz = "yes" ] ||
+ [ "$win2nix" = "yes" ]
then
cleanwarnings="yes"
fi
@@ -74,6 +91,13 @@ then
rm -f WARNINGS
fi
+if [ "$win2nix" = "yes" ]
+then
+ echo "Replacing..."
+ echo "Replacing..." >> WARNINGS
+ find ./ -name "*.[hc]" -exec vi "+%s/\\r$//" "+wq" "-es" {} ';' -print 2>> WARNINGS
+fi
+
if [ "$premake" = "yes" ]
then
echo "Pre-making..."
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 45ddd0a3..e986f887 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -26,7 +26,7 @@
// $DB_TYPE ="POSTGRESQL";
$DB_TYPE ="MYSQL";
$DB_SERVER ="localhost";
- $DB_DATABASE ="zabbix";
+ $DB_DATABASE ="osmiy";
$DB_USER ="root";
$DB_PASSWORD ="";
// END OF DATABASE CONFIGURATION
diff --git a/include/alias.h b/include/alias.h
new file mode 100755
index 00000000..d3b91214
--- /dev/null
+++ b/include/alias.h
@@ -0,0 +1,40 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ALIAS_H
+#define ZABBIX_ALIAS_H
+
+#define MAX_ALIAS_NAME 120
+
+struct zbx_alias
+{
+ struct zbx_alias *next;
+ char name[MAX_ALIAS_NAME];
+ char *value;
+};
+
+typedef struct zbx_alias ALIAS;
+
+int add_alias(const char *name, const char *value);
+int add_alias_from_config(char *value);
+void alias_list_free(void);
+void alias_expand(const char *orig, char *expanded, int exp_buf_len);
+
+
+#endif /* ZABBIX_ALIAS_H */
diff --git a/include/base64.h b/include/base64.h
new file mode 100644
index 00000000..b7e43d24
--- /dev/null
+++ b/include/base64.h
@@ -0,0 +1,26 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_BASE64_H
+#define ZABBIX_BASE64_H
+
+void str_base64_encode(char *p_str, char *p_b64str, int in_size);
+void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size);
+
+#endif /* ZABBIX_BASE64_H */
diff --git a/include/cfg.h b/include/cfg.h
index f46682cb..3b4635da 100644
--- a/include/cfg.h
+++ b/include/cfg.h
@@ -26,6 +26,21 @@
#define PARM_OPT 0
#define PARM_MAND 1
+//
+// Application flags
+//
+
+#define AF_STANDALONE 0x0001
+#define AF_USE_EVENT_LOG 0x0002
+#define AF_LOG_UNRESOLVED_SYMBOLS 0x0004
+
+extern int CONFIG_ZABBIX_FORKS;
+extern char *CONFIG_FILE;
+
+extern char *CONFIG_LOG_FILE;
+extern char CONFIG_ALLOW_ROOT_PERMISSION;
+extern int CONFIG_TIMEOUT;
+
struct cfg_line
{
char *parameter;
diff --git a/include/common.h b/include/common.h
index 8208b756..4ecaaf1f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -22,87 +22,14 @@
#include "sysinc.h"
+#include "zbxtypes.h"
+
#if defined(WIN32)
+
# pragma warning (disable: 4100)
-# define zbx_uint64_t __int64
-# define ZBX_FS_UI64 "%llu"
-
-//#undef _DEBUG
-# ifdef _DEBUG
-# define LOG_DEBUG_INFO(type, msg) \
- WriteLog(MSG_DEBUG_INFO,EVENTLOG_ERROR_TYPE, "d"type , GetCurrentThreadId(), msg)
-//# define ENABLE_CHECK_MEMOTY
-//# define ENABLE_FUNC_CALL
-# else
-# define LOG_DEBUG_INFO(a, b) ((void)0)
-# endif
-
-
-# if defined(ENABLE_FUNC_CALL)
-# define LOG_FUNC_CALL(msg) \
- WriteLog(MSG_DEBUG_INFO,EVENTLOG_ERROR_TYPE, "ds" , GetCurrentThreadId(), msg)
-# else
-# define LOG_FUNC_CALL(a) ((void)0)
-# endif
-
-# if defined(ENABLE_CHECK_MEMOTY)
-# include "crtdbg.h"
-
-# define REINIT_CHECK_MEMORY(a) \
- _CrtMemCheckpoint(& ## a ## oldMemState)
-
-# define INIT_CHECK_MEMORY(a) \
- char a ## DumpMessage[0xFFFF]; \
- _CrtMemState a ## oldMemState, a ## newMemState, a ## diffMemState; \
- REINIT_CHECK_MEMORY(a)
-
-# define CHECK_MEMORY(a, fncname, msg) \
- _CrtMemCheckpoint(& ## a ## newMemState); \
- if(_CrtMemDifference(& ## a ## diffMemState, & ## a ## oldMemState, & ## a ## newMemState)) \
- { \
- sprintf(a ## DumpMessage, \
- "%s\n" \
- "free: %10li bytes in %10li blocks\n" \
- "normal:%10li bytes in %10li blocks\n" \
- "CRT: %10li bytes in %10li blocks\n" \
- "ignore:%10li bytes in %10li blocks\n" \
- "client:%10li bytes in %10li blocks\n" \
- "max: %10li bytes in %10li blocks", \
- \
- fncname ": (" #a ") Memory changed! (" msg ")\n", \
- \
- (long) a ## diffMemState.lSizes[_FREE_BLOCK], \
- (long) a ## diffMemState.lCounts[_FREE_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_NORMAL_BLOCK], \
- (long) a ## diffMemState.lCounts[_NORMAL_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_CRT_BLOCK], \
- (long) a ## diffMemState.lCounts[_CRT_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_IGNORE_BLOCK], \
- (long) a ## diffMemState.lCounts[_IGNORE_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_CLIENT_BLOCK], \
- (long) a ## diffMemState.lCounts[_CLIENT_BLOCK], \
- \
- (long) a ## diffMemState.lSizes[_MAX_BLOCKS], \
- (long) a ## diffMemState.lCounts[_MAX_BLOCKS]); \
- LOG_DEBUG_INFO("s", a ## DumpMessage); \
- }
-# else
-# define INIT_CHECK_MEMORY(a) ((void)0)
-# define CHECK_MEMORY(a, fncname, msg) ((void)0)
-# endif
-#else
-# define zbx_uint64_t uint64_t
-# if __WORDSIZE == 64
-# define ZBX_FS_UI64 "%lu"
-# else
-# define ZBX_FS_UI64 "%llu"
-# endif
-#endif
+#endif /* WIN32 */
+
#ifndef HAVE_GETOPT_LONG
struct option {
@@ -112,14 +39,14 @@
int val;
};
# define getopt_long(argc, argv, optstring, longopts, longindex) getopt(argc, argv, optstring)
-#endif
+#endif /* ndef HAVE_GETOPT_LONG */
#define ZBX_UNUSED(a) ((void)0)(a)
#define ZBX_FS_DBL "%f"
-#define ZABBIX_REVDATE "1 July 2006"
-#define ZABBIX_VERSION "1.1.1"
+#define ZABBIX_REVDATE "12 July 2006"
+#define ZABBIX_VERSION "1.2.1"
#define MAX_LOG_FILE_LEN (1024*1024)
@@ -130,14 +57,6 @@
#define TIMEOUT_ERROR (-4)
#define AGENT_ERROR (-5)
-#define MAXFD 64
-
-/* show debug info to stderr */
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m)
-#define SDI(m) FDI("%s", m)
-#define IDI(i) FDI("%i", i)
-
-
/*
#define ZBX_POLLER
*/
@@ -277,7 +196,7 @@
#define SERVICE_ALGORITHM_MAX 1
#define SERVICE_ALGORITHM_MIN 2
-#define AGENTD_FORKS 5
+#define ZABBIX_FORKS 5
#define TRAPPERD_FORKS 5
#define POLLER_FORKS 11
@@ -304,7 +223,11 @@
#endif
/* Secure string copy */
-#define strscpy(x,y) { strncpy(x,y,sizeof(x)); x[sizeof(x)-1]=0; }
+#define strsncpy(x,y,size) { strncpy(x,y,size); x[size-1]='\0'; }
+#define strscpy(x,y) strsncpy(x,y,sizeof(x))
+
+#define zbx_free(ptr) { if(ptr){ free(ptr); ptr = NULL; } }
+#define zbx_fclose(f) { if(f){ fclose(f); f = NULL; } }
/* list structure as item of agent return vaile */
#define ZBX_LIST_ITEM struct zbx_list_item_s
@@ -339,6 +262,8 @@ AGENT_RESULT {
#define AR_TEXT 32
+/* SET RESULT */
+
#define SET_DBL_RESULT(res, val) \
{ \
(res)->type |= AR_DOUBLE; \
@@ -369,31 +294,48 @@ AGENT_RESULT {
(res)->msg = (char*)(val); \
}
-#define UNSET_DBL_RESULT(res) \
- { \
- (res)->type &= ~AR_DOUBLE; \
+/* UNSER RESULT */
+
+#define UNSET_DBL_RESULT(res) \
+ { \
+ (res)->type &= ~AR_DOUBLE; \
+ (res)->dbl = (double)(0); \
}
-#define UNSET_UI64_RESULT(res) \
- { \
- (res)->type &= ~AR_UINT64; \
+#define UNSET_UI64_RESULT(res) \
+ { \
+ (res)->type &= ~AR_UINT64; \
+ (res)->ui64 = (zbx_uint64_t)(0); \
}
-#define UNSET_STR_RESULT(res) \
- { \
- (res)->type &= ~AR_STRING; \
+#define UNSET_STR_RESULT(res) \
+ { \
+ if((res)->type & AR_STRING){ \
+ free((res)->str); \
+ (res)->str = NULL; \
+ (res)->type &= ~AR_STRING; \
+ } \
}
-#define UNSET_TEXT_RESULT(res) \
- { \
- (res)->type &= ~AR_TEXT; \
+#define UNSET_TEXT_RESULT(res) \
+ { \
+ if((res)->type & AR_TEXT){ \
+ free((res)->text); \
+ (res)->text = NULL; \
+ (res)->type &= ~AR_TEXT; \
+ } \
}
-#define UNSET_MSG_RESULT(res) \
- { \
- (res)->type &= ~AR_MESSAGE; \
+#define UNSET_MSG_RESULT(res) \
+ { \
+ if((res)->type & AR_MESSAGE){ \
+ free((res)->msg); \
+ (res)->msg = NULL; \
+ (res)->type &= ~AR_MESSAGE; \
+ } \
}
+
extern char *progname;
extern char title_message[];
extern char usage_message[];
@@ -403,16 +345,20 @@ void help();
void usage();
void version();
-#define ZBX_TASK_START 0
-#define ZBX_TASK_SHOW_HELP 1
-#define ZBX_TASK_SHOW_VERSION 2
-#define ZBX_TASK_PRINT_SUPPORTED 3
-#define ZBX_TASK_TEST_METRIC 4
-#define ZBX_TASK_SHOW_USAGE 5
-
/* MAX Length of base64 data */
#define ZBX_MAX_B64_LEN 16*1024
+#define ZBX_TASK_START 0
+#define ZBX_TASK_SHOW_HELP 1
+#define ZBX_TASK_SHOW_VERSION 2
+#define ZBX_TASK_PRINT_SUPPORTED 3
+#define ZBX_TASK_TEST_METRIC 4
+#define ZBX_TASK_SHOW_USAGE 5
+#define ZBX_TASK_INSTALL_SERVICE 6
+#define ZBX_TASK_UNINSTALL_SERVICE 7
+#define ZBX_TASK_START_SERVICE 8
+#define ZBX_TASK_STOP_SERVICE 9
+
void init_result(AGENT_RESULT *result);
int copy_result(AGENT_RESULT *src, AGENT_RESULT *dist);
void free_result(AGENT_RESULT *result);
@@ -430,6 +376,10 @@ void delete_reol(char *c);
int get_param(const char *param, int num, char *buf, int maxlen);
int num_param(const char *param);
int calculate_item_nextcheck(int delay, int now);
+void zbx_setproctitle(const char *fmt, ...);
+double zbx_getseconds(void);
+void zbx_error(const char *fmt, ...);
+void zbx_snprintf(char* str, size_t count, const char *fmt, ...);
int set_result_type(AGENT_RESULT *result, int value_type, char *c);
@@ -442,16 +392,16 @@ int comms_parse_response(char *xml,char *host,char *key, char *data, char *lastl
int parse_command(const char *command, char *cmd, int cmd_max_len, char *param, int param_max_len);
-/* Base64 functions */
-void str_base64_encode(char *p_str, char *p_b64str, int in_size);
-void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size);
-
/* Regular expressions */
char *zbx_regexp_match(const char *string, const char *pattern, int *len);
/* Misc functions */
int cmp_double(double a,double b);
+void zbx_on_exit();
+
int SYSTEM_LOCALTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
+int MAIN_ZABBIX_ENTRY(void);
+
#endif
diff --git a/include/daemon.h b/include/daemon.h
new file mode 100755
index 00000000..ed961c66
--- /dev/null
+++ b/include/daemon.h
@@ -0,0 +1,49 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+
+#ifndef ZABBIX_DAEMON_H
+#define ZABBIX_DAEMON_H
+
+#if defined(WIN32)
+# error "This module allowed only for Linux OS"
+#endif
+
+#define USE_PID_FILE (1)
+
+extern char *APP_PID_FILE;
+
+#include "threads.h"
+
+#define MAXFD 64
+
+void child_signal_handler(int sig);
+
+int daemon_start(int allow_root);
+void daemon_stop(void);
+
+void init_main_process(void);
+
+/* ask for application closing status - NOT needed for linux forks */
+#define ZBX_IS_RUNNING (1)
+
+/* tall all threads what application must be closed - NOT needed for linux forks */
+#define ZBX_DO_EXIT()
+
+#endif /* ZABBIX_DAEMON_H */
diff --git a/include/gnuregex.h b/include/gnuregex.h
new file mode 100755
index 00000000..0e570935
--- /dev/null
+++ b/include/gnuregex.h
@@ -0,0 +1,501 @@
+/* Definitions for data structures and routines for the regular
+ expression library, version 0.12.
+
+ Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef __REGEXP_LIBRARY_H__
+#define __REGEXP_LIBRARY_H__
+
+/* Allow the use in C++ code. */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* POSIX says that <sys/types.h> must be included (by the caller) before
+ <regex.h>. */
+
+#ifdef VMS
+/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
+ should be there. */
+#include <stddef.h>
+#endif
+
+
+/* The following bits are used to determine the regexp syntax we
+ recognize. The set/not-set meanings are chosen so that Emacs syntax
+ remains the value 0. The bits are given in alphabetical order, and
+ the definitions shifted by one from the previous bit; thus, when we
+ add or remove a bit, only one other definition need change. */
+typedef unsigned reg_syntax_t;
+
+/* If this bit is not set, then \ inside a bracket expression is literal.
+ If set, then such a \ quotes the following character. */
+#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
+
+/* If this bit is not set, then + and ? are operators, and \+ and \? are
+ literals.
+ If set, then \+ and \? are operators and + and ? are literals. */
+#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
+
+/* If this bit is set, then character classes are supported. They are:
+ [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
+ [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
+ If not set, then character classes are not supported. */
+#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
+
+/* If this bit is set, then ^ and $ are always anchors (outside bracket
+ expressions, of course).
+ If this bit is not set, then it depends:
+ ^ is an anchor if it is at the beginning of a regular
+ expression or after an open-group or an alternation operator;
+ $ is an anchor if it is at the end of a regular expression, or
+ before a close-group or an alternation operator.
+
+ This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
+ POSIX draft 11.2 says that * etc. in leading positions is undefined.
+ We already implemented a previous draft which made those constructs
+ invalid, though, so we haven't changed the code back. */
+#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
+
+/* If this bit is set, then special characters are always special
+ regardless of where they are in the pattern.
+ If this bit is not set, then special characters are special only in
+ some contexts; otherwise they are ordinary. Specifically,
+ * + ? and intervals are only special when not after the beginning,
+ open-group, or alternation operator. */
+#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
+
+/* If this bit is set, then *, +, ?, and { cannot be first in an re or
+ immediately after an alternation or begin-group operator. */
+#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
+
+/* If this bit is set, then . matches newline.
+ If not set, then it doesn't. */
+#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
+
+/* If this bit is set, then . doesn't match NUL.
+ If not set, then it does. */
+#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
+
+/* If this bit is set, nonmatching lists [^...] do not match newline.
+ If not set, they do. */
+#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
+
+/* If this bit is set, either \{...\} or {...} defines an
+ interval, depending on RE_NO_BK_BRACES.
+ If not set, \{, \}, {, and } are literals. */
+#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
+
+/* If this bit is set, +, ? and | aren't recognized as operators.
+ If not set, they are. */
+#define RE_LIMITED_OPS (RE_INTERVALS << 1)
+
+/* If this bit is set, newline is an alternation operator.
+ If not set, newline is literal. */
+#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
+
+/* If this bit is set, then `{...}' defines an interval, and \{ and \}
+ are literals.
+ If not set, then `\{...\}' defines an interval. */
+#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
+
+/* If this bit is set, (...) defines a group, and \( and \) are literals.
+ If not set, \(...\) defines a group, and ( and ) are literals. */
+#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
+
+/* If this bit is set, then \<digit> matches <digit>.
+ If not set, then \<digit> is a back-reference. */
+#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
+
+/* If this bit is set, then | is an alternation operator, and \| is literal.
+ If not set, then \| is an alternation operator, and | is literal. */
+#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
+
+/* If this bit is set, then an ending range point collating higher
+ than the starting range point, as in [z-a], is invalid.
+ If not set, then when ending range point collates higher than the
+ starting range point, the range is ignored. */
+#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
+
+/* If this bit is set, then an unmatched ) is ordinary.
+ If not set, then an unmatched ) is invalid. */
+#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
+
+/* This global variable defines the particular regexp syntax to use (for
+ some interfaces). When a regexp is compiled, the syntax used is
+ stored in the pattern buffer, so changing this does not affect
+ already-compiled regexps. */
+extern reg_syntax_t re_syntax_options;
+
+/* Define combinations of the above bits for the standard possibilities.
+ (The [[[ comments delimit what gets put into the Texinfo file, so
+ don't delete them!) */
+/* [[[begin syntaxes]]] */
+#define RE_SYNTAX_EMACS 0
+
+#define RE_SYNTAX_AWK \
+ (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+#define RE_SYNTAX_POSIX_AWK \
+ (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
+
+#define RE_SYNTAX_GREP \
+ (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
+ | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
+ | RE_NEWLINE_ALT)
+
+#define RE_SYNTAX_EGREP \
+ (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
+ | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
+ | RE_NO_BK_VBAR)
+
+#define RE_SYNTAX_POSIX_EGREP \
+ (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
+
+/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
+#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
+
+#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
+
+/* Syntax bits common to both basic and extended POSIX regex syntax. */
+#define _RE_SYNTAX_POSIX_COMMON \
+ (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
+ | RE_INTERVALS | RE_NO_EMPTY_RANGES)
+
+#define RE_SYNTAX_POSIX_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
+
+/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
+ RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
+ isn't minimal, since other operators, such as \`, aren't disabled. */
+#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
+
+#define RE_SYNTAX_POSIX_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
+ replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
+#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
+/* [[[end syntaxes]]] */
+
+/* Maximum number of duplicates an interval can allow. Some systems
+ (erroneously) define this in other header files, but we want our
+ value, so remove any previous define. */
+#ifdef RE_DUP_MAX
+#undef RE_DUP_MAX
+#endif
+#ifndef RE_DUP_MAX
+# define RE_DUP_MAX ((1 << 15) - 1)
+#endif
+
+
+/* POSIX `cflags' bits (i.e., information for `regcomp'). */
+
+/* If this bit is set, then use extended regular expression syntax.
+ If not set, then use basic regular expression syntax. */
+#define REG_EXTENDED 1
+
+/* If this bit is set, then ignore case when matching.
+ If not set, then case is significant. */
+#define REG_ICASE (REG_EXTENDED << 1)
+
+/* If this bit is set, then anchors do not match at newline
+ characters in the string.
+ If not set, then anchors do match at newlines. */
+#define REG_NEWLINE (REG_ICASE << 1)
+
+/* If this bit is set, then report only success or fail in regexec.
+ If not set, then returns differ between not matching and errors. */
+#define REG_NOSUB (REG_NEWLINE << 1)
+
+
+/* POSIX `eflags' bits (i.e., information for regexec). */
+
+/* If this bit is set, then the beginning-of-line operator doesn't match
+ the beginning of the string (presumably because it's not the
+ beginning of a line).
+ If not set, then the beginning-of-line operator does match the
+ beginning of the string. */
+#define REG_NOTBOL 1
+
+/* Like REG_NOTBOL, except for the end-of-line. */
+#define REG_NOTEOL (1 << 1)
+
+
+/* If any error codes are removed, changed, or added, update the
+ `re_error_msg' table in regex.c. */
+typedef enum
+{
+ REG_NOERROR = 0, /* Success. */
+ REG_NOMATCH, /* Didn't find a match (for regexec). */
+
+ /* POSIX regcomp return error codes. (In the order listed in the
+ standard.) */
+ REG_BADPAT, /* Invalid pattern. */
+ REG_ECOLLATE, /* Not implemented. */
+ REG_ECTYPE, /* Invalid character class name. */
+ REG_EESCAPE, /* Trailing backslash. */
+ REG_ESUBREG, /* Invalid back reference. */
+ REG_EBRACK, /* Unmatched left bracket. */
+ REG_EPAREN, /* Parenthesis imbalance. */
+ REG_EBRACE, /* Unmatched \{. */
+ REG_BADBR, /* Invalid contents of \{\}. */
+ REG_ERANGE, /* Invalid range end. */
+ REG_ESPACE, /* Ran out of memory. */
+ REG_BADRPT, /* No preceding re for repetition op. */
+
+ /* Error codes we've added. */
+ REG_EEND, /* Premature end. */
+ REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
+ REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
+} reg_errcode_t;
+
+/* This data structure represents a compiled pattern. Before calling
+ the pattern compiler, the fields `buffer', `allocated', `fastmap',
+ `translate', and `no_sub' can be set. After the pattern has been
+ compiled, the `re_nsub' field is available. All other fields are
+ private to the regex routines. */
+
+struct re_pattern_buffer
+{
+/* [[[begin pattern_buffer]]] */
+ /* Space that holds the compiled pattern. It is declared as
+ `unsigned char *' because its elements are
+ sometimes used as array indexes. */
+ unsigned char *buffer;
+
+ /* Number of bytes to which `buffer' points. */
+ unsigned long allocated;
+
+ /* Number of bytes actually used in `buffer'. */
+ unsigned long used;
+
+ /* Syntax setting with which the pattern was compiled. */
+ reg_syntax_t syntax;
+
+ /* Pointer to a fastmap, if any, otherwise zero. re_search uses
+ the fastmap, if there is one, to skip over impossible
+ starting points for matches. */
+ char *fastmap;
+
+ /* Either a translate table to apply to all characters before
+ comparing them, or zero for no translation. The translation
+ is applied to a pattern when it is compiled and to a string
+ when it is matched. */
+ char *translate;
+
+ /* Number of subexpressions found by the compiler. */
+ size_t re_nsub;
+
+ /* Zero if this pattern cannot match the empty string, one else.
+ Well, in truth it's used only in `re_search_2', to see
+ whether or not we should use the fastmap, so we don't set
+ this absolutely perfectly; see `re_compile_fastmap' (the
+ `duplicate' case). */
+ unsigned can_be_null : 1;
+
+ /* If REGS_UNALLOCATED, allocate space in the `regs' structure
+ for `max (RE_NREGS, re_nsub + 1)' groups.
+ If REGS_REALLOCATE, reallocate space if necessary.
+ If REGS_FIXED, use what's there. */
+#define REGS_UNALLOCATED 0
+#define REGS_REALLOCATE 1
+#define REGS_FIXED 2
+ unsigned regs_allocated : 2;
+
+ /* Set to zero when `regex_compile' compiles a pattern; set to one
+ by `re_compile_fastmap' if it updates the fastmap. */
+ unsigned fastmap_accurate : 1;
+
+ /* If set, `re_match_2' does not return information about
+ subexpressions. */
+ unsigned no_sub : 1;
+
+ /* If set, a beginning-of-line anchor doesn't match at the
+ beginning of the string. */
+ unsigned not_bol : 1;
+
+ /* Similarly for an end-of-line anchor. */
+ unsigned not_eol : 1;
+
+ /* If true, an anchor at a newline matches. */
+ unsigned newline_anchor : 1;
+
+/* [[[end pattern_buffer]]] */
+};
+
+typedef struct re_pattern_buffer regex_t;
+
+
+/* search.c (search_buffer) in Emacs needs this one opcode value. It is
+ defined both in `regex.c' and here. */
+#define RE_EXACTN_VALUE 1
+
+/* Type for byte offsets within the string. POSIX mandates this. */
+typedef int regoff_t;
+
+
+/* This is the structure we store register match data in. See
+ regex.texinfo for a full description of what registers match. */
+struct re_registers
+{
+ unsigned num_regs;
+ regoff_t *start;
+ regoff_t *end;
+};
+
+
+/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
+ `re_match_2' returns information about at least this many registers
+ the first time a `regs' structure is passed. */
+#ifndef RE_NREGS
+#define RE_NREGS 30
+#endif
+
+
+/* POSIX specification for registers. Aside from the different names than
+ `re_registers', POSIX uses an array of structures, instead of a
+ structure of arrays. */
+typedef struct
+{
+ regoff_t rm_so; /* Byte offset from string's start to substring's start. */
+ regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
+} regmatch_t;
+
+/* Declarations for routines. */
+
+/* To avoid duplicating every routine declaration -- once with a
+ prototype (if we are ANSI), and once without (if we aren't) -- we
+ use the following macro to declare argument types. This
+ unfortunately clutters up the declarations a bit, but I think it's
+ worth it. */
+
+#if __STDC__
+
+#define _RE_ARGS(args) args
+
+#else /* not __STDC__ */
+
+#define _RE_ARGS(args) ()
+
+#endif /* not __STDC__ */
+
+/* Sets the current default syntax to SYNTAX, and return the old syntax.
+ You can also simply assign to the `re_syntax_options' variable. */
+extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
+
+/* Compile the regular expression PATTERN, with length LENGTH
+ and syntax given by the global `re_syntax_options', into the buffer
+ BUFFER. Return NULL if successful, and an error string if not. */
+extern const char *re_compile_pattern
+ _RE_ARGS ((const char *pattern, int length,
+ struct re_pattern_buffer *buffer));
+
+
+/* Compile a fastmap for the compiled pattern in BUFFER; used to
+ accelerate searches. Return 0 if successful and -2 if was an
+ internal error. */
+extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
+
+
+/* Search in the string STRING (with length LENGTH) for the pattern
+ compiled into BUFFER. Start searching at position START, for RANGE
+ characters. Return the starting position of the match, -1 for no
+ match, or -2 for an internal error. Also return register
+ information in REGS (if REGS and BUFFER->no_sub are nonzero). */
+extern int re_search
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
+ int length, int start, int range, struct re_registers *regs));
+
+
+/* Like `re_search', but search in the concatenation of STRING1 and
+ STRING2. Also, stop searching at index START + STOP. */
+extern int re_search_2
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
+ int length1, const char *string2, int length2,
+ int start, int range, struct re_registers *regs, int stop));
+
+
+/* Like `re_search', but return how many characters in STRING the regexp
+ in BUFFER matched, starting at position START. */
+extern int re_match
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
+ int length, int start, struct re_registers *regs));
+
+
+/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
+extern int re_match_2
+ _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
+ int length1, const char *string2, int length2,
+ int start, struct re_registers *regs, int stop));
+
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using BUFFER and REGS will use this memory
+ for recording register information. STARTS and ENDS must be
+ allocated with malloc, and must each be at least `NUM_REGS * sizeof
+ (regoff_t)' bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ PATTERN_BUFFER will allocate its own register data, without
+ freeing the old data. */
+extern void re_set_registers
+ _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
+ unsigned num_regs, regoff_t *starts, regoff_t *ends));
+
+/* 4.2 bsd compatibility. */
+extern char *re_comp _RE_ARGS ((const char *));
+extern int re_exec _RE_ARGS ((const char *));
+
+/* POSIX compatibility. */
+extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
+extern int regexec
+ _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
+ regmatch_t pmatch[], int eflags));
+extern size_t regerror
+ _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
+ size_t errbuf_size));
+extern void regfree _RE_ARGS ((regex_t *preg));
+
+#ifdef __cplusplus
+}
+#endif /* C++ */
+
+#endif /* not __REGEXP_LIBRARY_H__ */
+
+/*
+Local variables:
+make-backup-files: t
+version-control: t
+trim-versions-without-asking: nil
+End:
+*/
diff --git a/include/log.h b/include/log.h
index 441e0929..31e6ae6d 100644
--- a/include/log.h
+++ b/include/log.h
@@ -24,7 +24,8 @@
#define LOG_LEVEL_CRIT 1
#define LOG_LEVEL_ERR 2
#define LOG_LEVEL_WARNING 3
-#define LOG_LEVEL_DEBUG 4
+#define LOG_LEVEL_INFORMATION 4
+#define LOG_LEVEL_DEBUG 5
#define LOG_TYPE_UNDEFINED 0
#define LOG_TYPE_SYSLOG 1
@@ -33,6 +34,10 @@
/* Type - 0 (syslog), 1 - file */
int zabbix_open_log(int type,int level, const char *filename);
void zabbix_log(int level, const char *fmt, ...);
+void zabbix_close_log(void);
void zabbix_set_log_level(int level);
+char *strerror_from_system(unsigned long error);
+char *strerror_from_module(unsigned long error, const char *module);
+
#endif
diff --git a/include/mutexs.h b/include/mutexs.h
new file mode 100755
index 00000000..3f9f82e7
--- /dev/null
+++ b/include/mutexs.h
@@ -0,0 +1,44 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_MUTEXS_H
+#define ZABBIX_MUTEXS_H
+
+#if defined(WIN32)
+
+ #define ZBX_MUTEX HANDLE
+ #define ZBX_MUTEX_ERROR (0)
+ #define ZBX_MUTEX_OK (1)
+
+#else /* not WIN32 */
+
+
+ #define ZBX_MUTEX int
+
+ #define ZBX_MUTEX_ERROR (-1)
+ #define ZBX_MUTEX_OK (1)
+
+#endif /* WIN32 */
+
+int zbx_mutex_create(ZBX_MUTEX *mutex, char *name);
+int zbx_mutex_lock(ZBX_MUTEX *mutex);
+int zbx_mutex_unlock(ZBX_MUTEX *mutex);
+int zbx_mutex_destroy(ZBX_MUTEX *mutex);
+
+#endif /* ZABBIX_MUTEXS_H */
diff --git a/include/perfmon.h b/include/perfmon.h
new file mode 100755
index 00000000..32cb6248
--- /dev/null
+++ b/include/perfmon.h
@@ -0,0 +1,58 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_PERFMON_H
+#define ZABBIX_PERFMON_H
+
+#if !defined(WIN32)
+# error "This module allowed only for Windows OS"
+#endif
+
+//
+// Performance Counter Indexes
+//
+
+#define PCI_SYSTEM (2)
+#define PCI_PROCESSOR (238)
+#define PCI_PROCESSOR_TIME (6)
+#define PCI_PROCESSOR_QUEUE_LENGTH (44)
+#define PCI_SYSTEM_UP_TIME (674)
+
+//
+// Performance Countername structure
+//
+
+#define MAX_PERFCOUNTER_NAME_LEN (108) /* old naming <MAX_COUNTER_NAME> */
+
+struct perfcounter
+{
+ struct perfcounter *next;
+ DWORD pdhIndex;
+ char name[MAX_PERFCOUNTER_NAME_LEN]; /* must be caracter array! if you want to rewrite */
+ /* to dinacal memory allocation CHECK for usage */
+ /* of sizeof function */
+};
+
+typedef struct perfcounter PERFCOUNTER;
+
+extern PERFCOUNTER *PerfCounterList;
+
+char *GetCounterName(DWORD index);
+
+#endif /* ZABBIX_PERFMON_H */
diff --git a/include/pid.h b/include/pid.h
index a39a66c9..5895610b 100644
--- a/include/pid.h
+++ b/include/pid.h
@@ -20,6 +20,11 @@
#ifndef ZABBIX_PID_H
#define ZABBIX_PID_H
-int create_pid_file(const char *pidfile);
+#if defined(WIN32)
+# error "This module allowed only for Linux OS"
+#endif
+
+int create_pid_file(const char *pidfile);
+void drop_pid_file(const char *pidfile);
#endif
diff --git a/include/service.h b/include/service.h
new file mode 100755
index 00000000..7b0225f6
--- /dev/null
+++ b/include/service.h
@@ -0,0 +1,55 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_SERVICE_H
+#define ZABBIX_SERVICE_H
+
+#if !defined(WIN32)
+# error "This module allowed only for Windows OS"
+#endif
+
+#include "threads.h"
+
+extern ZBX_THREAD_HANDLE *threads;
+
+#define ZABBIX_SERVICE_NAME "ZabbixAgentdW32"
+#define ZABBIX_EVENT_SOURCE "ZABBIX Win32 Agent"
+
+void service_start(void);
+
+int ZabbixCreateService(char *execName);
+int ZabbixRemoveService(void);
+int ZabbixStartService(void);
+int ZabbixStopService(void);
+
+
+/* APPLICATION running status */
+/* requred for closing application from service */
+extern int application_is_runned;
+
+#define ZBX_APP_STOPPED 1
+#define ZBX_APP_RUNNED 1
+
+/* ask for running application of closing status */
+#define ZBX_IS_RUNNING (ZBX_APP_RUNNED == application_is_runned)
+
+/* ask for application closing status */
+#define ZBX_DO_EXIT() (application_is_runned = ZBX_APP_STOPPED)
+
+#endif /* ZABBIX_SERVICE_H */
diff --git a/include/sysinc.h b/include/sysinc.h
index 33900010..d39cb75e 100644
--- a/include/sysinc.h
+++ b/include/sysinc.h
@@ -20,9 +20,7 @@
#ifndef ZABBIX_SYSINC_H
#define ZABBIX_SYSINC_H
-#if !defined(WIN32)
-# include "config.h"
-#endif
+#include "config.h"
#include <stdio.h>
#include <stdlib.h>
@@ -35,6 +33,34 @@
# include <errno.h>
#endif
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
+#ifdef HAVE_PROCESS_H
+# include <process.h>
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
+
+#ifdef HAVE_CONIO_H
+# include <conio.h>
+#endif
+
+#ifdef HAVE_PDH_H
+# include <pdh.h>
+#endif
+
+#ifdef HAVE_PSAPI_H
+# include <psapi.h>
+#endif
+
+#ifdef HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
@@ -99,6 +125,10 @@
# include <netdb.h>
#endif
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
@@ -137,6 +167,10 @@
# include <sys/pstat.h>
#endif
+#ifdef HAVE_PTHREAD_H
+# include <pthread.h>
+#endif
+
#ifdef HAVE_SYS_DK_H
# include <sys/dk.h>
#endif
@@ -197,6 +231,10 @@
# include <sys/vmmeter.h>
#endif
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
#ifdef HAVE_NLIST_H
# include <nlist.h>
#endif
@@ -228,6 +266,26 @@
# endif
#endif
+#ifdef HAVE_SYS_IPC_H
+# include <sys/ipc.h>
+#endif
+
+#ifdef HAVE_SYS_SEM_H
+# include <sys/sem.h>
+#endif
+
+#ifdef HAVE_SYS_SHM_H
+# include <sys/shm.h>
+#endif
+
+#ifdef HAVE_MATH_H
+# include <math.h>
+#endif
+
+#ifdef HAVE_REGEX_H
+# include <regex.h>
+#endif
+
#ifdef HAVE_VM_VM_PARAM_H
# include <vm/vm_param.h>
#endif
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 54b73ffe..f1751b1b 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -29,15 +29,15 @@ extern int CONFIG_ENABLE_REMOTE_COMMANDS;
#define SYSINFO_RET_FAIL 1
#define SYSINFO_RET_TIMEOUT 2
-#define ZBX_METRIC struct zbx_metric_type
-ZBX_METRIC
+typedef struct zbx_metric_type
{
char *key;
unsigned flags;
int (*function)();
char *main_param;
char *test_param;
-};
+} ZBX_METRIC;
+
/* flags for command */
#define CF_USEUPARAM 1 /* use user param */
@@ -116,7 +116,7 @@ int CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
int RUN_COMMAND(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
/* internal system functions */
-int EXECUTE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
+int EXECUTE_INT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result);
diff --git a/include/threads.h b/include/threads.h
new file mode 100755
index 00000000..6bed36de
--- /dev/null
+++ b/include/threads.h
@@ -0,0 +1,68 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_THREADS_H
+#define ZABBIX_THREADS_H
+
+#include "common.h"
+
+#if defined(WIN32)
+
+ #define ZBX_THREAD_ERROR (0)
+
+ #define ZBX_THREAD_HANDLE HANDLE
+
+ #define ZBX_THREAD_ENTRY_POINTER(pointer_name) \
+ unsigned (__stdcall * pointer_name )(void *)
+
+ #define ZBX_THREAD_ENTRY(entry_name, arg_name) \
+ unsigned __stdcall entry_name (void * arg_name)
+
+ #define zbx_tread_exit(status) \
+ _endthreadex((unsigned int)(status)); \
+ return ((unsigned)(status))
+
+ #define zbx_sleep(sec) Sleep(((DWORD)(sec))*((DWORD)1000))
+
+#else /* not WIN32 */
+
+ #define ZBX_THREAD_ERROR (-1)
+
+ #define ZBX_THREAD_HANDLE pid_t
+
+ #define ZBX_THREAD_ENTRY_POINTER(pointer_name) \
+ unsigned (* pointer_name )(void *)
+
+ #define ZBX_THREAD_ENTRY(entry_name, arg_name) \
+ unsigned entry_name (void * arg_name )
+
+ #define zbx_tread_exit(status) \
+ exit((int)(status)); \
+ return ((unsigned)(status))
+
+ #define zbx_sleep(sec) sleep((sec))
+
+#endif /* WIN32 */
+
+ZBX_THREAD_HANDLE zbx_thread_start(ZBX_THREAD_ENTRY_POINTER(handler), void *args);
+int zbx_thread_wait(ZBX_THREAD_HANDLE thread);
+/* zbx_tread_exit(status) // declared as define !!! */
+long int zbx_get_thread_id(void);
+
+#endif /* ZABBIX_THREADS_H */
diff --git a/include/zbxgetopt.h b/include/zbxgetopt.h
new file mode 100755
index 00000000..68d9e691
--- /dev/null
+++ b/include/zbxgetopt.h
@@ -0,0 +1,102 @@
+/* Declarations for getopt.
+ Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ 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, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef ZBX_GETOPT_H
+#define ZBX_GETOPT_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *zbx_optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns EOF, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, `optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int zbx_optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+ for unrecognized options. */
+
+extern int zbx_opterr;
+
+/* Set to an option character which was unrecognized. */
+
+extern int zbx_optopt;
+
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of `struct option' terminated by an element containing a name which is
+ zero.
+
+ The field `has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field `flag' is not NULL, it points to a variable that is set
+ to the value given in the field `val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an `int' to
+ a compiled-in constant, such as set a value from `optarg', set the
+ option's `flag' field to zero and its `val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero `flag' field, `getopt'
+ returns the contents of the `val' field. */
+
+struct zbx_option
+{
+ const char *name;
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'. */
+
+#define zbx_no_argument 0
+#define zbx_required_argument 1
+#define zbx_optional_argument 2
+#define zbx_exact_argument 0x10 /* no abbrev. */
+
+int zbx_getopt(int argc, char **argv, const char *optstring);
+int zbx_getopt_long(int argc, char **argv, const char *options,
+ const struct zbx_option *long_options, int *opt_index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZBX_GETOPT_H */
diff --git a/include/zbxplugin.h b/include/zbxplugin.h
new file mode 100755
index 00000000..dc7ea342
--- /dev/null
+++ b/include/zbxplugin.h
@@ -0,0 +1,61 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXPLUGIN_H
+#define ZABBIX_ZBXPLUGIN_H
+
+#ifdef WIN32
+
+# define __zabbix_api __cdecl
+typedef HMODULE ZBX_MODULE;
+
+#else /* not WIN32 */
+
+# define __zabbix_api
+typedef void* ZBX_MODULE;
+
+#endif /* WIN32 */
+
+#define MAX_CMDNAME 256
+
+typedef struct
+{
+ char name[MAX_CMDNAME];
+ int (__zabbix_api * handler_float)(char *,double *); /* Handler if return value is floating point numeric */
+ int (__zabbix_api * handler_string)(char *,char **); /* Handler if return value is string */
+} ZBX_PLUGIN_ARGS;
+
+struct zbx_plugin_list
+{
+ struct zbx_plugin_list *next; // Pointer to next element in a chain
+
+ ZBX_MODULE hModule; // DLL module handle
+ int runned;
+ int (__zabbix_api * init)(char *,ZBX_PLUGIN_ARGS **);
+ void (__zabbix_api * shutdown)(void);
+ ZBX_PLUGIN_ARGS *args; // List of subagent's commands
+};
+
+typedef struct zbx_plugin_list ZBX_PLUGIN_LIST;
+
+extern ZBX_PLUGIN_LIST *PluginsList;
+
+int add_plugin(char *args);
+
+#endif /* ZABBIX_ZBXPLUGIN_H */
diff --git a/include/zbxsecurity.h b/include/zbxsecurity.h
new file mode 100755
index 00000000..66e54e7c
--- /dev/null
+++ b/include/zbxsecurity.h
@@ -0,0 +1,27 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXSECURITY_H
+#define ZABBIX_ZBXSECURITY_H
+
+#include "zbxsock.h"
+
+int check_security(ZBX_SOCKET sock, char *ip_list, int allow_if_empty);
+
+#endif /* ZABBIX_ZBXSECURITY_H */
diff --git a/include/zbxsock.h b/include/zbxsock.h
new file mode 100755
index 00000000..52b4834c
--- /dev/null
+++ b/include/zbxsock.h
@@ -0,0 +1,72 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXSOCK_H
+#define ZABBIX_ZBXSOCK_H
+
+
+#if !defined(INVALID_SOCKET)
+# define INVALID_SOCKET (-1)
+#endif /* INVALID_SOCKET */
+
+#if !defined(SOCKET_ERROR)
+# define SOCKET_ERROR (-1)
+#endif /* SOCKET_ERROR */
+
+#if !defined (EINTR)
+# define EINTR WSAETIMEDOUT
+#endif /* EINTR */
+
+#if !defined(EHOSTUNREACH)
+# define EHOSTUNREACH WSAEHOSTUNREACH
+#endif /* EHOSTUNREACH */
+
+#if !defined(ECONNRESET)
+# define ECONNRESET WSAECONNRESET
+#endif /* ECONNRESET */
+
+#if !defined(SOMAXCONN)
+# define SOMAXCONN 1024
+#endif /* SOMAXCONN */
+
+#if defined(SOCKET)
+
+ typedef SOCKET ZBX_SOCKET;
+
+#else /* not SOCKET */
+
+ typedef int ZBX_SOCKET;
+
+#endif /* SOCKET */
+
+typedef struct sockaddr_in ZBX_SOCKADDR;
+
+int zbx_sock_read(ZBX_SOCKET sock, void *buf, int buflen, int timeout);
+int zbx_sock_write(ZBX_SOCKET sock, void *buf, int buflen);
+
+#if defined (WIN32)
+# define zbx_sock_close(sock) closesocket(sock)
+# define zbx_sock_last_error() WSAGetLastError()
+#else /* not WIN32 */
+# define zbx_sock_close(sock) close(sock)
+# define zbx_sock_last_error() errno
+#endif /* WIN32 */
+
+
+#endif /* ZABBIX_ZBXSOCK_H */
diff --git a/include/zbxtypes.h b/include/zbxtypes.h
new file mode 100755
index 00000000..ee94bf8f
--- /dev/null
+++ b/include/zbxtypes.h
@@ -0,0 +1,57 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_TYPES_H
+#define ZABBIX_TYPES_H
+
+#if defined(WIN32)
+
+# define zbx_uint64_t __int64
+# define ZBX_FS_UI64 "%llu"
+
+# define zbx_pid_t int
+
+# define stat _stat
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+
+# define alloca _alloca
+
+#ifndef uint32_t
+# define uint32_t __int32
+#endif /* uint32_t */
+
+#else /* WIN32 */
+
+# define zbx_uint64_t uint64_t
+# if __WORDSIZE == 64
+# define ZBX_FS_UI64 "%lu"
+# else /* __WORDSIZE == 64 */
+# define ZBX_FS_UI64 "%llu"
+# endif /* __WORDSIZE == 64 */
+
+# define zbx_pid_t pid_t
+
+#endif /* WIN32 */
+
+#ifndef S_ISREG
+# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
+#endif
+
+#endif
diff --git a/misc/conf/zabbix_agentd.conf b/misc/conf/zabbix_agentd.conf
index e3761c89..7251c752 100644
--- a/misc/conf/zabbix_agentd.conf
+++ b/misc/conf/zabbix_agentd.conf
@@ -49,8 +49,9 @@ StartAgents=5
# 0 - debug is not created
# 1 - critical information
# 2 - error information
-# 3 - warnings (default)
-# 4 - for debugging (produces lots of information)
+# 3 - warnings
+# 4 - information (default)
+# 5 - for debugging (produces lots of information)
DebugLevel=3
diff --git a/src/alphacode/poller/poller.c b/src/alphacode/poller/poller.c
index a9574697..570cee64 100644
--- a/src/alphacode/poller/poller.c
+++ b/src/alphacode/poller/poller.c
@@ -138,7 +138,7 @@ void wait_connect()
if ((poll_cli[i].revents&POLLOUT)==POLLOUT)
{
printf("[%d] remote socket ready for writing\n",i);
- snprintf(c, 1024 - 1, "%s\n", "system.uptime\n");
+ zbx_snprintf(c, sizeof(c), "%s\n", "system.uptime\n");
if( write(poll_cli[i].fd,c,strlen(c)) == -1 )
{
perror("write");
diff --git a/src/alphacode/poller/snmp.c b/src/alphacode/poller/snmp.c
index 9b29f77c..9f2bc583 100755
--- a/src/alphacode/poller/snmp.c
+++ b/src/alphacode/poller/snmp.c
@@ -121,7 +121,7 @@ void load_oids(void)
struct host *h;
struct oid *o;
- sprintf(sql,"select h.ip,i.snmp_community,i.snmp_oid from hosts h,items i where i.hostid=h.hostid and i.type=1 and i.status=0 and h.status=0 and h.useip=1");
+ zbx_snprintf(sql, sizeof(sql), "select h.ip,i.snmp_community,i.snmp_oid from hosts h,items i where i.hostid=h.hostid and i.type=1 and i.status=0 and h.status=0 and h.useip=1");
result=DBselect(sql);
diff --git a/src/libs/Makefile.am b/src/libs/Makefile.am
index 007ba8fe..4d499ff5 100644
--- a/src/libs/Makefile.am
+++ b/src/libs/Makefile.am
@@ -1,7 +1,7 @@
if AGENT
-AGENT_DIRS = zbxcommon zbxlog zbxcrypto zbxpid zbxnet zbxconf zbxsysinfo
+AGENT_DIRS = zbxcrypto zbxcommon zbxlog zbxnet zbxnix zbxconf zbxsysinfo zbxplugin zbxsys
endif
if SERVER
-SERVER_DIRS = zbxcommon zbxlog zbxcrypto zbxpid zbxnet zbxconf zbxdbhigh zbxemail zbxsms zbxsysinfo
+SERVER_DIRS = zbxcrypto zbxcommon zbxlog zbxnet zbxnix zbxconf zbxdbhigh zbxemail zbxsms zbxsysinfo zbxplugin zbxsys
endif
SUBDIRS=$(AGENT_DIRS) $(SERVER_DIRS)
diff --git a/src/libs/zbxcommon/Makefile.am b/src/libs/zbxcommon/Makefile.am
index 57a91218..1d958604 100644
--- a/src/libs/zbxcommon/Makefile.am
+++ b/src/libs/zbxcommon/Makefile.am
@@ -1,3 +1,3 @@
SUBDIRS=
lib_LIBRARIES=libzbxcommon.a
-libzbxcommon_a_SOURCES=base64.c misc.c regexp.c xml.c comms.c str.c
+libzbxcommon_a_SOURCES=misc.c regexp.c xml.c comms.c str.c zbxgetopt.c alias.c
diff --git a/src/libs/zbxcommon/alias.c b/src/libs/zbxcommon/alias.c
new file mode 100755
index 00000000..bd7de8b0
--- /dev/null
+++ b/src/libs/zbxcommon/alias.c
@@ -0,0 +1,128 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "alias.h"
+
+//
+// Static data
+//
+
+static ALIAS *aliasList=NULL;
+
+
+//
+// Add alias to the list
+// Returns 1 on success or 0 if alias with that name already exist
+//
+int add_alias_from_config(char *line)
+{
+ char *name = NULL,
+ *value = NULL;
+
+ name = line;
+ value = strchr(line,':');
+ if(NULL == value)
+ return FAIL;
+
+ *value = '\0';
+ value++;
+
+ return add_alias(name, value);
+}
+
+int add_alias(const char *name, const char *value)
+{
+ ALIAS *alias;
+
+ for(alias = aliasList; ; alias=alias->next)
+ {
+ /* Add new parameters */
+ if(alias == NULL)
+ {
+ alias = (ALIAS *)malloc(sizeof(ALIAS));
+ if (NULL != alias)
+ {
+ memset(alias,0,sizeof(ALIAS));
+ strncpy(alias->name, name, MAX_ALIAS_NAME-1);
+ alias->value = (char *)malloc(strlen(value)+1);
+ strcpy(alias->value,value);
+ alias->next=aliasList;
+ aliasList=alias;
+
+ return SUCCEED;
+ }
+ break;
+ }
+
+ /* Replace existing parameters */
+ if (strcmp(alias->name, name) == 0)
+ {
+ if(alias->value)
+ free(alias->value);
+
+ memset(alias, 0, sizeof(ALIAS));
+
+ strncpy(alias->name, name, MAX_ALIAS_NAME-1);
+
+ alias->value = (char *)malloc(strlen(value)+1);
+ strcpy(alias->value, value);
+
+ alias->next = aliasList;
+ aliasList = alias;
+
+ return SUCCEED;
+ }
+ }
+ return FAIL;
+}
+
+void alias_list_free(void)
+{
+ ALIAS *curr;
+ ALIAS *next;
+
+ next = aliasList;
+ while(next!=NULL)
+ {
+ curr = next;
+ next = curr->next;
+ free(curr->value);
+ free(curr);
+ }
+}
+
+//
+// Checks parameter and expands it if aliased
+//
+
+void alias_expand(const char *orig, char *expanded, int exp_buf_len)
+{
+ ALIAS *alias;
+
+ for(alias = aliasList; alias!=NULL; alias = alias->next)
+ {
+ if (!strcmp(alias->name,orig))
+ {
+ strsncpy(expanded, alias->value, exp_buf_len);
+ return;
+ }
+ }
+ strsncpy(expanded, orig, exp_buf_len);
+}
diff --git a/src/libs/zbxcommon/comms.c b/src/libs/zbxcommon/comms.c
index 344d30c3..9cee531a 100644
--- a/src/libs/zbxcommon/comms.c
+++ b/src/libs/zbxcommon/comms.c
@@ -1,8 +1,25 @@
-#include <string.h>
-#include <stdio.h>
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
#include "common.h"
#include "log.h"
+#include "base64.h"
int comms_create_request(char *host, char *key, char *data, char *lastlogsize, char *request,int maxlen)
{
@@ -30,11 +47,11 @@ int comms_create_request(char *host, char *key, char *data, char *lastlogsize, c
if(lastlogsize[0]==0)
{
- snprintf(request,maxlen,"<req><host>%s</host><key>%s</key><data>%s</data></req>",host_b64,key_b64,data_b64);
+ zbx_snprintf(request,maxlen,"<req><host>%s</host><key>%s</key><data>%s</data></req>",host_b64,key_b64,data_b64);
}
else
{
- snprintf(request,maxlen,"<req><host>%s</host><key>%s</key><data>%s</data><lastlogsize>%s</lastlogsize></req>",host_b64,key_b64,data_b64,lastlogsize_b64);
+ zbx_snprintf(request,maxlen,"<req><host>%s</host><key>%s</key><data>%s</data><lastlogsize>%s</lastlogsize></req>",host_b64,key_b64,data_b64,lastlogsize_b64);
}
/* fprintf(stderr, "Max [%d] Result [%s][%d]\n", maxlen , request, strlen(request));*/
diff --git a/src/libs/zbxcommon/gnuregex.c b/src/libs/zbxcommon/gnuregex.c
new file mode 100755
index 00000000..9a438f2c
--- /dev/null
+++ b/src/libs/zbxcommon/gnuregex.c
@@ -0,0 +1,4941 @@
+/* Extended regular expression matching and search library,
+ version 0.12.
+ (Implements POSIX draft P10003.2/D11.2, except for
+ internationalization features.)
+
+ Copyright (C) 1993 Free Software Foundation, Inc.
+
+ 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* AIX requires this to be the first thing in the file. */
+#if defined (_AIX) && !defined (REGEX_MALLOC)
+ #pragma alloca
+#endif
+
+#define _GNU_SOURCE
+
+#include "common.h"
+
+/* We need this for `regex.h', and perhaps for the Emacs include files. */
+#include <sys/types.h>
+
+/* The `emacs' switch turns on certain matching commands
+ that make sense only in Emacs. */
+#ifdef emacs
+
+#include "lisp.h"
+#include "buffer.h"
+#include "syntax.h"
+
+/* Emacs uses `NULL' as a predicate. */
+#undef NULL
+
+#else /* not emacs */
+
+/* We used to test for `BSTRING' here, but only GCC and Emacs define
+ `BSTRING', as far as I know, and neither of them use this code. */
+#if HAVE_STRING_H || STDC_HEADERS
+# include <string.h>
+# ifndef bcmp
+# define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
+# endif
+# ifndef bcopy
+# define bcopy(s, d, n) memcpy ((d), (s), (n))
+# endif
+# ifndef bzero
+# define bzero(s, n) memset ((s), 0, (n))
+# endif
+#else
+# include <strings.h>
+#endif
+
+/* Define the syntax stuff for \<, \>, etc. */
+
+/* This must be nonzero for the wordchar and notwordchar pattern
+ commands in re_match_2. */
+#ifndef Sword
+#define Sword 1
+#endif
+
+#ifdef SYNTAX_TABLE
+
+extern char *re_syntax_table;
+
+#else /* not SYNTAX_TABLE */
+
+/* How many characters in the character set. */
+#define CHAR_SET_SIZE 256
+
+static char re_syntax_table[CHAR_SET_SIZE];
+
+static void
+init_syntax_once ()
+{
+ register int c;
+ static int done = 0;
+
+ if (done)
+ return;
+
+ bzero (re_syntax_table, sizeof re_syntax_table);
+
+ for (c = 'a'; c <= 'z'; c++)
+ re_syntax_table[c] = Sword;
+
+ for (c = 'A'; c <= 'Z'; c++)
+ re_syntax_table[c] = Sword;
+
+ for (c = '0'; c <= '9'; c++)
+ re_syntax_table[c] = Sword;
+
+ re_syntax_table['_'] = Sword;
+
+ done = 1;
+}
+
+#endif /* not SYNTAX_TABLE */
+
+#define SYNTAX(c) re_syntax_table[c]
+
+#endif /* not emacs */
+
+/* Get the interface, including the syntax bits. */
+#include "gnuregex.h"
+
+/* isalpha etc. are used for the character classes. */
+#include <ctype.h>
+
+#ifndef isascii
+#define isascii(c) 1
+#endif
+
+#ifdef isblank
+#define ISBLANK(c) (isascii (c) && isblank (c))
+#else
+#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
+#endif
+#ifdef isgraph
+#define ISGRAPH(c) (isascii (c) && isgraph (c))
+#else
+#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c))
+#endif
+
+#define ISPRINT(c) (isascii (c) && isprint (c))
+#define ISDIGIT(c) (isascii (c) && isdigit (c))
+#define ISALNUM(c) (isascii (c) && isalnum (c))
+#define ISALPHA(c) (isascii (c) && isalpha (c))
+#define ISCNTRL(c) (isascii (c) && iscntrl (c))
+#define ISLOWER(c) (isascii (c) && islower (c))
+#define ISPUNCT(c) (isascii (c) && ispunct (c))
+#define ISSPACE(c) (isascii (c) && isspace (c))
+#define ISUPPER(c) (isascii (c) && isupper (c))
+#define ISXDIGIT(c) (isascii (c) && isxdigit (c))
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+/* We remove any previous definition of `SIGN_EXTEND_CHAR',
+ since ours (we hope) works properly with all combinations of
+ machines, compilers, `char' and `unsigned char' argument types.
+ (Per Bothner suggested the basic approach.) */
+#undef SIGN_EXTEND_CHAR
+#if __STDC__
+#define SIGN_EXTEND_CHAR(c) ((signed char) (c))
+#else /* not __STDC__ */
+/* As in Harbison and Steele. */
+#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
+#endif
+
+/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we
+ use `alloca' instead of `malloc'. This is because using malloc in
+ re_search* or re_match* could cause memory leaks when C-g is used in
+ Emacs; also, malloc is slower and causes storage fragmentation. On
+ the other hand, malloc is more portable, and easier to debug.
+
+ Because we sometimes use alloca, some routines have to be macros,
+ not functions -- `alloca'-allocated space disappears at the end of the
+ function it is called in. */
+
+#ifdef REGEX_MALLOC
+
+ #define REGEX_ALLOCATE malloc
+ #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
+
+#else /* not REGEX_MALLOC */
+
+/* Emacs already defines alloca, sometimes. */
+ #ifndef alloca
+/* Make alloca work the best possible way. */
+ #ifdef __GNUC__
+ #define alloca __builtin_alloca
+ #elif HAVE_ALLOCA_H
+ #include <alloca.h>
+ #elif WIN32
+ #define alloca _alloca
+ #elif !defined(_AIX) /* Already did AIX, up at the top. */
+ char *alloca ();
+ #endif /* __GNUC__ */
+ #endif /* not alloca */
+
+ #define REGEX_ALLOCATE alloca
+
+ /* Assumes a `char *destination' variable. */
+ #define REGEX_REALLOCATE(source, osize, nsize) \
+ (destination = (char *) alloca (nsize), \
+ bcopy (source, destination, osize), \
+ destination)
+
+#endif /* not REGEX_MALLOC */
+
+
+/* True if `size1' is non-NULL and PTR is pointing anywhere inside
+ `string1' or just past its end. This works if PTR is NULL, which is
+ a good thing. */
+#define FIRST_STRING_P(ptr) \
+ (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
+
+/* (Re)Allocate N items of type T using malloc, or fail. */
+#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
+#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
+#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
+
+#define BYTEWIDTH 8 /* In bits. */
+
+#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#if defined(boolean)
+typedef char boolean;
+#endif
+
+#define false 0
+#define true 1
+
+/* These are the command codes that appear in compiled regular
+ expressions. Some opcodes are followed by argument bytes. A
+ command code can specify any interpretation whatsoever for its
+ arguments. Zero bytes may appear in the compiled regular expression.
+
+ The value of `exactn' is needed in search.c (search_buffer) in Emacs.
+ So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of
+ `exactn' we use here must also be 1. */
+
+typedef enum
+{
+ no_op = 0,
+
+ /* Followed by one byte giving n, then by n literal bytes. */
+ exactn = 1,
+
+ /* Matches any (more or less) character. */
+ anychar,
+
+ /* Matches any one char belonging to specified set. First
+ following byte is number of bitmap bytes. Then come bytes
+ for a bitmap saying which chars are in. Bits in each byte
+ are ordered low-bit-first. A character is in the set if its
+ bit is 1. A character too large to have a bit in the map is
+ automatically not in the set. */
+ charset,
+
+ /* Same parameters as charset, but match any character that is
+ not one of those specified. */
+ charset_not,
+
+ /* Start remembering the text that is matched, for storing in a
+ register. Followed by one byte with the register number, in
+ the range 0 to one less than the pattern buffer's re_nsub
+ field. Then followed by one byte with the number of groups
+ inner to this one. (This last has to be part of the
+ start_memory only because we need it in the on_failure_jump
+ of re_match_2.) */
+ start_memory,
+
+ /* Stop remembering the text that is matched and store it in a
+ memory register. Followed by one byte with the register
+ number, in the range 0 to one less than `re_nsub' in the
+ pattern buffer, and one byte with the number of inner groups,
+ just like `start_memory'. (We need the number of inner
+ groups here because we don't have any easy way of finding the
+ corresponding start_memory when we're at a stop_memory.) */
+ stop_memory,
+
+ /* Match a duplicate of something remembered. Followed by one
+ byte containing the register number. */
+ duplicate,
+
+ /* Fail unless at beginning of line. */
+ begline,
+
+ /* Fail unless at end of line. */
+ endline,
+
+ /* Succeeds if at beginning of buffer (if emacs) or at beginning
+ of string to be matched (if not). */
+ begbuf,
+
+ /* Analogously, for end of buffer/string. */
+ endbuf,
+
+ /* Followed by two byte relative address to which to jump. */
+ jump,
+
+ /* Same as jump, but marks the end of an alternative. */
+ jump_past_alt,
+
+ /* Followed by two-byte relative address of place to resume at
+ in case of failure. */
+ on_failure_jump,
+
+ /* Like on_failure_jump, but pushes a placeholder instead of the
+ current string position when executed. */
+ on_failure_keep_string_jump,
+
+ /* Throw away latest failure point and then jump to following
+ two-byte relative address. */
+ pop_failure_jump,
+
+ /* Change to pop_failure_jump if know won't have to backtrack to
+ match; otherwise change to jump. This is used to jump
+ back to the beginning of a repeat. If what follows this jump
+ clearly won't match what the repeat does, such that we can be
+ sure that there is no use backtracking out of repetitions
+ already matched, then we change it to a pop_failure_jump.
+ Followed by two-byte address. */
+ maybe_pop_jump,
+
+ /* Jump to following two-byte address, and push a dummy failure
+ point. This failure point will be thrown away if an attempt
+ is made to use it for a failure. A `+' construct makes this
+ before the first repeat. Also used as an intermediary kind
+ of jump when compiling an alternative. */
+ dummy_failure_jump,
+
+ /* Push a dummy failure point and continue. Used at the end of
+ alternatives. */
+ push_dummy_failure,
+
+ /* Followed by two-byte relative address and two-byte number n.
+ After matching N times, jump to the address upon failure. */
+ succeed_n,
+
+ /* Followed by two-byte relative address, and two-byte number n.
+ Jump to the address N times, then fail. */
+ jump_n,
+
+ /* Set the following two-byte relative address to the
+ subsequent two-byte number. The address *includes* the two
+ bytes of number. */
+ set_number_at,
+
+ wordchar, /* Matches any word-constituent character. */
+ notwordchar, /* Matches any char that is not a word-constituent. */
+
+ wordbeg, /* Succeeds if at word beginning. */
+ wordend, /* Succeeds if at word end. */
+
+ wordbound, /* Succeeds if at a word boundary. */
+ notwordbound /* Succeeds if not at a word boundary. */
+
+#ifdef emacs
+ ,before_dot, /* Succeeds if before point. */
+ at_dot, /* Succeeds if at point. */
+ after_dot, /* Succeeds if after point. */
+
+ /* Matches any character whose syntax is specified. Followed by
+ a byte which contains a syntax code, e.g., Sword. */
+ syntaxspec,
+
+ /* Matches any character whose syntax is not that specified. */
+ notsyntaxspec
+#endif /* emacs */
+} re_opcode_t;
+
+/* Common operations on the compiled pattern. */
+
+/* Store NUMBER in two contiguous bytes starting at DESTINATION. */
+
+#define STORE_NUMBER(destination, number) \
+ do { \
+ (destination)[0] = (number) & 0377; \
+ (destination)[1] = (number) >> 8; \
+ } while (0)
+
+/* Same as STORE_NUMBER, except increment DESTINATION to
+ the byte after where the number is stored. Therefore, DESTINATION
+ must be an lvalue. */
+
+#define STORE_NUMBER_AND_INCR(destination, number) \
+ do { \
+ STORE_NUMBER (destination, number); \
+ (destination) += 2; \
+ } while (0)
+
+/* Put into DESTINATION a number stored in two contiguous bytes starting
+ at SOURCE. */
+
+#define EXTRACT_NUMBER(destination, source) \
+ do { \
+ (destination) = *(source) & 0377; \
+ (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \
+ } while (0)
+
+#ifdef DEBUG
+static void
+extract_number (dest, source)
+ int *dest;
+ unsigned char *source;
+{
+ int temp = SIGN_EXTEND_CHAR (*(source + 1));
+ *dest = *source & 0377;
+ *dest += temp << 8;
+}
+
+#ifndef EXTRACT_MACROS /* To debug the macros. */
+#undef EXTRACT_NUMBER
+#define EXTRACT_NUMBER(dest, src) extract_number (&dest, src)
+#endif /* not EXTRACT_MACROS */
+
+#endif /* DEBUG */
+
+/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number.
+ SOURCE must be an lvalue. */
+
+#define EXTRACT_NUMBER_AND_INCR(destination, source) \
+ do { \
+ EXTRACT_NUMBER (destination, source); \
+ (source) += 2; \
+ } while (0)
+
+#ifdef DEBUG
+static void
+extract_number_and_incr (destination, source)
+ int *destination;
+ unsigned char **source;
+{
+ extract_number (destination, *source);
+ *source += 2;
+}
+
+#ifndef EXTRACT_MACROS
+#undef EXTRACT_NUMBER_AND_INCR
+#define EXTRACT_NUMBER_AND_INCR(dest, src) \
+ extract_number_and_incr (&dest, &src)
+#endif /* not EXTRACT_MACROS */
+
+#endif /* DEBUG */
+
+/* If DEBUG is defined, Regex prints many voluminous messages about what
+ it is doing (if the variable `debug' is nonzero). If linked with the
+ main program in `iregex.c', you can enter patterns and strings
+ interactively. And if linked with the main program in `main.c' and
+ the other test files, you can run the already-written tests. */
+
+#ifdef DEBUG
+
+/* We use standard I/O for debugging. */
+#include <stdio.h>
+
+/* It is useful to test things that ``must'' be true when debugging. */
+#include <assert.h>
+
+static int debug = 0;
+
+#define DEBUG_STATEMENT(e) e
+#define DEBUG_PRINT1(x) if (debug) printf (x)
+#define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2)
+#define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3)
+#define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4)
+#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \
+ if (debug) print_partial_compiled_pattern (s, e)
+#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \
+ if (debug) print_double_string (w, s1, sz1, s2, sz2)
+
+
+extern void printchar ();
+
+/* Print the fastmap in human-readable form. */
+
+void
+print_fastmap (fastmap)
+ char *fastmap;
+{
+ unsigned was_a_range = 0;
+ unsigned i = 0;
+
+ while (i < (1 << BYTEWIDTH))
+ {
+ if (fastmap[i++])
+ {
+ was_a_range = 0;
+ printchar (i - 1);
+ while (i < (1 << BYTEWIDTH) && fastmap[i])
+ {
+ was_a_range = 1;
+ i++;
+ }
+ if (was_a_range)
+ {
+ printf ("-");
+ printchar (i - 1);
+ }
+ }
+ }
+ putchar ('\n');
+}
+
+
+/* Print a compiled pattern string in human-readable form, starting at
+ the START pointer into it and ending just before the pointer END. */
+
+void
+print_partial_compiled_pattern (start, end)
+ unsigned char *start;
+ unsigned char *end;
+{
+ int mcnt, mcnt2;
+ unsigned char *p = start;
+ unsigned char *pend = end;
+
+ if (start == NULL)
+ {
+ printf ("(null)\n");
+ return;
+ }
+
+ /* Loop over pattern commands. */
+ while (p < pend)
+ {
+ switch ((re_opcode_t) *p++)
+ {
+ case no_op:
+ printf ("/no_op");
+ break;
+
+ case exactn:
+ mcnt = *p++;
+ printf ("/exactn/%d", mcnt);
+ do
+ {
+ putchar ('/');
+ printchar (*p++);
+ }
+ while (--mcnt);
+ break;
+
+ case start_memory:
+ mcnt = *p++;
+ printf ("/start_memory/%d/%d", mcnt, *p++);
+ break;
+
+ case stop_memory:
+ mcnt = *p++;
+ printf ("/stop_memory/%d/%d", mcnt, *p++);
+ break;
+
+ case duplicate:
+ printf ("/duplicate/%d", *p++);
+ break;
+
+ case anychar:
+ printf ("/anychar");
+ break;
+
+ case charset:
+ case charset_not:
+ {
+ register int c;
+
+ printf ("/charset%s",
+ (re_opcode_t) *(p - 1) == charset_not ? "_not" : "");
+
+ assert (p + *p < pend);
+
+ for (c = 0; c < *p; c++)
+ {
+ unsigned bit;
+ unsigned char map_byte = p[1 + c];
+
+ putchar ('/');
+
+ for (bit = 0; bit < BYTEWIDTH; bit++)
+ if (map_byte & (1 << bit))
+ printchar (c * BYTEWIDTH + bit);
+ }
+ p += 1 + *p;
+ break;
+ }
+
+ case begline:
+ printf ("/begline");
+ break;
+
+ case endline:
+ printf ("/endline");
+ break;
+
+ case on_failure_jump:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/on_failure_jump/0/%d", mcnt);
+ break;
+
+ case on_failure_keep_string_jump:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/on_failure_keep_string_jump/0/%d", mcnt);
+ break;
+
+ case dummy_failure_jump:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/dummy_failure_jump/0/%d", mcnt);
+ break;
+
+ case push_dummy_failure:
+ printf ("/push_dummy_failure");
+ break;
+
+ case maybe_pop_jump:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/maybe_pop_jump/0/%d", mcnt);
+ break;
+
+ case pop_failure_jump:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/pop_failure_jump/0/%d", mcnt);
+ break;
+
+ case jump_past_alt:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/jump_past_alt/0/%d", mcnt);
+ break;
+
+ case jump:
+ extract_number_and_incr (&mcnt, &p);
+ printf ("/jump/0/%d", mcnt);
+ break;
+
+ case succeed_n:
+ extract_number_and_incr (&mcnt, &p);
+ extract_number_and_incr (&mcnt2, &p);
+ printf ("/succeed_n/0/%d/0/%d", mcnt, mcnt2);
+ break;
+
+ case jump_n:
+ extract_number_and_incr (&mcnt, &p);
+ extract_number_and_incr (&mcnt2, &p);
+ printf ("/jump_n/0/%d/0/%d", mcnt, mcnt2);
+ break;
+
+ case set_number_at:
+ extract_number_and_incr (&mcnt, &p);
+ extract_number_and_incr (&mcnt2, &p);
+ printf ("/set_number_at/0/%d/0/%d", mcnt, mcnt2);
+ break;
+
+ case wordbound:
+ printf ("/wordbound");
+ break;
+
+ case notwordbound:
+ printf ("/notwordbound");
+ break;
+
+ case wordbeg:
+ printf ("/wordbeg");
+ break;
+
+ case wordend:
+ printf ("/wordend");
+
+#ifdef emacs
+ case before_dot:
+ printf ("/before_dot");
+ break;
+
+ case at_dot:
+ printf ("/at_dot");
+ break;
+
+ case after_dot:
+ printf ("/after_dot");
+ break;
+
+ case syntaxspec:
+ printf ("/syntaxspec");
+ mcnt = *p++;
+ printf ("/%d", mcnt);
+ break;
+
+ case notsyntaxspec:
+ printf ("/notsyntaxspec");
+ mcnt = *p++;
+ printf ("/%d", mcnt);
+ break;
+#endif /* emacs */
+
+ case wordchar:
+ printf ("/wordchar");
+ break;
+
+ case notwordchar:
+ printf ("/notwordchar");
+ break;
+
+ case begbuf:
+ printf ("/begbuf");
+ break;
+
+ case endbuf:
+ printf ("/endbuf");
+ break;
+
+ default:
+ printf ("?%d", *(p-1));
+ }
+ }
+ printf ("/\n");
+}
+
+
+void
+print_compiled_pattern (bufp)
+ struct re_pattern_buffer *bufp;
+{
+ unsigned char *buffer = bufp->buffer;
+
+ print_partial_compiled_pattern (buffer, buffer + bufp->used);
+ printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated);
+
+ if (bufp->fastmap_accurate && bufp->fastmap)
+ {
+ printf ("fastmap: ");
+ print_fastmap (bufp->fastmap);
+ }
+
+ printf ("re_nsub: %d\t", bufp->re_nsub);
+ printf ("regs_alloc: %d\t", bufp->regs_allocated);
+ printf ("can_be_null: %d\t", bufp->can_be_null);
+ printf ("newline_anchor: %d\n", bufp->newline_anchor);
+ printf ("no_sub: %d\t", bufp->no_sub);
+ printf ("not_bol: %d\t", bufp->not_bol);
+ printf ("not_eol: %d\t", bufp->not_eol);
+ printf ("syntax: %d\n", bufp->syntax);
+ /* Perhaps we should print the translate table? */
+}
+
+
+void
+print_double_string (where, string1, size1, string2, size2)
+ const char *where;
+ const char *string1;
+ const char *string2;
+ int size1;
+ int size2;
+{
+ unsigned this_char;
+
+ if (where == NULL)
+ printf ("(null)");
+ else
+ {
+ if (FIRST_STRING_P (where))
+ {
+ for (this_char = where - string1; this_char < size1; this_char++)
+ printchar (string1[this_char]);
+
+ where = string2;
+ }
+
+ for (this_char = where - string2; this_char < size2; this_char++)
+ printchar (string2[this_char]);
+ }
+}
+
+#else /* not DEBUG */
+
+#undef assert
+#define assert(e)
+
+#define DEBUG_STATEMENT(e)
+#define DEBUG_PRINT1(x)
+#define DEBUG_PRINT2(x1, x2)
+#define DEBUG_PRINT3(x1, x2, x3)
+#define DEBUG_PRINT4(x1, x2, x3, x4)
+#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)
+#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)
+
+#endif /* not DEBUG */
+
+/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
+ also be assigned to arbitrarily: each pattern buffer stores its own
+ syntax, so it can be changed between regex compilations. */
+reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS;
+
+
+/* Specify the precise syntax of regexps for compilation. This provides
+ for compatibility for various utilities which historically have
+ different, incompatible syntaxes.
+
+ The argument SYNTAX is a bit mask comprised of the various bits
+ defined in regex.h. We return the old syntax. */
+
+reg_syntax_t
+re_set_syntax (syntax)
+ reg_syntax_t syntax;
+{
+ reg_syntax_t ret = re_syntax_options;
+
+ re_syntax_options = syntax;
+ return ret;
+}
+
+/* This table gives an error message for each of the error codes listed
+ in regex.h. Obviously the order here has to be same as there. */
+
+static const char *re_error_msg[] =
+ { NULL, /* REG_NOERROR */
+ "No match", /* REG_NOMATCH */
+ "Invalid regular expression", /* REG_BADPAT */
+ "Invalid collation character", /* REG_ECOLLATE */
+ "Invalid character class name", /* REG_ECTYPE */
+ "Trailing backslash", /* REG_EESCAPE */
+ "Invalid back reference", /* REG_ESUBREG */
+ "Unmatched [ or [^", /* REG_EBRACK */
+ "Unmatched ( or \\(", /* REG_EPAREN */
+ "Unmatched \\{", /* REG_EBRACE */
+ "Invalid content of \\{\\}", /* REG_BADBR */
+ "Invalid range end", /* REG_ERANGE */
+ "Memory exhausted", /* REG_ESPACE */
+ "Invalid preceding regular expression", /* REG_BADRPT */
+ "Premature end of regular expression", /* REG_EEND */
+ "Regular expression too big", /* REG_ESIZE */
+ "Unmatched ) or \\)", /* REG_ERPAREN */
+ };
+
+/* Subroutine declarations and macros for regex_compile. */
+
+static void store_op1 (), store_op2 ();
+static void insert_op1 (), insert_op2 ();
+static boolean at_begline_loc_p (), at_endline_loc_p ();
+static boolean group_in_compile_stack ();
+static reg_errcode_t compile_range ();
+
+/* Fetch the next character in the uncompiled pattern---translating it
+ if necessary. Also cast from a signed character in the constant
+ string passed to us by the user to an unsigned char that we can use
+ as an array index (in, e.g., `translate'). */
+#define PATFETCH(c) \
+ do {if (p == pend) return REG_EEND; \
+ c = (unsigned char) *p++; \
+ if (translate) c = translate[c]; \
+ } while (0)
+
+/* Fetch the next character in the uncompiled pattern, with no
+ translation. */
+#define PATFETCH_RAW(c) \
+ do {if (p == pend) return REG_EEND; \
+ c = (unsigned char) *p++; \
+ } while (0)
+
+/* Go backwards one character in the pattern. */
+#define PATUNFETCH p--
+
+
+/* If `translate' is non-null, return translate[D], else just D. We
+ cast the subscript to translate because some data is declared as
+ `char *', to avoid warnings when a string constant is passed. But
+ when we use a character as a subscript we must make it unsigned. */
+#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d))
+
+
+/* Macros for outputting the compiled pattern into `buffer'. */
+
+/* If the buffer isn't allocated when it comes in, use this. */
+#define INIT_BUF_SIZE 32
+
+/* Make sure we have at least N more bytes of space in buffer. */
+#define GET_BUFFER_SPACE(n) \
+ while ((unsigned long)(b - bufp->buffer + (n)) > bufp->allocated) \
+ EXTEND_BUFFER ()
+
+/* Make sure we have one more byte of buffer space and then add C to it. */
+#define BUF_PUSH(c) \
+ do { \
+ GET_BUFFER_SPACE (1); \
+ *b++ = (unsigned char) (c); \
+ } while (0)
+
+
+/* Ensure we have two more bytes of buffer space and then append C1 and C2. */
+#define BUF_PUSH_2(c1, c2) \
+ do { \
+ GET_BUFFER_SPACE (2); \
+ *b++ = (unsigned char) (c1); \
+ *b++ = (unsigned char) (c2); \
+ } while (0)
+
+
+/* As with BUF_PUSH_2, except for three bytes. */
+#define BUF_PUSH_3(c1, c2, c3) \
+ do { \
+ GET_BUFFER_SPACE (3); \
+ *b++ = (unsigned char) (c1); \
+ *b++ = (unsigned char) (c2); \
+ *b++ = (unsigned char) (c3); \
+ } while (0)
+
+
+/* Store a jump with opcode OP at LOC to location TO. We store a
+ relative address offset by the three bytes the jump itself occupies. */
+#define STORE_JUMP(op, loc, to) \
+ store_op1 (op, loc, (to) - (loc) - 3)
+
+/* Likewise, for a two-argument jump. */
+#define STORE_JUMP2(op, loc, to, arg) \
+ store_op2 (op, loc, (to) - (loc) - 3, arg)
+
+/* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */
+#define INSERT_JUMP(op, loc, to) \
+ insert_op1 (op, loc, (to) - (loc) - 3, b)
+
+/* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */
+#define INSERT_JUMP2(op, loc, to, arg) \
+ insert_op2 (op, loc, (to) - (loc) - 3, arg, b)
+
+
+/* This is not an arbitrary limit: the arguments which represent offsets
+ into the pattern are two bytes long. So if 2^16 bytes turns out to
+ be too small, many things would have to change. */
+#define MAX_BUF_SIZE (1L << 16)
+
+
+/* Extend the buffer by twice its current size via realloc and
+ reset the pointers that pointed into the old block to point to the
+ correct places in the new one. If extending the buffer results in it
+ being larger than MAX_BUF_SIZE, then flag memory exhausted. */
+#define EXTEND_BUFFER() \
+ do { \
+ unsigned char *old_buffer = bufp->buffer; \
+ if (bufp->allocated == MAX_BUF_SIZE) \
+ return REG_ESIZE; \
+ bufp->allocated <<= 1; \
+ if (bufp->allocated > MAX_BUF_SIZE) \
+ bufp->allocated = MAX_BUF_SIZE; \
+ bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\
+ if (bufp->buffer == NULL) \
+ return REG_ESPACE; \
+ /* If the buffer moved, move all the pointers into it. */ \
+ if (old_buffer != bufp->buffer) \
+ { \
+ b = (b - old_buffer) + bufp->buffer; \
+ begalt = (begalt - old_buffer) + bufp->buffer; \
+ if (fixup_alt_jump) \
+ fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\
+ if (laststart) \
+ laststart = (laststart - old_buffer) + bufp->buffer; \
+ if (pending_exact) \
+ pending_exact = (pending_exact - old_buffer) + bufp->buffer; \
+ } \
+ } while (0)
+
+
+/* Since we have one byte reserved for the register number argument to
+ {start,stop}_memory, the maximum number of groups we can report
+ things about is what fits in that byte. */
+#define MAX_REGNUM 255
+
+/* But patterns can have more than `MAX_REGNUM' registers. We just
+ ignore the excess. */
+typedef unsigned regnum_t;
+
+
+/* Macros for the compile stack. */
+
+/* Since offsets can go either forwards or backwards, this type needs to
+ be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */
+typedef int pattern_offset_t;
+
+typedef struct
+{
+ pattern_offset_t begalt_offset;
+ pattern_offset_t fixup_alt_jump;
+ pattern_offset_t inner_group_offset;
+ pattern_offset_t laststart_offset;
+ regnum_t regnum;
+} compile_stack_elt_t;
+
+
+typedef struct
+{
+ compile_stack_elt_t *stack;
+ unsigned size;
+ unsigned avail; /* Offset of next open position. */
+} compile_stack_type;
+
+
+#define INIT_COMPILE_STACK_SIZE 32
+
+#define COMPILE_STACK_EMPTY (compile_stack.avail == 0)
+#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size)
+
+/* The next available element. */
+#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
+
+
+/* Set the bit for character C in a list. */
+#define SET_LIST_BIT(c) \
+ (b[((unsigned char) (c)) / BYTEWIDTH] \
+ |= 1 << (((unsigned char) c) % BYTEWIDTH))
+
+
+/* Get the next unsigned number in the uncompiled pattern. */
+#define GET_UNSIGNED_NUMBER(num) \
+ { if (p != pend) \
+ { \
+ PATFETCH (c); \
+ while (ISDIGIT (c)) \
+ { \
+ if (num < 0) \
+ num = 0; \
+ num = num * 10 + c - '0'; \
+ if (p == pend) \
+ break; \
+ PATFETCH (c); \
+ } \
+ } \
+ }
+
+#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
+
+#define IS_CHAR_CLASS(string) \
+ (STREQ (string, "alpha") || STREQ (string, "upper") \
+ || STREQ (string, "lower") || STREQ (string, "digit") \
+ || STREQ (string, "alnum") || STREQ (string, "xdigit") \
+ || STREQ (string, "space") || STREQ (string, "print") \
+ || STREQ (string, "punct") || STREQ (string, "graph") \
+ || STREQ (string, "cntrl") || STREQ (string, "blank"))
+
+/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX.
+ Returns one of error codes defined in `regex.h', or zero for success.
+
+ Assumes the `allocated' (and perhaps `buffer') and `translate'
+ fields are set in BUFP on entry.
+
+ If it succeeds, results are put in BUFP (if it returns an error, the
+ contents of BUFP are undefined):
+ `buffer' is the compiled pattern;
+ `syntax' is set to SYNTAX;
+ `used' is set to the length of the compiled pattern;
+ `fastmap_accurate' is zero;
+ `re_nsub' is the number of subexpressions in PATTERN;
+ `not_bol' and `not_eol' are zero;
+
+ The `fastmap' and `newline_anchor' fields are neither
+ examined nor set. */
+
+static reg_errcode_t
+regex_compile (pattern, size, syntax, bufp)
+ const char *pattern;
+ int size;
+ reg_syntax_t syntax;
+ struct re_pattern_buffer *bufp;
+{
+ /* We fetch characters from PATTERN here. Even though PATTERN is
+ `char *' (i.e., signed), we declare these variables as unsigned, so
+ they can be reliably used as array indices. */
+ register unsigned char c, c1;
+
+ /* A random tempory spot in PATTERN. */
+ const char *p1;
+
+ /* Points to the end of the buffer, where we should append. */
+ register unsigned char *b;
+
+ /* Keeps track of unclosed groups. */
+ compile_stack_type compile_stack;
+
+ /* Points to the current (ending) position in the pattern. */
+ const char *p = pattern;
+ const char *pend = pattern + size;
+
+ /* How to translate the characters in the pattern. */
+ char *translate = bufp->translate;
+
+ /* Address of the count-byte of the most recently inserted `exactn'
+ command. This makes it possible to tell if a new exact-match
+ character can be added to that command or if the character requires
+ a new `exactn' command. */
+ unsigned char *pending_exact = 0;
+
+ /* Address of start of the most recently finished expression.
+ This tells, e.g., postfix * where to find the start of its
+ operand. Reset at the beginning of groups and alternatives. */
+ unsigned char *laststart = 0;
+
+ /* Address of beginning of regexp, or inside of last group. */
+ unsigned char *begalt;
+
+ /* Place in the uncompiled pattern (i.e., the {) to
+ which to go back if the interval is invalid. */
+ const char *beg_interval;
+
+ /* Address of the place where a forward jump should go to the end of
+ the containing expression. Each alternative of an `or' -- except the
+ last -- ends with a forward jump of this sort. */
+ unsigned char *fixup_alt_jump = 0;
+
+ /* Counts open-groups as they are encountered. Remembered for the
+ matching close-group on the compile stack, so the same register
+ number is put in the stop_memory as the start_memory. */
+ regnum_t regnum = 0;
+
+#ifdef DEBUG
+ DEBUG_PRINT1 ("\nCompiling pattern: ");
+ if (debug)
+ {
+ unsigned debug_count;
+
+ for (debug_count = 0; debug_count < size; debug_count++)
+ printchar (pattern[debug_count]);
+ putchar ('\n');
+ }
+#endif /* DEBUG */
+
+ /* Initialize the compile stack. */
+ compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t);
+ if (compile_stack.stack == NULL)
+ return REG_ESPACE;
+
+ compile_stack.size = INIT_COMPILE_STACK_SIZE;
+ compile_stack.avail = 0;
+
+ /* Initialize the pattern buffer. */
+ bufp->syntax = syntax;
+ bufp->fastmap_accurate = 0;
+ bufp->not_bol = bufp->not_eol = 0;
+
+ /* Set `used' to zero, so that if we return an error, the pattern
+ printer (for debugging) will think there's no pattern. We reset it
+ at the end. */
+ bufp->used = 0;
+
+ /* Always count groups, whether or not bufp->no_sub is set. */
+ bufp->re_nsub = 0;
+
+#if !defined (emacs) && !defined (SYNTAX_TABLE)
+ /* Initialize the syntax table. */
+ init_syntax_once ();
+#endif
+
+ if (bufp->allocated == 0)
+ {
+ if (bufp->buffer)
+ { /* If zero allocated, but buffer is non-null, try to realloc
+ enough space. This loses if buffer's address is bogus, but
+ that is the user's responsibility. */
+ RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char);
+ }
+ else
+ { /* Caller did not allocate a buffer. Do it for them. */
+ bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
+ }
+ if (!bufp->buffer) return REG_ESPACE;
+
+ bufp->allocated = INIT_BUF_SIZE;
+ }
+
+ begalt = b = bufp->buffer;
+
+ /* Loop through the uncompiled pattern until we're at the end. */
+ while (p != pend)
+ {
+ PATFETCH (c);
+
+ switch (c)
+ {
+ case '^':
+ {
+ if ( /* If at start of pattern, it's an operator. */
+ p == pattern + 1
+ /* If context independent, it's an operator. */
+ || syntax & RE_CONTEXT_INDEP_ANCHORS
+ /* Otherwise, depends on what's come before. */
+ || at_begline_loc_p (pattern, p, syntax))
+ BUF_PUSH (begline);
+ else
+ goto normal_char;
+ }
+ break;
+
+
+ case '$':
+ {
+ if ( /* If at end of pattern, it's an operator. */
+ p == pend
+ /* If context independent, it's an operator. */
+ || syntax & RE_CONTEXT_INDEP_ANCHORS
+ /* Otherwise, depends on what's next. */
+ || at_endline_loc_p (p, pend, syntax))
+ BUF_PUSH (endline);
+ else
+ goto normal_char;
+ }
+ break;
+
+
+ case '+':
+ case '?':
+ if ((syntax & RE_BK_PLUS_QM)
+ || (syntax & RE_LIMITED_OPS))
+ goto normal_char;
+ handle_plus:
+ case '*':
+ /* If there is no previous pattern... */
+ if (!laststart)
+ {
+ if (syntax & RE_CONTEXT_INVALID_OPS)
+ return REG_BADRPT;
+ else if (!(syntax & RE_CONTEXT_INDEP_OPS))
+ goto normal_char;
+ }
+
+ {
+ /* Are we optimizing this jump? */
+ boolean keep_string_p = false;
+
+ /* 1 means zero (many) matches is allowed. */
+ char zero_times_ok = 0, many_times_ok = 0;
+
+ /* If there is a sequence of repetition chars, collapse it
+ down to just one (the right one). We can't combine
+ interval operators with these because of, e.g., `a{2}*',
+ which should only match an even number of `a's. */
+
+ for (;;)
+ {
+ zero_times_ok |= c != '+';
+ many_times_ok |= c != '?';
+
+ if (p == pend)
+ break;
+
+ PATFETCH (c);
+
+ if (c == '*'
+ || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?')))
+ ;
+
+ else if (syntax & RE_BK_PLUS_QM && c == '\\')
+ {
+ if (p == pend) return REG_EESCAPE;
+
+ PATFETCH (c1);
+ if (!(c1 == '+' || c1 == '?'))
+ {
+ PATUNFETCH;
+ PATUNFETCH;
+ break;
+ }
+
+ c = c1;
+ }
+ else
+ {
+ PATUNFETCH;
+ break;
+ }
+
+ /* If we get here, we found another repeat character. */
+ }
+
+ /* Star, etc. applied to an empty pattern is equivalent
+ to an empty pattern. */
+ if (!laststart)
+ break;
+
+ /* Now we know whether or not zero matches is allowed
+ and also whether or not two or more matches is allowed. */
+ if (many_times_ok)
+ { /* More than one repetition is allowed, so put in at the
+ end a backward relative jump from `b' to before the next
+ jump we're going to put in below (which jumps from
+ laststart to after this jump).
+
+ But if we are at the `*' in the exact sequence `.*\n',
+ insert an unconditional jump backwards to the .,
+ instead of the beginning of the loop. This way we only
+ push a failure point once, instead of every time
+ through the loop. */
+ assert (p - 1 > pattern);
+
+ /* Allocate the space for the jump. */
+ GET_BUFFER_SPACE (3);
+
+ /* We know we are not at the first character of the pattern,
+ because laststart was nonzero. And we've already
+ incremented `p', by the way, to be the character after
+ the `*'. Do we have to do something analogous here
+ for null bytes, because of RE_DOT_NOT_NULL? */
+ if (TRANSLATE (*(p - 2)) == TRANSLATE ('.')
+ && zero_times_ok
+ && p < pend && TRANSLATE (*p) == TRANSLATE ('\n')
+ && !(syntax & RE_DOT_NEWLINE))
+ { /* We have .*\n. */
+ STORE_JUMP (jump, b, laststart);
+ keep_string_p = true;
+ }
+ else
+ /* Anything else. */
+ STORE_JUMP (maybe_pop_jump, b, laststart - 3);
+
+ /* We've added more stuff to the buffer. */
+ b += 3;
+ }
+
+ /* On failure, jump from laststart to b + 3, which will be the
+ end of the buffer after this jump is inserted. */
+ GET_BUFFER_SPACE (3);
+ INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump
+ : on_failure_jump,
+ laststart, b + 3);
+ pending_exact = 0;
+ b += 3;
+
+ if (!zero_times_ok)
+ {
+ /* At least one repetition is required, so insert a
+ `dummy_failure_jump' before the initial
+ `on_failure_jump' instruction of the loop. This
+ effects a skip over that instruction the first time
+ we hit that loop. */
+ GET_BUFFER_SPACE (3);
+ INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6);
+ b += 3;
+ }
+ }
+ break;
+
+
+ case '.':
+ laststart = b;
+ BUF_PUSH (anychar);
+ break;
+
+
+ case '[':
+ {
+ boolean had_char_class = false;
+
+ if (p == pend) return REG_EBRACK;
+
+ /* Ensure that we have enough space to push a charset: the
+ opcode, the length count, and the bitset; 34 bytes in all. */
+ GET_BUFFER_SPACE (34);
+
+ laststart = b;
+
+ /* We test `*p == '^' twice, instead of using an if
+ statement, so we only need one BUF_PUSH. */
+ BUF_PUSH (*p == '^' ? charset_not : charset);
+ if (*p == '^')
+ p++;
+
+ /* Remember the first position in the bracket expression. */
+ p1 = p;
+
+ /* Push the number of bytes in the bitmap. */
+ BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
+
+ /* Clear the whole map. */
+ bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH);
+
+ /* charset_not matches newline according to a syntax bit. */
+ if ((re_opcode_t) b[-2] == charset_not
+ && (syntax & RE_HAT_LISTS_NOT_NEWLINE))
+ SET_LIST_BIT ('\n');
+
+ /* Read in characters and ranges, setting map bits. */
+ for (;;)
+ {
+ if (p == pend) return REG_EBRACK;
+
+ PATFETCH (c);
+
+ /* \ might escape characters inside [...] and [^...]. */
+ if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
+ {
+ if (p == pend) return REG_EESCAPE;
+
+ PATFETCH (c1);
+ SET_LIST_BIT (c1);
+ continue;
+ }
+
+ /* Could be the end of the bracket expression. If it's
+ not (i.e., when the bracket expression is `[]' so
+ far), the ']' character bit gets set way below. */
+ if (c == ']' && p != p1 + 1)
+ break;
+
+ /* Look ahead to see if it's a range when the last thing
+ was a character class. */
+ if (had_char_class && c == '-' && *p != ']')
+ return REG_ERANGE;
+
+ /* Look ahead to see if it's a range when the last thing
+ was a character: if this is a hyphen not at the
+ beginning or the end of a list, then it's the range
+ operator. */
+ if (c == '-'
+ && !(p - 2 >= pattern && p[-2] == '[')
+ && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
+ && *p != ']')
+ {
+ reg_errcode_t ret
+ = compile_range (&p, pend, translate, syntax, b);
+ if (ret != REG_NOERROR) return ret;
+ }
+
+ else if (p[0] == '-' && p[1] != ']')
+ { /* This handles ranges made up of characters only. */
+ reg_errcode_t ret;
+
+ /* Move past the `-'. */
+ PATFETCH (c1);
+
+ ret = compile_range (&p, pend, translate, syntax, b);
+ if (ret != REG_NOERROR) return ret;
+ }
+
+ /* See if we're at the beginning of a possible character
+ class. */
+
+ else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':')
+ { /* Leave room for the null. */
+ char str[CHAR_CLASS_MAX_LENGTH + 1];
+
+ PATFETCH (c);
+ c1 = 0;
+
+ /* If pattern is `[[:'. */
+ if (p == pend) return REG_EBRACK;
+
+ for (;;)
+ {
+ PATFETCH (c);
+ if (c == ':' || c == ']' || p == pend
+ || c1 == CHAR_CLASS_MAX_LENGTH)
+ break;
+ str[c1++] = c;
+ }
+ str[c1] = '\0';
+
+ /* If isn't a word bracketed by `[:' and:`]':
+ undo the ending character, the letters, and leave
+ the leading `:' and `[' (but set bits for them). */
+ if (c == ':' && *p == ']')
+ {
+ int ch;
+ boolean is_alnum = STREQ (str, "alnum");
+ boolean is_alpha = STREQ (str, "alpha");
+ boolean is_blank = STREQ (str, "blank");
+ boolean is_cntrl = STREQ (str, "cntrl");
+ boolean is_digit = STREQ (str, "digit");
+ boolean is_graph = STREQ (str, "graph");
+ boolean is_lower = STREQ (str, "lower");
+ boolean is_print = STREQ (str, "print");
+ boolean is_punct = STREQ (str, "punct");
+ boolean is_space = STREQ (str, "space");
+ boolean is_upper = STREQ (str, "upper");
+ boolean is_xdigit = STREQ (str, "xdigit");
+
+ if (!IS_CHAR_CLASS (str)) return REG_ECTYPE;
+
+ /* Throw away the ] at the end of the character
+ class. */
+ PATFETCH (c);
+
+ if (p == pend) return REG_EBRACK;
+
+ for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
+ {
+ if ( (is_alnum && ISALNUM (ch))
+ || (is_alpha && ISALPHA (ch))
+ || (is_blank && ISBLANK (ch))
+ || (is_cntrl && ISCNTRL (ch))
+ || (is_digit && ISDIGIT (ch))
+ || (is_graph && ISGRAPH (ch))
+ || (is_lower && ISLOWER (ch))
+ || (is_print && ISPRINT (ch))
+ || (is_punct && ISPUNCT (ch))
+ || (is_space && ISSPACE (ch))
+ || (is_upper && ISUPPER (ch))
+ || (is_xdigit && ISXDIGIT (ch)))
+ SET_LIST_BIT (ch);
+ }
+ had_char_class = true;
+ }
+ else
+ {
+ c1++;
+ while (c1--)
+ PATUNFETCH;
+ SET_LIST_BIT ('[');
+ SET_LIST_BIT (':');
+ had_char_class = false;
+ }
+ }
+ else
+ {
+ had_char_class = false;
+ SET_LIST_BIT (c);
+ }
+ }
+
+ /* Discard any (non)matching list bytes that are all 0 at the
+ end of the map. Decrease the map-length byte too. */
+ while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
+ b[-1]--;
+ b += b[-1];
+ }
+ break;
+
+
+ case '(':
+ if (syntax & RE_NO_BK_PARENS)
+ goto handle_open;
+ else
+ goto normal_char;
+
+
+ case ')':
+ if (syntax & RE_NO_BK_PARENS)
+ goto handle_close;
+ else
+ goto normal_char;
+
+
+ case '\n':
+ if (syntax & RE_NEWLINE_ALT)
+ goto handle_alt;
+ else
+ goto normal_char;
+
+
+ case '|':
+ if (syntax & RE_NO_BK_VBAR)
+ goto handle_alt;
+ else
+ goto normal_char;
+
+
+ case '{':
+ if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES)
+ goto handle_interval;
+ else
+ goto normal_char;
+
+
+ case '\\':
+ if (p == pend) return REG_EESCAPE;
+
+ /* Do not translate the character after the \, so that we can
+ distinguish, e.g., \B from \b, even if we normally would
+ translate, e.g., B to b. */
+ PATFETCH_RAW (c);
+
+ switch (c)
+ {
+ case '(':
+ if (syntax & RE_NO_BK_PARENS)
+ goto normal_backslash;
+
+ handle_open:
+ bufp->re_nsub++;
+ regnum++;
+
+ if (COMPILE_STACK_FULL)
+ {
+ RETALLOC (compile_stack.stack, compile_stack.size << 1,
+ compile_stack_elt_t);
+ if (compile_stack.stack == NULL) return REG_ESPACE;
+
+ compile_stack.size <<= 1;
+ }
+
+ /* These are the values to restore when we hit end of this
+ group. They are all relative offsets, so that if the
+ whole pattern moves because of realloc, they will still
+ be valid. */
+ COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer;
+ COMPILE_STACK_TOP.fixup_alt_jump
+ = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0;
+ COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer;
+ COMPILE_STACK_TOP.regnum = regnum;
+
+ /* We will eventually replace the 0 with the number of
+ groups inner to this one. But do not push a
+ start_memory for groups beyond the last one we can
+ represent in the compiled pattern. */
+ if (regnum <= MAX_REGNUM)
+ {
+ COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2;
+ BUF_PUSH_3 (start_memory, regnum, 0);
+ }
+
+ compile_stack.avail++;
+
+ fixup_alt_jump = 0;
+ laststart = 0;
+ begalt = b;
+ /* If we've reached MAX_REGNUM groups, then this open
+ won't actually generate any code, so we'll have to
+ clear pending_exact explicitly. */
+ pending_exact = 0;
+ break;
+
+
+ case ')':
+ if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
+
+ if (COMPILE_STACK_EMPTY)
+ if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
+ goto normal_backslash;
+ else
+ return REG_ERPAREN;
+
+ handle_close:
+ if (fixup_alt_jump)
+ { /* Push a dummy failure point at the end of the
+ alternative for a possible future
+ `pop_failure_jump' to pop. See comments at
+ `push_dummy_failure' in `re_match_2'. */
+ BUF_PUSH (push_dummy_failure);
+
+ /* We allocated space for this jump when we assigned
+ to `fixup_alt_jump', in the `handle_alt' case below. */
+ STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1);
+ }
+
+ /* See similar code for backslashed left paren above. */
+ if (COMPILE_STACK_EMPTY)
+ if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
+ goto normal_char;
+ else
+ return REG_ERPAREN;
+
+ /* Since we just checked for an empty stack above, this
+ ``can't happen''. */
+ assert (compile_stack.avail != 0);
+ {
+ /* We don't just want to restore into `regnum', because
+ later groups should continue to be numbered higher,
+ as in `(ab)c(de)' -- the second group is #2. */
+ regnum_t this_group_regnum;
+
+ compile_stack.avail--;
+ begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset;
+ fixup_alt_jump
+ = COMPILE_STACK_TOP.fixup_alt_jump
+ ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1
+ : 0;
+ laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset;
+ this_group_regnum = COMPILE_STACK_TOP.regnum;
+ /* If we've reached MAX_REGNUM groups, then this open
+ won't actually generate any code, so we'll have to
+ clear pending_exact explicitly. */
+ pending_exact = 0;
+
+ /* We're at the end of the group, so now we know how many
+ groups were inside this one. */
+ if (this_group_regnum <= MAX_REGNUM)
+ {
+ unsigned char *inner_group_loc
+ = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset;
+
+ *inner_group_loc = regnum - this_group_regnum;
+ BUF_PUSH_3 (stop_memory, this_group_regnum,
+ regnum - this_group_regnum);
+ }
+ }
+ break;
+
+
+ case '|': /* `\|'. */
+ if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR)
+ goto normal_backslash;
+ handle_alt:
+ if (syntax & RE_LIMITED_OPS)
+ goto normal_char;
+
+ /* Insert before the previous alternative a jump which
+ jumps to this alternative if the former fails. */
+ GET_BUFFER_SPACE (3);
+ INSERT_JUMP (on_failure_jump, begalt, b + 6);
+ pending_exact = 0;
+ b += 3;
+
+ /* The alternative before this one has a jump after it
+ which gets executed if it gets matched. Adjust that
+ jump so it will jump to this alternative's analogous
+ jump (put in below, which in turn will jump to the next
+ (if any) alternative's such jump, etc.). The last such
+ jump jumps to the correct final destination. A picture:
+ _____ _____
+ | | | |
+ | v | v
+ a | b | c
+
+ If we are at `b', then fixup_alt_jump right now points to a
+ three-byte space after `a'. We'll put in the jump, set
+ fixup_alt_jump to right after `b', and leave behind three
+ bytes which we'll fill in when we get to after `c'. */
+
+ if (fixup_alt_jump)
+ STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
+
+ /* Mark and leave space for a jump after this alternative,
+ to be filled in later either by next alternative or
+ when know we're at the end of a series of alternatives. */
+ fixup_alt_jump = b;
+ GET_BUFFER_SPACE (3);
+ b += 3;
+
+ laststart = 0;
+ begalt = b;
+ break;
+
+
+ case '{':
+ /* If \{ is a literal. */
+ if (!(syntax & RE_INTERVALS)
+ /* If we're at `\{' and it's not the open-interval
+ operator. */
+ || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+ || (p - 2 == pattern && p == pend))
+ goto normal_backslash;
+
+ handle_interval:
+ {
+ /* If got here, then the syntax allows intervals. */
+
+ /* At least (most) this many matches must be made. */
+ int lower_bound = -1, upper_bound = -1;
+
+ beg_interval = p - 1;
+
+ if (p == pend)
+ {
+ if (syntax & RE_NO_BK_BRACES)
+ goto unfetch_interval;
+ else
+ return REG_EBRACE;
+ }
+
+ GET_UNSIGNED_NUMBER (lower_bound);
+
+ if (c == ',')
+ {
+ GET_UNSIGNED_NUMBER (upper_bound);
+ if (upper_bound < 0) upper_bound = RE_DUP_MAX;
+ }
+ else
+ /* Interval such as `{1}' => match exactly once. */
+ upper_bound = lower_bound;
+
+ if (lower_bound < 0 || upper_bound > RE_DUP_MAX
+ || lower_bound > upper_bound)
+ {
+ if (syntax & RE_NO_BK_BRACES)
+ goto unfetch_interval;
+ else
+ return REG_BADBR;
+ }
+
+ if (!(syntax & RE_NO_BK_BRACES))
+ {
+ if (c != '\\') return REG_EBRACE;
+
+ PATFETCH (c);
+ }
+
+ if (c != '}')
+ {
+ if (syntax & RE_NO_BK_BRACES)
+ goto unfetch_interval;
+ else
+ return REG_BADBR;
+ }
+
+ /* We just parsed a valid interval. */
+
+ /* If it's invalid to have no preceding re. */
+ if (!laststart)
+ {
+ if (syntax & RE_CONTEXT_INVALID_OPS)
+ return REG_BADRPT;
+ else if (syntax & RE_CONTEXT_INDEP_OPS)
+ laststart = b;
+ else
+ goto unfetch_interval;
+ }
+
+ /* If the upper bound is zero, don't want to succeed at
+ all; jump from `laststart' to `b + 3', which will be
+ the end of the buffer after we insert the jump. */
+ if (upper_bound == 0)
+ {
+ GET_BUFFER_SPACE (3);
+ INSERT_JUMP (jump, laststart, b + 3);
+ b += 3;
+ }
+
+ /* Otherwise, we have a nontrivial interval. When
+ we're all done, the pattern will look like:
+ set_number_at <jump count> <upper bound>
+ set_number_at <succeed_n count> <lower bound>
+ succeed_n <after jump addr> <succed_n count>
+ <body of loop>
+ jump_n <succeed_n addr> <jump count>
+ (The upper bound and `jump_n' are omitted if
+ `upper_bound' is 1, though.) */
+ else
+ { /* If the upper bound is > 1, we need to insert
+ more at the end of the loop. */
+ unsigned nbytes = 10 + (upper_bound > 1) * 10;
+
+ GET_BUFFER_SPACE (nbytes);
+
+ /* Initialize lower bound of the `succeed_n', even
+ though it will be set during matching by its
+ attendant `set_number_at' (inserted next),
+ because `re_compile_fastmap' needs to know.
+ Jump to the `jump_n' we might insert below. */
+ INSERT_JUMP2 (succeed_n, laststart,
+ b + 5 + (upper_bound > 1) * 5,
+ lower_bound);
+ b += 5;
+
+ /* Code to initialize the lower bound. Insert
+ before the `succeed_n'. The `5' is the last two
+ bytes of this `set_number_at', plus 3 bytes of
+ the following `succeed_n'. */
+ insert_op2 (set_number_at, laststart, 5, lower_bound, b);
+ b += 5;
+
+ if (upper_bound > 1)
+ { /* More than one repetition is allowed, so
+ append a backward jump to the `succeed_n'
+ that starts this interval.
+
+ When we've reached this during matching,
+ we'll have matched the interval once, so
+ jump back only `upper_bound - 1' times. */
+ STORE_JUMP2 (jump_n, b, laststart + 5,
+ upper_bound - 1);
+ b += 5;
+
+ /* The location we want to set is the second
+ parameter of the `jump_n'; that is `b-2' as
+ an absolute address. `laststart' will be
+ the `set_number_at' we're about to insert;
+ `laststart+3' the number to set, the source
+ for the relative address. But we are
+ inserting into the middle of the pattern --
+ so everything is getting moved up by 5.
+ Conclusion: (b - 2) - (laststart + 3) + 5,
+ i.e., b - laststart.
+
+ We insert this at the beginning of the loop
+ so that if we fail during matching, we'll
+ reinitialize the bounds. */
+ insert_op2 (set_number_at, laststart, b - laststart,
+ upper_bound - 1, b);
+ b += 5;
+ }
+ }
+ pending_exact = 0;
+ beg_interval = NULL;
+ }
+ break;
+
+ unfetch_interval:
+ /* If an invalid interval, match the characters as literals. */
+ assert (beg_interval);
+ p = beg_interval;
+ beg_interval = NULL;
+
+ /* normal_char and normal_backslash need `c'. */
+ PATFETCH (c);
+
+ if (!(syntax & RE_NO_BK_BRACES))
+ {
+ if (p > pattern && p[-1] == '\\')
+ goto normal_backslash;
+ }
+ goto normal_char;
+
+#ifdef emacs
+ /* There is no way to specify the before_dot and after_dot
+ operators. rms says this is ok. --karl */
+ case '=':
+ BUF_PUSH (at_dot);
+ break;
+
+ case 's':
+ laststart = b;
+ PATFETCH (c);
+ BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]);
+ break;
+
+ case 'S':
+ laststart = b;
+ PATFETCH (c);
+ BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]);
+ break;
+#endif /* emacs */
+
+
+ case 'w':
+ laststart = b;
+ BUF_PUSH (wordchar);
+ break;
+
+
+ case 'W':
+ laststart = b;
+ BUF_PUSH (notwordchar);
+ break;
+
+
+ case '<':
+ BUF_PUSH (wordbeg);
+ break;
+
+ case '>':
+ BUF_PUSH (wordend);
+ break;
+
+ case 'b':
+ BUF_PUSH (wordbound);
+ break;
+
+ case 'B':
+ BUF_PUSH (notwordbound);
+ break;
+
+ case '`':
+ BUF_PUSH (begbuf);
+ break;
+
+ case '\'':
+ BUF_PUSH (endbuf);
+ break;
+
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ if (syntax & RE_NO_BK_REFS)
+ goto normal_char;
+
+ c1 = c - '0';
+
+ if (c1 > regnum)
+ return REG_ESUBREG;
+
+ /* Can't back reference to a subexpression if inside of it. */
+ if (group_in_compile_stack (compile_stack, c1))
+ goto normal_char;
+
+ laststart = b;
+ BUF_PUSH_2 (duplicate, c1);
+ break;
+
+
+ case '+':
+ case '?':
+ if (syntax & RE_BK_PLUS_QM)
+ goto handle_plus;
+ else
+ goto normal_backslash;
+
+ default:
+ normal_backslash:
+ /* You might think it would be useful for \ to mean
+ not to translate; but if we don't translate it
+ it will never match anything. */
+ c = TRANSLATE (c);
+ goto normal_char;
+ }
+ break;
+
+
+ default:
+ /* Expects the character in `c'. */
+ normal_char:
+ /* If no exactn currently being built. */
+ if (!pending_exact
+
+ /* If last exactn not at current position. */
+ || pending_exact + *pending_exact + 1 != b
+
+ /* We have only one byte following the exactn for the count. */
+ || *pending_exact == (1 << BYTEWIDTH) - 1
+
+ /* If followed by a repetition operator. */
+ || *p == '*' || *p == '^'
+ || ((syntax & RE_BK_PLUS_QM)
+ ? *p == '\\' && (p[1] == '+' || p[1] == '?')
+ : (*p == '+' || *p == '?'))
+ || ((syntax & RE_INTERVALS)
+ && ((syntax & RE_NO_BK_BRACES)
+ ? *p == '{'
+ : (p[0] == '\\' && p[1] == '{'))))
+ {
+ /* Start building a new exactn. */
+
+ laststart = b;
+
+ BUF_PUSH_2 (exactn, 0);
+ pending_exact = b - 1;
+ }
+
+ BUF_PUSH (c);
+ (*pending_exact)++;
+ break;
+ } /* switch (c) */
+ } /* while p != pend */
+
+
+ /* Through the pattern now. */
+
+ if (fixup_alt_jump)
+ STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
+
+ if (!COMPILE_STACK_EMPTY)
+ return REG_EPAREN;
+
+ free (compile_stack.stack);
+
+ /* We have succeeded; set the length of the buffer. */
+ bufp->used = b - bufp->buffer;
+
+#ifdef DEBUG
+ if (debug)
+ {
+ DEBUG_PRINT1 ("\nCompiled pattern: ");
+ print_compiled_pattern (bufp);
+ }
+#endif /* DEBUG */
+
+ return REG_NOERROR;
+} /* regex_compile */
+
+/* Subroutines for `regex_compile'. */
+
+/* Store OP at LOC followed by two-byte integer parameter ARG. */
+
+static void
+store_op1 (op, loc, arg)
+ re_opcode_t op;
+ unsigned char *loc;
+ int arg;
+{
+ *loc = (unsigned char) op;
+ STORE_NUMBER (loc + 1, arg);
+}
+
+
+/* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */
+
+static void
+store_op2 (op, loc, arg1, arg2)
+ re_opcode_t op;
+ unsigned char *loc;
+ int arg1, arg2;
+{
+ *loc = (unsigned char) op;
+ STORE_NUMBER (loc + 1, arg1);
+ STORE_NUMBER (loc + 3, arg2);
+}
+
+
+/* Copy the bytes from LOC to END to open up three bytes of space at LOC
+ for OP followed by two-byte integer parameter ARG. */
+
+static void
+insert_op1 (op, loc, arg, end)
+ re_opcode_t op;
+ unsigned char *loc;
+ int arg;
+ unsigned char *end;
+{
+ register unsigned char *pfrom = end;
+ register unsigned char *pto = end + 3;
+
+ while (pfrom != loc)
+ *--pto = *--pfrom;
+
+ store_op1 (op, loc, arg);
+}
+
+
+/* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */
+
+static void
+insert_op2 (op, loc, arg1, arg2, end)
+ re_opcode_t op;
+ unsigned char *loc;
+ int arg1, arg2;
+ unsigned char *end;
+{
+ register unsigned char *pfrom = end;
+ register unsigned char *pto = end + 5;
+
+ while (pfrom != loc)
+ *--pto = *--pfrom;
+
+ store_op2 (op, loc, arg1, arg2);
+}
+
+
+/* P points to just after a ^ in PATTERN. Return true if that ^ comes
+ after an alternative or a begin-subexpression. We assume there is at
+ least one character before the ^. */
+
+static boolean
+at_begline_loc_p (pattern, p, syntax)
+ const char *pattern, *p;
+ reg_syntax_t syntax;
+{
+ const char *prev = p - 2;
+ boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
+
+ return
+ /* After a subexpression? */
+ (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash))
+ /* After an alternative? */
+ || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash));
+}
+
+
+/* The dual of at_begline_loc_p. This one is for $. We assume there is
+ at least one character after the $, i.e., `P < PEND'. */
+
+static boolean
+at_endline_loc_p (p, pend, syntax)
+ const char *p, *pend;
+ int syntax;
+{
+ const char *next = p;
+ boolean next_backslash = *next == '\\';
+ const char *next_next = p + 1 < pend ? p + 1 : NULL;
+
+ return
+ /* Before a subexpression? */
+ (syntax & RE_NO_BK_PARENS ? *next == ')'
+ : next_backslash && next_next && *next_next == ')')
+ /* Before an alternative? */
+ || (syntax & RE_NO_BK_VBAR ? *next == '|'
+ : next_backslash && next_next && *next_next == '|');
+}
+
+
+/* Returns true if REGNUM is in one of COMPILE_STACK's elements and
+ false if it's not. */
+
+static boolean
+group_in_compile_stack (compile_stack, regnum)
+ compile_stack_type compile_stack;
+ regnum_t regnum;
+{
+ int this_element;
+
+ for (this_element = compile_stack.avail - 1;
+ this_element >= 0;
+ this_element--)
+ if (compile_stack.stack[this_element].regnum == regnum)
+ return true;
+
+ return false;
+}
+
+
+/* Read the ending character of a range (in a bracket expression) from the
+ uncompiled pattern *P_PTR (which ends at PEND). We assume the
+ starting character is in `P[-2]'. (`P[-1]' is the character `-'.)
+ Then we set the translation of all bits between the starting and
+ ending characters (inclusive) in the compiled pattern B.
+
+ Return an error code.
+
+ We use these short variable names so we can use the same macros as
+ `regex_compile' itself. */
+
+static reg_errcode_t
+compile_range (p_ptr, pend, translate, syntax, b)
+ const char **p_ptr, *pend;
+ char *translate;
+ reg_syntax_t syntax;
+ unsigned char *b;
+{
+ unsigned this_char;
+
+ const char *p = *p_ptr;
+ int range_start, range_end;
+
+ if (p == pend)
+ return REG_ERANGE;
+
+ /* Even though the pattern is a signed `char *', we need to fetch
+ with unsigned char *'s; if the high bit of the pattern character
+ is set, the range endpoints will be negative if we fetch using a
+ signed char *.
+
+ We also want to fetch the endpoints without translating them; the
+ appropriate translation is done in the bit-setting loop below. */
+ range_start = ((unsigned char *) p)[-2];
+ range_end = ((unsigned char *) p)[0];
+
+ /* Have to increment the pointer into the pattern string, so the
+ caller isn't still at the ending character. */
+ (*p_ptr)++;
+
+ /* If the start is after the end, the range is empty. */
+ if (range_start > range_end)
+ return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
+
+ /* Here we see why `this_char' has to be larger than an `unsigned
+ char' -- the range is inclusive, so if `range_end' == 0xff
+ (assuming 8-bit characters), we would otherwise go into an infinite
+ loop, since all characters <= 0xff. */
+ for (this_char = range_start; this_char <= (unsigned)range_end; this_char++)
+ {
+ SET_LIST_BIT (TRANSLATE (this_char));
+ }
+
+ return REG_NOERROR;
+}
+
+/* Failure stack declarations and macros; both re_compile_fastmap and
+ re_match_2 use a failure stack. These have to be macros because of
+ REGEX_ALLOCATE. */
+
+
+/* Number of failure points for which to initially allocate space
+ when matching. If this number is exceeded, we allocate more
+ space, so it is not a hard limit. */
+#ifndef INIT_FAILURE_ALLOC
+#define INIT_FAILURE_ALLOC 5
+#endif
+
+/* Roughly the maximum number of failure points on the stack. Would be
+ exactly that if always used MAX_FAILURE_SPACE each time we failed.
+ This is a variable only so users of regex can assign to it; we never
+ change it ourselves. */
+int re_max_failures = 2000;
+
+typedef const unsigned char *fail_stack_elt_t;
+
+typedef struct
+{
+ fail_stack_elt_t *stack;
+ unsigned size;
+ unsigned avail; /* Offset of next open position. */
+} fail_stack_type;
+
+#define FAIL_STACK_EMPTY() (fail_stack.avail == 0)
+#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
+#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size)
+#define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail])
+
+
+/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */
+
+#define INIT_FAIL_STACK() \
+ do { \
+ fail_stack.stack = (fail_stack_elt_t *) \
+ REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \
+ \
+ if (fail_stack.stack == NULL) \
+ return -2; \
+ \
+ fail_stack.size = INIT_FAILURE_ALLOC; \
+ fail_stack.avail = 0; \
+ } while (0)
+
+
+/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items.
+
+ Return 1 if succeeds, and 0 if either ran out of memory
+ allocating space for it or it was already too large.
+
+ REGEX_REALLOCATE requires `destination' be declared. */
+
+#define DOUBLE_FAIL_STACK(fail_stack) \
+ ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \
+ ? 0 \
+ : ((fail_stack).stack = (fail_stack_elt_t *) \
+ REGEX_REALLOCATE ((fail_stack).stack, \
+ (fail_stack).size * sizeof (fail_stack_elt_t), \
+ ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \
+ \
+ (fail_stack).stack == NULL \
+ ? 0 \
+ : ((fail_stack).size <<= 1, \
+ 1)))
+
+
+/* Push PATTERN_OP on FAIL_STACK.
+
+ Return 1 if was able to do so and 0 if ran out of memory allocating
+ space to do so. */
+#define PUSH_PATTERN_OP(pattern_op, fail_stack) \
+ ((FAIL_STACK_FULL () \
+ && !DOUBLE_FAIL_STACK (fail_stack)) \
+ ? 0 \
+ : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \
+ 1))
+
+/* This pushes an item onto the failure stack. Must be a four-byte
+ value. Assumes the variable `fail_stack'. Probably should only
+ be called from within `PUSH_FAILURE_POINT'. */
+#define PUSH_FAILURE_ITEM(item) \
+ fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item
+
+/* The complement operation. Assumes `fail_stack' is nonempty. */
+#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail]
+
+/* Used to omit pushing failure point id's when we're not debugging. */
+#ifdef DEBUG
+#define DEBUG_PUSH PUSH_FAILURE_ITEM
+#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM ()
+#else
+#define DEBUG_PUSH(item)
+#define DEBUG_POP(item_addr)
+#endif
+
+
+/* Push the information about the state we will need
+ if we ever fail back to it.
+
+ Requires variables fail_stack, regstart, regend, reg_info, and
+ num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be
+ declared.
+
+ Does `return FAILURE_CODE' if runs out of memory. */
+
+#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \
+ do { \
+ char *destination; \
+ /* Must be int, so when we don't save any registers, the arithmetic \
+ of 0 + -1 isn't done as unsigned. */ \
+ int this_reg; \
+ \
+ DEBUG_STATEMENT (failure_id++); \
+ DEBUG_STATEMENT (nfailure_points_pushed++); \
+ DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \
+ DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\
+ DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\
+ \
+ DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \
+ DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \
+ \
+ /* Ensure we have enough space allocated for what we will push. */ \
+ while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \
+ { \
+ if (!DOUBLE_FAIL_STACK (fail_stack)) \
+ return failure_code; \
+ \
+ DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \
+ (fail_stack).size); \
+ DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\
+ } \
+ \
+ /* Push the info, starting with the registers. */ \
+ DEBUG_PRINT1 ("\n"); \
+ \
+ for (this_reg = lowest_active_reg; (unsigned)this_reg <= highest_active_reg; \
+ this_reg++) \
+ { \
+ DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \
+ DEBUG_STATEMENT (num_regs_pushed++); \
+ \
+ DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \
+ PUSH_FAILURE_ITEM (regstart[this_reg]); \
+ \
+ DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \
+ PUSH_FAILURE_ITEM (regend[this_reg]); \
+ \
+ DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \
+ DEBUG_PRINT2 (" match_null=%d", \
+ REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \
+ DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \
+ DEBUG_PRINT2 (" matched_something=%d", \
+ MATCHED_SOMETHING (reg_info[this_reg])); \
+ DEBUG_PRINT2 (" ever_matched=%d", \
+ EVER_MATCHED_SOMETHING (reg_info[this_reg])); \
+ DEBUG_PRINT1 ("\n"); \
+ PUSH_FAILURE_ITEM (reg_info[this_reg].word); \
+ } \
+ \
+ DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\
+ PUSH_FAILURE_ITEM (lowest_active_reg); \
+ \
+ DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\
+ PUSH_FAILURE_ITEM (highest_active_reg); \
+ \
+ DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \
+ DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \
+ PUSH_FAILURE_ITEM (pattern_place); \
+ \
+ DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \
+ DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \
+ size2); \
+ DEBUG_PRINT1 ("'\n"); \
+ PUSH_FAILURE_ITEM (string_place); \
+ \
+ DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \
+ DEBUG_PUSH (failure_id); \
+ } while (0)
+
+/* This is the number of items that are pushed and popped on the stack
+ for each register. */
+#define NUM_REG_ITEMS 3
+
+/* Individual items aside from the registers. */
+#ifdef DEBUG
+#define NUM_NONREG_ITEMS 5 /* Includes failure point id. */
+#else
+#define NUM_NONREG_ITEMS 4
+#endif
+
+/* We push at most this many items on the stack. */
+#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
+
+/* We actually push this many items. */
+#define NUM_FAILURE_ITEMS \
+ ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \
+ + NUM_NONREG_ITEMS)
+
+/* How many items can still be added to the stack without overflowing it. */
+#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
+
+
+/* Pops what PUSH_FAIL_STACK pushes.
+
+ We restore into the parameters, all of which should be lvalues:
+ STR -- the saved data position.
+ PAT -- the saved pattern position.
+ LOW_REG, HIGH_REG -- the highest and lowest active registers.
+ REGSTART, REGEND -- arrays of string positions.
+ REG_INFO -- array of information about each subexpression.
+
+ Also assumes the variables `fail_stack' and (if debugging), `bufp',
+ `pend', `string1', `size1', `string2', and `size2'. */
+
+#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
+{ \
+ DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \
+ int this_reg; \
+ const unsigned char *string_temp; \
+ \
+ assert (!FAIL_STACK_EMPTY ()); \
+ \
+ /* Remove failure points and point to how many regs pushed. */ \
+ DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \
+ DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \
+ DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \
+ \
+ assert (fail_stack.avail >= NUM_NONREG_ITEMS); \
+ \
+ DEBUG_POP (&failure_id); \
+ DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \
+ \
+ /* If the saved string location is NULL, it came from an \
+ on_failure_keep_string_jump opcode, and we want to throw away the \
+ saved NULL, thus retaining our current position in the string. */ \
+ string_temp = POP_FAILURE_ITEM (); \
+ if (string_temp != NULL) \
+ str = (const char *) string_temp; \
+ \
+ DEBUG_PRINT2 (" Popping string 0x%x: `", str); \
+ DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \
+ DEBUG_PRINT1 ("'\n"); \
+ \
+ pat = (unsigned char *) POP_FAILURE_ITEM (); \
+ DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \
+ DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \
+ \
+ /* Restore register info. */ \
+ high_reg = (unsigned) POP_FAILURE_ITEM (); \
+ DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \
+ \
+ low_reg = (unsigned) POP_FAILURE_ITEM (); \
+ DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \
+ \
+ for (this_reg = high_reg; (unsigned)this_reg >= low_reg; this_reg--) \
+ { \
+ DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \
+ \
+ reg_info[this_reg].word = POP_FAILURE_ITEM (); \
+ DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \
+ \
+ regend[this_reg] = (const char *) POP_FAILURE_ITEM (); \
+ DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \
+ \
+ regstart[this_reg] = (const char *) POP_FAILURE_ITEM (); \
+ DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \
+ } \
+ \
+ DEBUG_STATEMENT (nfailure_points_popped++); \
+} /* POP_FAILURE_POINT */
+
+/* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
+ BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible
+ characters can start a string that matches the pattern. This fastmap
+ is used by re_search to skip quickly over impossible starting points.
+
+ The caller must supply the address of a (1 << BYTEWIDTH)-byte data
+ area as BUFP->fastmap.
+
+ We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in
+ the pattern buffer.
+
+ Returns 0 if we succeed, -2 if an internal error. */
+
+int
+re_compile_fastmap (bufp)
+ struct re_pattern_buffer *bufp;
+{
+ int j, k;
+ fail_stack_type fail_stack;
+#ifndef REGEX_MALLOC
+ char *destination;
+#endif
+ /* We don't push any register information onto the failure stack. */
+ unsigned num_regs = 0;
+
+ register char *fastmap = bufp->fastmap;
+ unsigned char *pattern = bufp->buffer;
+ unsigned long size = bufp->used;
+ const unsigned char *p = pattern;
+ register unsigned char *pend = pattern + size;
+
+ /* Assume that each path through the pattern can be null until
+ proven otherwise. We set this false at the bottom of switch
+ statement, to which we get only if a particular path doesn't
+ match the empty string. */
+ boolean path_can_be_null = true;
+
+ /* We aren't doing a `succeed_n' to begin with. */
+ boolean succeed_n_p = false;
+
+ assert (fastmap != NULL && p != NULL);
+
+ INIT_FAIL_STACK ();
+ bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */
+ bufp->fastmap_accurate = 1; /* It will be when we're done. */
+ bufp->can_be_null = 0;
+
+ while (p != pend || !FAIL_STACK_EMPTY ())
+ {
+ if (p == pend)
+ {
+ bufp->can_be_null |= path_can_be_null;
+
+ /* Reset for next path. */
+ path_can_be_null = true;
+
+ p = fail_stack.stack[--fail_stack.avail];
+ }
+
+ /* We should never be about to go beyond the end of the pattern. */
+ assert (p < pend);
+
+#ifdef SWITCH_ENUM_BUG
+ switch ((int) ((re_opcode_t) *p++))
+#else
+ switch ((re_opcode_t) *p++)
+#endif
+ {
+
+ /* I guess the idea here is to simply not bother with a fastmap
+ if a backreference is used, since it's too hard to figure out
+ the fastmap for the corresponding group. Setting
+ `can_be_null' stops `re_search_2' from using the fastmap, so
+ that is all we do. */
+ case duplicate:
+ bufp->can_be_null = 1;
+ return 0;
+
+
+ /* Following are the cases which match a character. These end
+ with `break'. */
+
+ case exactn:
+ fastmap[p[1]] = 1;
+ break;
+
+
+ case charset:
+ for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
+ if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
+ fastmap[j] = 1;
+ break;
+
+
+ case charset_not:
+ /* Chars beyond end of map must be allowed. */
+ for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
+ fastmap[j] = 1;
+
+ for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
+ if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
+ fastmap[j] = 1;
+ break;
+
+
+ case wordchar:
+ for (j = 0; j < (1 << BYTEWIDTH); j++)
+ if (SYNTAX (j) == Sword)
+ fastmap[j] = 1;
+ break;
+
+
+ case notwordchar:
+ for (j = 0; j < (1 << BYTEWIDTH); j++)
+ if (SYNTAX (j) != Sword)
+ fastmap[j] = 1;
+ break;
+
+
+ case anychar:
+ /* `.' matches anything ... */
+ for (j = 0; j < (1 << BYTEWIDTH); j++)
+ fastmap[j] = 1;
+
+ /* ... except perhaps newline. */
+ if (!(bufp->syntax & RE_DOT_NEWLINE))
+ fastmap['\n'] = 0;
+
+ /* Return if we have already set `can_be_null'; if we have,
+ then the fastmap is irrelevant. Something's wrong here. */
+ else if (bufp->can_be_null)
+ return 0;
+
+ /* Otherwise, have to check alternative paths. */
+ break;
+
+
+#ifdef emacs
+ case syntaxspec:
+ k = *p++;
+ for (j = 0; j < (1 << BYTEWIDTH); j++)
+ if (SYNTAX (j) == (enum syntaxcode) k)
+ fastmap[j] = 1;
+ break;
+
+
+ case notsyntaxspec:
+ k = *p++;
+ for (j = 0; j < (1 << BYTEWIDTH); j++)
+ if (SYNTAX (j) != (enum syntaxcode) k)
+ fastmap[j] = 1;
+ break;
+
+
+ /* All cases after this match the empty string. These end with
+ `continue'. */
+
+
+ case before_dot:
+ case at_dot:
+ case after_dot:
+ continue;
+#endif /* not emacs */
+
+
+ case no_op:
+ case begline:
+ case endline:
+ case begbuf:
+ case endbuf:
+ case wordbound:
+ case notwordbound:
+ case wordbeg:
+ case wordend:
+ case push_dummy_failure:
+ continue;
+
+
+ case jump_n:
+ case pop_failure_jump:
+ case maybe_pop_jump:
+ case jump:
+ case jump_past_alt:
+ case dummy_failure_jump:
+ EXTRACT_NUMBER_AND_INCR (j, p);
+ p += j;
+ if (j > 0)
+ continue;
+
+ /* Jump backward implies we just went through the body of a
+ loop and matched nothing. Opcode jumped to should be
+ `on_failure_jump' or `succeed_n'. Just treat it like an
+ ordinary jump. For a * loop, it has pushed its failure
+ point already; if so, discard that as redundant. */
+ if ((re_opcode_t) *p != on_failure_jump
+ && (re_opcode_t) *p != succeed_n)
+ continue;
+
+ p++;
+ EXTRACT_NUMBER_AND_INCR (j, p);
+ p += j;
+
+ /* If what's on the stack is where we are now, pop it. */
+ if (!FAIL_STACK_EMPTY ()
+ && fail_stack.stack[fail_stack.avail - 1] == p)
+ fail_stack.avail--;
+
+ continue;
+
+
+ case on_failure_jump:
+ case on_failure_keep_string_jump:
+ handle_on_failure_jump:
+ EXTRACT_NUMBER_AND_INCR (j, p);
+
+ /* For some patterns, e.g., `(a?)?', `p+j' here points to the
+ end of the pattern. We don't want to push such a point,
+ since when we restore it above, entering the switch will
+ increment `p' past the end of the pattern. We don't need
+ to push such a point since we obviously won't find any more
+ fastmap entries beyond `pend'. Such a pattern can match
+ the null string, though. */
+ if (p + j < pend)
+ {
+ if (!PUSH_PATTERN_OP (p + j, fail_stack))
+ return -2;
+ }
+ else
+ bufp->can_be_null = 1;
+
+ if (succeed_n_p)
+ {
+ EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */
+ succeed_n_p = false;
+ }
+
+ continue;
+
+
+ case succeed_n:
+ /* Get to the number of times to succeed. */
+ p += 2;
+
+ /* Increment p past the n for when k != 0. */
+ EXTRACT_NUMBER_AND_INCR (k, p);
+ if (k == 0)
+ {
+ p -= 4;
+ succeed_n_p = true; /* Spaghetti code alert. */
+ goto handle_on_failure_jump;
+ }
+ continue;
+
+
+ case set_number_at:
+ p += 4;
+ continue;
+
+
+ case start_memory:
+ case stop_memory:
+ p += 2;
+ continue;
+
+
+ default:
+ abort (); /* We have listed all the cases. */
+ } /* switch *p++ */
+
+ /* Getting here means we have found the possible starting
+ characters for one path of the pattern -- and that the empty
+ string does not match. We need not follow this path further.
+ Instead, look at the next alternative (remembered on the
+ stack), or quit if no more. The test at the top of the loop
+ does these things. */
+ path_can_be_null = false;
+ p = pend;
+ } /* while p */
+
+ /* Set `can_be_null' for the last path (also the first path, if the
+ pattern is empty). */
+ bufp->can_be_null |= path_can_be_null;
+ return 0;
+} /* re_compile_fastmap */
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
+ this memory for recording register information. STARTS and ENDS
+ must be allocated using the malloc library routine, and must each
+ be at least NUM_REGS * sizeof (regoff_t) bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ PATTERN_BUFFER will allocate its own register data, without
+ freeing the old data. */
+
+void
+re_set_registers (bufp, regs, num_regs, starts, ends)
+ struct re_pattern_buffer *bufp;
+ struct re_registers *regs;
+ unsigned num_regs;
+ regoff_t *starts, *ends;
+{
+ if (num_regs)
+ {
+ bufp->regs_allocated = REGS_REALLOCATE;
+ regs->num_regs = num_regs;
+ regs->start = starts;
+ regs->end = ends;
+ }
+ else
+ {
+ bufp->regs_allocated = REGS_UNALLOCATED;
+ regs->num_regs = 0;
+ regs->start = regs->end = (regoff_t) 0;
+ }
+}
+
+/* Searching routines. */
+
+/* Like re_search_2, below, but only one string is specified, and
+ doesn't let you say where to stop matching. */
+
+int
+re_search (bufp, string, size, startpos, range, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ int size, startpos, range;
+ struct re_registers *regs;
+{
+ return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
+ regs, size);
+}
+
+
+/* Using the compiled pattern in BUFP->buffer, first tries to match the
+ virtual concatenation of STRING1 and STRING2, starting first at index
+ STARTPOS, then at STARTPOS + 1, and so on.
+
+ STRING1 and STRING2 have length SIZE1 and SIZE2, respectively.
+
+ RANGE is how far to scan while trying to match. RANGE = 0 means try
+ only at STARTPOS; in general, the last start tried is STARTPOS +
+ RANGE.
+
+ In REGS, return the indices of the virtual concatenation of STRING1
+ and STRING2 that matched the entire BUFP->buffer and its contained
+ subexpressions.
+
+ Do not consider matching one past the index STOP in the virtual
+ concatenation of STRING1 and STRING2.
+
+ We return either the position in the strings at which the match was
+ found, -1 if no match, or -2 if error (such as failure
+ stack overflow). */
+
+int
+re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ int size1, size2;
+ int startpos;
+ int range;
+ struct re_registers *regs;
+ int stop;
+{
+ int val;
+ register char *fastmap = bufp->fastmap;
+ register char *translate = bufp->translate;
+ int total_size = size1 + size2;
+ int endpos = startpos + range;
+
+ /* Check for out-of-range STARTPOS. */
+ if (startpos < 0 || startpos > total_size)
+ return -1;
+
+ /* Fix up RANGE if it might eventually take us outside
+ the virtual concatenation of STRING1 and STRING2. */
+ if (endpos < -1)
+ range = -1 - startpos;
+ else if (endpos > total_size)
+ range = total_size - startpos;
+
+ /* If the search isn't to be a backwards one, don't waste time in a
+ search for a pattern that must be anchored. */
+ if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0)
+ {
+ if (startpos > 0)
+ return -1;
+ else
+ range = 1;
+ }
+
+ /* Update the fastmap now if not correct already. */
+ if (fastmap && !bufp->fastmap_accurate)
+ if (re_compile_fastmap (bufp) == -2)
+ return -2;
+
+ /* Loop through the string, looking for a place to start matching. */
+ for (;;)
+ {
+ /* If a fastmap is supplied, skip quickly over characters that
+ cannot be the start of a match. If the pattern can match the
+ null string, however, we don't need to skip characters; we want
+ the first null string. */
+ if (fastmap && startpos < total_size && !bufp->can_be_null)
+ {
+ if (range > 0) /* Searching forwards. */
+ {
+ register const char *d;
+ register int lim = 0;
+ int irange = range;
+
+ if (startpos < size1 && startpos + range >= size1)
+ lim = range - (size1 - startpos);
+
+ d = (startpos >= size1 ? string2 - size1 : string1) + startpos;
+
+ /* Written out as an if-else to avoid testing `translate'
+ inside the loop. */
+ if (translate)
+ while (range > lim
+ && !fastmap[(unsigned char)
+ translate[(unsigned char) *d++]])
+ range--;
+ else
+ while (range > lim && !fastmap[(unsigned char) *d++])
+ range--;
+
+ startpos += irange - range;
+ }
+ else /* Searching backwards. */
+ {
+ register char c = (size1 == 0 || startpos >= size1
+ ? string2[startpos - size1]
+ : string1[startpos]);
+
+ if (!fastmap[(unsigned char) TRANSLATE (c)])
+ goto advance;
+ }
+ }
+
+ /* If can't match the null string, and that's all we have left, fail. */
+ if (range >= 0 && startpos == total_size && fastmap
+ && !bufp->can_be_null)
+ return -1;
+
+ val = re_match_2 (bufp, string1, size1, string2, size2,
+ startpos, regs, stop);
+ if (val >= 0)
+ return startpos;
+
+ if (val == -2)
+ return -2;
+
+ advance:
+ if (!range)
+ break;
+ else if (range > 0)
+ {
+ range--;
+ startpos++;
+ }
+ else
+ {
+ range++;
+ startpos--;
+ }
+ }
+ return -1;
+} /* re_search_2 */
+
+/* Declarations and macros for re_match_2. */
+
+static int bcmp_translate ();
+static boolean alt_match_null_string_p (),
+ common_op_match_null_string_p (),
+ group_match_null_string_p ();
+
+/* Structure for per-register (a.k.a. per-group) information.
+ This must not be longer than one word, because we push this value
+ onto the failure stack. Other register information, such as the
+ starting and ending positions (which are addresses), and the list of
+ inner groups (which is a bits list) are maintained in separate
+ variables.
+
+ We are making a (strictly speaking) nonportable assumption here: that
+ the compiler will pack our bit fields into something that fits into
+ the type of `word', i.e., is something that fits into one item on the
+ failure stack. */
+typedef union
+{
+ fail_stack_elt_t word;
+ struct
+ {
+ /* This field is one if this group can match the empty string,
+ zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */
+#define MATCH_NULL_UNSET_VALUE 3
+ unsigned match_null_string_p : 2;
+ unsigned is_active : 1;
+ unsigned matched_something : 1;
+ unsigned ever_matched_something : 1;
+ } bits;
+} register_info_type;
+
+#define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p)
+#define IS_ACTIVE(R) ((R).bits.is_active)
+#define MATCHED_SOMETHING(R) ((R).bits.matched_something)
+#define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something)
+
+
+/* Call this when have matched a real character; it sets `matched' flags
+ for the subexpressions which we are currently inside. Also records
+ that those subexprs have matched. */
+#define SET_REGS_MATCHED() \
+ do \
+ { \
+ unsigned r; \
+ for (r = lowest_active_reg; r <= highest_active_reg; r++) \
+ { \
+ MATCHED_SOMETHING (reg_info[r]) \
+ = EVER_MATCHED_SOMETHING (reg_info[r]) \
+ = 1; \
+ } \
+ } \
+ while (0)
+
+
+/* This converts PTR, a pointer into one of the search strings `string1'
+ and `string2' into an offset from the beginning of that string. */
+#define POINTER_TO_OFFSET(ptr) \
+ (FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1)
+
+/* Registers are set to a sentinel when they haven't yet matched. */
+#define REG_UNSET_VALUE ((char *) -1)
+#define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
+
+
+/* Macros for dealing with the split strings in re_match_2. */
+
+#define MATCHING_IN_FIRST_STRING (dend == end_match_1)
+
+/* Call before fetching a character with *d. This switches over to
+ string2 if necessary. */
+#define PREFETCH() \
+ while (d == dend) \
+ { \
+ /* End of string2 => fail. */ \
+ if (dend == end_match_2) \
+ goto fail; \
+ /* End of string1 => advance to string2. */ \
+ d = string2; \
+ dend = end_match_2; \
+ }
+
+
+/* Test if at very beginning or at very end of the virtual concatenation
+ of `string1' and `string2'. If only one string, it's `string2'. */
+#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2)
+#define AT_STRINGS_END(d) ((d) == end2)
+
+
+/* Test if D points to a character which is word-constituent. We have
+ two special cases to check for: if past the end of string1, look at
+ the first character in string2; and if before the beginning of
+ string2, look at the last character in string1. */
+#define WORDCHAR_P(d) \
+ (SYNTAX ((d) == end1 ? *string2 \
+ : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \
+ == Sword)
+
+/* Test if the character before D and the one at D differ with respect
+ to being word-constituent. */
+#define AT_WORD_BOUNDARY(d) \
+ (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \
+ || WORDCHAR_P (d - 1) != WORDCHAR_P (d))
+
+
+/* Free everything we malloc. */
+#ifdef REGEX_MALLOC
+#define FREE_VAR(var) if (var) free (var); var = NULL
+#define FREE_VARIABLES() \
+ do { \
+ FREE_VAR (fail_stack.stack); \
+ FREE_VAR (regstart); \
+ FREE_VAR (regend); \
+ FREE_VAR (old_regstart); \
+ FREE_VAR (old_regend); \
+ FREE_VAR (best_regstart); \
+ FREE_VAR (best_regend); \
+ FREE_VAR (reg_info); \
+ FREE_VAR (reg_dummy); \
+ FREE_VAR (reg_info_dummy); \
+ } while (0)
+#else /* not REGEX_MALLOC */
+/* Some MIPS systems (at least) want this to free alloca'd storage. */
+#define FREE_VARIABLES() alloca (0)
+#endif /* not REGEX_MALLOC */
+
+
+/* These values must meet several constraints. They must not be valid
+ register values; since we have a limit of 255 registers (because
+ we use only one byte in the pattern for the register number), we can
+ use numbers larger than 255. They must differ by 1, because of
+ NUM_FAILURE_ITEMS above. And the value for the lowest register must
+ be larger than the value for the highest register, so we do not try
+ to actually save any registers when none are active. */
+#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH)
+#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1)
+
+/* Matching routines. */
+
+#ifndef emacs /* Emacs never uses this. */
+/* re_match is like re_match_2 except it takes only a single string. */
+
+int
+re_match (bufp, string, size, pos, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ int size, pos;
+ struct re_registers *regs;
+ {
+ return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size);
+}
+#endif /* not emacs */
+
+
+/* re_match_2 matches the compiled pattern in BUFP against the
+ the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1
+ and SIZE2, respectively). We start matching at POS, and stop
+ matching at STOP.
+
+ If REGS is non-null and the `no_sub' field of BUFP is nonzero, we
+ store offsets for the substring each group matched in REGS. See the
+ documentation for exactly how many groups we fill.
+
+ We return -1 if no match, -2 if an internal error (such as the
+ failure stack overflowing). Otherwise, we return the length of the
+ matched substring. */
+
+int
+re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ int size1, size2;
+ int pos;
+ struct re_registers *regs;
+ int stop;
+{
+ /* General temporaries. */
+ int mcnt;
+ unsigned char *p1;
+
+ /* Just past the end of the corresponding string. */
+ const char *end1, *end2;
+
+ /* Pointers into string1 and string2, just past the last characters in
+ each to consider matching. */
+ const char *end_match_1, *end_match_2;
+
+ /* Where we are in the data, and the end of the current string. */
+ const char *d, *dend;
+
+ /* Where we are in the pattern, and the end of the pattern. */
+ unsigned char *p = bufp->buffer;
+ register unsigned char *pend = p + bufp->used;
+
+ /* We use this to map every character in the string. */
+ char *translate = bufp->translate;
+
+ /* Failure point stack. Each place that can handle a failure further
+ down the line pushes a failure point on this stack. It consists of
+ restart, regend, and reg_info for all registers corresponding to
+ the subexpressions we're currently inside, plus the number of such
+ registers, and, finally, two char *'s. The first char * is where
+ to resume scanning the pattern; the second one is where to resume
+ scanning the strings. If the latter is zero, the failure point is
+ a ``dummy''; if a failure happens and the failure point is a dummy,
+ it gets discarded and the next next one is tried. */
+ fail_stack_type fail_stack;
+#ifdef DEBUG
+ static unsigned failure_id = 0;
+ unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
+#endif
+
+ /* We fill all the registers internally, independent of what we
+ return, for use in backreferences. The number here includes
+ an element for register zero. */
+ unsigned num_regs = bufp->re_nsub + 1;
+
+ /* The currently active registers. */
+ unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG;
+ unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG;
+
+ /* Information on the contents of registers. These are pointers into
+ the input strings; they record just what was matched (on this
+ attempt) by a subexpression part of the pattern, that is, the
+ regnum-th regstart pointer points to where in the pattern we began
+ matching and the regnum-th regend points to right after where we
+ stopped matching the regnum-th subexpression. (The zeroth register
+ keeps track of what the whole pattern matches.) */
+ const char **regstart, **regend;
+
+ /* If a group that's operated upon by a repetition operator fails to
+ match anything, then the register for its start will need to be
+ restored because it will have been set to wherever in the string we
+ are when we last see its open-group operator. Similarly for a
+ register's end. */
+ const char **old_regstart, **old_regend;
+
+ /* The is_active field of reg_info helps us keep track of which (possibly
+ nested) subexpressions we are currently in. The matched_something
+ field of reg_info[reg_num] helps us tell whether or not we have
+ matched any of the pattern so far this time through the reg_num-th
+ subexpression. These two fields get reset each time through any
+ loop their register is in. */
+ register_info_type *reg_info;
+
+ /* The following record the register info as found in the above
+ variables when we find a match better than any we've seen before.
+ This happens as we backtrack through the failure points, which in
+ turn happens only if we have not yet matched the entire string. */
+ unsigned best_regs_set = false;
+ const char **best_regstart, **best_regend;
+
+ /* Logically, this is `best_regend[0]'. But we don't want to have to
+ allocate space for that if we're not allocating space for anything
+ else (see below). Also, we never need info about register 0 for
+ any of the other register vectors, and it seems rather a kludge to
+ treat `best_regend' differently than the rest. So we keep track of
+ the end of the best match so far in a separate variable. We
+ initialize this to NULL so that when we backtrack the first time
+ and need to test it, it's not garbage. */
+ const char *match_end = NULL;
+
+ /* Used when we pop values we don't care about. */
+ const char **reg_dummy;
+ register_info_type *reg_info_dummy;
+
+#ifdef DEBUG
+ /* Counts the total number of registers pushed. */
+ unsigned num_regs_pushed = 0;
+#endif
+
+ DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
+
+ INIT_FAIL_STACK ();
+
+ /* Do not bother to initialize all the register variables if there are
+ no groups in the pattern, as it takes a fair amount of time. If
+ there are groups, we include space for register 0 (the whole
+ pattern), even though we never use it, since it simplifies the
+ array indexing. We should fix this. */
+ if (bufp->re_nsub)
+ {
+ regstart = REGEX_TALLOC (num_regs, const char *);
+ regend = REGEX_TALLOC (num_regs, const char *);
+ old_regstart = REGEX_TALLOC (num_regs, const char *);
+ old_regend = REGEX_TALLOC (num_regs, const char *);
+ best_regstart = REGEX_TALLOC (num_regs, const char *);
+ best_regend = REGEX_TALLOC (num_regs, const char *);
+ reg_info = REGEX_TALLOC (num_regs, register_info_type);
+ reg_dummy = REGEX_TALLOC (num_regs, const char *);
+ reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type);
+
+ if (!(regstart && regend && old_regstart && old_regend && reg_info
+ && best_regstart && best_regend && reg_dummy && reg_info_dummy))
+ {
+ FREE_VARIABLES ();
+ return -2;
+ }
+ }
+#ifdef REGEX_MALLOC
+ else
+ {
+ /* We must initialize all our variables to NULL, so that
+ `FREE_VARIABLES' doesn't try to free them. */
+ regstart = regend = old_regstart = old_regend = best_regstart
+ = best_regend = reg_dummy = NULL;
+ reg_info = reg_info_dummy = (register_info_type *) NULL;
+ }
+#endif /* REGEX_MALLOC */
+
+ /* The starting position is bogus. */
+ if (pos < 0 || pos > size1 + size2)
+ {
+ FREE_VARIABLES ();
+ return -1;
+ }
+
+ /* Initialize subexpression text positions to -1 to mark ones that no
+ start_memory/stop_memory has been seen for. Also initialize the
+ register information struct. */
+ for (mcnt = 1; (unsigned)mcnt < num_regs; mcnt++)
+ {
+ regstart[mcnt] = regend[mcnt]
+ = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE;
+
+ REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE;
+ IS_ACTIVE (reg_info[mcnt]) = 0;
+ MATCHED_SOMETHING (reg_info[mcnt]) = 0;
+ EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0;
+ }
+
+ /* We move `string1' into `string2' if the latter's empty -- but not if
+ `string1' is null. */
+ if (size2 == 0 && string1 != NULL)
+ {
+ string2 = string1;
+ size2 = size1;
+ string1 = 0;
+ size1 = 0;
+ }
+ end1 = string1 + size1;
+ end2 = string2 + size2;
+
+ /* Compute where to stop matching, within the two strings. */
+ if (stop <= size1)
+ {
+ end_match_1 = string1 + stop;
+ end_match_2 = string2;
+ }
+ else
+ {
+ end_match_1 = end1;
+ end_match_2 = string2 + stop - size1;
+ }
+
+ /* `p' scans through the pattern as `d' scans through the data.
+ `dend' is the end of the input string that `d' points within. `d'
+ is advanced into the following input string whenever necessary, but
+ this happens before fetching; therefore, at the beginning of the
+ loop, `d' can be pointing at the end of a string, but it cannot
+ equal `string2'. */
+ if (size1 > 0 && pos <= size1)
+ {
+ d = string1 + pos;
+ dend = end_match_1;
+ }
+ else
+ {
+ d = string2 + pos - size1;
+ dend = end_match_2;
+ }
+
+ DEBUG_PRINT1 ("The compiled pattern is: ");
+ DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend);
+ DEBUG_PRINT1 ("The string to match is: `");
+ DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2);
+ DEBUG_PRINT1 ("'\n");
+
+ /* This loops over pattern commands. It exits by returning from the
+ function if the match is complete, or it drops through if the match
+ fails at this starting point in the input data. */
+ for (;;)
+ {
+ DEBUG_PRINT2 ("\n0x%x: ", p);
+
+ if (p == pend)
+ { /* End of pattern means we might have succeeded. */
+ DEBUG_PRINT1 ("end of pattern ... ");
+
+ /* If we haven't matched the entire string, and we want the
+ longest match, try backtracking. */
+ if (d != end_match_2)
+ {
+ DEBUG_PRINT1 ("backtracking.\n");
+
+ if (!FAIL_STACK_EMPTY ())
+ { /* More failure points to try. */
+ boolean same_str_p = (FIRST_STRING_P (match_end)
+ == MATCHING_IN_FIRST_STRING);
+
+ /* If exceeds best match so far, save it. */
+ if (!best_regs_set
+ || (same_str_p && d > match_end)
+ || (!same_str_p && !MATCHING_IN_FIRST_STRING))
+ {
+ best_regs_set = true;
+ match_end = d;
+
+ DEBUG_PRINT1 ("\nSAVING match as best so far.\n");
+
+ for (mcnt = 1; (unsigned)mcnt < num_regs; mcnt++)
+ {
+ best_regstart[mcnt] = regstart[mcnt];
+ best_regend[mcnt] = regend[mcnt];
+ }
+ }
+ goto fail;
+ }
+
+ /* If no failure points, don't restore garbage. */
+ else if (best_regs_set)
+ {
+ restore_best_regs:
+ /* Restore best match. It may happen that `dend ==
+ end_match_1' while the restored d is in string2.
+ For example, the pattern `x.*y.*z' against the
+ strings `x-' and `y-z-', if the two strings are
+ not consecutive in memory. */
+ DEBUG_PRINT1 ("Restoring best registers.\n");
+
+ d = match_end;
+ dend = ((d >= string1 && d <= end1)
+ ? end_match_1 : end_match_2);
+
+ for (mcnt = 1; (unsigned)mcnt < num_regs; mcnt++)
+ {
+ regstart[mcnt] = best_regstart[mcnt];
+ regend[mcnt] = best_regend[mcnt];
+ }
+ }
+ } /* d != end_match_2 */
+
+ DEBUG_PRINT1 ("Accepting match.\n");
+
+ /* If caller wants register contents data back, do it. */
+ if (regs && !bufp->no_sub)
+ {
+ /* Have the register data arrays been allocated? */
+ if (bufp->regs_allocated == REGS_UNALLOCATED)
+ { /* No. So allocate them with malloc. We need one
+ extra element beyond `num_regs' for the `-1' marker
+ GNU code uses. */
+ regs->num_regs = MAX (RE_NREGS, num_regs + 1);
+ regs->start = TALLOC (regs->num_regs, regoff_t);
+ regs->end = TALLOC (regs->num_regs, regoff_t);
+ if (regs->start == NULL || regs->end == NULL)
+ return -2;
+ bufp->regs_allocated = REGS_REALLOCATE;
+ }
+ else if (bufp->regs_allocated == REGS_REALLOCATE)
+ { /* Yes. If we need more elements than were already
+ allocated, reallocate them. If we need fewer, just
+ leave it alone. */
+ if (regs->num_regs < num_regs + 1)
+ {
+ regs->num_regs = num_regs + 1;
+ RETALLOC (regs->start, regs->num_regs, regoff_t);
+ RETALLOC (regs->end, regs->num_regs, regoff_t);
+ if (regs->start == NULL || regs->end == NULL)
+ return -2;
+ }
+ }
+ else
+ assert (bufp->regs_allocated == REGS_FIXED);
+
+ /* Convert the pointer data in `regstart' and `regend' to
+ indices. Register zero has to be set differently,
+ since we haven't kept track of any info for it. */
+ if (regs->num_regs > 0)
+ {
+ regs->start[0] = pos;
+ regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1
+ : d - string2 + size1);
+ }
+
+ /* Go through the first `min (num_regs, regs->num_regs)'
+ registers, since that is all we initialized. */
+ for (mcnt = 1; (unsigned)mcnt < MIN (num_regs, regs->num_regs); mcnt++)
+ {
+ if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt]))
+ regs->start[mcnt] = regs->end[mcnt] = -1;
+ else
+ {
+ regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]);
+ regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]);
+ }
+ }
+
+ /* If the regs structure we return has more elements than
+ were in the pattern, set the extra elements to -1. If
+ we (re)allocated the registers, this is the case,
+ because we always allocate enough to have at least one
+ -1 at the end. */
+ for (mcnt = num_regs; (unsigned)mcnt < regs->num_regs; mcnt++)
+ regs->start[mcnt] = regs->end[mcnt] = -1;
+ } /* regs && !bufp->no_sub */
+
+ FREE_VARIABLES ();
+ DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
+ nfailure_points_pushed, nfailure_points_popped,
+ nfailure_points_pushed - nfailure_points_popped);
+ DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed);
+
+ mcnt = d - pos - (MATCHING_IN_FIRST_STRING
+ ? string1
+ : string2 - size1);
+
+ DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
+
+ return mcnt;
+ }
+
+ /* Otherwise match next pattern command. */
+#ifdef SWITCH_ENUM_BUG
+ switch ((int) ((re_opcode_t) *p++))
+#else
+ switch ((re_opcode_t) *p++)
+#endif
+ {
+ /* Ignore these. Used to ignore the n of succeed_n's which
+ currently have n == 0. */
+ case no_op:
+ DEBUG_PRINT1 ("EXECUTING no_op.\n");
+ break;
+
+
+ /* Match the next n pattern characters exactly. The following
+ byte in the pattern defines n, and the n bytes after that
+ are the characters to match. */
+ case exactn:
+ mcnt = *p++;
+ DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt);
+
+ /* This is written out as an if-else so we don't waste time
+ testing `translate' inside the loop. */
+ if (translate)
+ {
+ do
+ {
+ PREFETCH ();
+ if (translate[(unsigned char) *d++] != (char) *p++)
+ goto fail;
+ }
+ while (--mcnt);
+ }
+ else
+ {
+ do
+ {
+ PREFETCH ();
+ if (*d++ != (char) *p++) goto fail;
+ }
+ while (--mcnt);
+ }
+ SET_REGS_MATCHED ();
+ break;
+
+
+ /* Match any character except possibly a newline or a null. */
+ case anychar:
+ DEBUG_PRINT1 ("EXECUTING anychar.\n");
+
+ PREFETCH ();
+
+ if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n')
+ || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000'))
+ goto fail;
+
+ SET_REGS_MATCHED ();
+ DEBUG_PRINT2 (" Matched `%d'.\n", *d);
+ d++;
+ break;
+
+
+ case charset:
+ case charset_not:
+ {
+ register unsigned char c;
+ boolean not = (re_opcode_t) *(p - 1) == charset_not;
+
+ DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : "");
+
+ PREFETCH ();
+ c = TRANSLATE (*d); /* The character to match. */
+
+ /* Cast to `unsigned' instead of `unsigned char' in case the
+ bit list is a full 32 bytes long. */
+ if (c < (unsigned) (*p * BYTEWIDTH)
+ && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
+ not = !not;
+
+ p += 1 + *p;
+
+ if (!not) goto fail;
+
+ SET_REGS_MATCHED ();
+ d++;
+ break;
+ }
+
+
+ /* The beginning of a group is represented by start_memory.
+ The arguments are the register number in the next byte, and the
+ number of groups inner to this one in the next. The text
+ matched within the group is recorded (in the internal
+ registers data structure) under the register number. */
+ case start_memory:
+ DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]);
+
+ /* Find out if this group can match the empty string. */
+ p1 = p; /* To send to group_match_null_string_p. */
+
+ if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE)
+ REG_MATCH_NULL_STRING_P (reg_info[*p])
+ = group_match_null_string_p (&p1, pend, reg_info);
+
+ /* Save the position in the string where we were the last time
+ we were at this open-group operator in case the group is
+ operated upon by a repetition operator, e.g., with `(a*)*b'
+ against `ab'; then we want to ignore where we are now in
+ the string in case this attempt to match fails. */
+ old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
+ ? REG_UNSET (regstart[*p]) ? d : regstart[*p]
+ : regstart[*p];
+ DEBUG_PRINT2 (" old_regstart: %d\n",
+ POINTER_TO_OFFSET (old_regstart[*p]));
+
+ regstart[*p] = d;
+ DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p]));
+
+ IS_ACTIVE (reg_info[*p]) = 1;
+ MATCHED_SOMETHING (reg_info[*p]) = 0;
+
+ /* This is the new highest active register. */
+ highest_active_reg = *p;
+
+ /* If nothing was active before, this is the new lowest active
+ register. */
+ if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
+ lowest_active_reg = *p;
+
+ /* Move past the register number and inner group count. */
+ p += 2;
+ break;
+
+
+ /* The stop_memory opcode represents the end of a group. Its
+ arguments are the same as start_memory's: the register
+ number, and the number of inner groups. */
+ case stop_memory:
+ DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]);
+
+ /* We need to save the string position the last time we were at
+ this close-group operator in case the group is operated
+ upon by a repetition operator, e.g., with `((a*)*(b*)*)*'
+ against `aba'; then we want to ignore where we are now in
+ the string in case this attempt to match fails. */
+ old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p])
+ ? REG_UNSET (regend[*p]) ? d : regend[*p]
+ : regend[*p];
+ DEBUG_PRINT2 (" old_regend: %d\n",
+ POINTER_TO_OFFSET (old_regend[*p]));
+
+ regend[*p] = d;
+ DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p]));
+
+ /* This register isn't active anymore. */
+ IS_ACTIVE (reg_info[*p]) = 0;
+
+ /* If this was the only register active, nothing is active
+ anymore. */
+ if (lowest_active_reg == highest_active_reg)
+ {
+ lowest_active_reg = NO_LOWEST_ACTIVE_REG;
+ highest_active_reg = NO_HIGHEST_ACTIVE_REG;
+ }
+ else
+ { /* We must scan for the new highest active register, since
+ it isn't necessarily one less than now: consider
+ (a(b)c(d(e)f)g). When group 3 ends, after the f), the
+ new highest active register is 1. */
+ unsigned char r = *p - 1;
+ while (r > 0 && !IS_ACTIVE (reg_info[r]))
+ r--;
+
+ /* If we end up at register zero, that means that we saved
+ the registers as the result of an `on_failure_jump', not
+ a `start_memory', and we jumped to past the innermost
+ `stop_memory'. For example, in ((.)*) we save
+ registers 1 and 2 as a result of the *, but when we pop
+ back to the second ), we are at the stop_memory 1.
+ Thus, nothing is active. */
+ if (r == 0)
+ {
+ lowest_active_reg = NO_LOWEST_ACTIVE_REG;
+ highest_active_reg = NO_HIGHEST_ACTIVE_REG;
+ }
+ else
+ highest_active_reg = r;
+ }
+
+ /* If just failed to match something this time around with a
+ group that's operated on by a repetition operator, try to
+ force exit from the ``loop'', and restore the register
+ information for this group that we had before trying this
+ last match. */
+ if ((!MATCHED_SOMETHING (reg_info[*p])
+ || (re_opcode_t) p[-3] == start_memory)
+ && (p + 2) < pend)
+ {
+ boolean is_a_jump_n = false;
+
+ p1 = p + 2;
+ mcnt = 0;
+ switch ((re_opcode_t) *p1++)
+ {
+ case jump_n:
+ is_a_jump_n = true;
+ case pop_failure_jump:
+ case maybe_pop_jump:
+ case jump:
+ case dummy_failure_jump:
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ if (is_a_jump_n)
+ p1 += 2;
+ break;
+
+ default:
+ /* do nothing */ ;
+ }
+ p1 += mcnt;
+
+ /* If the next operation is a jump backwards in the pattern
+ to an on_failure_jump right before the start_memory
+ corresponding to this stop_memory, exit from the loop
+ by forcing a failure after pushing on the stack the
+ on_failure_jump's jump in the pattern, and d. */
+ if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump
+ && (re_opcode_t) p1[3] == start_memory && p1[4] == *p)
+ {
+ /* If this group ever matched anything, then restore
+ what its registers were before trying this last
+ failed match, e.g., with `(a*)*b' against `ab' for
+ regstart[1], and, e.g., with `((a*)*(b*)*)*'
+ against `aba' for regend[3].
+
+ Also restore the registers for inner groups for,
+ e.g., `((a*)(b*))*' against `aba' (register 3 would
+ otherwise get trashed). */
+
+ if (EVER_MATCHED_SOMETHING (reg_info[*p]))
+ {
+ unsigned r;
+
+ EVER_MATCHED_SOMETHING (reg_info[*p]) = 0;
+
+ /* Restore this and inner groups' (if any) registers. */
+ for (r = *p; r < (unsigned)(*p + *(p + 1)); r++)
+ {
+ regstart[r] = old_regstart[r];
+
+ /* xx why this test? */
+ if ((int) old_regend[r] >= (int) regstart[r])
+ regend[r] = old_regend[r];
+ }
+ }
+ p1++;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ PUSH_FAILURE_POINT (p1 + mcnt, d, -2);
+
+ goto fail;
+ }
+ }
+
+ /* Move past the register number and the inner group count. */
+ p += 2;
+ break;
+
+
+ /* \<digit> has been turned into a `duplicate' command which is
+ followed by the numeric value of <digit> as the register number. */
+ case duplicate:
+ {
+ register const char *d2, *dend2;
+ int regno = *p++; /* Get which register to match against. */
+ DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno);
+
+ /* Can't back reference a group which we've never matched. */
+ if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno]))
+ goto fail;
+
+ /* Where in input to try to start matching. */
+ d2 = regstart[regno];
+
+ /* Where to stop matching; if both the place to start and
+ the place to stop matching are in the same string, then
+ set to the place to stop, otherwise, for now have to use
+ the end of the first string. */
+
+ dend2 = ((FIRST_STRING_P (regstart[regno])
+ == FIRST_STRING_P (regend[regno]))
+ ? regend[regno] : end_match_1);
+ for (;;)
+ {
+ /* If necessary, advance to next segment in register
+ contents. */
+ while (d2 == dend2)
+ {
+ if (dend2 == end_match_2) break;
+ if (dend2 == regend[regno]) break;
+
+ /* End of string1 => advance to string2. */
+ d2 = string2;
+ dend2 = regend[regno];
+ }
+ /* At end of register contents => success */
+ if (d2 == dend2) break;
+
+ /* If necessary, advance to next segment in data. */
+ PREFETCH ();
+
+ /* How many characters left in this segment to match. */
+ mcnt = dend - d;
+
+ /* Want how many consecutive characters we can match in
+ one shot, so, if necessary, adjust the count. */
+ if (mcnt > dend2 - d2)
+ mcnt = dend2 - d2;
+
+ /* Compare that many; failure if mismatch, else move
+ past them. */
+ if (translate
+ ? bcmp_translate (d, d2, mcnt, translate)
+ : bcmp (d, d2, mcnt))
+ goto fail;
+ d += mcnt, d2 += mcnt;
+ }
+ }
+ break;
+
+
+ /* begline matches the empty string at the beginning of the string
+ (unless `not_bol' is set in `bufp'), and, if
+ `newline_anchor' is set, after newlines. */
+ case begline:
+ DEBUG_PRINT1 ("EXECUTING begline.\n");
+
+ if (AT_STRINGS_BEG (d))
+ {
+ if (!bufp->not_bol) break;
+ }
+ else if (d[-1] == '\n' && bufp->newline_anchor)
+ {
+ break;
+ }
+ /* In all other cases, we fail. */
+ goto fail;
+
+
+ /* endline is the dual of begline. */
+ case endline:
+ DEBUG_PRINT1 ("EXECUTING endline.\n");
+
+ if (AT_STRINGS_END (d))
+ {
+ if (!bufp->not_eol) break;
+ }
+
+ /* We have to ``prefetch'' the next character. */
+ else if ((d == end1 ? *string2 : *d) == '\n'
+ && bufp->newline_anchor)
+ {
+ break;
+ }
+ goto fail;
+
+
+ /* Match at the very beginning of the data. */
+ case begbuf:
+ DEBUG_PRINT1 ("EXECUTING begbuf.\n");
+ if (AT_STRINGS_BEG (d))
+ break;
+ goto fail;
+
+
+ /* Match at the very end of the data. */
+ case endbuf:
+ DEBUG_PRINT1 ("EXECUTING endbuf.\n");
+ if (AT_STRINGS_END (d))
+ break;
+ goto fail;
+
+
+ /* on_failure_keep_string_jump is used to optimize `.*\n'. It
+ pushes NULL as the value for the string on the stack. Then
+ `pop_failure_point' will keep the current value for the
+ string, instead of restoring it. To see why, consider
+ matching `foo\nbar' against `.*\n'. The .* matches the foo;
+ then the . fails against the \n. But the next thing we want
+ to do is match the \n against the \n; if we restored the
+ string value, we would be back at the foo.
+
+ Because this is used only in specific cases, we don't need to
+ check all the things that `on_failure_jump' does, to make
+ sure the right things get saved on the stack. Hence we don't
+ share its code. The only reason to push anything on the
+ stack at all is that otherwise we would have to change
+ `anychar's code to do something besides goto fail in this
+ case; that seems worse than this. */
+ case on_failure_keep_string_jump:
+ DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump");
+
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt);
+
+ PUSH_FAILURE_POINT (p + mcnt, NULL, -2);
+ break;
+
+
+ /* Uses of on_failure_jump:
+
+ Each alternative starts with an on_failure_jump that points
+ to the beginning of the next alternative. Each alternative
+ except the last ends with a jump that in effect jumps past
+ the rest of the alternatives. (They really jump to the
+ ending jump of the following alternative, because tensioning
+ these jumps is a hassle.)
+
+ Repeats start with an on_failure_jump that points past both
+ the repetition text and either the following jump or
+ pop_failure_jump back to this on_failure_jump. */
+ case on_failure_jump:
+ on_failure:
+ DEBUG_PRINT1 ("EXECUTING on_failure_jump");
+
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt);
+
+ /* If this on_failure_jump comes right before a group (i.e.,
+ the original * applied to a group), save the information
+ for that group and all inner ones, so that if we fail back
+ to this point, the group's information will be correct.
+ For example, in \(a*\)*\1, we need the preceding group,
+ and in \(\(a*\)b*\)\2, we need the inner group. */
+
+ /* We can't use `p' to check ahead because we push
+ a failure point to `p + mcnt' after we do this. */
+ p1 = p;
+
+ /* We need to skip no_op's before we look for the
+ start_memory in case this on_failure_jump is happening as
+ the result of a completed succeed_n, as in \(a\)\{1,3\}b\1
+ against aba. */
+ while (p1 < pend && (re_opcode_t) *p1 == no_op)
+ p1++;
+
+ if (p1 < pend && (re_opcode_t) *p1 == start_memory)
+ {
+ /* We have a new highest active register now. This will
+ get reset at the start_memory we are about to get to,
+ but we will have saved all the registers relevant to
+ this repetition op, as described above. */
+ highest_active_reg = *(p1 + 1) + *(p1 + 2);
+ if (lowest_active_reg == NO_LOWEST_ACTIVE_REG)
+ lowest_active_reg = *(p1 + 1);
+ }
+
+ DEBUG_PRINT1 (":\n");
+ PUSH_FAILURE_POINT (p + mcnt, d, -2);
+ break;
+
+
+ /* A smart repeat ends with `maybe_pop_jump'.
+ We change it to either `pop_failure_jump' or `jump'. */
+ case maybe_pop_jump:
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt);
+ {
+ register unsigned char *p2 = p;
+
+ /* Compare the beginning of the repeat with what in the
+ pattern follows its end. If we can establish that there
+ is nothing that they would both match, i.e., that we
+ would have to backtrack because of (as in, e.g., `a*a')
+ then we can change to pop_failure_jump, because we'll
+ never have to backtrack.
+
+ This is not true in the case of alternatives: in
+ `(a|ab)*' we do need to backtrack to the `ab' alternative
+ (e.g., if the string was `ab'). But instead of trying to
+ detect that here, the alternative has put on a dummy
+ failure point which is what we will end up popping. */
+
+ /* Skip over open/close-group commands. */
+ while (p2 + 2 < pend
+ && ((re_opcode_t) *p2 == stop_memory
+ || (re_opcode_t) *p2 == start_memory))
+ p2 += 3; /* Skip over args, too. */
+
+ /* If we're at the end of the pattern, we can change. */
+ if (p2 == pend)
+ {
+ /* Consider what happens when matching ":\(.*\)"
+ against ":/". I don't really understand this code
+ yet. */
+ p[-3] = (unsigned char) pop_failure_jump;
+ DEBUG_PRINT1
+ (" End of pattern: change to `pop_failure_jump'.\n");
+ }
+
+ else if ((re_opcode_t) *p2 == exactn
+ || (bufp->newline_anchor && (re_opcode_t) *p2 == endline))
+ {
+ register unsigned char c
+ = *p2 == (unsigned char) endline ? '\n' : p2[2];
+ p1 = p + mcnt;
+
+ /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
+ to the `maybe_finalize_jump' of this case. Examine what
+ follows. */
+ if ((re_opcode_t) p1[3] == exactn && p1[5] != c)
+ {
+ p[-3] = (unsigned char) pop_failure_jump;
+ DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n",
+ c, p1[5]);
+ }
+
+ else if ((re_opcode_t) p1[3] == charset
+ || (re_opcode_t) p1[3] == charset_not)
+ {
+ int not = (re_opcode_t) p1[3] == charset_not;
+
+ if (c < (unsigned char) (p1[4] * BYTEWIDTH)
+ && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
+ not = !not;
+
+ /* `not' is equal to 1 if c would match, which means
+ that we can't change to pop_failure_jump. */
+ if (!not)
+ {
+ p[-3] = (unsigned char) pop_failure_jump;
+ DEBUG_PRINT1 (" No match => pop_failure_jump.\n");
+ }
+ }
+ }
+ }
+ p -= 2; /* Point at relative address again. */
+ if ((re_opcode_t) p[-1] != pop_failure_jump)
+ {
+ p[-1] = (unsigned char) jump;
+ DEBUG_PRINT1 (" Match => jump.\n");
+ goto unconditional_jump;
+ }
+ /* Note fall through. */
+
+
+ /* The end of a simple repeat has a pop_failure_jump back to
+ its matching on_failure_jump, where the latter will push a
+ failure point. The pop_failure_jump takes off failure
+ points put on by this pop_failure_jump's matching
+ on_failure_jump; we got through the pattern to here from the
+ matching on_failure_jump, so didn't fail. */
+ case pop_failure_jump:
+ {
+ /* We need to pass separate storage for the lowest and
+ highest registers, even though we don't care about the
+ actual values. Otherwise, we will restore only one
+ register from the stack, since lowest will == highest in
+ `pop_failure_point'. */
+ unsigned dummy_low_reg, dummy_high_reg;
+ unsigned char *pdummy;
+ const char *sdummy;
+
+ DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
+ POP_FAILURE_POINT (sdummy, pdummy,
+ dummy_low_reg, dummy_high_reg,
+ reg_dummy, reg_dummy, reg_info_dummy);
+ }
+ /* Note fall through. */
+
+
+ /* Unconditionally jump (without popping any failure points). */
+ case jump:
+ unconditional_jump:
+ EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */
+ DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt);
+ p += mcnt; /* Do the jump. */
+ DEBUG_PRINT2 ("(to 0x%x).\n", p);
+ break;
+
+
+ /* We need this opcode so we can detect where alternatives end
+ in `group_match_null_string_p' et al. */
+ case jump_past_alt:
+ DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n");
+ goto unconditional_jump;
+
+
+ /* Normally, the on_failure_jump pushes a failure point, which
+ then gets popped at pop_failure_jump. We will end up at
+ pop_failure_jump, also, and with a pattern of, say, `a+', we
+ are skipping over the on_failure_jump, so we have to push
+ something meaningless for pop_failure_jump to pop. */
+ case dummy_failure_jump:
+ DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n");
+ /* It doesn't matter what we push for the string here. What
+ the code at `fail' tests is the value for the pattern. */
+ PUSH_FAILURE_POINT (0, 0, -2);
+ goto unconditional_jump;
+
+
+ /* At the end of an alternative, we need to push a dummy failure
+ point in case we are followed by a `pop_failure_jump', because
+ we don't want the failure point for the alternative to be
+ popped. For example, matching `(a|ab)*' against `aab'
+ requires that we match the `ab' alternative. */
+ case push_dummy_failure:
+ DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n");
+ /* See comments just above at `dummy_failure_jump' about the
+ two zeroes. */
+ PUSH_FAILURE_POINT (0, 0, -2);
+ break;
+
+ /* Have to succeed matching what follows at least n times.
+ After that, handle like `on_failure_jump'. */
+ case succeed_n:
+ EXTRACT_NUMBER (mcnt, p + 2);
+ DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt);
+
+ assert (mcnt >= 0);
+ /* Originally, this is how many times we HAVE to succeed. */
+ if (mcnt > 0)
+ {
+ mcnt--;
+ p += 2;
+ STORE_NUMBER_AND_INCR (p, mcnt);
+ DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt);
+ }
+ else if (mcnt == 0)
+ {
+ DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2);
+ p[2] = (unsigned char) no_op;
+ p[3] = (unsigned char) no_op;
+ goto on_failure;
+ }
+ break;
+
+ case jump_n:
+ EXTRACT_NUMBER (mcnt, p + 2);
+ DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt);
+
+ /* Originally, this is how many times we CAN jump. */
+ if (mcnt)
+ {
+ mcnt--;
+ STORE_NUMBER (p + 2, mcnt);
+ goto unconditional_jump;
+ }
+ /* If don't have to jump any more, skip over the rest of command. */
+ else
+ p += 4;
+ break;
+
+ case set_number_at:
+ {
+ DEBUG_PRINT1 ("EXECUTING set_number_at.\n");
+
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ p1 = p + mcnt;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt);
+ STORE_NUMBER (p1, mcnt);
+ break;
+ }
+
+ case wordbound:
+ DEBUG_PRINT1 ("EXECUTING wordbound.\n");
+ if (AT_WORD_BOUNDARY (d))
+ break;
+ goto fail;
+
+ case notwordbound:
+ DEBUG_PRINT1 ("EXECUTING notwordbound.\n");
+ if (AT_WORD_BOUNDARY (d))
+ goto fail;
+ break;
+
+ case wordbeg:
+ DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
+ if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1)))
+ break;
+ goto fail;
+
+ case wordend:
+ DEBUG_PRINT1 ("EXECUTING wordend.\n");
+ if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1)
+ && (!WORDCHAR_P (d) || AT_STRINGS_END (d)))
+ break;
+ goto fail;
+
+#ifdef emacs
+#ifdef emacs19
+ case before_dot:
+ DEBUG_PRINT1 ("EXECUTING before_dot.\n");
+ if (PTR_CHAR_POS ((unsigned char *) d) >= point)
+ goto fail;
+ break;
+
+ case at_dot:
+ DEBUG_PRINT1 ("EXECUTING at_dot.\n");
+ if (PTR_CHAR_POS ((unsigned char *) d) != point)
+ goto fail;
+ break;
+
+ case after_dot:
+ DEBUG_PRINT1 ("EXECUTING after_dot.\n");
+ if (PTR_CHAR_POS ((unsigned char *) d) <= point)
+ goto fail;
+ break;
+#else /* not emacs19 */
+ case at_dot:
+ DEBUG_PRINT1 ("EXECUTING at_dot.\n");
+ if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point)
+ goto fail;
+ break;
+#endif /* not emacs19 */
+
+ case syntaxspec:
+ DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt);
+ mcnt = *p++;
+ goto matchsyntax;
+
+ case wordchar:
+ DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n");
+ mcnt = (int) Sword;
+ matchsyntax:
+ PREFETCH ();
+ if (SYNTAX (*d++) != (enum syntaxcode) mcnt)
+ goto fail;
+ SET_REGS_MATCHED ();
+ break;
+
+ case notsyntaxspec:
+ DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt);
+ mcnt = *p++;
+ goto matchnotsyntax;
+
+ case notwordchar:
+ DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n");
+ mcnt = (int) Sword;
+ matchnotsyntax:
+ PREFETCH ();
+ if (SYNTAX (*d++) == (enum syntaxcode) mcnt)
+ goto fail;
+ SET_REGS_MATCHED ();
+ break;
+
+#else /* not emacs */
+ case wordchar:
+ DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n");
+ PREFETCH ();
+ if (!WORDCHAR_P (d))
+ goto fail;
+ SET_REGS_MATCHED ();
+ d++;
+ break;
+
+ case notwordchar:
+ DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n");
+ PREFETCH ();
+ if (WORDCHAR_P (d))
+ goto fail;
+ SET_REGS_MATCHED ();
+ d++;
+ break;
+#endif /* not emacs */
+
+ default:
+ abort ();
+ }
+ continue; /* Successfully executed one pattern command; keep going. */
+
+
+ /* We goto here if a matching operation fails. */
+ fail:
+ if (!FAIL_STACK_EMPTY ())
+ { /* A restart point is known. Restore to that state. */
+ DEBUG_PRINT1 ("\nFAIL:\n");
+ POP_FAILURE_POINT (d, p,
+ lowest_active_reg, highest_active_reg,
+ regstart, regend, reg_info);
+
+ /* If this failure point is a dummy, try the next one. */
+ if (!p)
+ goto fail;
+
+ /* If we failed to the end of the pattern, don't examine *p. */
+ assert (p <= pend);
+ if (p < pend)
+ {
+ boolean is_a_jump_n = false;
+
+ /* If failed to a backwards jump that's part of a repetition
+ loop, need to pop this failure point and use the next one. */
+ switch ((re_opcode_t) *p)
+ {
+ case jump_n:
+ is_a_jump_n = true;
+ case maybe_pop_jump:
+ case pop_failure_jump:
+ case jump:
+ p1 = p + 1;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ p1 += mcnt;
+
+ if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n)
+ || (!is_a_jump_n
+ && (re_opcode_t) *p1 == on_failure_jump))
+ goto fail;
+ break;
+ default:
+ /* do nothing */ ;
+ }
+ }
+
+ if (d >= string1 && d <= end1)
+ dend = end_match_1;
+ }
+ else
+ break; /* Matching at this starting point really fails. */
+ } /* for (;;) */
+
+ if (best_regs_set)
+ goto restore_best_regs;
+
+ FREE_VARIABLES ();
+
+ return -1; /* Failure to match. */
+} /* re_match_2 */
+
+/* Subroutine definitions for re_match_2. */
+
+
+/* We are passed P pointing to a register number after a start_memory.
+
+ Return true if the pattern up to the corresponding stop_memory can
+ match the empty string, and false otherwise.
+
+ If we find the matching stop_memory, sets P to point to one past its number.
+ Otherwise, sets P to an undefined byte less than or equal to END.
+
+ We don't handle duplicates properly (yet). */
+
+static boolean
+group_match_null_string_p (p, end, reg_info)
+ unsigned char **p, *end;
+ register_info_type *reg_info;
+{
+ int mcnt;
+ /* Point to after the args to the start_memory. */
+ unsigned char *p1 = *p + 2;
+
+ while (p1 < end)
+ {
+ /* Skip over opcodes that can match nothing, and return true or
+ false, as appropriate, when we get to one that can't, or to the
+ matching stop_memory. */
+
+ switch ((re_opcode_t) *p1)
+ {
+ /* Could be either a loop or a series of alternatives. */
+ case on_failure_jump:
+ p1++;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+
+ /* If the next operation is not a jump backwards in the
+ pattern. */
+
+ if (mcnt >= 0)
+ {
+ /* Go through the on_failure_jumps of the alternatives,
+ seeing if any of the alternatives cannot match nothing.
+ The last alternative starts with only a jump,
+ whereas the rest start with on_failure_jump and end
+ with a jump, e.g., here is the pattern for `a|b|c':
+
+ /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6
+ /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3
+ /exactn/1/c
+
+ So, we have to first go through the first (n-1)
+ alternatives and then deal with the last one separately. */
+
+
+ /* Deal with the first (n-1) alternatives, which start
+ with an on_failure_jump (see above) that jumps to right
+ past a jump_past_alt. */
+
+ while ((re_opcode_t) p1[mcnt-3] == jump_past_alt)
+ {
+ /* `mcnt' holds how many bytes long the alternative
+ is, including the ending `jump_past_alt' and
+ its number. */
+
+ if (!alt_match_null_string_p (p1, p1 + mcnt - 3,
+ reg_info))
+ return false;
+
+ /* Move to right after this alternative, including the
+ jump_past_alt. */
+ p1 += mcnt;
+
+ /* Break if it's the beginning of an n-th alternative
+ that doesn't begin with an on_failure_jump. */
+ if ((re_opcode_t) *p1 != on_failure_jump)
+ break;
+
+ /* Still have to check that it's not an n-th
+ alternative that starts with an on_failure_jump. */
+ p1++;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ if ((re_opcode_t) p1[mcnt-3] != jump_past_alt)
+ {
+ /* Get to the beginning of the n-th alternative. */
+ p1 -= 3;
+ break;
+ }
+ }
+
+ /* Deal with the last alternative: go back and get number
+ of the `jump_past_alt' just before it. `mcnt' contains
+ the length of the alternative. */
+ EXTRACT_NUMBER (mcnt, p1 - 2);
+
+ if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info))
+ return false;
+
+ p1 += mcnt; /* Get past the n-th alternative. */
+ } /* if mcnt > 0 */
+ break;
+
+
+ case stop_memory:
+ assert (p1[1] == **p);
+ *p = p1 + 2;
+ return true;
+
+
+ default:
+ if (!common_op_match_null_string_p (&p1, end, reg_info))
+ return false;
+ }
+ } /* while p1 < end */
+
+ return false;
+} /* group_match_null_string_p */
+
+
+/* Similar to group_match_null_string_p, but doesn't deal with alternatives:
+ It expects P to be the first byte of a single alternative and END one
+ byte past the last. The alternative can contain groups. */
+
+static boolean
+alt_match_null_string_p (p, end, reg_info)
+ unsigned char *p, *end;
+ register_info_type *reg_info;
+{
+ int mcnt;
+ unsigned char *p1 = p;
+
+ while (p1 < end)
+ {
+ /* Skip over opcodes that can match nothing, and break when we get
+ to one that can't. */
+
+ switch ((re_opcode_t) *p1)
+ {
+ /* It's a loop. */
+ case on_failure_jump:
+ p1++;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ p1 += mcnt;
+ break;
+
+ default:
+ if (!common_op_match_null_string_p (&p1, end, reg_info))
+ return false;
+ }
+ } /* while p1 < end */
+
+ return true;
+} /* alt_match_null_string_p */
+
+
+/* Deals with the ops common to group_match_null_string_p and
+ alt_match_null_string_p.
+
+ Sets P to one after the op and its arguments, if any. */
+
+static boolean
+common_op_match_null_string_p (p, end, reg_info)
+ unsigned char **p, *end;
+ register_info_type *reg_info;
+{
+ int mcnt;
+ boolean ret;
+ int reg_no;
+ unsigned char *p1 = *p;
+
+ switch ((re_opcode_t) *p1++)
+ {
+ case no_op:
+ case begline:
+ case endline:
+ case begbuf:
+ case endbuf:
+ case wordbeg:
+ case wordend:
+ case wordbound:
+ case notwordbound:
+#ifdef emacs
+ case before_dot:
+ case at_dot:
+ case after_dot:
+#endif
+ break;
+
+ case start_memory:
+ reg_no = *p1;
+ assert (reg_no > 0 && reg_no <= MAX_REGNUM);
+ ret = group_match_null_string_p (&p1, end, reg_info);
+
+ /* Have to set this here in case we're checking a group which
+ contains a group and a back reference to it. */
+
+ if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE)
+ REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret;
+
+ if (!ret)
+ return false;
+ break;
+
+ /* If this is an optimized succeed_n for zero times, make the jump. */
+ case jump:
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ if (mcnt >= 0)
+ p1 += mcnt;
+ else
+ return false;
+ break;
+
+ case succeed_n:
+ /* Get to the number of times to succeed. */
+ p1 += 2;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+
+ if (mcnt == 0)
+ {
+ p1 -= 4;
+ EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ p1 += mcnt;
+ }
+ else
+ return false;
+ break;
+
+ case duplicate:
+ if (!REG_MATCH_NULL_STRING_P (reg_info[*p1]))
+ return false;
+ break;
+
+ case set_number_at:
+ p1 += 4;
+
+ default:
+ /* All other opcodes mean we cannot match the empty string. */
+ return false;
+ }
+
+ *p = p1;
+ return true;
+} /* common_op_match_null_string_p */
+
+
+/* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN
+ bytes; nonzero otherwise. */
+
+static int
+bcmp_translate (s1, s2, len, translate)
+ unsigned char *s1, *s2;
+ register int len;
+ char *translate;
+{
+ register unsigned char *p1 = s1, *p2 = s2;
+ while (len)
+ {
+ if (translate[*p1++] != translate[*p2++]) return 1;
+ len--;
+ }
+ return 0;
+}
+
+/* Entry points for GNU code. */
+
+/* re_compile_pattern is the GNU regular expression compiler: it
+ compiles PATTERN (of length SIZE) and puts the result in BUFP.
+ Returns 0 if the pattern was valid, otherwise an error string.
+
+ Assumes the `allocated' (and perhaps `buffer') and `translate' fields
+ are set in BUFP on entry.
+
+ We call regex_compile to do the actual compilation. */
+
+const char *
+re_compile_pattern (pattern, length, bufp)
+ const char *pattern;
+ int length;
+ struct re_pattern_buffer *bufp;
+{
+ reg_errcode_t ret;
+
+ /* GNU code is written to assume at least RE_NREGS registers will be set
+ (and at least one extra will be -1). */
+ bufp->regs_allocated = REGS_UNALLOCATED;
+
+ /* And GNU code determines whether or not to get register information
+ by passing null for the REGS argument to re_match, etc., not by
+ setting no_sub. */
+ bufp->no_sub = 0;
+
+ /* Match anchors at newline. */
+ bufp->newline_anchor = 1;
+
+ ret = regex_compile (pattern, length, re_syntax_options, bufp);
+
+ return re_error_msg[(int) ret];
+}
+
+/* Entry points compatible with 4.2 BSD regex library. We don't define
+ them if this is an Emacs or POSIX compilation. */
+
+#if !defined (emacs) && !defined (_POSIX_SOURCE)
+
+/* BSD has one and only one pattern buffer. */
+static struct re_pattern_buffer re_comp_buf;
+
+char *
+re_comp (s)
+ const char *s;
+{
+ reg_errcode_t ret;
+
+ if (!s)
+ {
+ if (!re_comp_buf.buffer)
+ return "No previous regular expression";
+ return 0;
+ }
+
+ if (!re_comp_buf.buffer)
+ {
+ re_comp_buf.buffer = (unsigned char *) malloc (200);
+ if (re_comp_buf.buffer == NULL)
+ return "Memory exhausted";
+ re_comp_buf.allocated = 200;
+
+ re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
+ if (re_comp_buf.fastmap == NULL)
+ return "Memory exhausted";
+ }
+
+ /* Since `re_exec' always passes NULL for the `regs' argument, we
+ don't need to initialize the pattern buffer fields which affect it. */
+
+ /* Match anchors at newlines. */
+ re_comp_buf.newline_anchor = 1;
+
+ ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
+
+ /* Yes, we're discarding `const' here. */
+ return (char *) re_error_msg[(int) ret];
+}
+
+
+int
+re_exec (s)
+ const char *s;
+{
+ const int len = strlen (s);
+ return
+ 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
+}
+#endif /* not emacs and not _POSIX_SOURCE */
+
+/* POSIX.2 functions. Don't define these for Emacs. */
+
+#ifndef emacs
+
+/* regcomp takes a regular expression as a string and compiles it.
+
+ PREG is a regex_t *. We do not expect any fields to be initialized,
+ since POSIX says we shouldn't. Thus, we set
+
+ `buffer' to the compiled pattern;
+ `used' to the length of the compiled pattern;
+ `syntax' to RE_SYNTAX_POSIX_EXTENDED if the
+ REG_EXTENDED bit in CFLAGS is set; otherwise, to
+ RE_SYNTAX_POSIX_BASIC;
+ `newline_anchor' to REG_NEWLINE being set in CFLAGS;
+ `fastmap' and `fastmap_accurate' to zero;
+ `re_nsub' to the number of subexpressions in PATTERN.
+
+ PATTERN is the address of the pattern string.
+
+ CFLAGS is a series of bits which affect compilation.
+
+ If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
+ use POSIX basic syntax.
+
+ If REG_NEWLINE is set, then . and [^...] don't match newline.
+ Also, regexec will try a match beginning after every newline.
+
+ If REG_ICASE is set, then we considers upper- and lowercase
+ versions of letters to be equivalent when matching.
+
+ If REG_NOSUB is set, then when PREG is passed to regexec, that
+ routine will report only success or failure, and nothing about the
+ registers.
+
+ It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
+ the return codes and their meanings.) */
+
+int
+regcomp (preg, pattern, cflags)
+ regex_t *preg;
+ const char *pattern;
+ int cflags;
+{
+ reg_errcode_t ret;
+ unsigned syntax
+ = (cflags & REG_EXTENDED) ?
+ RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC;
+
+ /* regex_compile will allocate the space for the compiled pattern. */
+ preg->buffer = 0;
+ preg->allocated = 0;
+
+ /* Don't bother to use a fastmap when searching. This simplifies the
+ REG_NEWLINE case: if we used a fastmap, we'd have to put all the
+ characters after newlines into the fastmap. This way, we just try
+ every character. */
+ preg->fastmap = 0;
+
+ if (cflags & REG_ICASE)
+ {
+ unsigned i;
+
+ preg->translate = (char *) malloc (CHAR_SET_SIZE);
+ if (preg->translate == NULL)
+ return (int) REG_ESPACE;
+
+ /* Map uppercase characters to corresponding lowercase ones. */
+ for (i = 0; i < CHAR_SET_SIZE; i++)
+ preg->translate[i] = ISUPPER (i) ? tolower (i) : i;
+ }
+ else
+ preg->translate = NULL;
+
+ /* If REG_NEWLINE is set, newlines are treated differently. */
+ if (cflags & REG_NEWLINE)
+ { /* REG_NEWLINE implies neither . nor [^...] match newline. */
+ syntax &= ~RE_DOT_NEWLINE;
+ syntax |= RE_HAT_LISTS_NOT_NEWLINE;
+ /* It also changes the matching behavior. */
+ preg->newline_anchor = 1;
+ }
+ else
+ preg->newline_anchor = 0;
+
+ preg->no_sub = !!(cflags & REG_NOSUB);
+
+ /* POSIX says a null character in the pattern terminates it, so we
+ can use strlen here in compiling the pattern. */
+ ret = regex_compile (pattern, strlen (pattern), syntax, preg);
+
+ /* POSIX doesn't distinguish between an unmatched open-group and an
+ unmatched close-group: both are REG_EPAREN. */
+ if (ret == REG_ERPAREN) ret = REG_EPAREN;
+
+ return (int) ret;
+}
+
+
+/* regexec searches for a given pattern, specified by PREG, in the
+ string STRING.
+
+ If NMATCH is zero or REG_NOSUB was set in the cflags argument to
+ `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
+ least NMATCH elements, and we set them to the offsets of the
+ corresponding matched substrings.
+
+ EFLAGS specifies `execution flags' which affect matching: if
+ REG_NOTBOL is set, then ^ does not match at the beginning of the
+ string; if REG_NOTEOL is set, then $ does not match at the end.
+
+ We return 0 if we find a match and REG_NOMATCH if not. */
+
+int
+regexec (preg, string, nmatch, pmatch, eflags)
+ const regex_t *preg;
+ const char *string;
+ size_t nmatch;
+ regmatch_t pmatch[];
+ int eflags;
+{
+ int ret;
+ struct re_registers regs;
+ regex_t private_preg;
+ int len = strlen (string);
+ boolean want_reg_info = !preg->no_sub && nmatch > 0;
+
+ private_preg = *preg;
+
+ private_preg.not_bol = !!(eflags & REG_NOTBOL);
+ private_preg.not_eol = !!(eflags & REG_NOTEOL);
+
+ /* The user has told us exactly how many registers to return
+ information about, via `nmatch'. We have to pass that on to the
+ matching routines. */
+ private_preg.regs_allocated = REGS_FIXED;
+
+ if (want_reg_info)
+ {
+ regs.num_regs = nmatch;
+ regs.start = TALLOC (nmatch, regoff_t);
+ regs.end = TALLOC (nmatch, regoff_t);
+ if (regs.start == NULL || regs.end == NULL)
+ return (int) REG_NOMATCH;
+ }
+
+ /* Perform the searching operation. */
+ ret = re_search (&private_preg, string, len,
+ /* start: */ 0, /* range: */ len,
+ want_reg_info ? &regs : (struct re_registers *) 0);
+
+ /* Copy the register information to the POSIX structure. */
+ if (want_reg_info)
+ {
+ if (ret >= 0)
+ {
+ unsigned r;
+
+ for (r = 0; r < nmatch; r++)
+ {
+ pmatch[r].rm_so = regs.start[r];
+ pmatch[r].rm_eo = regs.end[r];
+ }
+ }
+
+ /* If we needed the temporary register info, free the space now. */
+ free (regs.start);
+ free (regs.end);
+ }
+
+ /* We want zero return to mean success, unlike `re_search'. */
+ return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
+}
+
+
+/* Returns a message corresponding to an error code, ERRCODE, returned
+ from either regcomp or regexec. We don't use PREG here. */
+
+size_t
+regerror (errcode, preg, errbuf, errbuf_size)
+ int errcode;
+ const regex_t *preg;
+ char *errbuf;
+ size_t errbuf_size;
+{
+ const char *msg;
+ size_t msg_size;
+
+ if (errcode < 0
+ || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0])))
+ /* Only error codes returned by the rest of the code should be passed
+ to this routine. If we are given anything else, or if other regex
+ code generates an invalid error code, then the program has a bug.
+ Dump core so we can fix it. */
+ abort ();
+
+ msg = re_error_msg[errcode];
+
+ /* POSIX doesn't require that we do anything in this case, but why
+ not be nice. */
+ if (! msg)
+ msg = "Success";
+
+ msg_size = strlen (msg) + 1; /* Includes the null. */
+
+ if (errbuf_size != 0)
+ {
+ if (msg_size > errbuf_size)
+ {
+ strncpy (errbuf, msg, errbuf_size - 1);
+ errbuf[errbuf_size - 1] = 0;
+ }
+ else
+ strcpy (errbuf, msg);
+ }
+
+ return msg_size;
+}
+
+
+/* Free dynamically allocated space used by PREG. */
+
+void
+regfree (preg)
+ regex_t *preg;
+{
+ if (preg->buffer != NULL)
+ free (preg->buffer);
+ preg->buffer = NULL;
+
+ preg->allocated = 0;
+ preg->used = 0;
+
+ if (preg->fastmap != NULL)
+ free (preg->fastmap);
+ preg->fastmap = NULL;
+ preg->fastmap_accurate = 0;
+
+ if (preg->translate != NULL)
+ free (preg->translate);
+ preg->translate = NULL;
+}
+
+#endif /* not emacs */
+
+/*
+Local variables:
+make-backup-files: t
+version-control: t
+trim-versions-without-asking: nil
+End:
+*/
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index 8d50808a..129ce968 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -1,7 +1,85 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
#include "common.h"
-#include <stdlib.h>
-#include <math.h>
+/******************************************************************************
+ * *
+ * Function: zbx_getseconds *
+ * *
+ * Purpose: Retrieves the number of seconds that have elapsed since the *
+ * system was started. *
+ * *
+ * Parameters: *
+ * *
+ * Return value: Number of seconds *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ ******************************************************************************/
+double zbx_getseconds(void)
+{
+#ifdef WIN32
+
+ return ((double)GetTickCount()) / ((double)1000);
+
+#else /* not WIN32 */
+# if !defined (CLOCKS_PER_SEC) || (CLOCKS_PER_SEC == 0)
+# define CLOCKS_PER_SEC 100000
+# endif /* CLOCKS_PER_SEC */
+
+ return ((double)clock())/((double)CLOCKS_PER_SEC);
+
+#endif /* WIN32 */
+
+ return -1;
+}
+
+/******************************************************************************
+ * *
+ * Function: zbx_setproctitle *
+ * *
+ * Purpose: set process title *
+ * *
+ * Parameters: title - item's refresh rate in sec *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ ******************************************************************************/
+void zbx_setproctitle(const char *fmt, ...)
+{
+#ifdef HAVE_FUNCTION_SETPROCTITLE
+
+ char title[MAX_STRING_LEN];
+
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(title, MAX_STRING_LEN-1, fmt, args);
+ va_end(args);
+
+ setproctitle(title);
+
+#endif /* HAVE_FUNCTION_SETPROCTITLE */
+}
/******************************************************************************
* *
diff --git a/src/libs/zbxcommon/regexp.c b/src/libs/zbxcommon/regexp.c
index b7cec219..d8cd9b1a 100644
--- a/src/libs/zbxcommon/regexp.c
+++ b/src/libs/zbxcommon/regexp.c
@@ -1,17 +1,33 @@
-#include "config.h"
-
-#include <stdio.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include <sys/types.h>
-#include <regex.h>
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+
+#if defined(WIN32)
+# include "gnuregex.h"
+#endif /* WIN32 */
char *zbx_regexp_match(const char *string, const char *pattern, int *len)
-{
+{
+ char *c = NULL;
+
int status;
- char *c;
regex_t re;
regmatch_t match;
@@ -42,15 +58,3 @@ char *zbx_regexp_match(const char *string, const char *pattern, int *len)
return c;
}
-/*#define ZABBIX_TEST*/
-
-#ifdef ZABBIX_TEST
-int main()
-{
- int len=2;
- char s[1024];
-
- printf("[%s]\n", zbx_regexp_match("ABCDEFGH","^F",&len));
- printf("[%d]\n", len);
-}
-#endif
diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c
index dc0c3ffd..ddb99dc8 100644
--- a/src/libs/zbxcommon/str.c
+++ b/src/libs/zbxcommon/str.c
@@ -1,9 +1,24 @@
-#include "common.h"
-
-#include <string.h>
-#include <stdlib.h>
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
#include "common.h"
+#include "threads.h"
/******************************************************************************
* *
@@ -73,7 +88,9 @@ void help()
char **p = help_message;
app_title();
+ printf("\n");
usage();
+ printf("\n");
while (*p) printf("%s\n", *p++);
}
@@ -91,7 +108,7 @@ void help()
* *
* Author: Eugene Grigorjev *
* *
- * Comments: !!! beter use system functions like 'strchr' !!! *
+ * Comments: !!! beter use system functions like 'strchr' !!! *
* *
******************************************************************************/
int find_char(char *str,char c)
@@ -103,6 +120,79 @@ int find_char(char *str,char c)
return FAIL;
}
+/******************************************************************************
+ * *
+ * Function: zbx_error *
+ * *
+ * Purpose: Print error text to the stderr *
+ * *
+ * Parameters: fmt - format of mesage *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ ******************************************************************************/
+//#define ZBX_STDERR_FILE "zbx_errors.log"
+
+void zbx_error(const char *fmt, ...)
+{
+ va_list args;
+ FILE *f = NULL;
+
+#if defined(ZBX_STDERR_FILE)
+ f = fopen(ZBX_STDERR_FILE,"a+");
+#else
+ f = stderr;
+#endif /* ZBX_STDERR_FILE */
+
+ va_start(args, fmt);
+
+ fprintf(f, "%s [%li]: ",progname, zbx_get_thread_id());
+ vfprintf(f, fmt, args);
+ fprintf(f, "\n");
+ fflush(f);
+
+ va_end(args);
+
+#if defined(ZBX_STDERR_FILE)
+ zbx_fclose(f);
+#endif /* ZBX_STDERR_FILE */
+}
+
+/******************************************************************************
+ * *
+ * Function: zbx_snprintf *
+ * *
+ * Purpose: Sequrity version of snprintf function. *
+ * Add zero character at the end of string. *
+ * *
+ * Parameters: str - distination buffer poiner *
+ * count - size of distination buffer *
+ * fmt - format *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ ******************************************************************************/
+void zbx_snprintf(char* str, size_t count, const char *fmt, ...)
+{
+ va_list args;
+ int writen_len = 0;
+
+ assert(str);
+
+ va_start(args, fmt);
+
+ writen_len = vsnprintf(str, count, fmt, args);
+ writen_len = MIN(writen_len, ((int)count) - 1);
+ writen_len = MAX(writen_len, 0);
+
+ str[writen_len] = '\0';
+
+ va_end(args);
+}
/* Has to be rewritten to avoi malloc */
char *string_replace(char *str, const char *sub_str1, const char *sub_str2)
@@ -116,6 +206,8 @@ char *string_replace(char *str, const char *sub_str1, const char *sub_str2)
signed long diff;
unsigned long count = 0;
+ assert(str);
+
if ( (p=strstr(str, sub_str1)) == NULL )
return str;
++count;
diff --git a/src/libs/zbxcommon/xml.c b/src/libs/zbxcommon/xml.c
index 19024c00..f6938dd2 100644
--- a/src/libs/zbxcommon/xml.c
+++ b/src/libs/zbxcommon/xml.c
@@ -1,9 +1,25 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
#include "common.h"
#include "log.h"
-#include <stdio.h>
-#include <string.h>
-
/* Get DATA from <tag>DATA</tag> */
int xml_get_data(char *xml,char *tag, char *data, int maxlen)
{
@@ -13,8 +29,8 @@ int xml_get_data(char *xml,char *tag, char *data, int maxlen)
char tag_close[MAX_STRING_LEN];
int len;
- snprintf(tag_open,MAX_STRING_LEN-1,"<%s>",tag);
- snprintf(tag_close,MAX_STRING_LEN-1,"</%s>",tag);
+ zbx_snprintf(tag_open, sizeof(tag_open),"<%s>",tag);
+ zbx_snprintf(tag_close, sizeof(tag_close),"</%s>",tag);
if(NULL==(start=strstr(xml,tag_open)))
{
diff --git a/src/libs/zbxcommon/zbxgetopt.c b/src/libs/zbxcommon/zbxgetopt.c
new file mode 100755
index 00000000..2b202fb5
--- /dev/null
+++ b/src/libs/zbxcommon/zbxgetopt.c
@@ -0,0 +1,676 @@
+/* Getopt for GNU.
+ NOTE: getopt is now part of the C library, so if you don't know what
+ "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
+ before changing it!
+
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
+ Free Software Foundation, Inc.
+
+ 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, or (at your zbx_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, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+
+#include "common.h"
+
+
+/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
+ long-named zbx_option. Because this is not POSIX.2 compliant, it is
+ being phased out. */
+/* #define GETOPT_COMPAT */
+#undef GETOPT_COMPAT
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+ but it behaves differently for the user, since it allows the user
+ to intersperse the options with the other arguments.
+
+ As `getopt' works, it permutes the elements of ARGV so that,
+ when it is done, all the options precede everything else. Thus
+ all application programs are extended to handle flexible argument order.
+
+ Setting the environment variable POSIXLY_CORRECT disables permutation.
+ Then the behavior is completely standard.
+
+ GNU application programs can use a third alternative mode in which
+ they can distinguish the relative order of options and other arguments. */
+
+#include "zbxgetopt.h"
+
+#undef BAD_OPTION
+
+/* For communication from `getopt' to the caller.
+ When `getopt' finds an zbx_option that takes an argument,
+ the argument value is returned here.
+ Also, when `ordering' is RETURN_IN_ORDER,
+ each non-zbx_option ARGV-element is returned here. */
+
+char *zbx_optarg = NULL;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to `getopt'.
+
+ On entry to `getopt', zero means this is the first call; initialize.
+
+ When `getopt' returns EOF, this is the index of the first of the
+ non-zbx_option elements that the caller should itself scan.
+
+ Otherwise, `zbx_optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+/* XXX 1003.2 says this must be 1 before any call. */
+int zbx_optind = 0;
+
+/* The next char to be scanned in the zbx_option-element
+ in which the last zbx_option character we returned was found.
+ This allows us to pick up the scan where we left off.
+
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+
+static char *nextchar;
+
+/* Callers store zero here to inhibit the error message
+ for unrecognized options. */
+
+int zbx_opterr = 1;
+
+/* Set to an zbx_option character which was unrecognized.
+ This must be initialized on some systems to avoid linking in the
+ system's own getopt implementation. */
+
+#define BAD_OPTION '\0'
+int zbx_optopt = BAD_OPTION;
+
+/* Describe how to deal with options that follow non-zbx_option ARGV-elements.
+
+ If the caller did not specify anything,
+ the default is REQUIRE_ORDER if the environment variable
+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options;
+ stop zbx_option processing when the first non-zbx_option is seen.
+ This is what Unix does.
+ This mode of operation is selected by either setting the environment
+ variable POSIXLY_CORRECT, or using `+' as the first character
+ of the list of zbx_option characters.
+
+ PERMUTE is the default. We permute the contents of ARGV as we scan,
+ so that eventually all the non-options are at the end. This allows options
+ to be given in any order, even with programs that were not written to
+ expect this.
+
+ RETURN_IN_ORDER is an zbx_option available to programs that were written
+ to expect options and other ARGV-elements in any order and that care about
+ the ordering of the two. We describe each non-zbx_option ARGV-element
+ as if it were the argument of an zbx_option with character code 1.
+ Using `-' as the first character of the list of zbx_option characters
+ selects this mode of operation.
+
+ The special argument `--' forces an end of zbx_option-scanning regardless
+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
+ `--' can cause `getopt' to return EOF with `zbx_optind' != ARGC. */
+
+static enum
+{
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+} ordering;
+
+/* Handle permutation of arguments. */
+
+/* Describe the part of ARGV that contains non-options that have
+ been skipped. `first_nonopt' is the index in ARGV of the first of them;
+ `last_nonopt' is the index after the last of them. */
+
+static int first_nonopt;
+static int last_nonopt;
+
+/* Exchange two adjacent subsequences of ARGV.
+ One subsequence is elements [first_nonopt,last_nonopt)
+ which contains all the non-options that have been skipped so far.
+ The other is elements [last_nonopt,zbx_optind), which contains all
+ the options processed since those non-options were skipped.
+
+ `first_nonopt' and `last_nonopt' are relocated so that they describe
+ the new indices of the non-options in ARGV after they are moved.
+
+ To perform the swap, we first reverse the order of all elements. So
+ all options now come before all non options, but they are in the
+ wrong order. So we put back the options and non options in original
+ order by reversing them again. For example:
+ original input: a b c -x -y
+ reverse all: -y -x c b a
+ reverse options: -x -y c b a
+ reverse non options: -x -y a b c
+*/
+
+
+static void exchange (char **argv)
+{
+ char *temp; char **first, **last;
+
+ /* Reverse all the elements [first_nonopt, zbx_optind) */
+ first = &argv[first_nonopt];
+ last = &argv[zbx_optind-1];
+ while (first < last) {
+ temp = *first; *first = *last; *last = temp; first++; last--;
+ }
+ /* Put back the options in order */
+ first = &argv[first_nonopt];
+ first_nonopt += (zbx_optind - last_nonopt);
+ last = &argv[first_nonopt - 1];
+ while (first < last) {
+ temp = *first; *first = *last; *last = temp; first++; last--;
+ }
+
+ /* Put back the non options in order */
+ first = &argv[first_nonopt];
+ last_nonopt = zbx_optind;
+ last = &argv[last_nonopt-1];
+ while (first < last) {
+ temp = *first; *first = *last; *last = temp; first++; last--;
+ }
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for zbx_option characters
+ given in OPTSTRING.
+
+ If an element of ARGV starts with '-', and is not exactly "-" or "--",
+ then it is an zbx_option element. The characters of this element
+ (aside from the initial '-') are zbx_option characters. If `getopt'
+ is called repeatedly, it returns successively each of the zbx_option characters
+ from each of the zbx_option elements.
+
+ If `getopt' finds another zbx_option character, it returns that character,
+ updating `zbx_optind' and `nextchar' so that the next call to `getopt' can
+ resume the scan with the following zbx_option character or ARGV-element.
+
+ If there are no more zbx_option characters, `getopt' returns `EOF'.
+ Then `zbx_optind' is the index in ARGV of the first ARGV-element
+ that is not an zbx_option. (The ARGV-elements have been permuted
+ so that those that are not options now come last.)
+
+ OPTSTRING is a string containing the legitimate zbx_option characters.
+ If an zbx_option character is seen that is not listed in OPTSTRING,
+ return BAD_OPTION after printing an error message. If you set `zbx_opterr' to
+ zero, the error message is suppressed but we still return BAD_OPTION.
+
+ If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+ so the following text in the same ARGV-element, or the text of the following
+ ARGV-element, is returned in `zbx_optarg'. Two colons mean an zbx_option that
+ wants an optional arg; if there is text in the current ARGV-element,
+ it is returned in `zbx_optarg', otherwise `zbx_optarg' is set to zero.
+
+ If OPTSTRING starts with `-' or `+', it requests different methods of
+ handling the non-zbx_option ARGV-elements.
+ See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+
+ Long-named options begin with `--' instead of `-'.
+ Their names may be abbreviated as long as the abbreviation is unique
+ or is an exact match for some defined zbx_option. If they have an
+ argument, it follows the zbx_option name in the same ARGV-element, separated
+ from the zbx_option name by a `=', or else the in next ARGV-element.
+ When `getopt' finds a long-named zbx_option, it returns 0 if that zbx_option's
+ `flag' field is nonzero, the value of the zbx_option's `val' field
+ if the `flag' field is zero.
+
+ LONGOPTS is a vector of `struct zbx_option' terminated by an
+ element containing a name which is zero.
+
+ LONGIND returns the index in LONGOPT of the long-named zbx_option found.
+ It is only valid when a long-named zbx_option has been found by the most
+ recent call.
+
+ If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+ long-named options. */
+
+static int _getopt_internal (int argc, char **argv, const char *optstring,
+ const struct zbx_option *longopts, int *longind,
+ int long_only)
+{
+ static char empty_string[1];
+ int option_index;
+
+ if (longind != NULL)
+ *longind = -1;
+
+ zbx_optarg = 0;
+
+ /* Initialize the internal data when the first call is made.
+ Start processing options with ARGV-element 1 (since ARGV-element 0
+ is the program name); the sequence of previously skipped
+ non-zbx_option ARGV-elements is empty. */
+
+ if (zbx_optind == 0)
+ {
+ first_nonopt = last_nonopt = zbx_optind = 1;
+
+ nextchar = NULL;
+
+ /* Determine how to handle the ordering of options and nonoptions. */
+
+ if (optstring[0] == '-')
+ {
+ ordering = RETURN_IN_ORDER;
+ ++optstring;
+ }
+ else if (optstring[0] == '+')
+ {
+ ordering = REQUIRE_ORDER;
+ ++optstring;
+ }
+#if 0
+ else if (getenv ("POSIXLY_CORRECT") != NULL)
+ ordering = REQUIRE_ORDER;
+#endif
+ else
+ ordering = PERMUTE;
+ }
+
+ if (nextchar == NULL || *nextchar == '\0')
+ {
+ if (ordering == PERMUTE)
+ {
+ /* If we have just processed some options following some non-options,
+ exchange them so that the options come first. */
+
+ if (first_nonopt != last_nonopt && last_nonopt != zbx_optind)
+ exchange (argv);
+ else if (last_nonopt != zbx_optind)
+ first_nonopt = zbx_optind;
+
+ /* Now skip any additional non-options
+ and extend the range of non-options previously skipped. */
+
+ while (zbx_optind < argc
+ && (argv[zbx_optind][0] != '-' || argv[zbx_optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+ && (longopts == NULL
+ || argv[zbx_optind][0] != '+' || argv[zbx_optind][1] == '\0')
+#endif /* GETOPT_COMPAT */
+ )
+ zbx_optind++;
+ last_nonopt = zbx_optind;
+ }
+
+ /* Special ARGV-element `--' means premature end of options.
+ Skip it like a null zbx_option,
+ then exchange with previous non-options as if it were an zbx_option,
+ then skip everything else like a non-zbx_option. */
+
+ if (zbx_optind != argc && !strcmp (argv[zbx_optind], "--"))
+ {
+ zbx_optind++;
+
+ if (first_nonopt != last_nonopt && last_nonopt != zbx_optind)
+ exchange (argv);
+ else if (first_nonopt == last_nonopt)
+ first_nonopt = zbx_optind;
+ last_nonopt = argc;
+
+ zbx_optind = argc;
+ }
+
+ /* If we have done all the ARGV-elements, stop the scan
+ and back over any non-options that we skipped and permuted. */
+
+ if (zbx_optind == argc)
+ {
+ /* Set the next-arg-index to point at the non-options
+ that we previously skipped, so the caller will digest them. */
+ if (first_nonopt != last_nonopt)
+ zbx_optind = first_nonopt;
+ return EOF;
+ }
+
+ /* If we have come to a non-zbx_option and did not permute it,
+ either stop the scan or describe it to the caller and pass it by. */
+
+ if ((argv[zbx_optind][0] != '-' || argv[zbx_optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+ && (longopts == NULL
+ || argv[zbx_optind][0] != '+' || argv[zbx_optind][1] == '\0')
+#endif /* GETOPT_COMPAT */
+ )
+ {
+ if (ordering == REQUIRE_ORDER)
+ return EOF;
+ zbx_optarg = argv[zbx_optind++];
+ return 1;
+ }
+
+ /* We have found another zbx_option-ARGV-element.
+ Start decoding its characters. */
+
+ nextchar = (argv[zbx_optind] + 1
+ + (longopts != NULL && argv[zbx_optind][1] == '-'));
+ }
+
+ if (longopts != NULL
+ && ((argv[zbx_optind][0] == '-'
+ && (argv[zbx_optind][1] == '-' || long_only))
+#ifdef GETOPT_COMPAT
+ || argv[zbx_optind][0] == '+'
+#endif /* GETOPT_COMPAT */
+ ))
+ {
+ const struct zbx_option *p;
+ char *s = nextchar;
+ int exact = 0;
+ int ambig = 0;
+ const struct zbx_option *pfound = NULL;
+ int indfound = 0;
+ int needexact = 0;
+
+#if 1
+ /* allow `--zbx_option#value' because you cannout assign a '='
+ to an environment variable under DOS command.com */
+ while (*s && *s != '=' && * s != '#')
+ s++;
+#else
+ while (*s && *s != '=')
+ s++;
+#endif
+
+ /* Test all options for either exact match or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name;
+ p++, option_index++)
+ if (!strncmp (p->name, nextchar, (unsigned) (s - nextchar)))
+ {
+ if (p->has_arg & 0x10)
+ needexact = 1;
+ if ((unsigned) (s - nextchar) == strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second nonexact match found. */
+ ambig = 1;
+ }
+
+ /* don't allow nonexact longoptions */
+ if (needexact && !exact)
+ {
+ if (zbx_opterr)
+ zbx_error("unrecognized zbx_option `%s'", argv[zbx_optind]);
+
+ nextchar += strlen (nextchar);
+ zbx_optind++;
+ return BAD_OPTION;
+ }
+ if (ambig && !exact)
+ {
+ if (zbx_opterr)
+ zbx_error("zbx_option `%s' is ambiguous", argv[zbx_optind]);
+
+ nextchar += strlen (nextchar);
+ zbx_optind++;
+ return BAD_OPTION;
+ }
+
+ if (pfound != NULL)
+ {
+ int have_arg = (s[0] != '\0');
+ if (have_arg && (pfound->has_arg & 0xf))
+ have_arg = (s[1] != '\0');
+ option_index = indfound;
+ zbx_optind++;
+ if (have_arg)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg & 0xf)
+ zbx_optarg = s + 1;
+ else
+ {
+ if (zbx_opterr)
+ {
+ if (argv[zbx_optind - 1][1] == '-')
+ /* --zbx_option */
+ zbx_error("zbx_option `--%s' doesn't allow an argument",pfound->name);
+ else
+ /* +zbx_option or -zbx_option */
+ zbx_error("zbx_option `%c%s' doesn't allow an argument", argv[zbx_optind - 1][0], pfound->name);
+ }
+ nextchar += strlen (nextchar);
+ return BAD_OPTION;
+ }
+ }
+ else if ((pfound->has_arg & 0xf) == 1)
+ {
+#if 0
+ if (zbx_optind < argc)
+#else
+ if (zbx_optind < argc && (pfound->has_arg & 0x20) == 0)
+#endif
+ zbx_optarg = argv[zbx_optind++];
+ else
+ {
+ if (zbx_opterr)
+ zbx_error("zbx_option `--%s%s' requires an argument",
+ pfound->name, (pfound->has_arg & 0x20) ? "=" : "");
+ nextchar += strlen (nextchar);
+ return optstring[0] == ':' ? ':' : BAD_OPTION;
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+ /* Can't find it as a long zbx_option. If this is not getopt_long_only,
+ or the zbx_option starts with '--' or is not a valid short
+ zbx_option, then it's an error.
+ Otherwise interpret it as a short zbx_option. */
+ if (!long_only || argv[zbx_optind][1] == '-'
+#ifdef GETOPT_COMPAT
+ || argv[zbx_optind][0] == '+'
+#endif /* GETOPT_COMPAT */
+ || strchr (optstring, *nextchar) == NULL)
+ {
+ if (zbx_opterr)
+ {
+ if (argv[zbx_optind][1] == '-')
+ /* --zbx_option */
+ zbx_error("unrecognized zbx_option `--%s'", nextchar);
+ else
+ /* +zbx_option or -zbx_option */
+ zbx_error("unrecognized zbx_option `%c%s'", argv[zbx_optind][0], nextchar);
+ }
+ nextchar = empty_string;
+ zbx_optind++;
+ return BAD_OPTION;
+ }
+ (void) &ambig; /* UNUSED */
+ }
+
+ /* Look at and handle the next zbx_option-character. */
+
+ {
+ char c = *nextchar++;
+ const char *temp = strchr (optstring, c);
+
+ /* Increment `zbx_optind' when we start to process its last character. */
+ if (*nextchar == '\0')
+ ++zbx_optind;
+
+ if (temp == NULL || c == ':')
+ {
+ if (zbx_opterr)
+ {
+#if 0
+ if (c < 040 || c >= 0177)
+ zbx_error("unrecognized zbx_option, character code 0%o", c);
+ else
+ zbx_error("unrecognized zbx_option `-%c'", c);
+#else
+ /* 1003.2 specifies the format of this message. */
+ zbx_error("illegal zbx_option -- %c", c);
+#endif
+ }
+ zbx_optopt = c;
+ return BAD_OPTION;
+ }
+ if (temp[1] == ':')
+ {
+ if (temp[2] == ':')
+ {
+ /* This is an zbx_option that accepts an argument optionally. */
+ if (*nextchar != '\0')
+ {
+ zbx_optarg = nextchar;
+ zbx_optind++;
+ }
+ else
+ zbx_optarg = 0;
+ nextchar = NULL;
+ }
+ else
+ {
+ /* This is an zbx_option that requires an argument. */
+ if (*nextchar != '\0')
+ {
+ zbx_optarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ zbx_optind++;
+ }
+ else if (zbx_optind == argc)
+ {
+ if (zbx_opterr)
+ {
+#if 0
+ zbx_error("zbx_option `-%c' requires an argument", c);
+#else
+ /* 1003.2 specifies the format of this message. */
+ zbx_error("zbx_option requires an argument -- %c", c);
+#endif
+ }
+ zbx_optopt = c;
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = BAD_OPTION;
+ }
+ else
+ /* We already incremented `zbx_optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ zbx_optarg = argv[zbx_optind++];
+ nextchar = NULL;
+ }
+ }
+ return c;
+ }
+}
+
+int zbx_getopt(int argc, char **argv, const char *optstring)
+{
+ return _getopt_internal (argc, argv, optstring,
+ (const struct zbx_option *) 0,
+ (int *) 0,
+ 0);
+}
+
+int zbx_getopt_long(int argc, char **argv, const char *options,
+ const struct zbx_option *long_options, int *opt_index)
+{
+ return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+}
+
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+ the above definition of `getopt'. */
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = zbx_optind ? zbx_optind : 1;
+
+ c = getopt (argc, argv, "abc:d:0123456789");
+ if (c == EOF)
+ break;
+
+ switch (c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("zbx_option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("zbx_option a\n");
+ break;
+
+ case 'b':
+ printf ("zbx_option b\n");
+ break;
+
+ case 'c':
+ printf ("zbx_option c with value `%s'\n", zbx_optarg);
+ break;
+
+ case BAD_OPTION:
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (zbx_optind < argc)
+ {
+ printf ("non-zbx_option ARGV-elements: ");
+ while (zbx_optind < argc)
+ printf ("%s ", argv[zbx_optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/src/libs/zbxconf/cfg.c b/src/libs/zbxconf/cfg.c
index ef75246e..c7d7628c 100644
--- a/src/libs/zbxconf/cfg.c
+++ b/src/libs/zbxconf/cfg.c
@@ -17,13 +17,18 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include "common.h"
#include "cfg.h"
+#include "log.h"
+
+
+int CONFIG_ZABBIX_FORKS = ZABBIX_FORKS;
+char *CONFIG_FILE = NULL;
+
+
+char *CONFIG_LOG_FILE = NULL;
+char CONFIG_ALLOW_ROOT_PERMISSION = 0;
+int CONFIG_TIMEOUT = AGENT_TIMEOUT;
/******************************************************************************
* *
@@ -38,6 +43,7 @@
* FAIL - error processing config file *
* *
* Author: Alexei Vladishev *
+ * Eugene Grigorjev *
* *
* Comments: *
* *
@@ -45,116 +51,105 @@
int parse_cfg_file(char *cfg_file,struct cfg_line *cfg)
{
FILE *file;
- char line[MAX_STRING_LEN];
- char parameter[MAX_STRING_LEN];
- char *value;
int lineno;
- int i,var;
- char **c;
- int (*func)();
+ char line[MAX_STRING_LEN];
+ char *parameter;
+ char *value;
+ int i,var;
- file=fopen(cfg_file,"r");
- if(NULL == file)
+ if(NULL == (file = fopen(cfg_file,"r")))
{
- fprintf(stderr, "Cannot open config file [%s] [%s]\n",cfg_file,strerror(errno));
+ zbx_error("Cannot open config file [%s] [%s].",cfg_file,strerror(errno));
return FAIL;
}
- lineno=0;
- while(fgets(line,MAX_STRING_LEN,file) != NULL)
+
+ for(lineno = 1; fgets(line,MAX_STRING_LEN,file) != NULL; lineno++)
{
- lineno++;
-
if(line[0]=='#') continue;
- if(strlen(line)==1) continue;
-
- strscpy(parameter,line);
+ if(strlen(line) < 3) continue;
- value=strstr(line,"=");
+ parameter = line;
+ value = strstr(line,"=");
if(NULL == value)
{
- fprintf(stderr, "Error in line [%s] Line %d\n", line, lineno);
+ zbx_error("Error in line [%d] \"%s\"", lineno, line);
return FAIL;
}
- value++;
- value[strlen(value)-1]=0;
- parameter[value-line-1]=0;
+ *value = '\0';
+ value++;
- i=0;
- while(cfg[i].parameter != 0)
+ for(i = 0; value[i] != '\0'; i++)
{
- if(strcmp(cfg[i].parameter, parameter) == 0)
+ if(value[i] == '\n')
{
- if(cfg[i].function != 0)
- {
- func=cfg[i].function;
- if(func(value)!=SUCCEED)
- {
- fprintf(stderr, "Wrong value of [%s] in line %d.\n", cfg[i].parameter, lineno);
- return FAIL;
- }
- }
- else
- {
- if(cfg[i].type == TYPE_INT)
- {
- var=atoi(value);
- if( (cfg[i].min!=0) || (cfg[i].max!=0))
- {
- if( (var<cfg[i].min) || (var>cfg[i].max) )
- {
- fprintf(stderr, "Wrong value of [%s] in line %d. Should be between %d and %d.\n", cfg[i].parameter, lineno, cfg[i].min, cfg[i].max);
- return FAIL;
- }
-
- }
- *((int*)cfg[i].variable)=var;
- }
- else
- {
-/* Can this be done without "c" ? */
- c=(char **)cfg[i].variable;
- *c=(char *)strdup(value);
-/* *((char*)cfg[i].variable)=strdup(value);*/
- }
- }
+ value[i] = '\0';
+ break;
}
- i++;
}
- }
-/* Check for mandatory parameters */
- i=0;
- while(cfg[i].parameter != 0)
- {
- if(cfg[i].mandatory ==1)
+ for(i = 0; cfg[i].parameter != 0; i++)
{
- if(cfg[i].type == TYPE_INT)
+ if(strcmp(cfg[i].parameter, parameter))
+ continue;
+
+ zbx_error("Accepted configuration parameter: '%s' = '%s'",parameter, value);
+
+ if(cfg[i].function != 0)
{
-/* pointer=(int *)cfg[i].variable;
- if(*pointer==0)*/
- if(*((int*)cfg[i].variable) == 0)
- {
- fprintf(stderr,"Missing mandatory parameter [%s]\n", cfg[i].parameter);
- return FAIL;
- }
+ if(cfg[i].function(value) != SUCCEED)
+ goto lbl_incorrect_config;
}
- if(cfg[i].type == TYPE_STRING)
+ else if(TYPE_INT == cfg[i].type)
{
- c=(char **)cfg[i].variable;
- if(*c==NULL)
- {
- fprintf(stderr, "Missing mandatory parameter [%s]\n", cfg[i].parameter);
- return FAIL;
- }
+ var = atoi(value);
+
+ if(cfg[i].min)
+ if(var < cfg[i].min)
+ goto lbl_incorrect_config;
+
+ if(cfg[i].max)
+ if(var > cfg[i].max)
+ goto lbl_incorrect_config;
+
+ *((int*)cfg[i].variable) = var;
+ }
+ else
+ {
+ *((char **)cfg[i].variable) = strdup(value);
}
}
- i++;
+ }
+
+ /* Check for mandatory parameters */
+ for(i = 0; cfg[i].parameter != 0; i++)
+ {
+ if(!cfg[i].mandatory)
+ continue;
+
+ if(TYPE_INT == cfg[i].type)
+ {
+ if(*((int*)cfg[i].variable) == 0)
+ goto lbl_missing_mandatory;
+ }
+ else if(TYPE_STRING == cfg[i].type)
+ {
+ if((*(char **)cfg[i].variable) == NULL)
+ goto lbl_missing_mandatory;
+ }
}
return SUCCEED;
+
+lbl_missing_mandatory:
+ zbx_error("Missing mandatory parameter [%s].", cfg[i].parameter);
+ return FAIL;
+
+lbl_incorrect_config:
+ zbx_error("Wrong value of [%s] in line %d.", cfg[i].parameter, lineno);
+ return FAIL;
}
diff --git a/src/libs/zbxcrypto/Makefile.am b/src/libs/zbxcrypto/Makefile.am
index e9981ea9..3ff84e2a 100644
--- a/src/libs/zbxcrypto/Makefile.am
+++ b/src/libs/zbxcrypto/Makefile.am
@@ -1,3 +1,3 @@
SUBDIRS=
+libzbxcrypto_a_SOURCES=md5.c base64.c
lib_LIBRARIES=libzbxcrypto.a
-libzbxcrypto_a_SOURCES=md5.c
diff --git a/src/libs/zbxcrypto/base64.c b/src/libs/zbxcrypto/base64.c
new file mode 100644
index 00000000..c19fc7fc
--- /dev/null
+++ b/src/libs/zbxcrypto/base64.c
@@ -0,0 +1,274 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "base64.h"
+
+#define MAX_B64_SIZE 16*1024
+
+static char base64_set [] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static char char_base64_encode(unsigned char uc);
+static unsigned char char_base64_decode(char c);
+static int is_base64 (char c);
+
+/*------------------------------------------------------------------------
+ *
+ * Function : is_base64
+ *
+ * Purpose : Is the character passed in a base64 character ?
+ *
+ * Parameters :
+ *
+ * Returns :
+ *
+ * Comments :
+ *
+ *----------------------------------------------------------------------*/
+static int is_base64 (char c)
+{
+ if ( (c >= '0' && c <= '9')
+ || (c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || c == '/'
+ || c == '+'
+ || c == '=' )
+
+ {
+ return 1;
+ }
+
+ return 0;
+}
+/*------------------------------------------------------------------------
+ *
+ * Function : char_base64_encode
+ *
+ * Purpose : Encode a byte into a base64 character
+ *
+ * Parameters :
+ *
+ * Returns :
+ *
+ * Comments :
+ *
+ *----------------------------------------------------------------------*/
+static char char_base64_encode(unsigned char uc)
+{
+ return base64_set[uc];
+}
+
+/*------------------------------------------------------------------------
+ *
+ * Function : char_base64_decode
+ *
+ * Purpose : Decode a base64 character into a byte
+ *
+ * Parameters :
+ *
+ * Returns :
+ *
+ * Comments :
+ *
+ *----------------------------------------------------------------------*/
+static unsigned char char_base64_decode(char c)
+{
+ if (c >= 'A' && c <= 'Z')
+ {
+ return c - 'A';
+ }
+
+ if (c >= 'a' && c <= 'z')
+ {
+ return c - 'a' + 26;
+ }
+
+ if (c >= '0' && c <= '9')
+ {
+ return c - '0' + 52;
+ }
+
+ if (c == '+')
+ {
+ return 62;
+ }
+
+ return 63;
+}
+/*------------------------------------------------------------------------
+ *
+ * Function : str_base64_encode
+ *
+ * Purpose : Encode a string into a base64 string
+ *
+ * Parameters : p_str (in) - the string to encode
+ * p_b64str (out) - the encoded str to return
+ * in_size (in) - size (length) of input str
+ * Returns :
+ *
+ * Comments :
+ *
+ *----------------------------------------------------------------------*/
+void str_base64_encode(char *p_str, char *p_b64str, int in_size)
+{
+ int i;
+ unsigned char from1=0,from2=0,from3=0;
+ unsigned char to1=0,to2=0,to3=0,to4=0;
+
+ if ( 0 == in_size )
+ {
+ return;
+ };
+
+ for ( i = 0; i < in_size ; i += 3 )
+ {
+ from1 = from2 = from3 = 0;
+ from1 = p_str[i];
+ if (i+1 < in_size)
+ {
+ from2 = p_str[i+1];
+ }
+ if (i+2 < in_size)
+ {
+ from3 = p_str[i+2];
+ }
+
+ to1 = to2 = to3 = to4 = 0;
+ to1 = (from1>>2) & 0x3f;
+ to2 = ((from1&0x3)<<4)|(from2>>4);
+ to3 = ((from2&0xf)<<2)|(from3>>6);
+ to4 = from3&0x3f;
+
+ *(p_b64str++) = char_base64_encode(to1);
+ *(p_b64str++) = char_base64_encode(to2);
+
+ if (i+1 < in_size)
+ {
+ *(p_b64str++) = char_base64_encode(to3);
+ }
+ else
+ {
+ *(p_b64str++) = '='; /* Padding */
+ }
+ if (i+2 < in_size)
+ {
+ *(p_b64str++) = char_base64_encode(to4);
+ }
+ else
+ {
+ *(p_b64str++) = '='; /* Padding */
+ };
+
+/* if ( i % (76/4*3) == 0)
+ {
+ *(p_b64str++) = '\r';
+ *(p_b64str++) = '\n';
+ }*/
+ };
+
+ return;
+}
+/*------------------------------------------------------------------------
+ *
+ * Function : str_base64_decode
+ *
+ * Purpose : Decode a base64 string into a string
+ *
+ * Parameters : p_b64str (in) - the base64 string to decode
+ * p_str (out) - the encoded str to return
+ * p_out_size (out) - the size (len) of the str decoded
+ *
+ * Returns :
+ *
+ * Comments :
+ *
+ *----------------------------------------------------------------------*/
+void str_base64_decode(char *p_b64str, char *p_str, int *p_out_size)
+{
+ int i;
+ int j = 0;
+ int in_size;
+ char from1='A',from2='A',from3='A',from4='A';
+ unsigned char to1=0,to2=0,to3=0,to4=0;
+ char str_clean[MAX_B64_SIZE];/* str_clean is the string
+ * after removing the non-base64
+ * characters
+ */
+
+ in_size = strlen(p_b64str);
+ memset(str_clean, 0, sizeof(str_clean));
+ *p_out_size = 0;
+
+ /* Clean-up input string */
+ for ( i=0; i < in_size; i++ )
+ {
+ if (is_base64(p_b64str[i]))
+ {
+ str_clean[j++] = p_b64str[i];
+ }
+ }
+
+ /* Re-define in_size after clean-up */
+ in_size = strlen(str_clean);
+
+ if ( 0 == in_size )
+ {
+ return;
+ }
+
+ for ( i=0; i < in_size ;i+=4)
+ {
+ from1 = from2 = from3 = from4 = 'A';
+ from1 = str_clean[i];
+ if ( i+1 < in_size )
+ {
+ from2 = str_clean[i+1];
+ }
+ if ( i+2 < in_size )
+ {
+ from3 = str_clean[i+2];
+ }
+ if ( i+3 < in_size )
+ {
+ from4 = str_clean[i+3];
+ };
+
+ to1 = to2 = to3 = to4 = 0;
+ to1 = char_base64_decode(from1);
+ to2 = char_base64_decode(from2);
+ to3 = char_base64_decode(from3);
+ to4 = char_base64_decode(from4);
+
+ *(p_str++) = ( (to1<<2)|(to2>>4) );
+ (*p_out_size)++;
+ if (from3 != '=')
+ {
+ *(p_str++) = ( ((to2&0xf)<<4)|(to3>>2) );
+ (*p_out_size)++;
+ }
+ if (from4 != '=')
+ {
+ *(p_str++) = ( ((to3&0x3)<<6)|to4 );
+ (*p_out_size)++;
+ }
+ }
+
+ return;
+}
diff --git a/src/libs/zbxcrypto/md5.c b/src/libs/zbxcrypto/md5.c
index 2c9c2fcd..57848732 100644
--- a/src/libs/zbxcrypto/md5.c
+++ b/src/libs/zbxcrypto/md5.c
@@ -51,8 +51,9 @@
1999-05-03 lpd Original version.
*/
+#include "common.h"
#include "md5.h"
-#include <string.h>
+
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#ifdef ARCH_IS_BIG_ENDIAN
diff --git a/src/libs/zbxdbhigh/Makefile.am b/src/libs/zbxdbhigh/Makefile.am
index 0c0e10b1..78c15843 100644
--- a/src/libs/zbxdbhigh/Makefile.am
+++ b/src/libs/zbxdbhigh/Makefile.am
@@ -2,4 +2,4 @@ SUBDIRS=
INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @PGSQL_INCLUDE@ @ORACLE_INCLUDE@
libzbxdbhigh_a_SOURCES=action.c graph.c item.c trigger.c host.c db.c
lib_LIBRARIES=libzbxdbhigh.a
-libzbxdbhigh_a_LIBADD = ../zbxcommon/libzbxcommon.a
+#libzbxdbhigh_a_LIBADD = ../zbxcommon/libzbxcommon.a
diff --git a/src/libs/zbxdbhigh/action.c b/src/libs/zbxdbhigh/action.c
index 50649d33..43759384 100644
--- a/src/libs/zbxdbhigh/action.c
+++ b/src/libs/zbxdbhigh/action.c
@@ -44,7 +44,7 @@ int DBadd_action(int triggerid, int userid, char *subject, char *message, int sc
userid = usrgrpid;
}
- snprintf(sql, sizeof(sql)-1,"insert into actions (triggerid, userid, subject, message, scope, severity, recipient) values (%d, %d, '%s', '%s', %d, %d, %d)", triggerid, userid, subject_esc, message_esc, scope, severity, recipient);
+ zbx_snprintf(sql, sizeof(sql),"insert into actions (triggerid, userid, subject, message, scope, severity, recipient) values (%d, %d, '%s', '%s', %d, %d, %d)", triggerid, userid, subject_esc, message_esc, scope, severity, recipient);
if(FAIL == DBexecute(sql))
{
return FAIL;
@@ -69,7 +69,7 @@ int DBget_action_by_actionid(int actionid,DB_ACTION *action)
zabbix_log( LOG_LEVEL_DEBUG, "In DBget_action_by_actionid(%d)", actionid);
- snprintf(sql,sizeof(sql)-1,"select userid,recipient,subject,message from actions where actionid=%d", actionid);
+ zbx_snprintf(sql,sizeof(sql),"select userid,recipient,subject,message from actions where actionid=%d", actionid);
result=DBselect(sql);
row=DBfetch(result);
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index d4a933a1..b7fc1f7c 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -96,7 +96,7 @@ void DBconnect(void)
/* check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- zabbix_log(LOG_LEVEL_ERR, "Connection to database '%s' failed.\n", CONFIG_DBNAME);
+ zabbix_log(LOG_LEVEL_ERR, "Connection to database '%s' failed.", CONFIG_DBNAME);
exit(FAIL);
}
#endif
@@ -109,11 +109,11 @@ void DBconnect(void)
exit(FAIL);
}
/* login */
- snprintf(connect,MAX_STRING_LEN-1,"%s/%s@%s", CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBNAME);
+ zbx_snprintf(connect, sizeof(connect),"%s/%s@%s", CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBNAME);
if (SQLO_SUCCESS != sqlo_connect(&oracle, connect))
{
printf("Cannot login with %s\n", connect);
- zabbix_log(LOG_LEVEL_ERR, "Cannot login with %s\n", connect);
+ zabbix_log(LOG_LEVEL_ERR, "Cannot login with %s", connect);
exit(FAIL);
}
sqlo_autocommit_on(oracle);
@@ -168,8 +168,8 @@ int DBexecute(char *query)
{
zabbix_log( LOG_LEVEL_ERR, "Query::%s",query);
zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", sqlo_geterror(oracle) );
- fprintf(stderr, "Query::%s\n",query);
- fprintf(stderr, "Query failed:%s\n", sqlo_geterror(oracle) );
+ zbx_error("Query::%s.",query);
+ zbx_error("Query failed:%s.", sqlo_geterror(oracle) );
ret = FAIL;
}
return ret;
@@ -207,7 +207,7 @@ DB_ROW DBfetch(DB_RESULT result)
}
else
{
- fprintf(stderr, "Fetch failed:%s\n", sqlo_geterror(oracle) );
+ zbx_error("Fetch failed:%s", sqlo_geterror(oracle) );
exit(FAIL);
}
#endif
@@ -274,15 +274,15 @@ DB_RESULT DBselectN(char *query, int n)
{
char sql[MAX_STRING_LEN];
#ifdef HAVE_MYSQL
- snprintf(sql,MAX_STRING_LEN-1,"%s limit %d", query, n);
+ zbx_snprintf(sql,sizeof(sql),"%s limit %d", query, n);
return DBselect(sql);
#endif
#ifdef HAVE_PGSQL
- snprintf(sql,MAX_STRING_LEN-1,"%s limit %d", query, n);
+ zbx_snprintf(sql,sizeof(sql),"%s limit %d", query, n);
return DBselect(sql);
#endif
#ifdef HAVE_ORACLE
- snprintf(sql,MAX_STRING_LEN-1,"select * from (%s) where rownum<=%d", query, n);
+ zbx_snprintf(sql,sizeof(sql),"select * from (%s) where rownum<=%d", query, n);
return DBselect(sql);
#endif
}
@@ -426,7 +426,7 @@ int DBget_function_result(double *result,char *functionid)
char sql[MAX_STRING_LEN];
/* 0 is added to distinguish between lastvalue==NULL and empty result */
- snprintf( sql, sizeof(sql)-1, "select 0,lastvalue from functions where functionid=%s", functionid );
+ zbx_snprintf( sql, sizeof(sql), "select 0,lastvalue from functions where functionid=%s", functionid );
dbresult = DBselect(sql);
row = DBfetch(dbresult);
@@ -463,7 +463,7 @@ int DBget_prev_trigger_value(int triggerid)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_prev_trigger_value[%d]", triggerid);
- snprintf(sql,sizeof(sql)-1,"select max(clock) from alarms where triggerid=%d",triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select max(clock) from alarms where triggerid=%d",triggerid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
@@ -478,7 +478,7 @@ int DBget_prev_trigger_value(int triggerid)
clock=atoi(row[0]);
DBfree_result(result);
- snprintf(sql,sizeof(sql),"select max(clock) from alarms where triggerid=%d and clock<%d",triggerid,clock);
+ zbx_snprintf(sql,sizeof(sql),"select max(clock) from alarms where triggerid=%d and clock<%d",triggerid,clock);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
row=DBfetch(result);
@@ -495,7 +495,7 @@ status changes to TRUE for te first time */
clock=atoi(row[0]);
DBfree_result(result);
- snprintf(sql,sizeof(sql)-1,"select value from alarms where triggerid=%d and clock=%d",triggerid,clock);
+ zbx_snprintf(sql,sizeof(sql),"select value from alarms where triggerid=%d and clock=%d",triggerid,clock);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
row=DBfetch(result);
@@ -524,7 +524,7 @@ static int latest_alarm(int triggerid, int status)
zabbix_log(LOG_LEVEL_DEBUG,"In latest_alarm()");
- snprintf(sql,sizeof(sql)-1,"select value from alarms where triggerid=%d order by clock desc",triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select value from alarms where triggerid=%d order by clock desc",triggerid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselectN(sql,1);
row = DBfetch(result);
@@ -559,7 +559,7 @@ int latest_service_alarm(int serviceid, int status)
zabbix_log(LOG_LEVEL_DEBUG,"In latest_service_alarm()");
- snprintf(sql,sizeof(sql)-1,"select max(clock) from service_alarms where serviceid=%d",serviceid);
+ zbx_snprintf(sql,sizeof(sql),"select max(clock) from service_alarms where serviceid=%d",serviceid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
row = DBfetch(result);
@@ -574,7 +574,7 @@ int latest_service_alarm(int serviceid, int status)
clock=atoi(row[0]);
DBfree_result(result);
- snprintf(sql,sizeof(sql)-1,"select value from service_alarms where serviceid=%d and clock=%d",serviceid,clock);
+ zbx_snprintf(sql,sizeof(sql),"select value from service_alarms where serviceid=%d and clock=%d",serviceid,clock);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
row = DBfetch(result);
@@ -608,7 +608,7 @@ int add_alarm(int triggerid,int status,int clock,int *alarmid)
return FAIL;
}
- snprintf(sql,sizeof(sql)-1,"insert into alarms(triggerid,clock,value) values(%d,%d,%d)", triggerid, clock, status);
+ zbx_snprintf(sql,sizeof(sql),"insert into alarms(triggerid,clock,value) values(%d,%d,%d)", triggerid, clock, status);
DBexecute(sql);
*alarmid=DBinsert_id();
@@ -616,7 +616,7 @@ int add_alarm(int triggerid,int status,int clock,int *alarmid)
/* Cancel currently active alerts */
if(status == TRIGGER_VALUE_FALSE || status == TRIGGER_VALUE_TRUE)
{
- snprintf(sql,sizeof(sql)-1,"update alerts set retries=3,error='Trigger changed its status. WIll not send repeats.' where triggerid=%d and repeats>0 and status=%d", triggerid, ALERT_STATUS_NOT_SENT);
+ zbx_snprintf(sql,sizeof(sql),"update alerts set retries=3,error='Trigger changed its status. WIll not send repeats.' where triggerid=%d and repeats>0 and status=%d", triggerid, ALERT_STATUS_NOT_SENT);
DBexecute(sql);
}
@@ -636,7 +636,7 @@ int DBadd_service_alarm(int serviceid,int status,int clock)
return SUCCEED;
}
- snprintf(sql,sizeof(sql)-1,"insert into service_alarms(serviceid,clock,value) values(%d,%d,%d)", serviceid, clock, status);
+ zbx_snprintf(sql,sizeof(sql),"insert into service_alarms(serviceid,clock,value) values(%d,%d,%d)", serviceid, clock, status);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
DBexecute(sql);
@@ -667,17 +667,17 @@ int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *re
{
if(reason==NULL)
{
- snprintf(sql,sizeof(sql)-1,"update triggers set value=%d,lastchange=%d,error='' where triggerid=%d",new_value,now,trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update triggers set value=%d,lastchange=%d,error='' where triggerid=%d",new_value,now,trigger->triggerid);
}
else
{
- snprintf(sql,sizeof(sql)-1,"update triggers set value=%d,lastchange=%d,error='%s' where triggerid=%d",new_value,now,reason, trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update triggers set value=%d,lastchange=%d,error='%s' where triggerid=%d",new_value,now,reason, trigger->triggerid);
}
DBexecute(sql);
/* It is not required and is wrong! */
/* if(TRIGGER_VALUE_UNKNOWN == new_value)
{
- snprintf(sql,sizeof(sql)-1,"update functions set lastvalue=NULL where triggerid=%d",trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update functions set lastvalue=NULL where triggerid=%d",trigger->triggerid);
DBexecute(sql);
}*/
if( ((trigger->value == TRIGGER_VALUE_TRUE) && (new_value == TRIGGER_VALUE_FALSE)) ||
@@ -714,12 +714,12 @@ int DBupdate_trigger_value(int triggerid,int value,int clock)
zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value[%d,%d,%d]", triggerid, value, clock);
add_alarm(triggerid,value,clock);
- snprintf(sql,sizeof(sql)-1,"update triggers set value=%d,lastchange=%d where triggerid=%d",value,clock,triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update triggers set value=%d,lastchange=%d where triggerid=%d",value,clock,triggerid);
DBexecute(sql);
if(TRIGGER_VALUE_UNKNOWN == value)
{
- snprintf(sql,sizeof(sql)-1,"update functions set lastvalue=NULL where triggerid=%d",triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update functions set lastvalue=NULL where triggerid=%d",triggerid);
DBexecute(sql);
}
@@ -738,8 +738,8 @@ void update_triggers_status_to_unknown(int hostid,int clock,char *reason)
zabbix_log(LOG_LEVEL_DEBUG,"In update_triggers_status_to_unknown()");
-/* snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_<>'%s'",hostid,SERVER_STATUS_KEY);*/
- snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid,t.value from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_ not in ('%s','%s','%s')",hostid,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY);
+/* zbx_snprintf(sql,sizeof(sql),"select distinct t.triggerid from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_<>'%s'",hostid,SERVER_STATUS_KEY);*/
+ zbx_snprintf(sql,sizeof(sql),"select distinct t.triggerid,t.value from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_ not in ('%s','%s','%s')",hostid,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
@@ -760,9 +760,9 @@ void DBdelete_service(int serviceid)
{
char sql[MAX_STRING_LEN];
- snprintf(sql,sizeof(sql)-1,"delete from services_links where servicedownid=%d or serviceupid=%d", serviceid, serviceid);
+ zbx_snprintf(sql,sizeof(sql),"delete from services_links where servicedownid=%d or serviceupid=%d", serviceid, serviceid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from services where serviceid=%d", serviceid);
+ zbx_snprintf(sql,sizeof(sql),"delete from services where serviceid=%d", serviceid);
DBexecute(sql);
}
@@ -774,7 +774,7 @@ void DBdelete_services_by_triggerid(int triggerid)
DB_ROW row;
zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_services_by_triggerid(%d)", triggerid);
- snprintf(sql,sizeof(sql)-1,"select serviceid from services where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select serviceid from services where triggerid=%d", triggerid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -791,20 +791,20 @@ void DBdelete_trigger(int triggerid)
{
char sql[MAX_STRING_LEN];
- snprintf(sql,sizeof(sql)-1,"delete from trigger_depends where triggerid_down=%d or triggerid_up=%d", triggerid, triggerid);
+ zbx_snprintf(sql,sizeof(sql),"delete from trigger_depends where triggerid_down=%d or triggerid_up=%d", triggerid, triggerid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from functions where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"delete from functions where triggerid=%d", triggerid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from alarms where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"delete from alarms where triggerid=%d", triggerid);
DBexecute(sql);
-/* snprintf(sql,sizeof(sql)-1,"delete from actions where triggerid=%d and scope=%d", triggerid, ACTION_SCOPE_TRIGGER);
+/* zbx_snprintf(sql,sizeof(sql),"delete from actions where triggerid=%d and scope=%d", triggerid, ACTION_SCOPE_TRIGGER);
DBexecute(sql);*/
DBdelete_services_by_triggerid(triggerid);
- snprintf(sql,sizeof(sql)-1,"update sysmaps_links set triggerid=NULL where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update sysmaps_links set triggerid=NULL where triggerid=%d", triggerid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from triggers where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"delete from triggers where triggerid=%d", triggerid);
DBexecute(sql);
}
@@ -816,7 +816,7 @@ void DBdelete_triggers_by_itemid(int itemid)
DB_ROW row;
zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_triggers_by_itemid(%d)", itemid);
- snprintf(sql,sizeof(sql)-1,"select triggerid from functions where itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"select triggerid from functions where itemid=%d", itemid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -826,7 +826,7 @@ void DBdelete_triggers_by_itemid(int itemid)
}
DBfree_result(result);
- snprintf(sql,sizeof(sql)-1,"delete from functions where itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"delete from functions where itemid=%d", itemid);
DBexecute(sql);
zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_triggers_by_itemid(%d)", itemid);
@@ -836,7 +836,7 @@ void DBdelete_trends_by_itemid(int itemid)
{
char sql[MAX_STRING_LEN];
- snprintf(sql,sizeof(sql)-1,"delete from trends where itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"delete from trends where itemid=%d", itemid);
DBexecute(sql);
}
@@ -844,9 +844,9 @@ void DBdelete_history_by_itemid(int itemid)
{
char sql[MAX_STRING_LEN];
- snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"delete from history where itemid=%d", itemid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from history_str where itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"delete from history_str where itemid=%d", itemid);
DBexecute(sql);
}
@@ -854,7 +854,7 @@ void DBdelete_sysmaps_links_by_shostid(int shostid)
{
char sql[MAX_STRING_LEN];
- snprintf(sql,sizeof(sql)-1,"delete from sysmaps_links where shostid1=%d or shostid2=%d", shostid, shostid);
+ zbx_snprintf(sql,sizeof(sql),"delete from sysmaps_links where shostid1=%d or shostid2=%d", shostid, shostid);
DBexecute(sql);
}
@@ -866,7 +866,7 @@ void DBdelete_sysmaps_hosts_by_hostid(int hostid)
DB_ROW row;
zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_sysmaps_hosts(%d)", hostid);
- snprintf(sql,sizeof(sql)-1,"select shostid from sysmaps_hosts where hostid=%d", hostid);
+ zbx_snprintf(sql,sizeof(sql),"select shostid from sysmaps_hosts where hostid=%d", hostid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -876,7 +876,7 @@ void DBdelete_sysmaps_hosts_by_hostid(int hostid)
}
DBfree_result(result);
- snprintf(sql,sizeof(sql)-1,"delete from sysmaps_hosts where hostid=%d", hostid);
+ zbx_snprintf(sql,sizeof(sql),"delete from sysmaps_hosts where hostid=%d", hostid);
DBexecute(sql);
}
@@ -886,9 +886,9 @@ int DBdelete_history_pertial(int itemid)
char sql[MAX_STRING_LEN];
#ifdef HAVE_ORACLE
- snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d and rownum<500", itemid);
+ zbx_snprintf(sql,sizeof(sql),"delete from history where itemid=%d and rownum<500", itemid);
#else
- snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d limit 500", itemid);
+ zbx_snprintf(sql,sizeof(sql),"delete from history where itemid=%d limit 500", itemid);
#endif
DBexecute(sql);
@@ -912,7 +912,7 @@ void DBupdate_triggers_status_after_restart(void)
now=time(NULL);
- snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid,t.value from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and i.nextcheck+i.delay<%d and i.key_<>'%s' and h.status not in (%d,%d)",now,SERVER_STATUS_KEY, HOST_STATUS_DELETED, HOST_STATUS_TEMPLATE);
+ zbx_snprintf(sql,sizeof(sql),"select distinct t.triggerid,t.value from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and i.nextcheck+i.delay<%d and i.key_<>'%s' and h.status not in (%d,%d)",now,SERVER_STATUS_KEY, HOST_STATUS_DELETED, HOST_STATUS_TEMPLATE);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
@@ -921,7 +921,7 @@ void DBupdate_triggers_status_after_restart(void)
trigger.triggerid=atoi(row[0]);
trigger.value=atoi(row[1]);
- snprintf(sql,sizeof(sql)-1,"select min(i.nextcheck+i.delay) from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and i.nextcheck<>0 and t.triggerid=%d and i.type<>%d",trigger.triggerid,ITEM_TYPE_TRAPPER);
+ zbx_snprintf(sql,sizeof(sql),"select min(i.nextcheck+i.delay) from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and i.nextcheck<>0 and t.triggerid=%d and i.type<>%d",trigger.triggerid,ITEM_TYPE_TRAPPER);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result2 = DBselect(sql);
row2=DBfetch(result2);
@@ -963,7 +963,7 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error)
strscpy(error_esc,"");
}
- snprintf(sql,sizeof(sql)-1,"select available,disable_until from hosts where hostid=%d",hostid);
+ zbx_snprintf(sql,sizeof(sql),"select available,disable_until from hosts where hostid=%d",hostid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
row=DBfetch(result);
@@ -996,7 +996,7 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error)
if(available==HOST_AVAILABLE_TRUE)
{
- snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,error=' ',errors_from=0 where hostid=%d",HOST_AVAILABLE_TRUE,hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set available=%d,error=' ',errors_from=0 where hostid=%d",HOST_AVAILABLE_TRUE,hostid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
DBexecute(sql);
}
@@ -1004,14 +1004,14 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error)
{
/* if(disable_until+CONFIG_UNREACHABLE_PERIOD>clock)
{
- snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,disable_until=disable_until+%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,CONFIG_UNREACHABLE_DELAY,error_esc,hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set available=%d,disable_until=disable_until+%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,CONFIG_UNREACHABLE_DELAY,error_esc,hostid);
}
else
{
- snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,disable_until=%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,clock+CONFIG_UNREACHABLE_DELAY,error_esc,hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set available=%d,disable_until=%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,clock+CONFIG_UNREACHABLE_DELAY,error_esc,hostid);
}*/
/* '%s ' - space to make Oracle happy */
- snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,error='%s ' where hostid=%d",HOST_AVAILABLE_FALSE,error_esc,hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set available=%d,error='%s ' where hostid=%d",HOST_AVAILABLE_FALSE,error_esc,hostid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
DBexecute(sql);
}
@@ -1045,7 +1045,7 @@ int DBupdate_item_status_to_notsupported(int itemid, char *error)
}
/* '&s ' to make Oracle happy */
- snprintf(sql,sizeof(sql)-1,"update items set status=%d,error='%s ' where itemid=%d",ITEM_STATUS_NOTSUPPORTED,error_esc,itemid);
+ zbx_snprintf(sql,sizeof(sql),"update items set status=%d,error='%s ' where itemid=%d",ITEM_STATUS_NOTSUPPORTED,error_esc,itemid);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
DBexecute(sql);
@@ -1065,7 +1065,7 @@ int DBadd_trend(int itemid, double value, int clock)
hour=clock-clock%3600;
- snprintf(sql,sizeof(sql)-1,"select num,value_min,value_avg,value_max from trends where itemid=%d and clock=%d", itemid, hour);
+ zbx_snprintf(sql,sizeof(sql),"select num,value_min,value_avg,value_max from trends where itemid=%d and clock=%d", itemid, hour);
zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql);
result = DBselect(sql);
@@ -1083,11 +1083,11 @@ int DBadd_trend(int itemid, double value, int clock)
if(value>value_max) value_max=value;
value_avg=(num*value_avg+value)/(num+1);
num++;
- snprintf(sql,sizeof(sql)-1,"update trends set num=%d, value_min=%f, value_avg=%f, value_max=%f where itemid=%d and clock=%d", num, value_min, value_avg, value_max, itemid, hour);
+ zbx_snprintf(sql,sizeof(sql),"update trends set num=%d, value_min=%f, value_avg=%f, value_max=%f where itemid=%d and clock=%d", num, value_min, value_avg, value_max, itemid, hour);
}
else
{
- snprintf(sql,sizeof(sql)-1,"insert into trends (clock,itemid,num,value_min,value_avg,value_max) values (%d,%d,%d,%f,%f,%f)", hour, itemid, 1, value, value, value);
+ zbx_snprintf(sql,sizeof(sql),"insert into trends (clock,itemid,num,value_min,value_avg,value_max) values (%d,%d,%d,%f,%f,%f)", hour, itemid, 1, value, value, value);
}
DBexecute(sql);
@@ -1102,7 +1102,7 @@ int DBadd_history(int itemid, double value, int clock)
zabbix_log(LOG_LEVEL_DEBUG,"In add_history()");
- snprintf(sql,sizeof(sql)-1,"insert into history (clock,itemid,value) values (%d,%d,%f)",clock,itemid,value);
+ zbx_snprintf(sql,sizeof(sql),"insert into history (clock,itemid,value) values (%d,%d,%f)",clock,itemid,value);
DBexecute(sql);
DBadd_trend(itemid, value, clock);
@@ -1116,7 +1116,7 @@ int DBadd_history_uint(int itemid, zbx_uint64_t value, int clock)
zabbix_log(LOG_LEVEL_DEBUG,"In add_history_uint()");
- snprintf(sql,sizeof(sql)-1,"insert into history_uint (clock,itemid,value) values (%d,%d," ZBX_FS_UI64 ")",clock,itemid,value);
+ zbx_snprintf(sql,sizeof(sql),"insert into history_uint (clock,itemid,value) values (%d,%d," ZBX_FS_UI64 ")",clock,itemid,value);
DBexecute(sql);
DBadd_trend(itemid, (double)value, clock);
@@ -1132,7 +1132,7 @@ int DBadd_history_str(int itemid, char *value, int clock)
zabbix_log(LOG_LEVEL_DEBUG,"In add_history_str()");
DBescape_string(value,value_esc,MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"insert into history_str (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc);
+ zbx_snprintf(sql,sizeof(sql),"insert into history_str (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc);
DBexecute(sql);
return SUCCEED;
@@ -1171,7 +1171,7 @@ int DBadd_history_text(int itemid, char *value, int clock)
goto lbl_exit;
}
- snprintf(sql, sizeof(sql)-1, "insert into history_text (clock,itemid,value)"
+ zbx_snprintf(sql, sizeof(sql), "insert into history_text (clock,itemid,value)"
" values (%d,%d, EMPTY_CLOB()) returning value into :1", clock, itemid);
zabbix_log(LOG_LEVEL_DEBUG,"Query:%s", sql);
@@ -1250,7 +1250,7 @@ lbl_exit:
}
DBescape_string(value,value_esc,value_esc_max_len);
- snprintf(sql,sql_max_len, "insert into history_text (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc);
+ zbx_snprintf(sql,sql_max_len, "insert into history_text (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc);
DBexecute(sql);
free(value_esc);
@@ -1272,7 +1272,7 @@ int DBadd_history_log(int itemid, char *value, int clock, int timestamp,char *so
DBescape_string(value,value_esc,MAX_STRING_LEN);
DBescape_string(source,source_esc,MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"insert into history_log (clock,itemid,timestamp,value,source,severity) values (%d,%d,%d,'%s','%s',%d)",clock,itemid,timestamp,value_esc,source_esc,severity);
+ zbx_snprintf(sql,sizeof(sql),"insert into history_log (clock,itemid,timestamp,value,source,severity) values (%d,%d,%d,'%s','%s',%d)",clock,itemid,timestamp,value_esc,source_esc,severity);
DBexecute(sql);
return SUCCEED;
@@ -1288,7 +1288,7 @@ int DBget_items_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_items_count()");
- snprintf(sql,sizeof(sql)-1,"select count(*) from items");
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from items");
result=DBselect(sql);
row=DBfetch(result);
@@ -1317,7 +1317,7 @@ int DBget_triggers_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_triggers_count()");
- snprintf(sql,sizeof(sql)-1,"select count(*) from triggers");
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from triggers");
result=DBselect(sql);
@@ -1347,7 +1347,7 @@ int DBget_items_unsupported_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_items_unsupported_count()");
- snprintf(sql,sizeof(sql)-1,"select count(*) from items where status=%d", ITEM_STATUS_NOTSUPPORTED);
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from items where status=%d", ITEM_STATUS_NOTSUPPORTED);
result=DBselect(sql);
row=DBfetch(result);
@@ -1376,7 +1376,7 @@ int DBget_history_str_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_history_str_count()");
- snprintf(sql,sizeof(sql)-1,"select count(*) from history_str");
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from history_str");
result=DBselect(sql);
row=DBfetch(result);
@@ -1405,7 +1405,7 @@ int DBget_history_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_history_count()");
- snprintf(sql,sizeof(sql)-1,"select count(*) from history");
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from history");
result=DBselect(sql);
row=DBfetch(result);
@@ -1434,7 +1434,7 @@ int DBget_trends_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_trends_count()");
- snprintf(sql,sizeof(sql)-1,"select count(*) from trends");
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from trends");
result=DBselect(sql);
row=DBfetch(result);
@@ -1465,8 +1465,8 @@ int DBget_queue_count(void)
zabbix_log(LOG_LEVEL_DEBUG,"In DBget_queue_count()");
now=time(NULL);
-/* snprintf(sql,sizeof(sql)-1,"select count(*) from items i,hosts h where i.status=%d and i.type not in (%d) and h.status=%d and i.hostid=h.hostid and i.nextcheck<%d and i.key_<>'status'", ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, HOST_STATUS_MONITORED, now);*/
- snprintf(sql,sizeof(sql)-1,"select count(*) from items i,hosts h where i.status=%d and i.type not in (%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and i.hostid=h.hostid and i.nextcheck<%d and i.key_ not in ('%s','%s','%s','%s')", ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, SERVER_ZABBIXLOG_KEY);
+/* zbx_snprintf(sql,sizeof(sql),"select count(*) from items i,hosts h where i.status=%d and i.type not in (%d) and h.status=%d and i.hostid=h.hostid and i.nextcheck<%d and i.key_<>'status'", ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, HOST_STATUS_MONITORED, now);*/
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from items i,hosts h where i.status=%d and i.type not in (%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and i.hostid=h.hostid and i.nextcheck<%d and i.key_ not in ('%s','%s','%s','%s')", ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, SERVER_ZABBIXLOG_KEY);
result=DBselect(sql);
row=DBfetch(result);
@@ -1498,11 +1498,11 @@ int DBadd_alert(int actionid, int userid, int triggerid, int mediatypeid, char
now = time(NULL);
/* Does not work on PostgreSQL */
-/* snprintf(sql,sizeof(sql)-1,"insert into alerts (alertid,actionid,clock,mediatypeid,sendto,subject,message,status,retries) values (NULL,%d,%d,%d,'%s','%s','%s',0,0)",actionid,now,mediatypeid,sendto,subject,message);*/
+/* zbx_snprintf(sql,sizeof(sql),"insert into alerts (alertid,actionid,clock,mediatypeid,sendto,subject,message,status,retries) values (NULL,%d,%d,%d,'%s','%s','%s',0,0)",actionid,now,mediatypeid,sendto,subject,message);*/
DBescape_string(sendto,sendto_esc,MAX_STRING_LEN);
DBescape_string(subject,subject_esc,MAX_STRING_LEN);
DBescape_string(message,message_esc,MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"insert into alerts (actionid,triggerid,userid,clock,mediatypeid,sendto,subject,message,status,retries,maxrepeats,delay) values (%d,%d,%d,%d,%d,'%s','%s','%s',0,0,%d,%d)",actionid,triggerid,userid,now,mediatypeid,sendto_esc,subject_esc,message_esc, maxrepeats, repeatdelay);
+ zbx_snprintf(sql,sizeof(sql),"insert into alerts (actionid,triggerid,userid,clock,mediatypeid,sendto,subject,message,status,retries,maxrepeats,delay) values (%d,%d,%d,%d,%d,'%s','%s','%s',0,0,%d,%d)",actionid,triggerid,userid,now,mediatypeid,sendto_esc,subject_esc,message_esc, maxrepeats, repeatdelay);
DBexecute(sql);
return SUCCEED;
@@ -1522,13 +1522,13 @@ void DBvacuum(void)
char sql[MAX_STRING_LEN];
char *table;
int i;
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [vacuum DB]");
-#endif
+
+ zbx_setproctitle("housekeeper [vacuum DB]");
+
i=0;
while (NULL != (table = table_for_housekeeping[i++]))
{
- snprintf(sql,sizeof(sql)-1,"vacuum analyze %s", table);
+ zbx_snprintf(sql,sizeof(sql),"vacuum analyze %s", table);
DBexecute(sql);
}
#endif
diff --git a/src/libs/zbxdbhigh/graph.c b/src/libs/zbxdbhigh/graph.c
index 596884de..2ed55840 100644
--- a/src/libs/zbxdbhigh/graph.c
+++ b/src/libs/zbxdbhigh/graph.c
@@ -37,7 +37,7 @@ int DBadd_graph(char *name, int width, int height, int yaxistype, double yaxismi
DBescape_string(name,name_esc,GRAPH_NAME_LEN_MAX);
- snprintf(sql, sizeof(sql)-1,"insert into graphs (name,width,height,yaxistype,yaxismin,yaxismax) values ('%s',%d,%d,%d,%f,%f)", name_esc, width, height, yaxistype, yaxismin, yaxismax);
+ zbx_snprintf(sql, sizeof(sql),"insert into graphs (name,width,height,yaxistype,yaxismin,yaxismax) values ('%s',%d,%d,%d,%f,%f)", name_esc, width, height, yaxistype, yaxismin, yaxismax);
if(FAIL == DBexecute(sql))
{
return FAIL;
@@ -61,7 +61,7 @@ int DBadd_item_to_graph(int graphid,int itemid, char *color,int drawtype, int so
DBescape_string(color,color_esc,GRAPH_ITEM_COLOR_LEN_MAX);
- snprintf(sql, sizeof(sql)-1,"insert into graphs_items (graphid,itemid,drawtype,sortorder,color) values (%d,%d,%d,%d,'%s')", graphid, itemid, drawtype, sortorder, color_esc);
+ zbx_snprintf(sql, sizeof(sql),"insert into graphs_items (graphid,itemid,drawtype,sortorder,color) values (%d,%d,%d,%d,'%s')", graphid, itemid, drawtype, sortorder, color_esc);
if(FAIL == DBexecute(sql))
{
return FAIL;
@@ -86,7 +86,7 @@ int DBget_graph_item_by_gitemid(int gitemid, DB_GRAPH_ITEM *graph_item)
zabbix_log( LOG_LEVEL_DEBUG, "In DBget_graph_item_by_gitemid(%d)", gitemid);
- snprintf(sql,sizeof(sql)-1,"select gitemid, graphid, itemid, drawtype, sortorder, color from graphs_items where gitemid=%d", gitemid);
+ zbx_snprintf(sql,sizeof(sql),"select gitemid, graphid, itemid, drawtype, sortorder, color from graphs_items where gitemid=%d", gitemid);
result=DBselect(sql);
row=DBfetch(result);
@@ -118,7 +118,7 @@ int DBget_graph_by_graphid(int graphid, DB_GRAPH *graph)
zabbix_log( LOG_LEVEL_DEBUG, "In DBget_graph_by_graphid(%d)", graphid);
- snprintf(sql,sizeof(sql)-1,"select graphid,name,width,height,yaxistype,yaxismin,yaxismax from graphs where graphid=%d", graphid);
+ zbx_snprintf(sql,sizeof(sql),"select graphid,name,width,height,yaxistype,yaxismin,yaxismax from graphs where graphid=%d", graphid);
result=DBselect(sql);
row=DBfetch(result);
@@ -177,11 +177,11 @@ int DBadd_graph_item_to_linked_hosts(int gitemid,int hostid)
if(hostid==0)
{
- snprintf(sql,sizeof(sql)-1,"select hostid,templateid,graphs from hosts_templates where templateid=%d", item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"select hostid,templateid,graphs from hosts_templates where templateid=%d", item.hostid);
}
else
{
- snprintf(sql,sizeof(sql)-1,"select hostid,templateid,graphs from hosts_templates where hostid=%d and templateid=%d", hostid, item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"select hostid,templateid,graphs from hosts_templates where hostid=%d and templateid=%d", hostid, item.hostid);
}
zabbix_log( LOG_LEVEL_DEBUG, "\tSQL [%s]", sql);
@@ -191,7 +191,7 @@ int DBadd_graph_item_to_linked_hosts(int gitemid,int hostid)
{
if( (atoi(row[2])&1) == 0) continue;
- snprintf(sql,sizeof(sql)-1,"select i.itemid from items i where i.key_='%s' and i.hostid=%d", item.key, atoi(row[0]));
+ zbx_snprintf(sql,sizeof(sql),"select i.itemid from items i where i.key_='%s' and i.hostid=%d", item.key, atoi(row[0]));
zabbix_log( LOG_LEVEL_DEBUG, "\t\tSQL [%s]", sql);
result2=DBselect(sql);
@@ -210,7 +210,7 @@ int DBadd_graph_item_to_linked_hosts(int gitemid,int hostid)
if(DBget_host_by_hostid(atoi(row[0]), &host) == FAIL) continue;
- snprintf(sql,sizeof(sql)-1,"select distinct g.graphid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=%d and g.graphid=gi.graphid and g.name='%s'", atoi(row[0]), name_esc);
+ zbx_snprintf(sql,sizeof(sql),"select distinct g.graphid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=%d and g.graphid=gi.graphid and g.name='%s'", atoi(row[0]), name_esc);
result2=DBselect(sql);
rows=0;
diff --git a/src/libs/zbxdbhigh/host.c b/src/libs/zbxdbhigh/host.c
index 5a8870a4..5d2e9b7b 100644
--- a/src/libs/zbxdbhigh/host.c
+++ b/src/libs/zbxdbhigh/host.c
@@ -34,7 +34,7 @@ int DBadd_host(char *server, int port, int status, int useip, char *ip, int disa
char sql[MAX_STRING_LEN];
int hostid;
- snprintf(sql, sizeof(sql)-1,"insert into hosts (host,port,status,useip,ip,disable_until,available) values ('%s',%d,%d,%d,'%s',%d,%d)", server, port, status, useip, ip, disable_until, available);
+ zbx_snprintf(sql, sizeof(sql),"insert into hosts (host,port,status,useip,ip,disable_until,available) values ('%s',%d,%d,%d,'%s',%d,%d)", server, port, status, useip, ip, disable_until, available);
if(FAIL == DBexecute(sql))
{
return FAIL;
@@ -57,7 +57,7 @@ int DBhost_exists(char *server)
char sql[MAX_STRING_LEN];
int ret = SUCCEED;
- snprintf(sql,sizeof(sql)-1,"select hostid from hosts where host='%s'", server);
+ zbx_snprintf(sql,sizeof(sql),"select hostid from hosts where host='%s'", server);
result = DBselect(sql);
row = DBfetch(result);
@@ -78,7 +78,7 @@ int DBadd_templates_to_host(int hostid,int host_templateid)
zabbix_log( LOG_LEVEL_DEBUG, "In DBadd_templates_to_host(%d,%d)", hostid, host_templateid);
- snprintf(sql,sizeof(sql)-1,"select templateid,items,triggers,graphs from hosts_templates where hostid=%d", host_templateid);
+ zbx_snprintf(sql,sizeof(sql),"select templateid,items,triggers,graphs from hosts_templates where hostid=%d", host_templateid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -98,7 +98,7 @@ int DBadd_template_linkage(int hostid,int templateid,int items,int triggers,int
zabbix_log( LOG_LEVEL_DEBUG, "In DBadd_template_linkage(%d)", hostid);
- snprintf(sql,sizeof(sql)-1,"insert into hosts_templates (hostid,templateid,items,triggers,graphs) values (%d,%d,%d,%d,%d)",hostid, templateid, items, triggers, graphs);
+ zbx_snprintf(sql,sizeof(sql),"insert into hosts_templates (hostid,templateid,items,triggers,graphs) values (%d,%d,%d,%d,%d)",hostid, templateid, items, triggers, graphs);
return DBexecute(sql);
}
@@ -111,7 +111,7 @@ int DBsync_host_with_templates(int hostid)
zabbix_log( LOG_LEVEL_DEBUG, "In DBsync_host_with_templates(%d)", hostid);
- snprintf(sql,sizeof(sql)-1,"select templateid,items,triggers,graphs from hosts_templates where hostid=%d", hostid);
+ zbx_snprintf(sql,sizeof(sql),"select templateid,items,triggers,graphs from hosts_templates where hostid=%d", hostid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -134,7 +134,7 @@ int DBsync_host_with_template(int hostid,int templateid,int items,int triggers,i
zabbix_log( LOG_LEVEL_DEBUG, "In DBsync_host_with_template(%d,%d)", hostid, templateid);
/* Sync items */
- snprintf(sql,sizeof(sql)-1,"select itemid from items where hostid=%d", templateid);
+ zbx_snprintf(sql,sizeof(sql),"select itemid from items where hostid=%d", templateid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -144,7 +144,7 @@ int DBsync_host_with_template(int hostid,int templateid,int items,int triggers,i
DBfree_result(result);
/* Sync triggers */
- snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid from hosts h, items i,triggers t,functions f where h.hostid=%d and h.hostid=i.hostid and t.triggerid=f.triggerid and i.itemid=f.itemid", templateid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct t.triggerid from hosts h, items i,triggers t,functions f where h.hostid=%d and h.hostid=i.hostid and t.triggerid=f.triggerid and i.itemid=f.itemid", templateid);
result = DBselect(sql);
while((row=DBfetch(result)))
{
@@ -153,7 +153,7 @@ int DBsync_host_with_template(int hostid,int templateid,int items,int triggers,i
DBfree_result(result);
/* Sync graphs */
- snprintf(sql,sizeof(sql)-1,"select distinct gi.gitemid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=%d and g.graphid=gi.graphid", templateid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct gi.gitemid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=%d and g.graphid=gi.graphid", templateid);
result = DBselect(sql);
while((row=DBfetch(result)))
{
@@ -173,7 +173,7 @@ int DBget_host_by_hostid(int hostid,DB_HOST *host)
zabbix_log( LOG_LEVEL_DEBUG, "In DBget_host_by_hostid(%d)", hostid);
- snprintf(sql,sizeof(sql)-1,"select hostid,host,useip,ip,port,status,disable_until,errors_from,error,available from hosts where hostid=%d", hostid);
+ zbx_snprintf(sql,sizeof(sql),"select hostid,host,useip,ip,port,status,disable_until,errors_from,error,available from hosts where hostid=%d", hostid);
result=DBselect(sql);
row=DBfetch(result);
diff --git a/src/libs/zbxdbhigh/item.c b/src/libs/zbxdbhigh/item.c
index b1d508d5..4b78b7e6 100644
--- a/src/libs/zbxdbhigh/item.c
+++ b/src/libs/zbxdbhigh/item.c
@@ -38,7 +38,7 @@ int DBget_item_by_itemid(int itemid,DB_ITEM *item)
zabbix_log( LOG_LEVEL_DEBUG, "In DBget_item_by_itemid(%d)", itemid);
- snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.hostid from items i,hosts h where h.hostid=i.hostid and i.itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"select i.itemid,i.key_,h.hostid from items i,hosts h where h.hostid=i.hostid and i.itemid=%d", itemid);
result=DBselect(sql);
row = DBfetch(result);
@@ -71,7 +71,7 @@ int DBadd_item_to_linked_hosts(int itemid, int hostid)
zabbix_log( LOG_LEVEL_DEBUG, "In DBadd_item_to_linked_hosts(%d,%d)", itemid, hostid);
- snprintf(sql,sizeof(sql)-1,"select description,key_,hostid,delay,history,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends,logtimefmt from items where itemid=%d", itemid);
+ zbx_snprintf(sql,sizeof(sql),"select description,key_,hostid,delay,history,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends,logtimefmt from items where itemid=%d", itemid);
result3=DBselect(sql);
row3=DBfetch(result3);
@@ -110,11 +110,11 @@ int DBadd_item_to_linked_hosts(int itemid, int hostid)
/* Link with one host only */
if(hostid!=0)
{
- snprintf(sql,sizeof(sql)-1,"select hostid,templateid,items from hosts_templates where hostid=%d and templateid=%d", hostid, item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"select hostid,templateid,items from hosts_templates where hostid=%d and templateid=%d", hostid, item.hostid);
}
else
{
- snprintf(sql,sizeof(sql)-1,"select hostid,templateid,items from hosts_templates where templateid=%d", item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"select hostid,templateid,items from hosts_templates where templateid=%d", item.hostid);
}
result = DBselect(sql);
@@ -122,7 +122,7 @@ int DBadd_item_to_linked_hosts(int itemid, int hostid)
{
if( (atoi(row[2])&1) == 0) continue;
- snprintf(sql,sizeof(sql)-1,"select itemid from items where key_='%s' and hostid=%d", item.key, atoi(row[0]));
+ zbx_snprintf(sql,sizeof(sql),"select itemid from items where key_='%s' and hostid=%d", item.key, atoi(row[0]));
result2=DBselect(sql);
row2=DBfetch(result2);
if(!row2)
@@ -157,7 +157,7 @@ int DBadd_item(char *description, char *key, int hostid, int delay, int history,
DBescape_string(snmpv3_authpassphrase,snmpv3_authpassphrase_esc,MAX_STRING_LEN);
DBescape_string(snmpv3_privpassphrase,snmpv3_privpassphrase_esc,MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"insert into items (description,key_,hostid,delay,history,nextcheck,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends,logtimefmt) values ('%s','%s',%d,%d,%d,0,%d,%d,'%s','%s',%d,'%s',%d,'%s',%d,%d,'%s',%d,'%s','%s','%s',%d,'%s')", description_esc, key_esc, hostid,delay,history,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname_esc,snmpv3_securitylevel,snmpv3_authpassphrase_esc,snmpv3_privpassphrase_esc,formula,trends,logtimefmt_esc);
+ zbx_snprintf(sql,sizeof(sql),"insert into items (description,key_,hostid,delay,history,nextcheck,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends,logtimefmt) values ('%s','%s',%d,%d,%d,0,%d,%d,'%s','%s',%d,'%s',%d,'%s',%d,%d,'%s',%d,'%s','%s','%s',%d,'%s')", description_esc, key_esc, hostid,delay,history,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname_esc,snmpv3_securitylevel,snmpv3_authpassphrase_esc,snmpv3_privpassphrase_esc,formula,trends,logtimefmt_esc);
return DBexecute(sql);
}
diff --git a/src/libs/zbxdbhigh/trigger.c b/src/libs/zbxdbhigh/trigger.c
index 5e0bce16..8007532e 100644
--- a/src/libs/zbxdbhigh/trigger.c
+++ b/src/libs/zbxdbhigh/trigger.c
@@ -50,7 +50,7 @@ int DBadd_trigger_to_linked_hosts(int triggerid,int hostid)
zabbix_log( LOG_LEVEL_DEBUG, "In DBadd_trigger_to_linked_hosts(%d,%d)",triggerid, hostid);
- snprintf(sql,sizeof(sql)-1,"select description, priority,status,comments,url,value,expression from triggers where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select description, priority,status,comments,url,value,expression from triggers where triggerid=%d", triggerid);
result2=DBselect(sql);
row2=DBfetch(result2);
@@ -72,7 +72,7 @@ int DBadd_trigger_to_linked_hosts(int triggerid,int hostid)
DBfree_result(result2);
- snprintf(sql,sizeof(sql)-1,"select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=%d", triggerid);
result=DBselect(sql);
row=DBfetch(result);
@@ -84,12 +84,12 @@ int DBadd_trigger_to_linked_hosts(int triggerid,int hostid)
if(hostid==0)
{
- snprintf(sql,sizeof(sql)-1,"select hostid,templateid,triggers from hosts_templates where templateid=%d", atoi(row[0]));
+ zbx_snprintf(sql,sizeof(sql),"select hostid,templateid,triggers from hosts_templates where templateid=%d", atoi(row[0]));
}
/* Link to one host only */
else
{
- snprintf(sql,sizeof(sql)-1,"select hostid,templateid,triggers from hosts_templates where hostid=%d and templateid=%d", hostid, atoi(row[0]));
+ zbx_snprintf(sql,sizeof(sql),"select hostid,templateid,triggers from hosts_templates where hostid=%d and templateid=%d", hostid, atoi(row[0]));
}
DBfree_result(result);
@@ -107,48 +107,48 @@ int DBadd_trigger_to_linked_hosts(int triggerid,int hostid)
DBescape_string(trigger.comments,comments_esc,TRIGGER_COMMENTS_LEN_MAX);
DBescape_string(trigger.url,url_esc,TRIGGER_URL_LEN_MAX);
- snprintf(sql,sizeof(sql)-1,"insert into triggers (description,priority,status,comments,url,value,expression) values ('%s',%d,%d,'%s','%s',2,'%s')",description_esc, trigger.priority, trigger.status, comments_esc, url_esc, expression_old);
+ zbx_snprintf(sql,sizeof(sql),"insert into triggers (description,priority,status,comments,url,value,expression) values ('%s',%d,%d,'%s','%s',2,'%s')",description_esc, trigger.priority, trigger.status, comments_esc, url_esc, expression_old);
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]",sql);
DBexecute(sql);
triggerid_new=DBinsert_id();
- snprintf(sql,sizeof(sql)-1,"select i.key_,f.parameter,f.function,f.functionid from functions f,items i where i.itemid=f.itemid and f.triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select i.key_,f.parameter,f.function,f.functionid from functions f,items i where i.itemid=f.itemid and f.triggerid=%d", triggerid);
result2=DBselect(sql);
/* Loop: functions */
while((row2=DBfetch(result2)))
{
- snprintf(sql,sizeof(sql)-1,"select itemid from items where key_='%s' and hostid=%d", row2[0], atoi(row[0]));
+ zbx_snprintf(sql,sizeof(sql),"select itemid from items where key_='%s' and hostid=%d", row2[0], atoi(row[0]));
result3=DBselect(sql);
row3=DBfetch(result3);
if(!row3)
{
DBfree_result(result3);
- snprintf(sql,sizeof(sql)-1,"delete from triggers where triggerid=%d", triggerid_new);
+ zbx_snprintf(sql,sizeof(sql),"delete from triggers where triggerid=%d", triggerid_new);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from functions where triggerid=%d", triggerid_new);
+ zbx_snprintf(sql,sizeof(sql),"delete from functions where triggerid=%d", triggerid_new);
DBexecute(sql);
break;
}
- snprintf(sql,sizeof(sql)-1,"insert into functions (itemid,triggerid,function,parameter) values (%d,%d,'%s','%s')", atoi(row3[0]), triggerid_new, row2[2], row2[1]);
+ zbx_snprintf(sql,sizeof(sql),"insert into functions (itemid,triggerid,function,parameter) values (%d,%d,'%s','%s')", atoi(row3[0]), triggerid_new, row2[2], row2[1]);
DBexecute(sql);
functionid=DBinsert_id();
- snprintf(sql,sizeof(sql)-1,"update triggers set expression='%s' where triggerid=%d", expression_old, triggerid_new );
+ zbx_snprintf(sql,sizeof(sql),"update triggers set expression='%s' where triggerid=%d", expression_old, triggerid_new );
DBexecute(sql);
- snprintf(old, sizeof(old)-1,"{%d}", atoi(row2[3]));
- snprintf(new, sizeof(new)-1,"{%d}", functionid);
+ zbx_snprintf(old, sizeof(old),"{%d}", atoi(row2[3]));
+ zbx_snprintf(new, sizeof(new),"{%d}", functionid);
/* Possible memory leak here as expression can be malloced */
expression=string_replace(expression_old, old, new);
strscpy(expression_old, expression);
- snprintf(sql,sizeof(sql)-1,"update triggers set expression='%s' where triggerid=%d", expression, triggerid_new );
+ zbx_snprintf(sql,sizeof(sql),"update triggers set expression='%s' where triggerid=%d", expression, triggerid_new );
free(expression);
DBexecute(sql);
@@ -188,7 +188,7 @@ int DBget_trigger_by_triggerid(int triggerid,DB_TRIGGER *trigger)
zabbix_log( LOG_LEVEL_DEBUG, "In DBget_trigger_by_triggerid(%d)", triggerid);
- snprintf(sql,sizeof(sql)-1,"select triggerid, expression,description,url,comments,status,value,priority from triggers where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select triggerid, expression,description,url,comments,status,value,priority from triggers where triggerid=%d", triggerid);
result=DBselect(sql);
row=DBfetch(result);
diff --git a/src/libs/zbxemail/email.c b/src/libs/zbxemail/email.c
index 062dddaa..7e1c9edf 100644
--- a/src/libs/zbxemail/email.c
+++ b/src/libs/zbxemail/email.c
@@ -71,7 +71,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Cannot get IP for mailserver [%s]",smtp_server);
zabbix_syslog("Cannot get IP for mailserver [%s]",smtp_server);
- snprintf(error,max_error_len-1,"Cannot get IP for mailserver [%s]",smtp_server);
+ zbx_snprintf(error,max_error_len,"Cannot get IP for mailserver [%s]",smtp_server);
return FAIL;
}
@@ -95,7 +95,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Cannot create socket [%s]", strerror(errno));
zabbix_syslog("Cannot create socket [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Cannot create socket [%s]",strerror(errno));
+ zbx_snprintf(error,max_error_len,"Cannot create socket [%s]",strerror(errno));
return FAIL;
}
@@ -107,7 +107,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Cannot connect to SMTP server [%s] Error [%s]",smtp_server, strerror(errno));
zabbix_syslog("Cannot connect to SMTP server [%s] Error [%s]",smtp_server, strerror(errno));
- snprintf(error,max_error_len-1,"Cannot connect to SMTP server [%s] [%s]", smtp_server, strerror(errno));
+ zbx_snprintf(error,max_error_len,"Cannot connect to SMTP server [%s] [%s]", smtp_server, strerror(errno));
close(s);
return FAIL;
}
@@ -122,7 +122,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error receiving initial string from SMTP server [%m]");
zabbix_syslog("Error receiving initial string from SMTP server [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error receiving initial string from SMTP server [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error receiving initial string from SMTP server [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -130,7 +130,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "No welcome message 220* from SMTP server [%s]", c);
zabbix_syslog("No welcome message 220* from SMTP server [%s]", c);
- snprintf(error,max_error_len-1,"No welcome message 220* from SMTP server [%s]", c);
+ zbx_snprintf(error,max_error_len,"No welcome message 220* from SMTP server [%s]", c);
close(s);
return FAIL;
}
@@ -138,7 +138,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
if(strlen(smtp_helo) != 0)
{
memset(c,0,MAX_STRING_LEN);
- snprintf(c,sizeof(c)-1,"HELO %s\r\n",smtp_helo);
+ zbx_snprintf(c,sizeof(c),"HELO %s\r\n",smtp_helo);
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL7");
@@ -146,7 +146,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending HELO to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending HELO to mailserver [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error sending HELO to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending HELO to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -160,7 +160,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error receiving answer on HELO request [%s]", strerror(errno));
zabbix_syslog("Error receiving answer on HELO request [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error receiving answer on HELO request [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error receiving answer on HELO request [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -168,15 +168,17 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Wrong answer on HELO [%s]",c);
zabbix_syslog("Wrong answer on HELO [%s]",c);
- snprintf(error,max_error_len-1,"Wrong answer on HELO [%s]", c);
+ zbx_snprintf(error,max_error_len,"Wrong answer on HELO [%s]", c);
close(s);
return FAIL;
}
}
memset(c,0,MAX_STRING_LEN);
-/* sprintf(c,"MAIL FROM: %s\r\n",smtp_email);*/
- snprintf(c,sizeof(c)-1,"MAIL FROM: <%s>\r\n",smtp_email);
+
+ /* zbx_snprintf(c,sizeof(c),"MAIL FROM: %s\r\n",smtp_email); */
+ zbx_snprintf(c,sizeof(c),"MAIL FROM: <%s>\r\n",smtp_email);
+
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL9");
@@ -184,7 +186,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending MAIL FROM to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending MAIL FROM to mailserver [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error sending MAIL FROM to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending MAIL FROM to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -198,7 +200,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error receiving answer on MAIL FROM request [%s]", strerror(errno));
zabbix_syslog("Error receiving answer on MAIL FROM request [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error receiving answer on MAIL FROM request [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error receiving answer on MAIL FROM request [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -206,13 +208,13 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Wrong answer on MAIL FROM [%s]", c);
zabbix_syslog("Wrong answer on MAIL FROM [%s]", c);
- snprintf(error,max_error_len-1,"Wrong answer on MAIL FROM [%s]", c);
+ zbx_snprintf(error,max_error_len,"Wrong answer on MAIL FROM [%s]", c);
close(s);
return FAIL;
}
memset(c,0,MAX_STRING_LEN);
- snprintf(c,sizeof(c)-1,"RCPT TO: <%s>\r\n",mailto);
+ zbx_snprintf(c,sizeof(c),"RCPT TO: <%s>\r\n",mailto);
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL11");
@@ -220,7 +222,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending RCPT TO to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending RCPT TO to mailserver [%s]", strerror(errno) );
- snprintf(error,max_error_len-1,"Error sending RCPT TO to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending RCPT TO to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -233,7 +235,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error receiving answer on RCPT TO request [%s]", strerror(errno));
zabbix_syslog("Error receiving answer on RCPT TO request [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error receiving answer on RCPT TO request [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error receiving answer on RCPT TO request [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -242,13 +244,13 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Wrong answer on RCPT TO [%s]", c);
zabbix_syslog("Wrong answer on RCPT TO [%s]", c);
- snprintf(error,max_error_len-1,"Wrong answer on RCPT TO [%s]", c);
+ zbx_snprintf(error,max_error_len,"Wrong answer on RCPT TO [%s]", c);
close(s);
return FAIL;
}
memset(c,0,MAX_STRING_LEN);
- snprintf(c,sizeof(c)-1,"DATA\r\n");
+ zbx_snprintf(c,sizeof(c),"DATA\r\n");
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL13");
@@ -256,7 +258,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending DATA to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending DATA to mailserver [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error sending DATA to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending DATA to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -269,7 +271,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error receivng answer on DATA request [%s]", strerror(errno));
zabbix_syslog("Error receivng answer on DATA request [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error receivng answer on DATA request [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error receivng answer on DATA request [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -277,7 +279,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Wrong answer on DATA [%s]", c);
zabbix_syslog("Wrong answer on DATA [%s]", c);
- snprintf(error,max_error_len-1,"Wrong answer on DATA [%s]", c);
+ zbx_snprintf(error,max_error_len,"Wrong answer on DATA [%s]", c);
close(s);
return FAIL;
}
@@ -286,22 +288,22 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
time(&email_time);
local_time = localtime(&email_time);
strftime( str_time, MAX_STRING_LEN, "%a, %d %b %Y %H:%M:%S %z", local_time );
-/* sprintf(c,"Subject: %s\r\n%s",mailsubject, mailbody);*/
-/* snprintf(c,sizeof(c)-1,"From:<%s>\r\nTo:<%s>\r\nSubject: %s\r\n\r\n%s",smtp_email,mailto,mailsubject, mailbody);*/
- snprintf(c,sizeof(c)-1,"From:<%s>\r\nTo:<%s>\r\nDate: %s\r\nSubject: %s\r\n\r\n%s",smtp_email,mailto,str_time,mailsubject, mailbody);
+/* zbx_snprintf(c,sizeof(c),"Subject: %s\r\n%s",mailsubject, mailbody);*/
+/* zbx_snprintf(c,sizeof(c),"From:<%s>\r\nTo:<%s>\r\nSubject: %s\r\n\r\n%s",smtp_email,mailto,mailsubject, mailbody);*/
+ zbx_snprintf(c,sizeof(c),"From:<%s>\r\nTo:<%s>\r\nDate: %s\r\nSubject: %s\r\n\r\n%s",smtp_email,mailto,str_time,mailsubject, mailbody);
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
if(e == -1)
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending mail subject and body to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending mail subject and body to mailserver [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error sending mail subject and body to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending mail subject and body to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
memset(c,0,MAX_STRING_LEN);
- snprintf(c,sizeof(c)-1,"\r\n.\r\n");
+ zbx_snprintf(c,sizeof(c),"\r\n.\r\n");
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL15");
@@ -309,7 +311,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending . to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending . to mailserver [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error sending . to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending . to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -322,7 +324,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error receivng answer on . request [%s]", strerror(errno));
zabbix_syslog("Error receivng answer on . request [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error receivng answer on . request [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error receivng answer on . request [%s]", strerror(errno));
close(s);
return FAIL;
}
@@ -330,13 +332,13 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Wrong answer on end of data [%s]", c);
zabbix_syslog("Wrong answer on end of data [%s]", c);
- snprintf(error,max_error_len-1,"Wrong answer on end of data [%s]", c);
+ zbx_snprintf(error,max_error_len,"Wrong answer on end of data [%s]", c);
close(s);
return FAIL;
}
memset(c,0,MAX_STRING_LEN);
- snprintf(c,sizeof(c)-1,"QUIT\r\n");
+ zbx_snprintf(c,sizeof(c),"QUIT\r\n");
/* e=sendto(s,c,strlen(c),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)); */
e=write(s,c,strlen(c));
zabbix_log( LOG_LEVEL_DEBUG, "SENDING MAIL18");
@@ -344,7 +346,7 @@ int send_email(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,c
{
zabbix_log(LOG_LEVEL_DEBUG, "Error sending QUIT to mailserver [%s]", strerror(errno));
zabbix_syslog("Error sending QUIT to mailserver [%s]", strerror(errno));
- snprintf(error,max_error_len-1,"Error sending QUIT to mailserver [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error sending QUIT to mailserver [%s]", strerror(errno));
close(s);
return FAIL;
}
diff --git a/src/libs/zbxlog/log.c b/src/libs/zbxlog/log.c
index da58295b..a5c3d7df 100644
--- a/src/libs/zbxlog/log.c
+++ b/src/libs/zbxlog/log.c
@@ -18,63 +18,130 @@
**/
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <syslog.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <time.h>
-
-#include "log.h"
#include "common.h"
+#include "log.h"
+
+#include "mutexs.h"
+#include "threads.h"
static char log_filename[MAX_STRING_LEN];
static int log_type = LOG_TYPE_UNDEFINED;
-static int log_level;
+static int log_level = LOG_LEVEL_ERR;
+
+static ZBX_MUTEX log_file_access;
-int zabbix_open_log(int type,int level, const char *filename)
+#if defined(WIN32)
+
+#include "messages.h"
+#include "service.h"
+
+static HANDLE system_log_handle = INVALID_HANDLE_VALUE;
+
+#endif
+
+int zabbix_open_log(int type, int level, const char *filename)
{
FILE *log_file = NULL;
-/* Just return if we do not want to write debug */
+
+ zbx_error("Log file is '%s'",filename);
+
+
log_level = level;
- if(level == LOG_LEVEL_EMPTY)
+ if(LOG_LEVEL_EMPTY == level)
{
return SUCCEED;
}
- if(type == LOG_TYPE_SYSLOG)
+ if(LOG_TYPE_FILE == type && NULL == filename)
+ {
+ type = LOG_TYPE_SYSLOG;
+ }
+
+ if(LOG_TYPE_SYSLOG == type)
{
- openlog("zabbix_suckerd",LOG_PID,LOG_USER);
- setlogmask(LOG_UPTO(LOG_WARNING));
log_type = LOG_TYPE_SYSLOG;
+
+#if defined(WIN32)
+
+ system_log_handle = RegisterEventSource(NULL, ZABBIX_EVENT_SOURCE);
+
+#else /* not WIN32 */
+
+ openlog("zabbix_suckerd", LOG_PID, LOG_USER);
+ setlogmask(LOG_UPTO(LOG_WARNING));
+
+#endif /* WIN32 */
}
- else if(type == LOG_TYPE_FILE)
+
+ else if(LOG_TYPE_FILE == type)
{
- log_file = fopen(filename,"a+");
- if(log_file == NULL)
+ if(strlen(filename) >= MAX_STRING_LEN)
{
- fprintf(stderr, "Unable to open log file [%s] [%s]\n", filename, strerror(errno));
+ zbx_error("To large path for logfile.");
return FAIL;
}
+
+ if(ZBX_MUTEX_ERROR == zbx_mutex_create(&log_file_access, "log"))
+ {
+ zbx_error("Unable to create mutex for log file");
+ return FAIL;
+ }
+
+ if(NULL == (log_file = fopen(filename,"a+")))
+ {
+ zbx_error("Unable to open log file [%s] [%s]", filename, strerror(errno));
+ return FAIL;
+ }
+
log_type = LOG_TYPE_FILE;
strscpy(log_filename,filename);
- fclose(log_file);
+ zbx_fclose(log_file);
}
else
{
-/* Not supported logging type */
- fprintf(stderr, "Not supported loggin type [%d]\n", type);
+ /* Not supported logging type */
+
+ if(ZBX_MUTEX_ERROR == zbx_mutex_create(&log_file_access, "/tmp/zbxlmtx"))
+ {
+ zbx_error("Unable to create mutex for log file");
+ return FAIL;
+ }
+
+ zbx_error("Not supported loggin type [%d]", type);
return FAIL;
}
+
return SUCCEED;
}
+void zabbix_close_log(void)
+{
+ if(LOG_TYPE_SYSLOG == log_type)
+ {
+#if defined(WIN32)
+
+ if(system_log_handle)
+ DeregisterEventSource(system_log_handle);
+
+#else /* not WIN32 */
+
+ closelog();
+
+#endif /* WIN32 */
+ }
+ else if(log_type == LOG_TYPE_FILE)
+ {
+ zbx_mutex_destroy(&log_file_access);
+ }
+ else
+ {
+ /* Not supported loggin type */
+ zbx_mutex_destroy(&log_file_access);
+ }
+}
+
void zabbix_set_log_level(int level)
{
log_level = level;
@@ -82,69 +149,203 @@ void zabbix_set_log_level(int level)
void zabbix_log(int level, const char *fmt, ...)
{
- FILE *log_file = NULL;
+ FILE *log_file = NULL;
+
+ char message[MAX_STRING_LEN];
- char str[MAX_BUF_LEN];
- char str2[MAX_BUF_LEN];
time_t t;
struct tm *tm;
- va_list ap;
+ va_list args;
+
+ struct stat buf;
- struct stat buf;
char filename_old[MAX_STRING_LEN];
+
+#if defined(WIN32)
+
+ WORD wType;
+ char *strings[2] = {message, NULL};
- if( (level>log_level) || (level == LOG_LEVEL_EMPTY))
+#endif /* WIN32 */
+
+ if( (level > log_level) || (LOG_LEVEL_EMPTY == level))
{
return;
}
- if(log_type == LOG_TYPE_SYSLOG)
+ va_start(args, fmt);
+ vsnprintf(message, MAX_STRING_LEN-2, fmt, args);
+ va_end(args);
+ strncat(message,"\0",MAX_STRING_LEN);
+
+ if(LOG_TYPE_SYSLOG == log_type)
{
- va_start(ap,fmt);
- vsprintf(str,fmt,ap);
- strncat(str,"\n",MAX_BUF_LEN);
- str[MAX_BUF_LEN-1]=0;
- syslog(LOG_DEBUG,str);
- va_end(ap);
+#if defined(WIN32)
+ switch(level)
+ {
+ case LOG_LEVEL_CRIT:
+ case LOG_LEVEL_ERR:
+ wType = EVENTLOG_ERROR_TYPE;
+ break;
+ case LOG_LEVEL_WARNING:
+ wType = EVENTLOG_WARNING_TYPE;
+ break;
+ default:
+ wType = EVENTLOG_INFORMATION_TYPE;
+ break;
+ }
+
+ ReportEvent(system_log_handle, wType, 0, MSG_ZABBIX_MESSAGE, NULL, 1, 0, strings, NULL);
+
+#else /* not WIN32 */
+
+ syslog(LOG_DEBUG,message);
+
+#endif /* WIN32 */
}
else if(log_type == LOG_TYPE_FILE)
{
- t=time(NULL);
- tm=localtime(&t);
- snprintf(str2,sizeof(str2)-1,"%.6d:%.4d%.2d%.2d:%.2d%.2d%.2d ",(int)getpid(),tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
-
- va_start(ap,fmt);
- vsnprintf(str,MAX_BUF_LEN,fmt,ap);
- va_end(ap);
-
+ zbx_mutex_lock(&log_file_access);
+
log_file = fopen(log_filename,"a+");
- if(log_file == NULL)
+
+ if(NULL != log_file)
{
- return;
- }
- fprintf(log_file,"%s",str2);
- fprintf(log_file,"%s",str);
- fprintf(log_file,"\n");
- fclose(log_file);
+ t = time(NULL);
+ tm = localtime(&t);
+ fprintf(log_file,
+ "%6lu:%.4d%.2d%.2d:%.2d%.2d%.2d ",
+ (unsigned long)zbx_get_thread_id(),
+ tm->tm_year+1900,
+ tm->tm_mon+1,
+ tm->tm_mday,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec
+ );
- if(stat(log_filename,&buf) == 0)
- {
- if(buf.st_size > MAX_LOG_FILE_LEN)
+ va_start(args,fmt);
+
+
+ vfprintf(log_file,fmt, args);
+
+ va_end(args);
+
+ fprintf(log_file,"\n");
+ zbx_fclose(log_file);
+
+ if(stat(log_filename,&buf) == 0)
{
- strscpy(filename_old,log_filename);
- strncat(filename_old,".old",MAX_STRING_LEN);
- if(rename(log_filename,filename_old) != 0)
+ if(buf.st_size > MAX_LOG_FILE_LEN)
{
-/* exit(1);*/
+ strscpy(filename_old,log_filename);
+ strncat(filename_old,".old",MAX_STRING_LEN);
+ remove(filename_old);
+ if(rename(log_filename,filename_old) != 0)
+ {
+ zbx_error("Can't rename log file [%s] to [%s] [%s]", log_filename, filename_old, strerror(errno));
+ }
}
}
}
+
+ zbx_mutex_unlock(&log_file_access);
}
else
{
- /* Log is not opened */
+ zbx_mutex_lock(&log_file_access);
+
+ switch(level)
+ {
+ case LOG_LEVEL_CRIT:
+ zbx_error("ERROR: %s", message);
+ break;
+ case LOG_LEVEL_ERR:
+ zbx_error("Error: %s", message);
+ break;
+ case LOG_LEVEL_WARNING:
+ zbx_error("Warning: %s", message);
+ break;
+ case LOG_LEVEL_DEBUG:
+ zbx_error("DEBUG: %s", message);
+ break;
+ default:
+ zbx_error("%s", message);
+ break;
+ }
+
+ zbx_mutex_unlock(&log_file_access);
}
return;
}
+//
+// Get system error string by call to FormatMessage
+//
+#define ZBX_MESSAGE_BUF_SIZE 1024
+
+char *strerror_from_system(unsigned long error)
+{
+#if defined(WIN32)
+
+ static char buffer[ZBX_MESSAGE_BUF_SIZE]; /* !!! Attention static !!! not thread safely - Win32*/
+
+ memset(buffer, 0, ZBX_MESSAGE_BUF_SIZE);
+
+ if(FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ error,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ buffer,
+ 1023,
+ NULL) == 0)
+ {
+ zbx_snprintf(buffer, sizeof(buffer), "3. MSG 0x%08X - Unable to find message text [0x%X]", error , GetLastError());
+ }
+
+ return buffer;
+
+#else /* not WIN32 */
+
+ return strerror(errno);
+
+#endif /* WIN32 */
+}
+
+//
+// Get system error string by call to FormatMessage
+//
+
+char *strerror_from_module(unsigned long error, const char *module)
+{
+#if defined(WIN32)
+
+ static char buffer[ZBX_MESSAGE_BUF_SIZE]; /* !!! Attention static !!! not thread safely - Win32*/
+
+ assert(module);
+
+ memset(buffer, 0, ZBX_MESSAGE_BUF_SIZE);
+
+ if (FormatMessage(
+ FORMAT_MESSAGE_FROM_HMODULE,
+ GetModuleHandle(module),
+ error,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ buffer,
+ 1024,
+ NULL) == 0)
+ {
+ zbx_snprintf(buffer, sizeof(buffer), "3. MSG 0x%08X - Unable to find message text [0x%X]", error , GetLastError());
+ }
+
+ return buffer;
+
+#else /* not WIN32 */
+
+ return strerror(errno);
+
+#endif /* WIN32 */
+
+}
diff --git a/src/libs/zbxnet/Makefile.am b/src/libs/zbxnet/Makefile.am
index f2a00f45..32d03ce0 100644
--- a/src/libs/zbxnet/Makefile.am
+++ b/src/libs/zbxnet/Makefile.am
@@ -1,3 +1,3 @@
SUBDIRS=
lib_LIBRARIES=libzbxnet.a
-libzbxnet_a_SOURCES=security.c
+libzbxnet_a_SOURCES=security.c zbxsock.c
diff --git a/src/libs/zbxnet/security.c b/src/libs/zbxnet/security.c
index db4f841f..151de56c 100644
--- a/src/libs/zbxnet/security.c
+++ b/src/libs/zbxnet/security.c
@@ -18,19 +18,20 @@
**/
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
+//#include <sys/types.h>
+//#include <sys/socket.h>
+//#include <netinet/in.h>
+//#include <arpa/inet.h>
+//#include <netdb.h>
-#include <string.h>
+//#include <string.h>
-#include <errno.h>
+//#include <errno.h>
/* config.h is required for socklen_t (undefined under Solaris) */
#include "config.h"
#include "common.h"
+#include "zbxsock.h"
#include "log.h"
/******************************************************************************
@@ -51,58 +52,59 @@
* Comments: *
* *
******************************************************************************/
-int check_security(int sockfd, char *ip_list, int allow_if_empty)
+
+int check_security(ZBX_SOCKET sock, char *ip_list, int allow_if_empty)
{
- struct sockaddr_in name;
- int i;
- char *sip, *host;
+ ZBX_SOCKADDR name;
+ int nlen;
+
struct hostent *hp;
- char tmp[MAX_STRING_LEN], sname[MAX_STRING_LEN];
+ char tmp[MAX_STRING_LEN],
+ sname[MAX_STRING_LEN],
+ *sip,
+ *host;
zabbix_log( LOG_LEVEL_DEBUG, "In check_security()");
- if( (1 == allow_if_empty) && (strlen(ip_list)==0) )
+ if( (1 == allow_if_empty) && (0 == strlen(ip_list)) )
{
return SUCCEED;
}
- i=sizeof(name);
-
- if(getpeername(sockfd, (struct sockaddr *)&name, (socklen_t *)&i) == 0)
+ nlen = sizeof(ZBX_SOCKADDR);
+ if( 0 != getpeername(sock, (struct sockaddr*)&name, &nlen))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Connection rejected. Getpeername failed [%s].",strerror(errno));
+ return FAIL;
+ }
+ else
{
- i=sizeof(struct sockaddr_in);
+ strcpy(sname, inet_ntoa(name.sin_addr));
- strcpy(sname,inet_ntoa(name.sin_addr));
+ strscpy(tmp,ip_list);
- zabbix_log( LOG_LEVEL_DEBUG, "Connection from [%s]. Allowed servers [%s] ",sname, ip_list);
+ host = (char *)strtok(tmp,",");
- strscpy(tmp,ip_list);
- host=(char *)strtok(tmp,",");
- while(host!=NULL)
+ while( NULL != host )
{
/* Allow IP addresses or DNS names for authorization */
- if((hp=gethostbyname(host)) == 0)
+ if( 0 == (hp = gethostbyname(host)))
{
- zabbix_log( LOG_LEVEL_WARNING, "Error gethostbyname, can not resolve [%s]",host);
+ zabbix_log( LOG_LEVEL_WARNING, "Error on gethostbyname, can not resolve [%s]",host);
}
else
{
- sip=inet_ntoa(*((struct in_addr *)hp->h_addr));
- if(strcmp(sname, sip)==0)
+ sip = inet_ntoa(*((struct in_addr *)hp->h_addr));
+ if( 0 == strcmp(sname, sip))
{
+ zabbix_log( LOG_LEVEL_DEBUG, "Connection from [%s] accepted. Allowed servers [%s] ",sname, ip_list);
return SUCCEED;
}
}
- host=(char *)strtok(NULL,",");
+ host = (char *)strtok(NULL,",");
}
}
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error getpeername [%s]",strerror(errno));
- zabbix_log( LOG_LEVEL_WARNING, "Connection rejected");
- return FAIL;
- }
zabbix_log( LOG_LEVEL_WARNING, "Connection from [%s] rejected. Allowed server is [%s] ",sname, ip_list);
return FAIL;
}
diff --git a/src/libs/zbxnet/zbxsock.c b/src/libs/zbxnet/zbxsock.c
new file mode 100755
index 00000000..dd087ea6
--- /dev/null
+++ b/src/libs/zbxnet/zbxsock.c
@@ -0,0 +1,111 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "zbxsock.h"
+
+#include "log.h"
+
+#if !defined(WIN32)
+
+static void sock_signal_handler(int sig)
+{
+ switch(sig)
+ {
+ case SIGALRM:
+ signal(SIGALRM , sock_signal_handler);
+ zabbix_log( LOG_LEVEL_WARNING, "Timeout while answering request");
+ break;
+ default:
+ zabbix_log( LOG_LEVEL_WARNING, "Sock handler: Got signal [%d]. Ignoring ...", sig);
+ }
+}
+
+#endif /* not WIN32 */
+
+int zbx_sock_read(ZBX_SOCKET sock, void *buf, int buflen, int timeout)
+{
+#if defined (WIN32)
+
+ TIMEVAL time = {0,0};
+ FD_SET rdfs;
+
+ int rc = 0;
+
+ /* Wait for command from server */
+ FD_ZERO(&rdfs);
+ FD_SET(sock, &rdfs); /* ignore WARNING '...whle(0)' */
+
+ time.tv_sec = timeout;
+ time.tv_usec = 0;
+
+ rc = select(sock+1, &rdfs, (fd_set *)NULL, (fd_set *)NULL, &time);
+
+ if (rc == SOCKET_ERROR)
+ {
+ return (SOCKET_ERROR);
+ }
+ else if(rc == 0)
+ {
+ return (0); /* time out */
+ }
+
+ return (int)recv(sock, buf, buflen, 0);
+
+
+#else /* not WIN32 */
+
+ static struct sigaction phan;
+ int nread = 0;
+
+ phan.sa_handler = sock_signal_handler; /* set up sig handler using sigaction() */
+ sigemptyset(&phan.sa_mask);
+ phan.sa_flags = 0;
+
+ sigaction(SIGALRM, &phan, NULL);
+
+ alarm(timeout);
+
+ if( (nread = read(sock, buf, MAX_STRING_LEN)) == SOCKET_ERROR)
+ {
+ return (SOCKET_ERROR);
+ }
+ alarm(0);
+
+ return nread;
+
+#endif /* WIN32 */
+
+ /* normal case the program will never reach this point. */
+ return SOCKET_ERROR;
+}
+
+int zbx_sock_write(ZBX_SOCKET sock, void *buf, int buflen)
+{
+#if defined (WIN32)
+
+ return send(sock, buf, buflen,0);
+
+#else /* not WIN32 */
+
+ return write(sock, buf, buflen);
+
+#endif /* WIN32 */
+
+}
diff --git a/src/libs/zbxnix/Makefile.am b/src/libs/zbxnix/Makefile.am
new file mode 100755
index 00000000..a941a070
--- /dev/null
+++ b/src/libs/zbxnix/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS=
+lib_LIBRARIES=libzbxnix.a
+libzbxnix_a_SOURCES=daemon.c pid.c
diff --git a/src/libs/zbxnix/daemon.c b/src/libs/zbxnix/daemon.c
new file mode 100755
index 00000000..c5137e68
--- /dev/null
+++ b/src/libs/zbxnix/daemon.c
@@ -0,0 +1,194 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "daemon.h"
+
+#include "pid.h"
+#include "log.h"
+
+char *APP_PID_FILE = NULL;
+
+static int parent = 0;
+
+#define uninit() { if(parent == 1) zbx_on_exit(); }
+
+void child_signal_handler(int sig)
+{
+ switch(sig)
+ {
+ case SIGALRM:
+ signal(SIGALRM , child_signal_handler);
+ zabbix_log( LOG_LEVEL_WARNING, "Timeout while answering request");
+ break;
+ case SIGQUIT:
+ case SIGINT:
+ case SIGTERM:
+ zabbix_log( LOG_LEVEL_WARNING, "Got signal. Exiting ...");
+ uninit();
+ exit( FAIL );
+ break;
+ case SIGPIPE:
+ zabbix_log( LOG_LEVEL_WARNING, "Got SIGPIPE. Where it came from???");
+ break;
+ default:
+ zabbix_log( LOG_LEVEL_WARNING, "Got signal [%d]. Ignoring ...", sig);
+ }
+}
+
+static void parent_signal_handler(int sig)
+{
+ switch(sig)
+ {
+ case SIGCHLD:
+ zabbix_log( LOG_LEVEL_WARNING, "One child process died. Exiting ...");
+ uninit();
+ exit( FAIL );
+ break;
+ default:
+ child_signal_handler(sig);
+ }
+}
+
+
+/******************************************************************************
+ * *
+ * Function: daemon_start *
+ * *
+ * Purpose: init process as daemon *
+ * *
+ * Parameters: allow_root - allow root permision for application *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: it doesn't allow running under 'root' if allow_root is zerro *
+ * *
+ ******************************************************************************/
+
+int daemon_start(int allow_root)
+{
+ int i;
+ pid_t pid;
+ struct passwd *pwd;
+ struct sigaction phan;
+
+ /* running as root ?*/
+ if((0 == allow_root) && (0 == getuid() || 0 == getgid()))
+ {
+ pwd = getpwnam("zabbix");
+ if (NULL == pwd)
+ {
+ zbx_error("User zabbix does not exist.");
+ zbx_error("Cannot run as root !");
+ exit(FAIL);
+ }
+ if( (setgid(pwd->pw_gid) ==-1) || (setuid(pwd->pw_uid) == -1) )
+ {
+ zbx_error("Cannot setgid or setuid to zabbix [%s].", strerror(errno));
+ exit(FAIL);
+ }
+
+#ifdef HAVE_FUNCTION_SETEUID
+ if( (setegid(pwd->pw_gid) ==-1) || (seteuid(pwd->pw_uid) == -1) )
+ {
+ zbx_error("Cannot setegid or seteuid to zabbix [%s].", strerror(errno));
+ exit(FAIL);
+ }
+#endif /* HAVE_FUNCTION_SETEUID */
+
+ }
+
+ if( (pid = fork()) != 0 )
+ {
+ exit( 0 );
+ }
+
+ setsid();
+
+ signal( SIGHUP, SIG_IGN );
+
+ if( (pid = fork()) !=0 )
+ {
+ exit( 0 );
+ }
+
+ chdir("/");
+ umask(002 /* 022 */);
+
+ for(i=0; i<MAXFD; i++)
+ {
+ /* Do not close stderr */
+ if(i == fileno(stderr)) continue; //TODO!!! redirection;
+ /* Do not close stdout */
+ if(i == fileno(stdout)) continue; //TODO!!! redirestion;
+
+ close(i);
+ }
+
+#ifdef HAVE_SYS_RESOURCE_SETPRIORITY
+
+ if(setpriority(PRIO_PROCESS,0,5)!=0)
+ {
+ zbx_error("Unable to set process priority to 5. Leaving default.");
+ }
+
+#endif /* HAVE_SYS_RESOURCE_SETPRIORITY */
+
+//------------------------------------------------
+
+ if( FAIL == create_pid_file(APP_PID_FILE))
+ {
+ exit(FAIL);
+ }
+
+ phan.sa_handler = child_signal_handler;
+ sigemptyset(&phan.sa_mask);
+ phan.sa_flags = 0;
+
+ sigaction(SIGINT, &phan, NULL);
+ sigaction(SIGQUIT, &phan, NULL);
+ sigaction(SIGTERM, &phan, NULL);
+ sigaction(SIGPIPE, &phan, NULL);
+
+ zbx_setproctitle("main process");
+
+ return MAIN_ZABBIX_ENTRY();
+}
+
+void daemon_stop(void)
+{
+ drop_pid_file(APP_PID_FILE);
+}
+
+void init_main_process(void)
+{
+ struct sigaction phan;
+
+ parent = 1; /* signalize signal_handler what this process isi a PARENT process */
+
+ phan.sa_handler = parent_signal_handler;
+ sigemptyset(&phan.sa_mask);
+ phan.sa_flags = 0;
+
+ /* For parent only. To avoid problems with EXECUTE_INT */
+ sigaction(SIGCHLD, &phan, NULL);
+}
+
diff --git a/src/libs/zbxnix/pid.c b/src/libs/zbxnix/pid.c
new file mode 100755
index 00000000..fdf6b32e
--- /dev/null
+++ b/src/libs/zbxnix/pid.c
@@ -0,0 +1,65 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "pid.h"
+
+#include "log.h"
+#include "threads.h"
+
+int create_pid_file(const char *pidfile)
+{
+ FILE *f = NULL;
+
+ /* check if pid file already exists */
+ if( NULL != (f = fopen(pidfile, "r")) )
+ {
+ zbx_error("File [%s] exists. Is this process already running ?", pidfile);
+ zabbix_log( LOG_LEVEL_CRIT, "File [%s] exists. Is this process already running ?", pidfile);
+
+ zbx_fclose(f);
+
+ return FAIL;
+ }
+
+ /* open pid file */
+ if( NULL == (f = fopen(pidfile, "w")))
+ {
+ zbx_error("Cannot create PID file [%s] [%s]", pidfile, strerror(errno));
+ zabbix_log( LOG_LEVEL_CRIT, "Cannot create PID file [%s] [%s]", pidfile, strerror(errno));
+
+ return FAIL;
+ }
+
+ /* frite pid to file */
+ fprintf(f, "%li", zbx_get_thread_id());
+
+ /* close pid file */
+ zbx_fclose(f);
+
+ return SUCCEED;
+}
+
+void drop_pid_file(const char *pidfile)
+{
+ if(-1 == unlink(pidfile))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot remove PID file [%s] [%s]", pidfile, strerror(errno));
+ }
+}
diff --git a/src/libs/zbxplugin/Makefile.am b/src/libs/zbxplugin/Makefile.am
new file mode 100644
index 00000000..edd081b1
--- /dev/null
+++ b/src/libs/zbxplugin/Makefile.am
@@ -0,0 +1,4 @@
+SUBDIRS=
+lib_LIBRARIES=libzbxplugin.a
+libzbxplugin_a_SOURCES=zbxplugin.c
+
diff --git a/src/libs/zbxplugin/zbxplugin.c b/src/libs/zbxplugin/zbxplugin.c
new file mode 100755
index 00000000..736f433a
--- /dev/null
+++ b/src/libs/zbxplugin/zbxplugin.c
@@ -0,0 +1,33 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+
+#include "zbxplugin.h"
+
+ZBX_PLUGIN_LIST *PluginsList = NULL;
+
+
+int add_plugin(char *args)
+{
+#ifdef TODO
+# error ADD REALIZATION!!!
+#endif
+ return 0;
+}
diff --git a/src/libs/zbxsms/sms.c b/src/libs/zbxsms/sms.c
index 9209287f..9731f65d 100644
--- a/src/libs/zbxsms/sms.c
+++ b/src/libs/zbxsms/sms.c
@@ -43,13 +43,13 @@ static int write_gsm(int fd, char *str, char *error, int max_error_len)
len = strlen(str);
- zabbix_log(LOG_LEVEL_WARNING, "Write [%s]\n", str);
+ zabbix_log(LOG_LEVEL_WARNING, "Write [%s]", str);
if (write(fd, str, len) < len)
{
zabbix_log(LOG_LEVEL_DEBUG, "Error writing to GSM modem [%s]", strerror(errno));
zabbix_syslog("Error writing to GSM modem [%s]", strerror(errno));
- snprintf(error,max_error_len-1, "Error writing to GSM modem [%s]", strerror(errno));
+ zbx_snprintf(error,max_error_len, "Error writing to GSM modem [%s]", strerror(errno));
return FAIL;
}
@@ -76,14 +76,14 @@ static int read_gsm(int fd, char *expect, char *error, int max_error_len)
/* printf("Read buffer [%s]\n", buffer);
for(i=0;i<strlen(buffer);i++)
printf("[%x]\n",buffer[i]);*/
- zabbix_log(LOG_LEVEL_WARNING, "Read buffer [%s]\n", buffer);
+ zabbix_log(LOG_LEVEL_WARNING, "Read buffer [%s]", buffer);
for(i=0;i<strlen(buffer);i++)
- zabbix_log(LOG_LEVEL_WARNING, "[%x]\n", buffer[i]);
+ zabbix_log(LOG_LEVEL_WARNING, "[%x]", buffer[i]);
if (strstr(buffer, expect) == NULL)
{
zabbix_log(LOG_LEVEL_DEBUG, "Read something unexpected from GSM modem");
zabbix_syslog("Read something unexpected from GSM modem");
- snprintf(error,max_error_len-1, "Read something unexpected from GSM modem");
+ zbx_snprintf(error,max_error_len, "Read something unexpected from GSM modem");
ret = FAIL;
}
return ret;
@@ -103,7 +103,7 @@ int send_sms(char *device,char *number,char *message, char *error, int max_error
{
zabbix_log(LOG_LEVEL_DEBUG, "Error open(%s) [%s]", device, strerror(errno));
zabbix_syslog("Error open(%s) [%s]", device, strerror(errno));
- snprintf(error,max_error_len-1, "Error open(%s) [%s]", device, strerror(errno));
+ zbx_snprintf(error,max_error_len, "Error open(%s) [%s]", device, strerror(errno));
return FAIL;
}
fcntl(f, F_SETFL,0);
@@ -141,7 +141,7 @@ int send_sms(char *device,char *number,char *message, char *error, int max_error
/* Send phone number */
if(ret == SUCCEED)
{
- snprintf(str, MAX_STRING_LEN-1,"AT+CMGS=\"%s\"\r", number);
+ zbx_snprintf(str, sizeof(str),"AT+CMGS=\"%s\"\r", number);
ret = write_gsm(f,str, error, max_error_len);
}
if(ret == SUCCEED)
@@ -150,7 +150,7 @@ int send_sms(char *device,char *number,char *message, char *error, int max_error
/* Send message */
if(ret == SUCCEED)
{
- snprintf(str, MAX_STRING_LEN-1,"%s\x01a", message);
+ zbx_snprintf(str, sizeof(str),"%s\x01a", message);
ret = write_gsm(f, str, error, max_error_len);
}
if(ret == SUCCEED)
diff --git a/src/libs/zbxsys/Makefile.am b/src/libs/zbxsys/Makefile.am
new file mode 100755
index 00000000..0bdc60ac
--- /dev/null
+++ b/src/libs/zbxsys/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS=
+lib_LIBRARIES=libzbxsys.a
+libzbxsys_a_SOURCES=threads.c mutexs.c
diff --git a/src/libs/zbxsys/mutexs.c b/src/libs/zbxsys/mutexs.c
new file mode 100755
index 00000000..56a3e676
--- /dev/null
+++ b/src/libs/zbxsys/mutexs.c
@@ -0,0 +1,227 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "mutexs.h"
+
+#if !defined(WIN32)
+
+# if !defined(semun)
+ union semun
+ {
+ int val; /* <= value for SETVAL */
+ struct semid_ds *buf; /* <= buffer for IPC_STAT & IPC_SET */
+ unsigned short int *array; /* <= array for GETALL & SETALL */
+ struct seminfo *__buf; /* <= buffer for IPC_INFO */
+ };
+# endif /* semun */
+
+# include "cfg.h"
+
+#endif /* not WIN32 */
+
+#include "log.h"
+
+/******************************************************************************
+ * *
+ * Function: zbx_mutex_create *
+ * *
+ * Purpose: Create the mutex *
+ * *
+ * Parameters: mutex - handle of mutex *
+ * *
+ * Return value: If the function succeeds, the return ZBX_MUTEX_OK, *
+ * ZBX_MUTEX_ERROR on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: LINUX version can create ONLY ONE mutex!!!!!!! *
+ * *
+ ******************************************************************************/
+
+int zbx_mutex_create(ZBX_MUTEX *mutex, char *name)
+{
+#if defined(WIN32)
+
+ if(NULL == ((*mutex) = CreateMutex(NULL, FALSE, NULL)))
+ {
+ zbx_error("Error on mutex creating. [%s]", strerror_from_system(GetLastError()));
+ return ZBX_MUTEX_ERROR;
+ }
+
+#else /* not WIN32 */
+
+ key_t sem_key;
+ int sem_id;
+ union semun semopts;
+
+ if( -1 == (sem_key = ftok(CONFIG_FILE, (int)'z') ))
+ {
+ zbx_error("Can not create IPC key for path '%s', try to create for path '.' [%s]", CONFIG_FILE, strerror(errno));
+ if( -1 == (sem_key = ftok(".", (int)'z') ))
+ {
+ zbx_error("Can not create IPC key for path '.' [%s]", strerror(errno));
+ return ZBX_MUTEX_ERROR;
+ }
+ }
+
+ if ( -1 == (sem_id = semget(sem_key, 1, IPC_CREAT | /* 0022 */ 0666)) )
+ {
+ zbx_error("Can not create Semaphore [%s]", strerror(errno));
+ return ZBX_MUTEX_ERROR;
+ }
+
+ /* set default semaphore value */
+ semopts.val = 1;
+ semctl(sem_id, 0, SETVAL, semopts);
+
+ *mutex = sem_id;
+
+#endif /* WIN32 */
+
+ return ZBX_MUTEX_OK;
+}
+
+/******************************************************************************
+ * *
+ * Function: zbx_mutex_lock *
+ * *
+ * Purpose: Waits until the mutex is in the signaled state *
+ * *
+ * Parameters: mutex - handle of mutex *
+ * *
+ * Return value: If the function succeeds, the return 1, 0 on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+int zbx_mutex_lock(ZBX_MUTEX *mutex)
+{
+
+ if(!*mutex) return ZBX_MUTEX_OK;
+
+#if defined(WIN32)
+
+ if(WaitForSingleObject(*mutex, INFINITE) != WAIT_OBJECT_0)
+ {
+ zbx_error("Error on mutex locking. [%s]", strerror_from_system(GetLastError()));
+ return ZBX_MUTEX_ERROR;
+ }
+
+#else /* not WIN32 */
+
+ struct sembuf sem_lock = { 0, -1, 0 };
+
+ if (-1 == (semop(*mutex, &sem_lock, 1)))
+ {
+ zbx_error("Lock failed [%s]", strerror(errno));
+ return ZBX_MUTEX_ERROR;
+ }
+
+#endif /* WIN32 */
+
+ return ZBX_MUTEX_OK;
+}
+
+/******************************************************************************
+ * *
+ * Function: zbx_mutex_unlock *
+ * *
+ * Purpose: Unlock the mutex *
+ * *
+ * Parameters: mutex - handle of mutex *
+ * *
+ * Return value: If the function succeeds, the return 1, 0 on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+int zbx_mutex_unlock(ZBX_MUTEX *mutex)
+{
+
+ if(!*mutex) return ZBX_MUTEX_OK;
+
+#if defined(WIN32)
+
+ if(ReleaseMutex(*mutex) == 0)
+ {
+ zbx_error("Error on mutex UNlocking. [%s]", strerror_from_system(GetLastError()));
+ return ZBX_MUTEX_ERROR;
+ }
+
+#else /* not WIN32 */
+
+ struct sembuf sem_unlock = { 0, 1, 0};
+
+ if ((semop(*mutex, &sem_unlock, 1)) == -1)
+ {
+ zbx_error("Unlock failed [%s]", strerror(errno));
+ return ZBX_MUTEX_ERROR;
+ }
+
+#endif /* WIN32 */
+
+ return ZBX_MUTEX_OK;
+}
+
+/******************************************************************************
+ * *
+ * Function: zbx_mutex_destroy *
+ * *
+ * Purpose: Destroy the mutex *
+ * *
+ * Parameters: mutex - handle of mutex *
+ * *
+ * Return value: If the function succeeds, the return 1, 0 on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+int zbx_mutex_destroy(ZBX_MUTEX *mutex)
+{
+ if(!*mutex) return ZBX_MUTEX_OK;
+
+#if defined(WIN32)
+
+ if(CloseHandle(*mutex) == 0)
+ {
+ zbx_error("Error on mutex destroying. [%s]", strerror_from_system(GetLastError()));
+ return ZBX_MUTEX_ERROR;
+ }
+
+#else /* not WIN32 */
+
+ semctl(*mutex, 0, IPC_RMID, 0);
+
+#endif /* WIN32 */
+
+ *mutex = (ZBX_MUTEX)NULL;
+
+ return ZBX_MUTEX_OK;
+}
+
diff --git a/src/libs/zbxsys/threads.c b/src/libs/zbxsys/threads.c
new file mode 100755
index 00000000..3ae8ca05
--- /dev/null
+++ b/src/libs/zbxsys/threads.c
@@ -0,0 +1,138 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "threads.h"
+
+#include "log.h"
+
+/******************************************************************************
+ * *
+ * Function: zbx_thread_start *
+ * *
+ * Purpose: Start the handled function as "thread" *
+ * *
+ * Parameters: "thread" handle *
+ * *
+ * Return value: returns a handle to the newly created "thread", *
+ * ZBX_THREAD_ERROR on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * The zbx_tread_exit must be called from the handler! *
+ * *
+ ******************************************************************************/
+
+ZBX_THREAD_HANDLE zbx_thread_start(ZBX_THREAD_ENTRY_POINTER(handler), void *args)
+{
+ ZBX_THREAD_HANDLE thread = 0;
+
+#if defined(WIN32)
+
+ unsigned thrdaddr;
+
+ if(0 == (thread = (ZBX_THREAD_HANDLE)_beginthreadex(NULL,0,handler,args,0,&thrdaddr))) /* NOTE: _beginthreadex returns 0 on failure, rather than –1 */
+ {
+ zbx_error("Error on thread creation. [%s]", strerror_from_system(GetLastError()));
+ thread = (ZBX_THREAD_HANDLE)(ZBX_THREAD_ERROR);
+ }
+
+#else /* not WIN32 */
+
+ thread = fork();
+
+ if(thread == 0) /* child process */
+ {
+ (*handler)(args);
+
+ /* The zbx_tread_exit must be called from the handler */
+ /* And in normal case the program will never reach this point. */
+ zbx_tread_exit(0);
+ /* Program will never reach this point. */
+ }
+ else if(thread < 0)
+ {
+ zbx_error("Error on thread creation.");
+ thread = (ZBX_THREAD_HANDLE)(ZBX_THREAD_ERROR);
+ }
+
+#endif /* WIN32 */
+
+ return (ZBX_THREAD_HANDLE)(thread);
+}
+
+/******************************************************************************
+ * *
+ * Function: zbx_thread_wait *
+ * *
+ * Purpose: Waits until the "thread" is in the signaled state *
+ * *
+ * Parameters: "thread" handle *
+ * *
+ * Return value: If the function succeeds, the return 1,0 on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+int zbx_thread_wait(ZBX_THREAD_HANDLE thread)
+{
+#if defined(WIN32)
+
+ if(WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0)
+ {
+ zbx_error("Error on thread waiting. [%s]", strerror_from_system(GetLastError()));
+ return (0);
+ }
+
+ if(CloseHandle(thread) == 0)
+ {
+ zbx_error("Error on thread closing. [%s]", strerror_from_system(GetLastError()));
+ return (0);
+ }
+
+#else /* not WIN32 */
+
+ if(waitpid(thread, (int *)0, 0) <= 0)
+ {
+ zbx_error("Error on thread waiting.");
+ return (0);
+ }
+
+#endif /* WIN32 */
+
+ return (1);
+}
+
+long int zbx_get_thread_id(void)
+{
+#if defined(WIN32)
+
+ return (long int) GetCurrentThreadId();
+
+#else /* not WIN32 */
+
+ return (long int) getpid();
+
+#endif /* WIN32 */
+}
+
diff --git a/src/libs/zbxsysinfo/Makefile.am b/src/libs/zbxsysinfo/Makefile.am
index 522d2cd8..d33b5db8 100644
--- a/src/libs/zbxsysinfo/Makefile.am
+++ b/src/libs/zbxsysinfo/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS=@ARCH@
-libzbxsysinfo_a_LIBADD = ../zbxcommon/libzbxcommon.a ../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo_a_LIBADD = ../zbxcommon/libzbxcommon.a ../zbxcrypto/libzbxcrypto.a
libzbxsysinfo_a_SOURCES=common/common.c common/file.c common/ntp.c common/system.c common/http.c @ARCH@/@ARCH@.c
lib_LIBRARIES=libzbxsysinfo.a
diff --git a/src/libs/zbxsysinfo/aix/AIX_new.c b/src/libs/zbxsysinfo/aix/AIX_new.c
index 015435da..a4edcb0c 100644
--- a/src/libs/zbxsysinfo/aix/AIX_new.c
+++ b/src/libs/zbxsysinfo/aix/AIX_new.c
@@ -73,7 +73,7 @@ void init() {
if (!p_info) {
- fprintf(stderr, "not enough memory\n");
+ zbx_error("not enough memory.");
return;
}
diff --git a/src/libs/zbxsysinfo/aix/Makefile.am b/src/libs/zbxsysinfo/aix/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/aix/Makefile.am
+++ b/src/libs/zbxsysinfo/aix/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/aix/aix.c b/src/libs/zbxsysinfo/aix/aix.c
index fb6cd580..a0b6ca2e 100644
--- a/src/libs/zbxsysinfo/aix/aix.c
+++ b/src/libs/zbxsysinfo/aix/aix.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/aix/cpu.c b/src/libs/zbxsysinfo/aix/cpu.c
index 75a8db56..a1b98d54 100644
--- a/src/libs/zbxsysinfo/aix/cpu.c
+++ b/src/libs/zbxsysinfo/aix/cpu.c
@@ -135,7 +135,7 @@ CPU_FNCLIST
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
@@ -149,7 +149,7 @@ CPU_FNCLIST
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type) "user");
}
if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -509,7 +509,7 @@ CPU_FNCLIST
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
@@ -523,7 +523,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/aix/diskio.c b/src/libs/zbxsysinfo/aix/diskio.c
index 333b177a..c486acfd 100644
--- a/src/libs/zbxsysinfo/aix/diskio.c
+++ b/src/libs/zbxsysinfo/aix/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -178,7 +178,7 @@ DEV_FNCLIST
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -254,7 +254,7 @@ DEV_FNCLIST
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/aix/diskspace.c b/src/libs/zbxsysinfo/aix/diskspace.c
index fd89f469..d5736df6 100644
--- a/src/libs/zbxsysinfo/aix/diskspace.c
+++ b/src/libs/zbxsysinfo/aix/diskspace.c
@@ -224,7 +224,7 @@ FS_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/aix/inodes.c b/src/libs/zbxsysinfo/aix/inodes.c
index d773c1e0..82c76a4d 100644
--- a/src/libs/zbxsysinfo/aix/inodes.c
+++ b/src/libs/zbxsysinfo/aix/inodes.c
@@ -223,7 +223,7 @@ FS_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/aix/memory.c b/src/libs/zbxsysinfo/aix/memory.c
index dab28847..9fe4d1b6 100644
--- a/src/libs/zbxsysinfo/aix/memory.c
+++ b/src/libs/zbxsysinfo/aix/memory.c
@@ -25,7 +25,7 @@
static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- FILE *f;
+ FILE *f = NULL;
char *t;
char c[MAX_STRING_LEN];
zbx_uint64_t res = 0;
@@ -34,8 +34,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if( NULL == ( f = fopen("/proc/meminfo","r")))
{
return SYSINFO_RET_FAIL;
}
@@ -56,7 +55,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -387,7 +386,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -395,7 +394,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/aix/proc.c b/src/libs/zbxsysinfo/aix/proc.c
index bb6983dc..55bd280f 100644
--- a/src/libs/zbxsysinfo/aix/proc.c
+++ b/src/libs/zbxsysinfo/aix/proc.c
@@ -148,7 +148,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
while((entries=readdir(dir))!=NULL)
{
- snprintf(filename,MAX_STRING_LEN,"/proc/%s/psinfo",entries->d_name);
+ zbx_snprintf(filename, sizeof(filename), "/proc/%s/psinfo",entries->d_name);
if(stat(filename,&buf)==0)
{
@@ -221,7 +221,7 @@ lbl_skip_procces:
if(proccomm[0] != '\0')
{
init_result(&proc_args);
- snprintf(get_args_cmd, MAX_STRING_LEN-1, "ps -p %i -oargs=", ProcessBuffer.pi_pid);
+ zbx_snprintf(get_args_cmd, sizeof(get_args_cmd), "ps -p %i -oargs=", ProcessBuffer.pi_pid);
if(EXECUTE_STR(cmd, get_args_cmd, flags, &proc_args) != SYSINFO_RET_OK)
{
free_result(&proc_args);
@@ -395,7 +395,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
while((entries=readdir(dir))!=NULL)
{
- snprintf(filename,MAX_STRING_LEN,"/proc/%s/psinfo",entries->d_name);
+ zbx_snprintf(filename, sizeof(filename),"/proc/%s/psinfo",entries->d_name);
if(stat(filename,&buf)==0)
{
@@ -456,7 +456,7 @@ lbl_skip_procces:
if(proccomm[0] != '\0')
{
init_result(&proc_args);
- snprintf(get_args_cmd, MAX_STRING_LEN-1, "ps -p %i -oargs=", ProcessBuffer.pi_pid);
+ zbx_snprintf(get_args_cmd, sizeof(get_args_cmd), "ps -p %i -oargs=", ProcessBuffer.pi_pid);
if(EXECUTE_STR(cmd, get_args_cmd, flags, &proc_args) != SYSINFO_RET_OK)
{
free_result(&proc_args);
diff --git a/src/libs/zbxsysinfo/aix/sensors.c b/src/libs/zbxsysinfo/aix/sensors.c
index cc5a3af8..0b594605 100644
--- a/src/libs/zbxsysinfo/aix/sensors.c
+++ b/src/libs/zbxsysinfo/aix/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r")))
{
continue;
}
- fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ fgets(line, MAX_STRING_LEN, f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/aix/swap.c b/src/libs/zbxsysinfo/aix/swap.c
index 2bfd5511..151c8b6a 100644
--- a/src/libs/zbxsysinfo/aix/swap.c
+++ b/src/libs/zbxsysinfo/aix/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index 8155a28f..a8edb0a2 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -17,13 +17,10 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
-
-#include <sys/wait.h>
-
#include "common.h"
#include "sysinfo.h"
+#include "alias.h"
#include "md5.h"
#include "log.h"
@@ -34,11 +31,6 @@ ZBX_METRIC parameters_common[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
{"system.localtime", 0, SYSTEM_LOCALTIME, 0, 0},
- {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
- {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
- {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
- {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"system.run", CF_USEUPARAM, RUN_COMMAND, 0, "echo test"},
{"web.page.get", CF_USEUPARAM, WEB_PAGE_GET, 0, "www.zabbix.com,,80"},
{"web.page.perf", CF_USEUPARAM, WEB_PAGE_PERF, 0, "www.zabbix.com,,80"},
@@ -145,7 +137,7 @@ void init_metrics()
{
int i;
- commands=malloc(sizeof(ZBX_METRIC));
+ commands = malloc(sizeof(ZBX_METRIC));
commands[0].key=NULL;
for(i=0;parameters_common[i].key!=0;i++)
@@ -232,27 +224,19 @@ int copy_result(AGENT_RESULT *src, AGENT_RESULT *dist)
void free_result(AGENT_RESULT *result)
{
- if(result->type & AR_STRING)
- {
- free(result->str);
- }
-
- if(result->type & AR_TEXT)
- {
- free(result->text);
- }
-
- if(result->type & AR_MESSAGE)
- {
- free(result->msg);
- }
+ UNSET_DBL_RESULT(result);
+ UNSET_UI64_RESULT(result);
+ UNSET_STR_RESULT(result);
+ UNSET_TEXT_RESULT(result);
+ UNSET_MSG_RESULT(result);
if(result->type & AR_LIST)
{
free_result_list(&(result->list));
+
+ result->type &= ~AR_LIST;
}
- init_result(result);
}
void init_result(AGENT_RESULT *result)
@@ -406,7 +390,7 @@ int replace_param(const char *cmd, const char *param, char *out, int outlen)
{
pr[0] = '\0';
strncat(out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
+ outlen -= MIN((int)strlen(pl), (int)outlen);
pr[0] = '$';
if (pr[1] >= '0' && pr[1] <= '9')
@@ -423,7 +407,7 @@ int replace_param(const char *cmd, const char *param, char *out, int outlen)
}
strncat(out, buf, outlen);
- outlen -= MIN(strlen(buf), outlen);
+ outlen -= MIN((int)strlen(buf), (int)outlen);
pl = pr + 2;
continue;
@@ -433,7 +417,7 @@ int replace_param(const char *cmd, const char *param, char *out, int outlen)
outlen -= 1;
}
strncat(out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
+ outlen -= MIN((int)strlen(pl), (int)outlen);
return ret;
}
@@ -456,11 +440,12 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
assert(result);
- init_result(result);
+ init_result(result);
- strncpy(usr_command, in_command, MAX_STRING_LEN);
- usr_command_len = strlen(usr_command);
+ alias_expand(in_command, usr_command, MAX_STRING_LEN);
+ usr_command_len = strlen(usr_command);
+
for( p=usr_command+usr_command_len-1; p>usr_command && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p );
if( (p[1]=='\r') || (p[1]=='\n') || (p[1]==' '))
@@ -483,9 +468,9 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
}
}
+ param[0] = '\0';
if(function != 0)
{
- param[0] = '\0';
if(commands[i].flags & CF_USEUPARAM)
{
@@ -509,7 +494,7 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
}
else
{
- snprintf(param, MAX_STRING_LEN, "%s", usr_param);
+ zbx_snprintf(param, sizeof(param), "%s", usr_param);
}
if(err != FAIL)
@@ -567,8 +552,9 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
int VFS_FILE_MD5SUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- int fd;
- int i,nr;
+ FILE *file = NULL;
+ int i;
+ size_t nr;
struct stat buf_stat;
md5_state_t state;
@@ -605,24 +591,25 @@ int VFS_FILE_MD5SUM(const char *cmd, const char *param, unsigned flags, AGENT_RE
return SYSINFO_RET_FAIL;
}
- fd=open(filename,O_RDONLY);
- if(fd == -1)
+ if(NULL == (file = fopen(filename,"r")))
{
return SYSINFO_RET_FAIL;
}
md5_init(&state);
- while ((nr = read(fd, buf, sizeof(buf))) > 0)
+ while ((nr = fread(buf, (size_t)sizeof(buf), 1, file)) > 0)
{
- md5_append(&state,(const md5_byte_t *)buf,nr);
+ md5_append(&state,(const md5_byte_t *)buf, nr);
}
md5_finish(&state,(md5_byte_t *)hash);
- close(fd);
+ zbx_fclose(file);
/* Convert MD5 hash to text form */
for(i=0;i<MD5_DIGEST_SIZE;i++)
- sprintf((char *)&hashText[i<<1],"%02x",hash[i]);
+ {
+ zbx_snprintf((char *)&hashText[i<<1], 2,"%02x",hash[i]);
+ }
SET_STR_RESULT(result, strdup((char*)hashText));
@@ -699,12 +686,14 @@ int VFS_FILE_CKSUM(const char *cmd, const char *param, unsigned flags, AGENT_RES
{
register u_char *p;
register int nr;
+
/* AV Crashed under 64 platforms. Must be 32 bit! */
/* register u_long crc, len;*/
register uint32_t crc, len;
+
u_char buf[16 * 1024];
u_long cval, clen;
- int fd;
+ FILE *f;
char filename[MAX_STRING_LEN];
assert(result);
@@ -721,8 +710,7 @@ int VFS_FILE_CKSUM(const char *cmd, const char *param, unsigned flags, AGENT_RES
return SYSINFO_RET_FAIL;
}
- fd=open(filename,O_RDONLY);
- if(fd == -1)
+ if(NULL == (f = fopen(filename,"r")))
{
return SYSINFO_RET_FAIL;
}
@@ -730,14 +718,14 @@ int VFS_FILE_CKSUM(const char *cmd, const char *param, unsigned flags, AGENT_RES
#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
crc = len = 0;
- while ((nr = read(fd, buf, sizeof(buf))) > 0)
+ while ((nr = fread(buf, sizeof(buf), 1, f)) > 0)
{
for( len += nr, p = buf; nr--; ++p)
{
COMPUTE(crc, *p);
}
}
- close(fd);
+ zbx_fclose(f);
if (nr < 0)
{
@@ -780,42 +768,45 @@ crc_buf2(p, clen, cval)
int get_stat(const char *key, unsigned flags, AGENT_RESULT *result)
{
- FILE *f;
+ FILE *f = NULL;
char line[MAX_STRING_LEN];
char name1[MAX_STRING_LEN];
char name2[MAX_STRING_LEN];
+ int ret = SYSINFO_RET_FAIL;
assert(result);
init_result(result);
- f=fopen("/tmp/zabbix_agentd.tmp","r");
- if(f==NULL)
+ if(NULL == (f = fopen("/tmp/zabbix_agentd.tmp","r")))
{
return SYSINFO_RET_FAIL;
}
+
while(fgets(line,MAX_STRING_LEN,f))
{
if(sscanf(line,"%s %s\n",name1,name2)==2)
{
if(strcmp(name1,key) == 0)
{
- fclose(f);
SET_UI64_RESULT(result, atoi(name2));
- return SYSINFO_RET_OK;
+ ret = SYSINFO_RET_OK;
+ break;
}
}
}
- fclose(f);
- return SYSINFO_RET_FAIL;
+
+ zbx_fclose(f);
+
+ return ret;
}
int NET_IF_IBYTES1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"netloadin1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"netloadin1[%s]",param);
return get_stat(key, flags, result);
}
@@ -824,7 +815,7 @@ int NET_IF_IBYTES5(const char *cmd, const char *param, unsigned flags, AGENT_RES
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"netloadin5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"netloadin5[%s]",param);
return get_stat(key, flags, result);
}
@@ -833,7 +824,7 @@ int NET_IF_IBYTES15(const char *cmd, const char *param, unsigned flags, AGENT_RE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"netloadin15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"netloadin15[%s]",param);
return get_stat(key, flags, result);
}
@@ -842,7 +833,7 @@ int NET_IF_OBYTES1(const char *cmd, const char *param, unsigned flags, AGENT_RES
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"netloadout1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"netloadout1[%s]",param);
return get_stat(key, flags, result);
}
@@ -851,7 +842,7 @@ int NET_IF_OBYTES5(const char *cmd, const char *param, unsigned flags, AGENT_RES
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"netloadout5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"netloadout5[%s]",param);
return get_stat(key, flags, result);
}
@@ -860,7 +851,7 @@ int NET_IF_OBYTES15(const char *cmd, const char *param, unsigned flags, AGENT_RE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"netloadout15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"netloadout15[%s]",param);
return get_stat(key, flags, result);
}
@@ -868,10 +859,11 @@ int NET_IF_OBYTES15(const char *cmd, const char *param, unsigned flags, AGENT_RE
int TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- FILE *f;
+ FILE *f = NULL;
char c[MAX_STRING_LEN];
char porthex[MAX_STRING_LEN];
char pattern[MAX_STRING_LEN];
+ int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -890,26 +882,25 @@ int TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
strscpy(pattern,porthex);
strncat(pattern," 00000000:0000 0A", MAX_STRING_LEN);
- f=fopen("/proc/net/tcp","r");
- if(NULL == f)
+ if(NULL == (f = fopen("/proc/net/tcp","r")))
{
return SYSINFO_RET_FAIL;
}
- while (NULL!=fgets(c,MAX_STRING_LEN,f))
+ while (NULL != fgets(c,MAX_STRING_LEN,f))
{
if(NULL != strstr(c,pattern))
{
- fclose(f);
SET_UI64_RESULT(result, 1);
- return SYSINFO_RET_OK;
+ ret = SYSINFO_RET_OK;
+ break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, 0);
- return SYSINFO_RET_OK;
+ return ret;
#else
return SYSINFO_RET_FAIL;
#endif
@@ -928,21 +919,23 @@ int getPROC(char *file, int lineno, int fieldno, unsigned flags, AGENT_RESULT *r
init_result(result);
- f=fopen(file,"r");
- if(NULL == f)
+ if(NULL == (f = fopen(file,"r")))
{
return SYSINFO_RET_FAIL;
}
- for(i=1;i<=lineno;i++)
+
+ for(i=1; i<=lineno; i++)
{
fgets(c,MAX_STRING_LEN,f);
}
+
t=(char *)strtok(c," ");
- for(i=2;i<=fieldno;i++)
+ for(i=2; i<=fieldno; i++)
{
t=(char *)strtok(NULL," ");
}
- fclose(f);
+
+ zbx_fclose(f);
sscanf(t, "%lf", &value);
SET_DBL_RESULT(result, value);
@@ -1064,17 +1057,18 @@ int PROCCOUNT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r")))
{
continue;
}
+
/* This check can be skipped. No need to read anything from this file. */
if(NULL != fgets(line,MAX_STRING_LEN,f))
{
proccount++;
}
- fclose(f);
+
+ zbx_fclose(f);
}
}
closedir(dir);
@@ -1135,8 +1129,22 @@ int OLD_VERSION(const char *cmd, const char *param, unsigned flags, AGENT_RE
int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
+
+#if defined(WIN32)
+
+ STARTUPINFO si = {0};
+ PROCESS_INFORMATION pi = {0};
+ SECURITY_ATTRIBUTES sa;
+ HANDLE hOutput;
+ char szTempPath[MAX_PATH],szTempFile[MAX_PATH];
+
+#else /* not WIN32 */
+
FILE *f;
- char c[MAX_STRING_LEN];
+
+#endif /* WIN32 */
+
+ char cmd_result[MAX_STRING_LEN];
char command[MAX_STRING_LEN];
int i,len;
@@ -1144,22 +1152,74 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
init_result(result);
- strncpy(command, param, MAX_STRING_LEN);
-
- f=popen(command,"r");
- if(f==0)
+ strsncpy(command, param, MAX_STRING_LEN);
+ memset(cmd_result, 0, MAX_STRING_LEN);
+
+#if defined(WIN32)
+
+ // Create temporary file to hold process output
+ GetTempPath( MAX_PATH-1, szTempPath);
+ GetTempFileName( szTempPath, "zbx", 0, szTempFile);
+
+ sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = TRUE;
+
+ if(INVALID_HANDLE_VALUE == (hOutput = CreateFile(
+ szTempFile,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,
+ &sa,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_TEMPORARY,
+ NULL)))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Unable to create temporary file: '%s' [%s]", szTempFile, strerror_from_system(GetLastError()));
+ return SYSINFO_RET_FAIL;
+ }
+
+ // Fill in process startup info structure
+ memset(&si,0,sizeof(STARTUPINFO));
+ si.cb = sizeof(STARTUPINFO);
+ si.dwFlags = STARTF_USESTDHANDLES;
+ si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
+ si.hStdOutput = hOutput;
+ si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+
+ // Create new process
+ if (!CreateProcess(NULL,command,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Unable to create process: '%s' [%s]", command, strerror_from_system(GetLastError()));
+ return SYSINFO_RET_FAIL;
+ }
+
+ // Wait for process termination and close all handles
+ WaitForSingleObject(pi.hProcess,INFINITE);
+ CloseHandle(pi.hThread);
+ CloseHandle(pi.hProcess);
+
+ // Rewind temporary file for reading
+ SetFilePointer(hOutput,0,NULL,FILE_BEGIN);
+
+ // Read process output
+ ReadFile(hOutput, cmd_result, MAX_STRING_LEN-1, &len, NULL);
+
+ cmd_result[len] = '\0';
+
+#else /* not WIN32 */
+
+ if(0 == (f = popen(command,"r")))
{
switch (errno)
{
case EINTR:
-/* (char *) to avoid compiler warning */
return SYSINFO_RET_TIMEOUT;
default:
return SYSINFO_RET_FAIL;
}
}
- len = fread(c, 1, MAX_STRING_LEN-1, f);
+ len = fread(cmd_result, 1, MAX_STRING_LEN-1, f);
if(0 != ferror(f))
{
@@ -1167,7 +1227,6 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
{
case EINTR:
pclose(f);
-/* (char *) to avoid compiler warning */
return SYSINFO_RET_TIMEOUT;
default:
pclose(f);
@@ -1175,113 +1234,81 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
}
}
- c[len]=0;
+ cmd_result[len] = '\0';
- zabbix_log(LOG_LEVEL_DEBUG, "Run remote command [%s] Result [%d] [%s]", command, strlen(c), c);
+ zabbix_log(LOG_LEVEL_DEBUG, "Run remote command [%s] Result [%d] [%s]", command, strlen(cmd_result), cmd_result);
if(pclose(f) != 0)
{
switch (errno)
{
case EINTR:
-/* (char *) to avoid compiler warning */
return SYSINFO_RET_TIMEOUT;
default:
return SYSINFO_RET_FAIL;
}
}
+#endif /* WIN32 */
+
/* We got EOL only */
- if(c[0] == '\n')
+ if(cmd_result[0] == '\n')
{
return SYSINFO_RET_FAIL;
}
-
- for(i=strlen(c); i>0; i--)
+
+ for(i = len-1; i >= 0 && (cmd_result[i] == '\n' || cmd_result[i] == '\r' || cmd_result[i] == '\0'); i++)
{
- if(c[i] == '\n')
- {
- c[i] = '\0';
- break;
- }
+ cmd_result[i] = '\0';
}
-
- SET_TEXT_RESULT(result, strdup(c));
-
+
+ SET_TEXT_RESULT(result, strdup(cmd_result));
+
return SYSINFO_RET_OK;
+
}
-int EXECUTE(const char *cmd, const char *command, unsigned flags, AGENT_RESULT *result)
+int EXECUTE_INT(const char *cmd, const char *command, unsigned flags, AGENT_RESULT *result)
{
- FILE *f;
- char c[MAX_STRING_LEN];
- double value = 0;
+ int ret = SYSINFO_RET_FAIL;
+ double value = 0;
- assert(result);
-
- init_result(result);
-
- f=popen( command,"r");
- if(f==0)
- {
- switch (errno)
- {
- case EINTR:
- return SYSINFO_RET_TIMEOUT;
- default:
- return SYSINFO_RET_FAIL;
- }
- }
+ ret = EXECUTE_STR(cmd,command,flags,result);
- if(NULL == fgets(c,MAX_STRING_LEN,f))
+ if(SYSINFO_RET_OK == ret)
{
- pclose(f);
- switch (errno)
- {
- case EINTR:
- return SYSINFO_RET_TIMEOUT;
- default:
- return SYSINFO_RET_FAIL;
- }
- }
+ sscanf(result->text, "%lf", &value);
- if(pclose(f) != 0)
- {
- switch (errno)
- {
- case EINTR:
- return SYSINFO_RET_TIMEOUT;
- default:
- return SYSINFO_RET_FAIL;
- }
- }
+ UNSET_TEXT_RESULT(result);
- /* We got EOL only */
- if(c[0] == '\n')
- {
- return SYSINFO_RET_FAIL;
+ SET_DBL_RESULT(result, value);
}
- sscanf(c, "%lf", &value);
- SET_DBL_RESULT(result, value);
-
- return SYSINFO_RET_OK;
+ return ret;
}
int RUN_COMMAND(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- char command[MAX_STRING_LEN];
#define MAX_FLAG_LEN 10
+
+ char command[MAX_STRING_LEN];
char flag[MAX_FLAG_LEN];
+
+#if defined (WIN32)
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+
+ char full_command[MAX_STRING_LEN];
+#else /* not WIN32 */
pid_t pid;
+#endif
+
assert(result);
init_result(result);
-zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
-
if(CONFIG_ENABLE_REMOTE_COMMANDS != 1)
{
SET_MSG_RESULT(result, strdup("ZBX_NOTSUPPORTED"));
@@ -1293,7 +1320,7 @@ zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, command, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, command, sizeof(command)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -1302,21 +1329,22 @@ zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
{
return SYSINFO_RET_FAIL;
}
+
+ zabbix_log(LOG_LEVEL_WARNING, "Run command '%s'",command);
- if(get_param(param, 2, flag, MAX_FLAG_LEN) != 0)
+ if(get_param(param, 2, flag, sizeof(flag)) != 0)
{
flag[0] = '\0';
}
if(flag[0] == '\0')
{
- snprintf(flag,MAX_FLAG_LEN,"wait");
+ zbx_snprintf(flag,sizeof(flag),"wait");
}
- zabbix_log(LOG_LEVEL_DEBUG, "RUN_COMMAND flag = '%s'",flag);
if(strcmp(flag,"wait") == 0)
{
- zabbix_log(LOG_LEVEL_DEBUG, "RUN_COMMAND is running as WAIT",flag);
+ zabbix_log(LOG_LEVEL_DEBUG, "Run wait command '%s'",command);
return EXECUTE_STR(cmd,command,flags,result);
}
else if(strcmp(flag,"nowait") != 0)
@@ -1324,15 +1352,39 @@ zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
return SYSINFO_RET_FAIL;
}
- zabbix_log(LOG_LEVEL_DEBUG, "Run remote command '%s'", command);
-
- zabbix_log(LOG_LEVEL_DEBUG, "RUN_COMMAND to be started as NOWAIT",flag);
+ zabbix_log(LOG_LEVEL_DEBUG, "Run nowait command '%s'",command);
+#if defined(WIN32)
+
+ zbx_snprintf(full_command, sizeof(full_command), "cmd /C \"%s\"", command);
+
+ GetStartupInfo(&si);
+
+ zabbix_log(LOG_LEVEL_WARNING, "Execute command '%s'",full_command);
+
+ if(!CreateProcess(
+ NULL, // No module name (use command line)
+ full_command,// Name of app to launch
+ NULL, // Default process security attributes
+ NULL, // Default thread security attributes
+ FALSE, // Don't inherit handles from the parent
+ 0, // Normal priority
+ NULL, // Use the same environment as the parent
+ NULL, // Launch in the current directory
+ &si, // Startup Information
+ &pi)) // Process information stored upon return
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+
+#else /* not WIN32 */
+
pid = fork(); /* run new thread 1 */
switch(pid)
{
case -1:
- zabbix_log(LOG_LEVEL_WARNING, "fork failed for '%s'",command);
+ zabbix_log(LOG_LEVEL_WARNING, "fork failed for command '%s'",command);
return SYSINFO_RET_FAIL;
case 0:
pid = fork(); /* run new tread 2 to replace by command */
@@ -1343,7 +1395,7 @@ zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
return SYSINFO_RET_FAIL;
case 0:
/*
- * DON'T REMVE SLEEP
+ * DON'T REMOVE SLEEP
* sleep needed to return server result as "1"
* then we can run "execl"
* otherwise command print result into socket with STDOUT id
@@ -1354,8 +1406,7 @@ zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
/* replace thread 2 by the execution of command */
if(execl("/bin/sh", "sh", "-c", command, (char *)0))
{
- zabbix_log(LOG_LEVEL_WARNING, "execl failed for '%s'",command);
- exit(1);
+ zabbix_log(LOG_LEVEL_WARNING, "execl failed for command '%s'",command);
}
/* In normal case the program will never reach this point */
exit(0);
@@ -1369,12 +1420,15 @@ zabbix_log(LOG_LEVEL_WARNING, "RUN_COMMAND cmd = '%s'",cmd);
break;
}
+#endif /* WIN32 */
+
SET_UI64_RESULT(result, 1);
return SYSINFO_RET_OK;
}
int forward_request(char *proxy, char *command, int port, unsigned flags, AGENT_RESULT *result)
{
+#ifdef TODO /* TODO !!! */
char *haddr;
char c[1024];
@@ -1435,8 +1489,10 @@ int forward_request(char *proxy, char *command, int port, unsigned flags, AGENT_
close(s);
SET_STR_RESULT(result, strdup(c));
-
return SYSINFO_RET_OK;
+#endif /* TODO */
+
+ return SYSINFO_RET_FAIL;
}
@@ -1446,6 +1502,8 @@ int forward_request(char *proxy, char *command, int port, unsigned flags, AGENT_
* */
int tcp_expect(char *hostname, short port, char *request,char *expect,char *sendtoclose, int *value_int)
{
+#ifdef TODO /* TODO !!! */
+
char *haddr;
char c[1024];
@@ -1508,13 +1566,14 @@ int tcp_expect(char *hostname, short port, char *request,char *expect,char *send
*value_int = 1;
return SYSINFO_RET_OK;
}
- else
- {
- send(s,sendtoclose,strlen(sendtoclose),0);
- close(s);
- *value_int = 0;
- return SYSINFO_RET_OK;
- }
+ send(s,sendtoclose,strlen(sendtoclose),0);
+ close(s);
+ *value_int = 0;
+
+ return SYSINFO_RET_OK;
+#endif /* TODO */
+
+ return SYSINFO_RET_FAIL;
}
#ifdef HAVE_LDAP
@@ -1585,6 +1644,7 @@ int check_ldap(char *hostname, short port, int *value_int)
* */
int check_ssh(char *hostname, short port, int *value_int)
{
+#ifdef TODO /* TODO !!! */
char *haddr;
char c[MAX_STRING_LEN];
char out[MAX_STRING_LEN];
@@ -1639,7 +1699,7 @@ int check_ssh(char *hostname, short port, int *value_int)
/* printf("[%s] [%s]\n",ssh_proto, ssh_server);*/
- snprintf(out,sizeof(out)-1,"SSH-%s-%s\r\n", ssh_proto, "zabbix_agent");
+ zbx_snprintf(out,sizeof(out),"SSH-%s-%s\r\n", ssh_proto, "zabbix_agent");
send(s,out,strlen(out),0);
/* printf("[%s]\n",out);*/
@@ -1652,13 +1712,20 @@ int check_ssh(char *hostname, short port, int *value_int)
send(s,"0\n",2,0);
close(s);
*value_int = 0;
+
return SYSINFO_RET_OK;
+
+#endif /* TODO */
+
+ return SYSINFO_RET_FAIL;
}
/* Example check_service[ssh], check_service[smtp,29],check_service[ssh,127.0.0.1,22]*/
/* check_service[ssh,127.0.0.1,ssh] */
int CHECK_SERVICE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
+#ifdef TODO /* TODO !!! */
+
int port=0;
char service[MAX_STRING_LEN];
char ip[MAX_STRING_LEN];
@@ -1782,19 +1849,23 @@ int CHECK_SERVICE_PERF(const char *cmd, const char *param, unsigned flags, AGENT
SET_DBL_RESULT(result, 0.0);
return SYSINFO_RET_OK;
+
+#endif /* TODO */
+
+ return SYSINFO_RET_FAIL;
}
/* Example check_service[ssh], check_service[smtp,29],check_service[ssh,127.0.0.1,22]*/
/* check_service[ssh,127.0.0.1,ssh] */
int CHECK_SERVICE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- int port=0;
+ short port=0;
char service[MAX_STRING_LEN];
char ip[MAX_STRING_LEN];
char str_port[MAX_STRING_LEN];
int ret;
- int value_int;
+ int value_int = 0;
assert(result);
@@ -1897,14 +1968,17 @@ int CHECK_SERVICE(const char *cmd, const char *param, unsigned flags, AGENT_RESU
return SYSINFO_RET_FAIL;
}
- SET_UI64_RESULT(result, value_int);
+ if(SYSINFO_RET_OK == ret)
+ {
+ SET_UI64_RESULT(result, value_int);
+ }
return ret;
}
int CHECK_PORT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- int port=0;
+ short port=0;
int value_int;
int ret;
char ip[MAX_STRING_LEN];
@@ -1954,6 +2028,7 @@ int CHECK_PORT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
int CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
+#ifdef TODO /* TODO !!! */
int res;
char ip[MAX_STRING_LEN];
char zone[MAX_STRING_LEN];
@@ -2031,33 +2106,19 @@ int CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
SET_UI64_RESULT(result, res != -1 ? 1 : 0);
return SYSINFO_RET_OK;
-}
-int SYSTEM_UNUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
-{
- assert(result);
+#endif /* TODO */
- init_result(result);
-
- return EXECUTE(cmd, "who|wc -l", flags, result);
-}
-
-int SYSTEM_UNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
-{
- assert(result);
-
- init_result(result);
-
- return EXECUTE_STR(cmd, "uname -a", flags, result);
+ return SYSINFO_RET_FAIL;
}
-int SYSTEM_HOSTNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int SYSTEM_UNUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
assert(result);
init_result(result);
- return EXECUTE_STR(cmd, "hostname", flags, result);
+ return EXECUTE_INT(cmd, "who|wc -l", flags, result);
}
int OLD_SYSTEM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -2085,7 +2146,7 @@ int OLD_SYSTEM(const char *cmd, const char *param, unsigned flags, AGENT_RES
}
else if(strcmp(key,"procrunning") == 0)
{
- ret = EXECUTE(cmd, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '", flags, result);
+ ret = EXECUTE_INT(cmd, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '", flags, result);
}
else if(strcmp(key,"uptime") == 0)
{
diff --git a/src/libs/zbxsysinfo/common/file.c b/src/libs/zbxsysinfo/common/file.c
index 2073b77d..e6e261f4 100644
--- a/src/libs/zbxsysinfo/common/file.c
+++ b/src/libs/zbxsysinfo/common/file.c
@@ -135,6 +135,8 @@ int VFS_FILE_EXISTS(const char *cmd, const char *param, unsigned flags, AGENT_RE
return SYSINFO_RET_OK;
}
+/* #include<malloc.h> */
+
int VFS_FILE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char filename[MAX_STRING_LEN];
@@ -144,7 +146,6 @@ int VFS_FILE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RE
char tmp[MAX_STRING_LEN];
char *c;
- int ret = SYSINFO_RET_OK;
char *buf = NULL;
assert(result);
@@ -155,72 +156,54 @@ int VFS_FILE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(get_param(param, 1, filename, MAX_STRING_LEN) != 0)
{
- ret = SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
if(get_param(param, 2, regexp, MAX_STRING_LEN) != 0)
{
- ret = SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
- if(ret == SYSINFO_RET_OK)
+ if(NULL == (f = fopen(filename,"r")))
{
- f=fopen(filename,"r");
- if(f==NULL)
- {
- ret = SYSINFO_RET_FAIL;
- }
+ return SYSINFO_RET_FAIL;
}
- if(ret == SYSINFO_RET_OK)
+
+ if(NULL == (buf = (char*)calloc((size_t)MAX_FILE_LEN, 1)))
{
- buf = (char*)malloc((size_t)MAX_FILE_LEN);
- if(buf == NULL)
- {
- ret = SYSINFO_RET_FAIL;
- }
- else
- {
- memset(buf,0,(size_t)MAX_FILE_LEN);
- }
+ goto lbl_fail;
}
- if(ret == SYSINFO_RET_OK)
+ if(0 == fread(buf, 1, MAX_FILE_LEN-1, f))
{
- if(0 == fread(buf, 1, MAX_FILE_LEN-1, f))
- {
- ret = SYSINFO_RET_FAIL;
- }
+ goto lbl_fail;
}
+ zbx_fclose(f);
+ c = zbx_regexp_match(buf, regexp, &len);
- if(f != NULL)
+ if(c == NULL)
{
- fclose(f);
+ tmp[0]=0;
}
-
- if(ret == SYSINFO_RET_OK)
+ else
{
- c=zbx_regexp_match(buf, regexp, &len);
+ strncpy(tmp,c,len);
+ }
- if(c == NULL)
- {
- tmp[0]=0;
- }
- else
- {
- strncpy(tmp,c,len);
- }
+ SET_STR_RESULT(result, strdup(tmp));
- SET_STR_RESULT(result, strdup(tmp));
- }
+ zbx_free(buf);
- if(buf != NULL)
- {
- free(buf);
- }
+ return SYSINFO_RET_OK;
- return ret;
+lbl_fail:
+
+ zbx_free(buf);
+ zbx_fclose(f);
+
+ return SYSINFO_RET_FAIL;
}
int VFS_FILE_REGMATCH(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -231,7 +214,6 @@ int VFS_FILE_REGMATCH(const char *cmd, const char *param, unsigned flags, AGENT_
int len;
char *c;
- int ret = SYSINFO_RET_OK;
char *buf = NULL;
assert(result);
@@ -240,68 +222,51 @@ int VFS_FILE_REGMATCH(const char *cmd, const char *param, unsigned flags, AGENT_
if(get_param(param, 1, filename, MAX_STRING_LEN) != 0)
{
- ret = SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
if(get_param(param, 2, regexp, MAX_STRING_LEN) != 0)
{
- ret = SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
- if(ret == SYSINFO_RET_OK)
+ if(NULL == (f = fopen(filename,"r")))
{
- f=fopen(filename,"r");
- if(f==NULL)
- {
- ret = SYSINFO_RET_FAIL;
- }
+ return SYSINFO_RET_FAIL;
}
- if(ret == SYSINFO_RET_OK)
+
+ if(NULL == (buf = (char*)calloc((size_t)MAX_FILE_LEN, 1)))
{
- buf = (char*)malloc((size_t)MAX_FILE_LEN);
- if(buf == NULL)
- {
- ret = SYSINFO_RET_FAIL;
- }
- else
- {
- memset(buf,0,(size_t)MAX_FILE_LEN);
- }
+ goto lbl_fail;
}
- if(ret == SYSINFO_RET_OK)
+ if(0 == fread(buf, 1, MAX_FILE_LEN-1, f))
{
- if(0 == fread(buf, 1, MAX_FILE_LEN-1, f))
- {
- ret = SYSINFO_RET_FAIL;
- }
+ goto lbl_fail;
}
+ zbx_fclose(f);
- if(f != NULL)
- {
- fclose(f);
- }
+ c = zbx_regexp_match(buf, regexp, &len);
- if(ret == SYSINFO_RET_OK)
+ if(c == NULL)
{
- c=zbx_regexp_match(buf, regexp, &len);
-
- if(c == NULL)
- {
- SET_UI64_RESULT(result, 0);
- }
- else
- {
- SET_UI64_RESULT(result, 1);
- }
+ SET_UI64_RESULT(result, 0);
}
-
- if(buf != NULL)
+ else
{
- free(buf);
+ SET_UI64_RESULT(result, 1);
}
- return ret;
+ zbx_free(buf);
+
+ return SYSINFO_RET_OK;
+
+lbl_fail:
+
+ zbx_free(buf);
+ zbx_fclose(f);
+
+ return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c
index 16b5956b..beae6fdd 100644
--- a/src/libs/zbxsysinfo/common/http.c
+++ b/src/libs/zbxsysinfo/common/http.c
@@ -17,20 +17,25 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
-
#include "common.h"
#include "sysinfo.h"
+
#include "log.h"
+#include "zbxsock.h"
+#include "cfg.h"
-static int get_http_page(char *hostname, char *param, int port, char *buffer, int max_buf_len)
+static int get_http_page(char *hostname, char *param, unsigned short port, char *buffer, int max_buf_len)
{
char *haddr;
char c[MAX_STRING_LEN];
- int s;
- struct sockaddr_in addr;
- int addrlen, n, total;
+ ZBX_SOCKET s;
+ ZBX_SOCKADDR addr;
+ int
+ addrlen,
+ n,
+ total,
+ ret = SYSINFO_RET_FAIL;
struct hostent *host;
@@ -46,35 +51,27 @@ static int get_http_page(char *hostname, char *param, int port, char *buffer, in
memset(&addr, 0, addrlen);
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
- bcopy(haddr, (void *) &addr.sin_addr.s_addr, 4);
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s == -1)
- {
- close(s);
- return SYSINFO_RET_FAIL;
- }
+ memcpy(haddr, (void *) &addr.sin_addr.s_addr, 4);
- if (connect(s, (struct sockaddr *) &addr, addrlen) == -1)
+ if((s = socket(AF_INET, SOCK_STREAM, 0)) != SOCKET_ERROR)
{
- close(s);
- return SYSINFO_RET_FAIL;
- }
+ if (connect(s, (struct sockaddr *) &addr, addrlen) != SOCKET_ERROR)
+ {
+ zbx_snprintf(c, sizeof(c), "GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, hostname);
- snprintf(c,MAX_STRING_LEN-1,"GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, hostname);
+ zbx_sock_write(s, c, strlen(c));
- write(s,c,strlen(c));
+ memset(buffer, 0, max_buf_len);
- memset(buffer, 0, max_buf_len);
+ for(total=0; (n = zbx_sock_read(s, buffer+total, max_buf_len-1-total, CONFIG_TIMEOUT)) > 0; total+=n);
- total=0;
- while((n=read(s, buffer+total, max_buf_len-1-total))>0)
- {
- total+=n;
+ ret = SYSINFO_RET_OK;
+ }
}
- close(s);
- return SYSINFO_RET_OK;
+ zbx_sock_close(s);
+ return ret;
}
int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -86,9 +83,6 @@ int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
char *buffer;
- int ret;
-
-
assert(result);
init_result(result);
@@ -118,8 +112,8 @@ int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
strscpy(port_str, "80");
}
- buffer=malloc(ZABBIX_MAX_WEBPAGE_SIZE);
- if(get_http_page(hostname, path, atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE) == SYSINFO_RET_OK)
+ buffer = calloc(1, ZABBIX_MAX_WEBPAGE_SIZE);
+ if(SYSINFO_RET_OK == get_http_page(hostname, path, (unsigned short)atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE))
{
SET_TEXT_RESULT(result, buffer);
}
@@ -129,7 +123,7 @@ int WEB_PAGE_GET(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
SET_TEXT_RESULT(result, strdup("EOF"));
}
- return ret;
+ return SYSINFO_RET_OK;
}
int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -141,19 +135,12 @@ int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESU
char *buffer;
- int ret = SYSINFO_RET_OK;
-
- struct timeval t1,t2;
- struct timezone tz1,tz2;
-
- long exec_time;
+ double start_time;
assert(result);
init_result(result);
- gettimeofday(&t1,&tz1);
-
if(num_param(param) > 3)
{
return SYSINFO_RET_FAIL;
@@ -179,13 +166,12 @@ int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESU
strscpy(port_str, "80");
}
- buffer=malloc(ZABBIX_MAX_WEBPAGE_SIZE);
- if(get_http_page(hostname, path, atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE) == SYSINFO_RET_OK)
- {
- gettimeofday(&t2,&tz2);
- exec_time=(t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
+ start_time = zbx_getseconds();
- SET_DBL_RESULT(result, exec_time / 1000000.0);
+ buffer = calloc(1, ZABBIX_MAX_WEBPAGE_SIZE);
+ if(get_http_page(hostname, path, (unsigned short)atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE) == SYSINFO_RET_OK)
+ {
+ SET_DBL_RESULT(result, zbx_getseconds() - start_time);
}
else
{
@@ -193,7 +179,7 @@ int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESU
}
free(buffer);
- return ret;
+ return SYSINFO_RET_OK;
}
int WEB_PAGE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -252,8 +238,8 @@ int WEB_PAGE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RE
return SYSINFO_RET_FAIL;
}
- buffer=malloc(ZABBIX_MAX_WEBPAGE_SIZE);
- if(get_http_page(hostname, path, atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE) == SYSINFO_RET_OK)
+ buffer = calloc(1, ZABBIX_MAX_WEBPAGE_SIZE);
+ if(get_http_page(hostname, path, (unsigned short)atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE) == SYSINFO_RET_OK)
{
found = zbx_regexp_match(buffer,regexp,&l);
if(found!=NULL)
@@ -271,16 +257,3 @@ int WEB_PAGE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RE
return ret;
}
-
-/*#define ZABBIX_TEST*/
-
-#ifdef ZABBIX_TEST
-int main()
-{
- char buffer[100*1024];
-
- get_http_page("www.zabbix.com", "", 80, buffer, 100*1024);
-
- printf("Back [%d] [%s]\n", strlen(buffer), buffer);
-}
-#endif
diff --git a/src/libs/zbxsysinfo/common/ntp.c b/src/libs/zbxsysinfo/common/ntp.c
index 24d9dfd1..187bec0c 100644
--- a/src/libs/zbxsysinfo/common/ntp.c
+++ b/src/libs/zbxsysinfo/common/ntp.c
@@ -17,12 +17,9 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include <unistd.h>
-
-#include "config.h"
-
#include "common.h"
#include "sysinfo.h"
+#include "zbxsock.h"
#define JAN_1970 2208988800.0 /* 1970 - 1900 in seconds */
#define NTP_SCALE 4294967296.0 /* 2^32, of course! */
@@ -58,7 +55,10 @@ typedef struct NTP_DATA {
double dispersion, reference, originate, receive, transmit, current;
} ntp_data;
-double current_time (double offset) {
+double current_time (double offset)
+{
+
+#if !defined(WIN32) || (defined(WIN32) && defined(TODO))
/* Get the current UTC time in seconds since the Epoch plus an offset (usually
the time from the beginning of the century to the Epoch!) */
@@ -66,11 +66,21 @@ the time from the beginning of the century to the Epoch!) */
struct timeval current;
errno = 0;
+#ifdef WIN32
+# error "Replace <gettimeofday> function"
+#endif /* WIN32 */
+
if (gettimeofday(&current,NULL))
{
/* No processing of error condition here */
}
- return offset+current.tv_sec+1.0e-6*current.tv_usec;
+ return offset+current.tv_sec+1.0e-6*current.tv_usec;\
+
+#else
+
+ return 0.;
+
+#endif /* TODO */
}
void make_packet (ntp_data *data)
@@ -222,14 +232,17 @@ systems do not set the return value from (s)printf. */
int check_ntp(char *host, int port, int *value_int)
{
- int s;
+
+#if !defined(WIN32) || (defined(WIN32) && defined(TODO))
+
+ ZBX_SOCKET s;
+ ZBX_SOCKADDR servaddr_in;
+
int len;
unsigned char c[MAX_STRING_LEN];
struct hostent *hp;
- struct sockaddr_in servaddr_in;
-
char text[50];
ntp_data data;
@@ -244,7 +257,7 @@ int check_ntp(char *host, int port, int *value_int)
if(hp==NULL)
{
-/* fprintf(stderr, "gethostbyname(%s) failed [%s]", host, hstrerror(h_errno));*/
+/* zbx_error("gethostbyname(%s) failed [%s]", host, hstrerror(h_errno));*/
return SYSINFO_RET_OK;
}
@@ -256,12 +269,13 @@ int check_ntp(char *host, int port, int *value_int)
if(s == -1)
{
-/* fprintf(stderr, "Cannot create socket [%s]", strerror(errno));*/
+/* zbx_error("Cannot create socket [%s]", strerror(errno));*/
return SYSINFO_RET_OK;
}
if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
{
+ /* useless code
switch (errno)
{
case EINTR:
@@ -270,16 +284,20 @@ int check_ntp(char *host, int port, int *value_int)
break;
default:
break;
- }
-/* fprintf(stderr, "Cannot connect [%s]", strerror(errno));*/
- close(s);
- return SYSINFO_RET_OK;
+ }
+ */
+/* zbx_error("Cannot connect [%s]", strerror(errno));*/
+ goto lbl_error;
}
pack_ntp(packet,NTP_PACKET_MIN,&data);
+#ifdef WIN32
+# error "TIDO replace <write> function"
+#endif /* WIN32 */
if( write(s,&packet,NTP_PACKET_MIN) == -1 )
{
+ /* useless code
switch (errno)
{
case EINTR:
@@ -287,16 +305,22 @@ int check_ntp(char *host, int port, int *value_int)
default:
break;
}
-/* fprintf(stderr, "Cannot write [%s]", strerror(errno));*/
- close(s);
- return SYSINFO_RET_OK;
+ */
+/* zbx_error("Cannot write [%s]", strerror(errno));*/
+ goto lbl_error;
}
memset(c,0,MAX_STRING_LEN);
- len=read(s,c,MAX_STRING_LEN);
+
+#ifdef WIN32
+# error "TIDO replace <read> function"
+#endif /* WIN32 */
+
+ len = read(s,c,MAX_STRING_LEN);
if(len == -1)
{
+ /* useless code
switch (errno)
{
case EINTR:
@@ -306,17 +330,17 @@ int check_ntp(char *host, int port, int *value_int)
default:
break;
}
-/* fprintf(stderr, "Cannot read0 [%d]", errno);*/
- close(s);
- return SYSINFO_RET_OK;
+ */
+/* zbx_error("Cannot read0 [%d]", errno);*/
+ goto lbl_error;
}
- close(s);
+ zbx_sock_close(s);
unpack_ntp(&data,c,len);
/* display_data(&data); */
- sprintf(text,"%d",0);
+ zbx_snprintf(text, sizeof(text), "%d",0);
/* format_time(text,75,offset,error,0.0,-1.0);*/
@@ -331,5 +355,11 @@ int check_ntp(char *host, int port, int *value_int)
*value_int = format_time(text,75,0,0,0.0,-1.0);
return SYSINFO_RET_OK;
+
+lbl_error:
+ zbx_sock_close(s);
+
+#endif /* TODO */
+ return SYSINFO_RET_OK;
}
diff --git a/src/libs/zbxsysinfo/common/system.c b/src/libs/zbxsysinfo/common/system.c
index 8a70c07f..a6443822 100644
--- a/src/libs/zbxsysinfo/common/system.c
+++ b/src/libs/zbxsysinfo/common/system.c
@@ -34,3 +34,25 @@ int SYSTEM_LOCALTIME(const char *cmd, const char *param, unsigned flags, AGENT_R
return ret;
}
+
+#if !defined(WIN32)
+
+int SYSTEM_UNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ assert(result);
+
+ init_result(result);
+
+ return EXECUTE_STR(cmd, "uname -a", flags, result);
+}
+
+int SYSTEM_HOSTNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ assert(result);
+
+ init_result(result);
+
+ return EXECUTE_STR(cmd, "hostname", flags, result);
+}
+
+#endif /* not WIN32 */
diff --git a/src/libs/zbxsysinfo/freebsd/Makefile.am b/src/libs/zbxsysinfo/freebsd/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/freebsd/Makefile.am
+++ b/src/libs/zbxsysinfo/freebsd/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/freebsd/cpu.c b/src/libs/zbxsysinfo/freebsd/cpu.c
index 75a8db56..ea15a71e 100644
--- a/src/libs/zbxsysinfo/freebsd/cpu.c
+++ b/src/libs/zbxsysinfo/freebsd/cpu.c
@@ -128,31 +128,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(type)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type) "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -502,28 +502,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/freebsd/diskio.c b/src/libs/zbxsysinfo/freebsd/diskio.c
index 333b177a..d2288761 100644
--- a/src/libs/zbxsysinfo/freebsd/diskio.c
+++ b/src/libs/zbxsysinfo/freebsd/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -166,22 +166,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type) "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode) "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -242,22 +242,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(mode)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(mode), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode)"avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/freebsd/diskspace.c b/src/libs/zbxsysinfo/freebsd/diskspace.c
index fd89f469..ab2e4dd7 100644
--- a/src/libs/zbxsysinfo/freebsd/diskspace.c
+++ b/src/libs/zbxsysinfo/freebsd/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode) "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/freebsd/freebsd.c b/src/libs/zbxsysinfo/freebsd/freebsd.c
index ec5a0837..8c85c385 100644
--- a/src/libs/zbxsysinfo/freebsd/freebsd.c
+++ b/src/libs/zbxsysinfo/freebsd/freebsd.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/freebsd/inodes.c b/src/libs/zbxsysinfo/freebsd/inodes.c
index a27e8644..9e6d195e 100644
--- a/src/libs/zbxsysinfo/freebsd/inodes.c
+++ b/src/libs/zbxsysinfo/freebsd/inodes.c
@@ -197,19 +197,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/freebsd/memory.c b/src/libs/zbxsysinfo/freebsd/memory.c
index dab28847..a1e08470 100644
--- a/src/libs/zbxsysinfo/freebsd/memory.c
+++ b/src/libs/zbxsysinfo/freebsd/memory.c
@@ -25,7 +25,7 @@
static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
- FILE *f;
+ FILE *f = NULL;
char *t;
char c[MAX_STRING_LEN];
zbx_uint64_t res = 0;
@@ -34,12 +34,12 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if(NULL == (f = fopen("/proc/meminfo","r")))
{
return SYSINFO_RET_FAIL;
}
- while(NULL!=fgets(c,MAX_STRING_LEN,f))
+
+ while(NULL != fgets(c,MAX_STRING_LEN,f))
{
if(strncmp(c,"Cached:",7) == 0)
{
@@ -56,7 +56,8 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -387,7 +388,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -395,7 +396,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/freebsd/proc.c b/src/libs/zbxsysinfo/freebsd/proc.c
index f9ec223c..bcb6e6c6 100644
--- a/src/libs/zbxsysinfo/freebsd/proc.c
+++ b/src/libs/zbxsysinfo/freebsd/proc.c
@@ -138,15 +138,14 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
/* Better approach: check if /proc/x/ is symbolic link */
if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
{
- continue;
+ continue; /* readdir */
}
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r")))
{
- continue;
+ continue; /* readdir */
}
if(procname[0] != 0)
@@ -165,8 +164,8 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(proc_ok == 0)
{
- fclose(f);
- continue;
+ zbx_fclose(f);
+ continue; /* readdir */
}
}
else
@@ -181,12 +180,12 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(sscanf(line, "%s\t%lli\n", name1, &llvalue) != 2)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name1,"Uid:") != 0)
{
- continue;
+ continue; /* fgets */
}
if(usrinfo->pw_uid == (uid_t)(llvalue))
@@ -208,12 +207,12 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(sscanf(line, "%s\t%lli %s\n", name1, &llvalue, name2) != 3)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name1,"VmSize:") != 0)
{
- continue;
+ continue; /* fgets */
}
proccount++;
@@ -259,8 +258,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
}
}
-
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
@@ -391,7 +389,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
/* Better approach: check if /proc/x/ is symbolic link */
if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
{
- continue;
+ continue; /* readdir */
}
strscpy(filename,"/proc/");
@@ -400,10 +398,9 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if( NULL == (f = fopen(filename,"r")))
{
- continue;
+ continue; /* readdir */
}
if(procname[0] != 0)
@@ -422,8 +419,8 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(proc_ok == 0)
{
- fclose(f);
- continue;
+ zbx_fclose(f);
+ continue; /* readdir */
}
}
else
@@ -438,12 +435,12 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name1,"State:") != 0)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name2, procstat))
@@ -465,12 +462,12 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name1,"Uid:") != 0)
{
- continue;
+ continue; /* fgets */
}
if(usrinfo->pw_uid == (uid_t)(lvalue))
@@ -490,7 +487,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
proccount++;
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
diff --git a/src/libs/zbxsysinfo/freebsd/sensors.c b/src/libs/zbxsysinfo/freebsd/sensors.c
index cc5a3af8..4df957a9 100644
--- a/src/libs/zbxsysinfo/freebsd/sensors.c
+++ b/src/libs/zbxsysinfo/freebsd/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r")))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/freebsd/swap.c b/src/libs/zbxsysinfo/freebsd/swap.c
index 2bfd5511..62ebe789 100644
--- a/src/libs/zbxsysinfo/freebsd/swap.c
+++ b/src/libs/zbxsysinfo/freebsd/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev),"all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/hpux/Makefile.am b/src/libs/zbxsysinfo/hpux/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/hpux/Makefile.am
+++ b/src/libs/zbxsysinfo/hpux/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/hpux/cpu.c b/src/libs/zbxsysinfo/hpux/cpu.c
index 8203daab..9b125afa 100644
--- a/src/libs/zbxsysinfo/hpux/cpu.c
+++ b/src/libs/zbxsysinfo/hpux/cpu.c
@@ -128,31 +128,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type), "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -255,28 +255,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/hpux/diskio.c b/src/libs/zbxsysinfo/hpux/diskio.c
index 333b177a..cc73aabc 100644
--- a/src/libs/zbxsysinfo/hpux/diskio.c
+++ b/src/libs/zbxsysinfo/hpux/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -166,22 +166,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sieof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -242,22 +242,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/hpux/diskspace.c b/src/libs/zbxsysinfo/hpux/diskspace.c
index fd89f469..f37aeb7c 100644
--- a/src/libs/zbxsysinfo/hpux/diskspace.c
+++ b/src/libs/zbxsysinfo/hpux/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/hpux/hpux.c b/src/libs/zbxsysinfo/hpux/hpux.c
index fb6cd580..32974871 100644
--- a/src/libs/zbxsysinfo/hpux/hpux.c
+++ b/src/libs/zbxsysinfo/hpux/hpux.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/hpux/inodes.c b/src/libs/zbxsysinfo/hpux/inodes.c
index d773c1e0..b4af34c1 100644
--- a/src/libs/zbxsysinfo/hpux/inodes.c
+++ b/src/libs/zbxsysinfo/hpux/inodes.c
@@ -211,19 +211,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/hpux/memory.c b/src/libs/zbxsysinfo/hpux/memory.c
index dab28847..9d975205 100644
--- a/src/libs/zbxsysinfo/hpux/memory.c
+++ b/src/libs/zbxsysinfo/hpux/memory.c
@@ -34,11 +34,11 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if(NULL == (f = fopen("/proc/meminfo","r")))
{
return SYSINFO_RET_FAIL;
}
+
while(NULL!=fgets(c,MAX_STRING_LEN,f))
{
if(strncmp(c,"Cached:",7) == 0)
@@ -56,7 +56,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -387,7 +387,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -395,7 +395,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/hpux/proc.c b/src/libs/zbxsysinfo/hpux/proc.c
index f9ec223c..8f8d4511 100644
--- a/src/libs/zbxsysinfo/hpux/proc.c
+++ b/src/libs/zbxsysinfo/hpux/proc.c
@@ -143,30 +143,29 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r")))
{
- continue;
+ continue; /* readdir */
}
if(procname[0] != 0)
{
fgets(line,MAX_STRING_LEN,f);
if(sscanf(line,"%s\t%s\n",name1,name2)==2)
- {
- if(strcmp(name1,"Name:") == 0)
- {
- if(strcmp(procname,name2)==0)
- {
- proc_ok = 1;
- }
- }
- }
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
if(proc_ok == 0)
{
- fclose(f);
- continue;
+ zbx_fclose(f);
+ continue; /* readdir */
}
}
else
@@ -181,12 +180,12 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(sscanf(line, "%s\t%lli\n", name1, &llvalue) != 2)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name1,"Uid:") != 0)
{
- continue;
+ continue; /* fgets */
}
if(usrinfo->pw_uid == (uid_t)(llvalue))
@@ -208,12 +207,12 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(sscanf(line, "%s\t%lli %s\n", name1, &llvalue, name2) != 3)
{
- continue;
+ continue; /* fgets */
}
if(strcmp(name1,"VmSize:") != 0)
{
- continue;
+ continue; /* fgets */
}
proccount++;
@@ -260,7 +259,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
@@ -400,8 +399,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r")))
{
continue;
}
@@ -422,7 +420,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -490,7 +488,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
proccount++;
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
diff --git a/src/libs/zbxsysinfo/hpux/sensors.c b/src/libs/zbxsysinfo/hpux/sensors.c
index cc5a3af8..5b4e3eb5 100644
--- a/src/libs/zbxsysinfo/hpux/sensors.c
+++ b/src/libs/zbxsysinfo/hpux/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if( NULL == (f = fopen(filename,"r")))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/hpux/swap.c b/src/libs/zbxsysinfo/hpux/swap.c
index 2bfd5511..c2e91a77 100644
--- a/src/libs/zbxsysinfo/hpux/swap.c
+++ b/src/libs/zbxsysinfo/hpux/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode)), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/linux/Makefile.am b/src/libs/zbxsysinfo/linux/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/linux/Makefile.am
+++ b/src/libs/zbxsysinfo/linux/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/linux/cpu.c b/src/libs/zbxsysinfo/linux/cpu.c
index acf5f9c9..da64f6bd 100644
--- a/src/libs/zbxsysinfo/linux/cpu.c
+++ b/src/libs/zbxsysinfo/linux/cpu.c
@@ -128,31 +128,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type), "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -502,28 +502,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
@@ -559,8 +559,7 @@ int SYSTEM_CPU_INTR(const char *cmd, const char *param, unsigned flags, AGEN
init_result(result);
- f=fopen("/proc/stat","r");
- if(f)
+ if(NULL != ( f = fopen("/proc/stat","r") ))
{
while(fgets(line,MAX_STRING_LEN,f) != NULL)
{
@@ -574,7 +573,7 @@ int SYSTEM_CPU_INTR(const char *cmd, const char *param, unsigned flags, AGEN
break;
}
}
- fclose(f);
+ zbx_fclose(f);
}
return ret;
diff --git a/src/libs/zbxsysinfo/linux/diskio.c b/src/libs/zbxsysinfo/linux/diskio.c
index 02de011e..03837ba3 100644
--- a/src/libs/zbxsysinfo/linux/diskio.c
+++ b/src/libs/zbxsysinfo/linux/diskio.c
@@ -97,8 +97,7 @@ static int get_disk_stat(const char *interface, struct disk_stat_s *result)
assert(result);
- f=fopen(INFO_FILE_NAME,"r");
- if(f)
+ if(NULL != (f = fopen(INFO_FILE_NAME,"r") ))
{
while(fgets(line,MAX_STRING_LEN,f) != NULL)
{
@@ -110,7 +109,7 @@ static int get_disk_stat(const char *interface, struct disk_stat_s *result)
break;
}
}
- fclose(f);
+ zbx_fclose(f);
}
if(ret != SYSINFO_RET_OK)
@@ -137,12 +136,12 @@ int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESU
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -150,7 +149,7 @@ int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESU
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "sectors");
+ zbx_snprintf(mode, sizeof(mode), "sectors");
}
ret = get_disk_stat(devname, &ds);
@@ -192,12 +191,12 @@ int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -205,7 +204,7 @@ int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "sectors");
+ zbx_snprintf(mode, sizeof(mode), "sectors");
}
ret = get_disk_stat(devname, &ds);
diff --git a/src/libs/zbxsysinfo/linux/diskspace.c b/src/libs/zbxsysinfo/linux/diskspace.c
index 58f869b0..a75ffa08 100644
--- a/src/libs/zbxsysinfo/linux/diskspace.c
+++ b/src/libs/zbxsysinfo/linux/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/linux/inodes.c b/src/libs/zbxsysinfo/linux/inodes.c
index d349d108..b5edc281 100644
--- a/src/libs/zbxsysinfo/linux/inodes.c
+++ b/src/libs/zbxsysinfo/linux/inodes.c
@@ -211,19 +211,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/linux/kernel.c b/src/libs/zbxsysinfo/linux/kernel.c
index 9815b19c..a63041de 100644
--- a/src/libs/zbxsysinfo/linux/kernel.c
+++ b/src/libs/zbxsysinfo/linux/kernel.c
@@ -35,8 +35,7 @@ int KERNEL_MAXFILES(const char *cmd, const char *param, unsigned flags, AGENT_RE
init_result(result);
- f=fopen("/proc/sys/fs/file-max","r");
- if(f)
+ if(NULL != ( f = fopen("/proc/sys/fs/file-max","r") ))
{
if(fgets(line,MAX_STRING_LEN,f) != NULL);
{
@@ -46,7 +45,7 @@ int KERNEL_MAXFILES(const char *cmd, const char *param, unsigned flags, AGENT_RE
ret = SYSINFO_RET_OK;
}
}
- fclose(f);
+ zbx_fclose(f);
}
return ret;
diff --git a/src/libs/zbxsysinfo/linux/linux.c b/src/libs/zbxsysinfo/linux/linux.c
index f4f85677..0926604e 100644
--- a/src/libs/zbxsysinfo/linux/linux.c
+++ b/src/libs/zbxsysinfo/linux/linux.c
@@ -25,207 +25,25 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "sda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "sda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "sda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "sda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "sda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "sda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "sda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "sda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "sda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "sda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "sda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "sda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "sda,operations"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "sda,sectors"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
@@ -240,19 +58,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "sda,operations"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "sda,sectors"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "total"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/linux/memory.c b/src/libs/zbxsysinfo/linux/memory.c
index 3769c4b1..b95995af 100644
--- a/src/libs/zbxsysinfo/linux/memory.c
+++ b/src/libs/zbxsysinfo/linux/memory.c
@@ -33,8 +33,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if(NULL == (f = fopen("/proc/meminfo","r") ))
{
return SYSINFO_RET_FAIL;
}
@@ -55,7 +54,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -183,7 +182,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -191,7 +190,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/linux/net.c b/src/libs/zbxsysinfo/linux/net.c
index 8fad22a6..7d7b0259 100644
--- a/src/libs/zbxsysinfo/linux/net.c
+++ b/src/libs/zbxsysinfo/linux/net.c
@@ -34,7 +34,7 @@ struct net_stat_s {
unsigned long colls;
};
-static int get_net_stat(const char *interface, struct net_stat_s *result)
+static int get_net_stat(const char *if_name, struct net_stat_s *result)
{
int ret = SYSINFO_RET_FAIL;
char line[MAX_STRING_LEN];
@@ -47,8 +47,7 @@ static int get_net_stat(const char *interface, struct net_stat_s *result)
assert(result);
- f=fopen("/proc/net/dev","r");
- if(f)
+ if(NULL != (f = fopen("/proc/net/dev","r") ))
{
while(fgets(line,MAX_STRING_LEN,f) != NULL)
@@ -78,14 +77,14 @@ static int get_net_stat(const char *interface, struct net_stat_s *result)
&(tmp) /* compressed */
) == 17)
{
- if(strncmp(name, interface, MAX_STRING_LEN) == 0)
+ if(strncmp(name, if_name, MAX_STRING_LEN) == 0)
{
ret = SYSINFO_RET_OK;
break;
}
}
}
- fclose(f);
+ zbx_fclose(f);
}
if(ret != SYSINFO_RET_OK)
@@ -100,7 +99,7 @@ int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
{
struct net_stat_s ns;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
@@ -114,22 +113,22 @@ int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
- ret = get_net_stat(interface, &ns);
+ ret = get_net_stat(if_name, &ns);
if(ret == SYSINFO_RET_OK)
@@ -163,7 +162,7 @@ int NET_IF_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
{
struct net_stat_s ns;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
@@ -177,22 +176,22 @@ int NET_IF_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
- ret = get_net_stat(interface, &ns);
+ ret = get_net_stat(if_name, &ns);
if(ret == SYSINFO_RET_OK)
@@ -226,7 +225,7 @@ int NET_IF_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
{
struct net_stat_s ns;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
@@ -240,22 +239,22 @@ int NET_IF_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
- ret = get_net_stat(interface, &ns);
+ ret = get_net_stat(if_name, &ns);
if(ret == SYSINFO_RET_OK)
@@ -298,7 +297,7 @@ int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AG
{
struct net_stat_s ns;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
@@ -311,13 +310,13 @@ int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AG
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_net_stat(interface, &ns);
+ ret = get_net_stat(if_name, &ns);
if(ret == SYSINFO_RET_OK)
diff --git a/src/libs/zbxsysinfo/linux/proc.c b/src/libs/zbxsysinfo/linux/proc.c
index fcf098f9..f50876f8 100644
--- a/src/libs/zbxsysinfo/linux/proc.c
+++ b/src/libs/zbxsysinfo/linux/proc.c
@@ -134,11 +134,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
while((entries=readdir(dir))!=NULL)
{
- if(f)
- {
- fclose(f);
- f = NULL;
- }
+ zbx_fclose(f);
proc_ok = 0;
usr_ok = 0;
@@ -156,8 +152,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == ( f = fopen(filename,"r") ))
{
continue;
}
@@ -220,10 +215,11 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
strncat(filename,entries->d_name,MAX_STRING_LEN);
strncat(filename,"/cmdline",MAX_STRING_LEN);
- if(stat(filename,&buf)!=0) continue;
+ if(stat(filename,&buf)!=0)
+ continue;
- f2=fopen(filename,"r");
- if(f2==NULL) continue;
+ if(NULL == (f2 = fopen(filename,"r") ))
+ continue;
if(fgets(line, MAX_STRING_LEN, f2) != NULL)
{
@@ -231,7 +227,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
comm_ok = 1;
}
- fclose(f2);
+ zbx_fclose(f2);
} else {
comm_ok = 1;
}
@@ -296,7 +292,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
}
}
}
- if(f) fclose(f);
+ zbx_fclose(f);
closedir(dir);
if(first == 0)
@@ -437,8 +433,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
continue;
}
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -460,7 +455,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -524,7 +519,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
{
usr_ok = 1;
}
- fclose(f);
+ zbx_fclose(f);
comm_ok = 0;
if(proccomm[0] != '\0')
@@ -533,16 +528,17 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
strncat(filename,entries->d_name,MAX_STRING_LEN);
strncat(filename,"/cmdline",MAX_STRING_LEN);
- if(stat(filename,&buf)!=0) continue;
+ if(stat(filename,&buf)!=0)
+ continue;
- f=fopen(filename,"r");
- if(f==NULL) continue;
+ if(NULL == (f = fopen(filename,"r") ))
+ continue;
if(fgets(line, MAX_STRING_LEN, f) != NULL)
if(zbx_regexp_match(line,proccomm,NULL) != NULL)
comm_ok = 1;
- fclose(f);
+ zbx_fclose(f);
} else {
comm_ok = 1;
}
diff --git a/src/libs/zbxsysinfo/linux/sensors.c b/src/libs/zbxsysinfo/linux/sensors.c
index cc5a3af8..b01bfecc 100644
--- a/src/libs/zbxsysinfo/linux/sensors.c
+++ b/src/libs/zbxsysinfo/linux/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if( NULL == (f = fopen(filename,"r") ))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/linux/swap.c b/src/libs/zbxsysinfo/linux/swap.c
index 430dac4b..03145a81 100644
--- a/src/libs/zbxsysinfo/linux/swap.c
+++ b/src/libs/zbxsysinfo/linux/swap.c
@@ -100,7 +100,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -108,7 +108,7 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
if(strncmp(swapdev, "all", MAX_STRING_LEN))
@@ -116,7 +116,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -124,7 +124,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/netbsd/Makefile.am b/src/libs/zbxsysinfo/netbsd/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/netbsd/Makefile.am
+++ b/src/libs/zbxsysinfo/netbsd/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/netbsd/cpu.c b/src/libs/zbxsysinfo/netbsd/cpu.c
index 75a8db56..135e7534 100644
--- a/src/libs/zbxsysinfo/netbsd/cpu.c
+++ b/src/libs/zbxsysinfo/netbsd/cpu.c
@@ -128,31 +128,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type), "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -502,28 +502,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/netbsd/diskio.c b/src/libs/zbxsysinfo/netbsd/diskio.c
index 333b177a..dada912d 100644
--- a/src/libs/zbxsysinfo/netbsd/diskio.c
+++ b/src/libs/zbxsysinfo/netbsd/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -166,22 +166,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type) ) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -254,7 +254,7 @@ DEV_FNCLIST
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/netbsd/diskspace.c b/src/libs/zbxsysinfo/netbsd/diskspace.c
index fd89f469..7e7eb5f1 100644
--- a/src/libs/zbxsysinfo/netbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/netbsd/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode) "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/netbsd/inodes.c b/src/libs/zbxsysinfo/netbsd/inodes.c
index a27e8644..2f4990ce 100644
--- a/src/libs/zbxsysinfo/netbsd/inodes.c
+++ b/src/libs/zbxsysinfo/netbsd/inodes.c
@@ -197,19 +197,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname))) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/netbsd/memory.c b/src/libs/zbxsysinfo/netbsd/memory.c
index dab28847..6813604d 100644
--- a/src/libs/zbxsysinfo/netbsd/memory.c
+++ b/src/libs/zbxsysinfo/netbsd/memory.c
@@ -34,8 +34,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if( NULL == (f = fopen("/proc/meminfo","r") ))
{
return SYSINFO_RET_FAIL;
}
@@ -56,7 +55,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -395,7 +394,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/netbsd/netbsd.c b/src/libs/zbxsysinfo/netbsd/netbsd.c
index fb6cd580..e39c93fb 100644
--- a/src/libs/zbxsysinfo/netbsd/netbsd.c
+++ b/src/libs/zbxsysinfo/netbsd/netbsd.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
- {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
- {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/netbsd/proc.c b/src/libs/zbxsysinfo/netbsd/proc.c
index f9ec223c..1f9b90e6 100644
--- a/src/libs/zbxsysinfo/netbsd/proc.c
+++ b/src/libs/zbxsysinfo/netbsd/proc.c
@@ -143,8 +143,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if( NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -165,7 +164,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -260,7 +259,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
@@ -400,8 +399,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -422,7 +420,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -490,7 +488,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
proccount++;
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
diff --git a/src/libs/zbxsysinfo/netbsd/sensors.c b/src/libs/zbxsysinfo/netbsd/sensors.c
index cc5a3af8..d0357b6c 100644
--- a/src/libs/zbxsysinfo/netbsd/sensors.c
+++ b/src/libs/zbxsysinfo/netbsd/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/netbsd/swap.c b/src/libs/zbxsysinfo/netbsd/swap.c
index 2bfd5511..00679cb7 100644
--- a/src/libs/zbxsysinfo/netbsd/swap.c
+++ b/src/libs/zbxsysinfo/netbsd/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swadev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/openbsd/Makefile.am b/src/libs/zbxsysinfo/openbsd/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/openbsd/Makefile.am
+++ b/src/libs/zbxsysinfo/openbsd/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/openbsd/OpenBSD3.7.c b/src/libs/zbxsysinfo/openbsd/OpenBSD3.7.c
index fb3ea30d..9d6c69ca 100755
--- a/src/libs/zbxsysinfo/openbsd/OpenBSD3.7.c
+++ b/src/libs/zbxsysinfo/openbsd/OpenBSD3.7.c
@@ -1819,7 +1819,7 @@ ZBX_METRIC agent_commands[]=
{"system[hostname]" ,0, EXECUTE_STR, "hostname"},
{"system[uname]" ,0, EXECUTE_STR, "uname -a"},
{"system[uptime]" ,UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
+ {"system[users]" ,EXECUTE_INT, 0,"who|wc -l"},
{"ping" ,PING, 0, 0},
{"tcp_count" ,TCP_SOCKETS, 0, 0},
diff --git a/src/libs/zbxsysinfo/openbsd/cpu.c b/src/libs/zbxsysinfo/openbsd/cpu.c
index 998d998c..c9d3e4b7 100644
--- a/src/libs/zbxsysinfo/openbsd/cpu.c
+++ b/src/libs/zbxsysinfo/openbsd/cpu.c
@@ -96,21 +96,21 @@ CPU_PARAMLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
cpuname[0] = '\0';
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname) "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -240,28 +240,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/openbsd/diskio.c b/src/libs/zbxsysinfo/openbsd/diskio.c
index 41bc7bbc..ffa5b722 100644
--- a/src/libs/zbxsysinfo/openbsd/diskio.c
+++ b/src/libs/zbxsysinfo/openbsd/diskio.c
@@ -212,12 +212,12 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -225,7 +225,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, fl[0].mode);
+ zbx_snprintf(mode, sizeof(mode), fl[0].mode);
}
for(i=0; fl[i].mode!=0; i++)
@@ -269,12 +269,12 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -282,7 +282,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, fl[0].mode);
+ zbx_snprintf(mode, sizeof(mode), fl[0].mode);
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/openbsd/diskspace.c b/src/libs/zbxsysinfo/openbsd/diskspace.c
index fd89f469..f37aeb7c 100644
--- a/src/libs/zbxsysinfo/openbsd/diskspace.c
+++ b/src/libs/zbxsysinfo/openbsd/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/openbsd/inodes.c b/src/libs/zbxsysinfo/openbsd/inodes.c
index a27e8644..fbc50fc1 100644
--- a/src/libs/zbxsysinfo/openbsd/inodes.c
+++ b/src/libs/zbxsysinfo/openbsd/inodes.c
@@ -197,19 +197,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/openbsd/memory.c b/src/libs/zbxsysinfo/openbsd/memory.c
index 4c70e997..d710b029 100644
--- a/src/libs/zbxsysinfo/openbsd/memory.c
+++ b/src/libs/zbxsysinfo/openbsd/memory.c
@@ -97,7 +97,7 @@ MEM_FNCLIST
}
else
{
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -105,7 +105,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode) "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/openbsd/net.c b/src/libs/zbxsysinfo/openbsd/net.c
index 467cf1bb..200c3935 100644
--- a/src/libs/zbxsysinfo/openbsd/net.c
+++ b/src/libs/zbxsysinfo/openbsd/net.c
@@ -88,7 +88,7 @@ static int get_ifdata(const char *device, struct ifnet *result)
static int NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -100,12 +100,12 @@ static int NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned fla
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -119,7 +119,7 @@ static int NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned fla
static int NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -131,12 +131,12 @@ static int NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned f
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -150,7 +150,7 @@ static int NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned f
static int NET_IF_IN_ERRORS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -162,12 +162,12 @@ static int NET_IF_IN_ERRORS(const char *cmd, const char *param, unsigned fl
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -195,7 +195,7 @@ NET_FNCLIST
{0, 0}
};
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
@@ -208,26 +208,26 @@ NET_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
- return (fl[i].function)(cmd, interface, flags, result);
+ return (fl[i].function)(cmd, if_name, flags, result);
}
}
@@ -237,7 +237,7 @@ NET_FNCLIST
static int NET_IF_OUT_BYTES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -249,12 +249,12 @@ static int NET_IF_OUT_BYTES(const char *cmd, const char *param, unsigned fl
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -268,7 +268,7 @@ static int NET_IF_OUT_BYTES(const char *cmd, const char *param, unsigned fl
static int NET_IF_OUT_PACKETS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -280,12 +280,12 @@ static int NET_IF_OUT_PACKETS(const char *cmd, const char *param, unsigned
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -299,7 +299,7 @@ static int NET_IF_OUT_PACKETS(const char *cmd, const char *param, unsigned
static int NET_IF_OUT_ERRORS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -311,12 +311,12 @@ static int NET_IF_OUT_ERRORS(const char *cmd, const char *param, unsigned f
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -344,7 +344,7 @@ NET_FNCLIST
{0, 0}
};
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
@@ -357,26 +357,26 @@ NET_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
- return (fl[i].function)(cmd, interface, flags, result);
+ return (fl[i].function)(cmd, if_name, flags, result);
}
}
@@ -386,7 +386,7 @@ NET_FNCLIST
static int NET_IF_TOTAL_BYTES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -398,12 +398,12 @@ static int NET_IF_TOTAL_BYTES(const char *cmd, const char *param, unsigned
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -417,7 +417,7 @@ static int NET_IF_TOTAL_BYTES(const char *cmd, const char *param, unsigned
static int NET_IF_TOTAL_PACKETS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -429,12 +429,12 @@ static int NET_IF_TOTAL_PACKETS(const char *cmd, const char *param, unsigne
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -448,7 +448,7 @@ static int NET_IF_TOTAL_PACKETS(const char *cmd, const char *param, unsigne
static int NET_IF_TOTAL_ERRORS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -460,12 +460,12 @@ static int NET_IF_TOTAL_ERRORS(const char *cmd, const char *param, unsigned
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
@@ -493,7 +493,7 @@ NET_FNCLIST
{0, 0}
};
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
@@ -506,26 +506,26 @@ NET_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
- return (fl[i].function)(cmd, interface, flags, result);
+ return (fl[i].function)(cmd, if_name, flags, result);
}
}
@@ -544,7 +544,7 @@ int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT
int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
struct ifnet value;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret = SYSINFO_RET_FAIL;
assert(result);
@@ -556,12 +556,12 @@ int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AG
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_ifdata(interface, &value);
+ ret = get_ifdata(if_name, &value);
if(ret == SYSINFO_RET_OK)
{
diff --git a/src/libs/zbxsysinfo/openbsd/openbsd.c b/src/libs/zbxsysinfo/openbsd/openbsd.c
index 3d57642c..35104abf 100644
--- a/src/libs/zbxsysinfo/openbsd/openbsd.c
+++ b/src/libs/zbxsysinfo/openbsd/openbsd.c
@@ -25,212 +25,29 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "total"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,bytes"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,operations"},
+
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
-
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +57,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,bytes"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,operations"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,idle"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/openbsd/sensors.c b/src/libs/zbxsysinfo/openbsd/sensors.c
index cc5a3af8..665e1d47 100644
--- a/src/libs/zbxsysinfo/openbsd/sensors.c
+++ b/src/libs/zbxsysinfo/openbsd/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r"))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/openbsd/swap.c b/src/libs/zbxsysinfo/openbsd/swap.c
index 301a3203..dfbaba51 100644
--- a/src/libs/zbxsysinfo/openbsd/swap.c
+++ b/src/libs/zbxsysinfo/openbsd/swap.c
@@ -124,7 +124,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -132,15 +132,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -148,7 +148,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
@@ -253,7 +253,7 @@ int SYSTEM_SWAP_IN(const char *cmd, const char *param, unsigned flags, AGENT_RES
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -261,15 +261,15 @@ int SYSTEM_SWAP_IN(const char *cmd, const char *param, unsigned flags, AGENT_RES
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -310,7 +310,7 @@ int SYSTEM_SWAP_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RE
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -318,15 +318,15 @@ int SYSTEM_SWAP_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/osf/Makefile.am b/src/libs/zbxsysinfo/osf/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/osf/Makefile.am
+++ b/src/libs/zbxsysinfo/osf/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/osf/cpu.c b/src/libs/zbxsysinfo/osf/cpu.c
index 7084446b..8cdd5179 100644
--- a/src/libs/zbxsysinfo/osf/cpu.c
+++ b/src/libs/zbxsysinfo/osf/cpu.c
@@ -29,22 +29,22 @@ int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
static int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF))}'", flags, result);
+ return EXECUTE_INT(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF))}'", flags, result);
}
static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF-1))}'", flags, result);
+ return EXECUTE_INT(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF-1))}'", flags, result);
}
static int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF-2))}'", flags, result);
+ return EXECUTE_INT(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF-2))}'", flags, result);
}
static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF-3))}'", flags, result);
+ return EXECUTE_INT(cmd, "iostat | tail -n 1 | awk '{printf(\"%s\",$(NF-3))}'", flags, result);
}
int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -81,31 +81,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname)"all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(tupe), "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -113,7 +113,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -131,17 +131,17 @@ CPU_FNCLIST
int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "uptime | awk '{printf(\"%s\", $(NF))}' | sed 's/[ ,]//g'", flags, result);
+ return EXECUTE_INT(cmd, "uptime | awk '{printf(\"%s\", $(NF))}' | sed 's/[ ,]//g'", flags, result);
}
int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "uptime | awk '{printf(\"%s\", $(NF-1))}' | sed 's/[ ,]//g'", flags, result);
+ return EXECUTE_INT(cmd, "uptime | awk '{printf(\"%s\", $(NF-1))}' | sed 's/[ ,]//g'", flags, result);
}
int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return EXECUTE(cmd, "uptime | awk '{printf(\"%s\", $(NF-2))}' | sed 's/[ ,]//g'", flags, result);
+ return EXECUTE_INT(cmd, "uptime | awk '{printf(\"%s\", $(NF-2))}' | sed 's/[ ,]//g'", flags, result);
}
int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -175,28 +175,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/osf/diskio.c b/src/libs/zbxsysinfo/osf/diskio.c
index 333b177a..0f70ba14 100644
--- a/src/libs/zbxsysinfo/osf/diskio.c
+++ b/src/libs/zbxsysinfo/osf/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -166,22 +166,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -242,22 +242,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/osf/diskspace.c b/src/libs/zbxsysinfo/osf/diskspace.c
index fd89f469..f37aeb7c 100644
--- a/src/libs/zbxsysinfo/osf/diskspace.c
+++ b/src/libs/zbxsysinfo/osf/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osf/inodes.c b/src/libs/zbxsysinfo/osf/inodes.c
index d773c1e0..b4af34c1 100644
--- a/src/libs/zbxsysinfo/osf/inodes.c
+++ b/src/libs/zbxsysinfo/osf/inodes.c
@@ -211,19 +211,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osf/memory.c b/src/libs/zbxsysinfo/osf/memory.c
index d2cff851..b1286083 100644
--- a/src/libs/zbxsysinfo/osf/memory.c
+++ b/src/libs/zbxsysinfo/osf/memory.c
@@ -28,7 +28,7 @@ static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, A
init_result(result);
- return EXECUTE(cmd,"vmstat -s | awk 'BEGIN{pages=0}{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if(($2==\"inactive\"||$2==\"active\"||$2==\"wired\")&&$3==\"pages\")pages+=$1}END{printf (pages*pgsize)}'", flags, result);
+ return EXECUTE_INT(cmd,"vmstat -s | awk 'BEGIN{pages=0}{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if(($2==\"inactive\"||$2==\"active\"||$2==\"wired\")&&$3==\"pages\")pages+=$1}END{printf (pages*pgsize)}'", flags, result);
}
static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -74,7 +74,7 @@ static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AG
init_result(result);
- return EXECUTE(cmd, "vmstat -s | awk '{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if($2==\"free\"&&$3==\"pages\")pages=($1)}END{printf (pages*pgsize)}'", flags, result);
+ return EXECUTE_INT(cmd, "vmstat -s | awk '{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);if($2==\"free\"&&$3==\"pages\")pages=($1)}END{printf (pages*pgsize)}'", flags, result);
}
int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -104,7 +104,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -112,7 +112,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osf/osf.c b/src/libs/zbxsysinfo/osf/osf.c
index fb6cd580..efc42446 100644
--- a/src/libs/zbxsysinfo/osf/osf.c
+++ b/src/libs/zbxsysinfo/osf/osf.c
@@ -25,207 +25,25 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
@@ -240,19 +58,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/osf/sensors.c b/src/libs/zbxsysinfo/osf/sensors.c
index cc5a3af8..d0357b6c 100644
--- a/src/libs/zbxsysinfo/osf/sensors.c
+++ b/src/libs/zbxsysinfo/osf/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/osf/swap.c b/src/libs/zbxsysinfo/osf/swap.c
index 2bfd5511..1cd947df 100644
--- a/src/libs/zbxsysinfo/osf/swap.c
+++ b/src/libs/zbxsysinfo/osf/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osx/Makefile.am b/src/libs/zbxsysinfo/osx/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/osx/Makefile.am
+++ b/src/libs/zbxsysinfo/osx/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/osx/cpu.c b/src/libs/zbxsysinfo/osx/cpu.c
index 75a8db56..dab5e77d 100644
--- a/src/libs/zbxsysinfo/osx/cpu.c
+++ b/src/libs/zbxsysinfo/osx/cpu.c
@@ -128,31 +128,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpumame), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type), "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -502,28 +502,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpumode), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/osx/diskio.c b/src/libs/zbxsysinfo/osx/diskio.c
index 333b177a..2d03f262 100644
--- a/src/libs/zbxsysinfo/osx/diskio.c
+++ b/src/libs/zbxsysinfo/osx/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -166,19 +166,19 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -242,22 +242,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type) "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/osx/diskspace.c b/src/libs/zbxsysinfo/osx/diskspace.c
index fd89f469..f37aeb7c 100644
--- a/src/libs/zbxsysinfo/osx/diskspace.c
+++ b/src/libs/zbxsysinfo/osx/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osx/inodes.c b/src/libs/zbxsysinfo/osx/inodes.c
index d773c1e0..b4af34c1 100644
--- a/src/libs/zbxsysinfo/osx/inodes.c
+++ b/src/libs/zbxsysinfo/osx/inodes.c
@@ -211,19 +211,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osx/memory.c b/src/libs/zbxsysinfo/osx/memory.c
index dab28847..9f42bbfc 100644
--- a/src/libs/zbxsysinfo/osx/memory.c
+++ b/src/libs/zbxsysinfo/osx/memory.c
@@ -34,11 +34,11 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if(NULL == (f = fopen("/proc/meminfo","r") ))
{
return SYSINFO_RET_FAIL;
}
+
while(NULL!=fgets(c,MAX_STRING_LEN,f))
{
if(strncmp(c,"Cached:",7) == 0)
@@ -56,7 +56,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -387,7 +387,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -395,7 +395,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/osx/osx.c b/src/libs/zbxsysinfo/osx/osx.c
index ec5a0837..8c85c385 100644
--- a/src/libs/zbxsysinfo/osx/osx.c
+++ b/src/libs/zbxsysinfo/osx/osx.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/osx/proc.c b/src/libs/zbxsysinfo/osx/proc.c
index f9ec223c..c0a98716 100644
--- a/src/libs/zbxsysinfo/osx/proc.c
+++ b/src/libs/zbxsysinfo/osx/proc.c
@@ -143,8 +143,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -165,7 +164,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -260,7 +259,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
@@ -400,8 +399,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -422,7 +420,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -490,7 +488,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
proccount++;
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
diff --git a/src/libs/zbxsysinfo/osx/sensors.c b/src/libs/zbxsysinfo/osx/sensors.c
index cc5a3af8..d0357b6c 100644
--- a/src/libs/zbxsysinfo/osx/sensors.c
+++ b/src/libs/zbxsysinfo/osx/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/osx/swap.c b/src/libs/zbxsysinfo/osx/swap.c
index 2bfd5511..151c8b6a 100644
--- a/src/libs/zbxsysinfo/osx/swap.c
+++ b/src/libs/zbxsysinfo/osx/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/solaris/Makefile.am b/src/libs/zbxsysinfo/solaris/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/solaris/Makefile.am
+++ b/src/libs/zbxsysinfo/solaris/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/solaris/SunOS5.9.c b/src/libs/zbxsysinfo/solaris/SunOS5.9.c
index 091b1f42..ca4d35e6 100755
--- a/src/libs/zbxsysinfo/solaris/SunOS5.9.c
+++ b/src/libs/zbxsysinfo/solaris/SunOS5.9.c
@@ -1546,9 +1546,9 @@ static int TCP_LISTEN(const char *cmd, const char *parameter,double *value, con
memset(command, '\0', sizeof command);
- snprintf(command, sizeof command-1, "netstat -an | grep '*.%s' | wc -l", parameter);
+ zbx_snprintf(command, sizeof(command), "netstat -an | grep '*.%s' | wc -l", parameter);
- return EXECUTE(NULL, command, value, msg, mlen_max);
+ return EXECUTE_INT(NULL, command, value, msg, mlen_max);
}
*/
@@ -1742,10 +1742,10 @@ ZBX_METRIC agent_commands[]=
{"system[hostname]" ,0, EXECUTE_STR, "hostname"},
{"system[uname]" ,0, EXECUTE_STR, "uname -a"},
{"system[uptime]" ,UPTIME, 0, 0},
- {"system[users]" ,EXECUTE, 0,"who|wc -l"},
+ {"system[users]" ,EXECUTE_INT, 0,"who|wc -l"},
{"ping" ,PING, 0, 0},
- {"tcp_count" ,EXECUTE, 0, "netstat -s -P tcp | grep tcpCurrEstab | cut -f2 | tr -s ' ' | cut -d' ' -f3"},
+ {"tcp_count" ,EXECUTE_INT, 0, "netstat -s -P tcp | grep tcpCurrEstab | cut -f2 | tr -s ' ' | cut -d' ' -f3"},
{"tcp_listen[*]" ,TCP_LISTEN, 0, "22"},
diff --git a/src/libs/zbxsysinfo/solaris/cpu.c b/src/libs/zbxsysinfo/solaris/cpu.c
index dde73e12..3efeadc6 100644
--- a/src/libs/zbxsysinfo/solaris/cpu.c
+++ b/src/libs/zbxsysinfo/solaris/cpu.c
@@ -91,21 +91,21 @@ int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RE
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
cpuname[0] = '\0';
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
if(strncmp(cpuname, "all", MAX_STRING_LEN))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -113,7 +113,7 @@ int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(mode[0] == '\0')
{
/* default parameter */
- strscpy(mode, "idle");
+ zbx_snprintf(mode, sizeof(mode),"idle");
}
if(strcmp(mode,"idle") == 0)
@@ -239,28 +239,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(spuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/solaris/diskio.c b/src/libs/zbxsysinfo/solaris/diskio.c
index 19919d51..766d4fb7 100644
--- a/src/libs/zbxsysinfo/solaris/diskio.c
+++ b/src/libs/zbxsysinfo/solaris/diskio.c
@@ -22,11 +22,6 @@
#include "common.h"
#include "sysinfo.h"
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FDI("%s", m) // string info
-#define IDI(i) FDI("%i", i) // integer info
-*/
#if 0
/*
@@ -358,19 +353,19 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mofe)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
@@ -414,19 +409,19 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/solaris/diskspace.c b/src/libs/zbxsysinfo/solaris/diskspace.c
index 92dd00e4..181bec40 100644
--- a/src/libs/zbxsysinfo/solaris/diskspace.c
+++ b/src/libs/zbxsysinfo/solaris/diskspace.c
@@ -196,19 +196,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/solaris/inodes.c b/src/libs/zbxsysinfo/solaris/inodes.c
index 47410ff7..c8fca602 100644
--- a/src/libs/zbxsysinfo/solaris/inodes.c
+++ b/src/libs/zbxsysinfo/solaris/inodes.c
@@ -197,19 +197,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/solaris/memory.c b/src/libs/zbxsysinfo/solaris/memory.c
index 60e5cbe8..56b97c58 100644
--- a/src/libs/zbxsysinfo/solaris/memory.c
+++ b/src/libs/zbxsysinfo/solaris/memory.c
@@ -60,7 +60,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/solaris/net.c b/src/libs/zbxsysinfo/solaris/net.c
index 2cf8655f..78ba13ca 100644
--- a/src/libs/zbxsysinfo/solaris/net.c
+++ b/src/libs/zbxsysinfo/solaris/net.c
@@ -55,7 +55,7 @@ static int get_kstat_named_field(
static int NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -67,19 +67,19 @@ static int NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned flags, A
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "rbytes64", &kn);
+ ret = get_kstat_named_field(if_name, "rbytes64", &kn);
if (ret == SYSINFO_RET_OK)
{
SET_UI64_RESULT(result, kn.value.ui64);
}
else
{
- ret = get_kstat_named_field(interface, "rbytes", &kn);
+ ret = get_kstat_named_field(if_name, "rbytes", &kn);
SET_UI64_RESULT(result, kn.value.ui32);
}
@@ -89,7 +89,7 @@ static int NET_IF_IN_BYTES(const char *cmd, const char *param, unsigned flags, A
static int NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -101,19 +101,19 @@ static int NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned flags,
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "ipackets64", &kn);
+ ret = get_kstat_named_field(if_name, "ipackets64", &kn);
if (ret == SYSINFO_RET_OK)
{
SET_UI64_RESULT(result, kn.value.ui64);
}
else
{
- ret = get_kstat_named_field(interface, "ipackets", &kn);
+ ret = get_kstat_named_field(if_name, "ipackets", &kn);
SET_UI64_RESULT(result, kn.value.ui32);
}
@@ -123,7 +123,7 @@ static int NET_IF_IN_PACKETS(const char *cmd, const char *param, unsigned flags,
static int NET_IF_IN_ERRORS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -135,12 +135,12 @@ static int NET_IF_IN_ERRORS(const char *cmd, const char *param, unsigned flags,
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "ierrors", &kn);
+ ret = get_kstat_named_field(if_name, "ierrors", &kn);
SET_UI64_RESULT(result, kn.value.ui32);
@@ -150,7 +150,7 @@ static int NET_IF_IN_ERRORS(const char *cmd, const char *param, unsigned flags,
static int NET_IF_OUT_BYTES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -162,19 +162,19 @@ static int NET_IF_OUT_BYTES(const char *cmd, const char *param, unsigned flags,
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "obytes64", &kn);
+ ret = get_kstat_named_field(if_name, "obytes64", &kn);
if (ret == SYSINFO_RET_OK)
{
SET_UI64_RESULT(result, kn.value.ui64);
}
else
{
- ret = get_kstat_named_field(interface, "obytes", &kn);
+ ret = get_kstat_named_field(if_name, "obytes", &kn);
SET_UI64_RESULT(result, kn.value.ui32);
}
@@ -184,7 +184,7 @@ static int NET_IF_OUT_BYTES(const char *cmd, const char *param, unsigned flags,
static int NET_IF_OUT_PACKETS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -196,19 +196,19 @@ static int NET_IF_OUT_PACKETS(const char *cmd, const char *param, unsigned flags
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "opackets64", &kn);
+ ret = get_kstat_named_field(if_name, "opackets64", &kn);
if (ret == SYSINFO_RET_OK)
{
SET_UI64_RESULT(result, kn.value.ui64);
}
else
{
- ret = get_kstat_named_field(interface, "opackets", &kn);
+ ret = get_kstat_named_field(if_name, "opackets", &kn);
SET_UI64_RESULT(result, kn.value.ui32);
}
@@ -218,7 +218,7 @@ static int NET_IF_OUT_PACKETS(const char *cmd, const char *param, unsigned flags
static int NET_IF_OUT_ERRORS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -230,12 +230,12 @@ static int NET_IF_OUT_ERRORS(const char *cmd, const char *param, unsigned flags,
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "oerrors", &kn);
+ ret = get_kstat_named_field(if_name, "oerrors", &kn);
SET_UI64_RESULT(result, kn.value.ui32);
@@ -246,7 +246,7 @@ static int NET_IF_TOTAL_BYTES(const char *cmd, const char *param, unsigned flags
{
kstat_named_t ikn;
kstat_named_t okn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -258,19 +258,19 @@ static int NET_IF_TOTAL_BYTES(const char *cmd, const char *param, unsigned flags
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "rbytes64", &ikn) & get_kstat_named_field(interface, "obytes64", &okn);
+ ret = get_kstat_named_field(if_name, "rbytes64", &ikn) & get_kstat_named_field(if_name, "obytes64", &okn);
if (ret == SYSINFO_RET_OK)
{
SET_UI64_RESULT(result, ikn.value.ui64 + okn.value.ui64);
}
else
{
- ret = get_kstat_named_field(interface, "rbytes", &ikn) & get_kstat_named_field(interface, "obytes", &okn);
+ ret = get_kstat_named_field(if_name, "rbytes", &ikn) & get_kstat_named_field(if_name, "obytes", &okn);
SET_UI64_RESULT(result, ikn.value.ui32 + okn.value.ui32);
}
@@ -281,7 +281,7 @@ static int NET_IF_TOTAL_PACKETS(const char *cmd, const char *param, unsigned fla
{
kstat_named_t ikn;
kstat_named_t okn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -293,19 +293,19 @@ static int NET_IF_TOTAL_PACKETS(const char *cmd, const char *param, unsigned fla
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "ipackets64", &ikn) & get_kstat_named_field(interface, "opackets64", &okn);
+ ret = get_kstat_named_field(if_name, "ipackets64", &ikn) & get_kstat_named_field(if_name, "opackets64", &okn);
if (ret == SYSINFO_RET_OK)
{
SET_UI64_RESULT(result, ikn.value.ui64 + okn.value.ui64);
}
else
{
- ret = get_kstat_named_field(interface, "ipackets", &ikn) & get_kstat_named_field(interface, "opackets", &okn);
+ ret = get_kstat_named_field(if_name, "ipackets", &ikn) & get_kstat_named_field(if_name, "opackets", &okn);
SET_UI64_RESULT(result, ikn.value.ui32 + okn.value.ui32);
}
@@ -316,7 +316,7 @@ static int NET_IF_TOTAL_ERRORS(const char *cmd, const char *param, unsigned flag
{
kstat_named_t ikn;
kstat_named_t okn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -328,12 +328,12 @@ static int NET_IF_TOTAL_ERRORS(const char *cmd, const char *param, unsigned flag
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "ierrors", &ikn) & get_kstat_named_field(interface, "oerrors", &okn);
+ ret = get_kstat_named_field(if_name, "ierrors", &ikn) & get_kstat_named_field(if_name, "oerrors", &okn);
SET_UI64_RESULT(result, ikn.value.ui32 + okn.value.ui32);
return ret;
@@ -342,7 +342,7 @@ static int NET_IF_TOTAL_ERRORS(const char *cmd, const char *param, unsigned flag
int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_named_t kn;
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
int ret;
assert(result);
@@ -354,12 +354,12 @@ int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- ret = get_kstat_named_field(interface, "collisions", &kn);
+ ret = get_kstat_named_field(if_name, "collisions", &kn);
if(ret == SYSINFO_RET_OK)
{
@@ -379,9 +379,9 @@ int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RES
memset(command, '\0', sizeof(command));
- snprintf(command, sizeof(command)-1, "netstat -an | grep '*.%s' | wc -l", param);
+ zbx_snprintf(command, sizeof(command), "netstat -an | grep '*.%s' | wc -l", param);
- return EXECUTE(NULL, command, flags, result);
+ return EXECUTE_INT(NULL, command, flags, result);
}
int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
@@ -402,7 +402,7 @@ NET_FNCLIST
{0, 0}
};
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
@@ -415,26 +415,26 @@ NET_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
- return (fl[i].function)(cmd, interface, flags, result);
+ return (fl[i].function)(cmd, if_name, flags, result);
}
}
@@ -458,7 +458,7 @@ NET_FNCLIST
{0, 0}
};
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
@@ -471,26 +471,26 @@ NET_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(mode)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
- return (fl[i].function)(cmd, interface, flags, result);
+ return (fl[i].function)(cmd, if_name, flags, result);
}
}
@@ -514,7 +514,7 @@ NET_FNCLIST
{0, 0}
};
- char interface[MAX_STRING_LEN];
+ char if_name[MAX_STRING_LEN];
char mode[MAX_STRING_LEN];
int i;
@@ -527,26 +527,26 @@ NET_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, interface, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, if_name, sizeof(if_name)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "bytes");
+ zbx_snprintf(mode, sizeof(mode), "bytes");
}
for(i=0; fl[i].mode!=0; i++)
{
if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
{
- return (fl[i].function)(cmd, interface, flags, result);
+ return (fl[i].function)(cmd, if_name, flags, result);
}
}
diff --git a/src/libs/zbxsysinfo/solaris/sensors.c b/src/libs/zbxsysinfo/solaris/sensors.c
index cc5a3af8..d0357b6c 100644
--- a/src/libs/zbxsysinfo/solaris/sensors.c
+++ b/src/libs/zbxsysinfo/solaris/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/solaris/solaris.c b/src/libs/zbxsysinfo/solaris/solaris.c
index 9bd627cc..d4261f43 100644
--- a/src/libs/zbxsysinfo/solaris/solaris.c
+++ b/src/libs/zbxsysinfo/solaris/solaris.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "free"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "hme0"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "hme0"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "hme0"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "hme0"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "hme0"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "hme0"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "hme0"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "hme0"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "hme0"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "hme0"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "hme0"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "hme0"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "sd0"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "sd0"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "sd0"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "sd0"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "sd0"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "sd0"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "sd0"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "sd0"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "sd0"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "sd0"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "sd0"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "sd0"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
-
- {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
- {"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "sd0,bytes"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "sd0,bytes"},
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+ {"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "hme0,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "hme0"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "sd0,bytes"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "sd0,bytes"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,idle"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/solaris/swap.c b/src/libs/zbxsysinfo/solaris/swap.c
index ec3d52d4..6085507f 100644
--- a/src/libs/zbxsysinfo/solaris/swap.c
+++ b/src/libs/zbxsysinfo/solaris/swap.c
@@ -144,7 +144,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -152,15 +152,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -168,7 +168,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
@@ -292,7 +292,7 @@ int SYSTEM_SWAP_IN(const char *cmd, const char *param, unsigned flags, AGENT_RES
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -300,22 +300,22 @@ int SYSTEM_SWAP_IN(const char *cmd, const char *param, unsigned flags, AGENT_RES
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(sapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
- strscpy(mode, "count");
+ zbx_snprintf(mode, sizeof(mode), "count");
}
if(strcmp(mode,"count") == 0)
@@ -354,7 +354,7 @@ int SYSTEM_SWAP_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RE
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -362,22 +362,22 @@ int SYSTEM_SWAP_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev), "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdef)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
- strscpy(mode, "count");
+ zbx_snprintf(mode, sizeof(mode), "count");
}
if(strcmp(mode,"count") == 0)
diff --git a/src/libs/zbxsysinfo/unknown/Makefile.am b/src/libs/zbxsysinfo/unknown/Makefile.am
index 94393287..1905eecf 100644
--- a/src/libs/zbxsysinfo/unknown/Makefile.am
+++ b/src/libs/zbxsysinfo/unknown/Makefile.am
@@ -3,4 +3,4 @@ SUBDIRS=
libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
-libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
+#libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/unknown/cpu.c b/src/libs/zbxsysinfo/unknown/cpu.c
index 75a8db56..135e7534 100644
--- a/src/libs/zbxsysinfo/unknown/cpu.c
+++ b/src/libs/zbxsysinfo/unknown/cpu.c
@@ -128,31 +128,31 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "user");
+ zbx_snprintf(type, sizeof(type), "user");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -160,7 +160,7 @@ CPU_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -502,28 +502,28 @@ CPU_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
{
return SYSINFO_RET_FAIL;
}
if(cpuname[0] == '\0')
{
/* default parameter */
- sprintf(cpuname, "all");
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
}
- if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ if(strncmp(cpuname, "all", sizeof(cpuname)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].mode!=0; i++)
{
diff --git a/src/libs/zbxsysinfo/unknown/diskio.c b/src/libs/zbxsysinfo/unknown/diskio.c
index 333b177a..bad61e3a 100644
--- a/src/libs/zbxsysinfo/unknown/diskio.c
+++ b/src/libs/zbxsysinfo/unknown/diskio.c
@@ -26,7 +26,7 @@ static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -35,7 +35,7 @@ static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGEN
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -44,7 +44,7 @@ static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -53,7 +53,7 @@ static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -62,7 +62,7 @@ static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -71,7 +71,7 @@ static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_read_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -80,7 +80,7 @@ static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops1[%s]",param);
return get_stat(key, flags, result);
}
@@ -89,7 +89,7 @@ static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGE
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops5[%s]",param);
return get_stat(key, flags, result);
}
@@ -98,7 +98,7 @@ static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_ops15[%s]",param);
return get_stat(key, flags, result);
}
@@ -107,7 +107,7 @@ static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks1[%s]",param);
return get_stat(key, flags, result);
}
@@ -116,7 +116,7 @@ static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AG
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param);
+ zbx_snprintf(key,sizeof(key), "disk_write_blks5[%s]",param);
return get_stat(key, flags, result);
}
@@ -125,7 +125,7 @@ static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, A
{
char key[MAX_STRING_LEN];
- snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param);
+ zbx_snprintf(key,sizeof(key),"disk_write_blks15[%s]",param);
return get_stat(key, flags, result);
}
@@ -166,19 +166,19 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
@@ -189,7 +189,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
@@ -242,22 +242,22 @@ DEV_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, devname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, devname, sizeof(devname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, type, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, type, sizeof(type)) != 0)
{
type[0] = '\0';
}
if(type[0] == '\0')
{
/* default parameter */
- sprintf(type, "bps");
+ zbx_snprintf(type, sizeof(type), "bps");
}
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -265,7 +265,7 @@ DEV_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "avg1");
+ zbx_snprintf(mode, sizeof(mode), "avg1");
}
for(i=0; fl[i].type!=0; i++)
diff --git a/src/libs/zbxsysinfo/unknown/diskspace.c b/src/libs/zbxsysinfo/unknown/diskspace.c
index fd89f469..f37aeb7c 100644
--- a/src/libs/zbxsysinfo/unknown/diskspace.c
+++ b/src/libs/zbxsysinfo/unknown/diskspace.c
@@ -212,19 +212,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/unknown/inodes.c b/src/libs/zbxsysinfo/unknown/inodes.c
index d773c1e0..b4af34c1 100644
--- a/src/libs/zbxsysinfo/unknown/inodes.c
+++ b/src/libs/zbxsysinfo/unknown/inodes.c
@@ -211,19 +211,19 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, fsname, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, fsname, sizeof(fsname)) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/unknown/memory.c b/src/libs/zbxsysinfo/unknown/memory.c
index dab28847..60c3286f 100644
--- a/src/libs/zbxsysinfo/unknown/memory.c
+++ b/src/libs/zbxsysinfo/unknown/memory.c
@@ -34,8 +34,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
init_result(result);
- f=fopen("/proc/meminfo","r");
- if(NULL == f)
+ if(NULL == (f = fopen("/proc/meminfo","r") ))
{
return SYSINFO_RET_FAIL;
}
@@ -56,7 +55,7 @@ static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags,
break;
}
}
- fclose(f);
+ zbx_fclose(f);
SET_UI64_RESULT(result, res);
return SYSINFO_RET_OK;
@@ -387,7 +386,7 @@ MEM_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -395,7 +394,7 @@ MEM_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "total");
+ zbx_snprintf(mode, sizeof(mode), "total");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/unknown/proc.c b/src/libs/zbxsysinfo/unknown/proc.c
index f9ec223c..1f9b90e6 100644
--- a/src/libs/zbxsysinfo/unknown/proc.c
+++ b/src/libs/zbxsysinfo/unknown/proc.c
@@ -143,8 +143,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if( NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -165,7 +164,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -260,7 +259,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
@@ -400,8 +399,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if(NULL == (f = fopen(filename,"r") ))
{
continue;
}
@@ -422,7 +420,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
if(proc_ok == 0)
{
- fclose(f);
+ zbx_fclose(f);
continue;
}
}
@@ -490,7 +488,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
proccount++;
}
- fclose(f);
+ zbx_fclose(f);
}
}
closedir(dir);
diff --git a/src/libs/zbxsysinfo/unknown/sensors.c b/src/libs/zbxsysinfo/unknown/sensors.c
index cc5a3af8..b01bfecc 100644
--- a/src/libs/zbxsysinfo/unknown/sensors.c
+++ b/src/libs/zbxsysinfo/unknown/sensors.c
@@ -53,13 +53,12 @@ static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result)
if(stat(filename,&buf)==0)
{
- f=fopen(filename,"r");
- if(f==NULL)
+ if( NULL == (f = fopen(filename,"r") ))
{
continue;
}
fgets(line,MAX_STRING_LEN,f);
- fclose(f);
+ zbx_fclose(f);
if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3)
{
diff --git a/src/libs/zbxsysinfo/unknown/swap.c b/src/libs/zbxsysinfo/unknown/swap.c
index 2bfd5511..ba48d579 100644
--- a/src/libs/zbxsysinfo/unknown/swap.c
+++ b/src/libs/zbxsysinfo/unknown/swap.c
@@ -211,7 +211,7 @@ SWP_FNCLIST
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, swapdev, MAX_STRING_LEN) != 0)
+ if(get_param(param, 1, swapdev, sizeof(swapdev)) != 0)
{
return SYSINFO_RET_FAIL;
}
@@ -219,15 +219,15 @@ SWP_FNCLIST
if(swapdev[0] == '\0')
{
/* default parameter */
- sprintf(swapdev, "all");
+ zbx_snprintf(swapdev, sizeof(swapdev) "all");
}
- if(strncmp(swapdev, "all", MAX_STRING_LEN))
+ if(strncmp(swapdev, "all", sizeof(swapdev)))
{
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
{
mode[0] = '\0';
}
@@ -235,7 +235,7 @@ SWP_FNCLIST
if(mode[0] == '\0')
{
/* default parameter */
- sprintf(mode, "free");
+ zbx_snprintf(mode, sizeof(mode), "free");
}
for(i=0; fl[i].mode!=0; i++)
diff --git a/src/libs/zbxsysinfo/unknown/unknown.c b/src/libs/zbxsysinfo/unknown/unknown.c
index 62ae30c0..0591e666 100644
--- a/src/libs/zbxsysinfo/unknown/unknown.c
+++ b/src/libs/zbxsysinfo/unknown/unknown.c
@@ -25,212 +25,28 @@ ZBX_METRIC parameters_specific[]=
/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
{
-/* Outdated */
-/* incorrect OLD naming */
- {"cpu", CF_USEUPARAM, OLD_CPU, 0, "idle1"},
-/*
- {"cpu[idle1]", 0, 0, 0, 0},
- {"cpu[idle5]", 0, 0, 0, 0},
- {"cpu[idle15]", 0, 0, 0, 0},
- {"cpu[nice1]", 0, 0, 0, 0},
- {"cpu[nice5]", 0, 0, 0, 0},
- {"cpu[nice15]", 0, 0, 0, 0},
- {"cpu[system1]", 0, 0, 0, 0},
- {"cpu[system5]", 0, 0, 0, 0},
- {"cpu[system15]", 0, 0, 0, 0},
- {"cpu[user1]", 0, 0, 0, 0},
- {"cpu[user5]", 0, 0, 0, 0},
- {"cpu[user15]", 0, 0, 0, 0},
-*/
- {"io", CF_USEUPARAM, OLD_IO, 0, "disk_io"},
-/*
- {"io[disk_io]", 0, 0, 0, 0},
- {"io[disk_rio]", 0, 0, 0, 0},
- {"io[disk_wio]", 0, 0, 0, 0},
- {"io[disk_rblk]", 0, 0, 0, 0},
- {"io[disk_wblk]", 0, 0, 0, 0},
-*/
- {"kern", CF_USEUPARAM, OLD_KERNEL, 0, "maxfiles"},
-/*
- {"kern[maxfiles]", 0, 0, 0, 0},
- {"kern[maxproc]", 0, 0, 0, 0},
-*/
- {"memory", CF_USEUPARAM, OLD_MEMORY, 0, "buffers"},
-/*
- {"memory[buffers]", 0, 0, 0, 0},
- {"memory[cached]", 0, 0, 0, 0},
- {"memory[free]", 0, 0, 0, 0},
- {"memory[shared]", 0, 0, 0, 0},
- {"memory[total]", 0, 0, 0, 0},
-*/
- {"system", CF_USEUPARAM, OLD_SYSTEM, 0, "uname"},
-/*
- {"system[proccount]", 0, 0, 0, 0},
-
- {"system[procload]", 0, 0, 0, 0},
- {"system[procload5]", 0, 0, 0, 0},
- {"system[procload15]", 0, 0, 0, 0},
- {"system[hostname]", 0, 0, 0, 0},
- {"system[uname]", 0, 0, 0, 0},
- {"system[uptime]", 0, 0, 0, 0},
- {"system[users]", 0, 0, 0, 0},
-
- {"system[procrunning]", 0, 0, 0, 0},
-*/
- {"sensor", CF_USEUPARAM, OLD_SENSOR, 0, "temp1"},
-/*
- {"sensor[temp1]", 0, 0, 0, 0},
- {"sensor[temp2]", 0, 0, 0, 0},
- {"sensor[temp3]", 0, 0, 0, 0},
-*/
- {"swap", CF_USEUPARAM, OLD_SWAP, 0, "total"},
-/*
- {"swap[free]", 0, 0, 0, 0},
- {"swap[total]", 0, 0, 0, 0},
-*/
- {"version", CF_USEUPARAM, OLD_VERSION, 0, "zabbix_agent"},
-/*
- {"version[zabbix_agent]", 0, OLD_VERSION, 0, 0},
-*/
-/* correct OLD naming */
-/*
- {"cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
-*/
-/*
- {"diskfree", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"disktotal", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"diskused", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"diskfree_perc", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"diskused_perc", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"file", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
- {"filesize", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
-*/
-/*
- {"inodefree", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"inodetotal", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"inodefree_perc", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-*/
-/*
- {"netloadin1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"netloadin5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"netloadin15", CF_USEUPARAM, NET_IF_IBYTES15, 0, "lo"},
- {"netloadout1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"netloadout5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"netloadout15", CF_USEUPARAM, NET_IF_OBYTES15, 0, "lo"},
-*/
-/*
- {"ping", 0, AGENT_PING, 0, 0},
-*/
-/* New naming */
-/*
- {"system.cpu.idle1", 0, SYSTEM_CPU_IDLE1, 0, 0},
- {"system.cpu.idle5", 0, SYSTEM_CPU_IDLE5, 0, 0},
- {"system.cpu.idle15", 0, SYSTEM_CPU_IDLE15, 0, 0},
- {"system.cpu.nice1", 0, SYSTEM_CPU_NICE1, 0, 0},
- {"system.cpu.nice5", 0, SYSTEM_CPU_NICE5, 0, 0},
- {"system.cpu.nice15", 0, SYSTEM_CPU_NICE15, 0, 0},
- {"system.cpu.sys1", 0, SYSTEM_CPU_SYS1, 0, 0},
- {"system.cpu.sys5", 0, SYSTEM_CPU_SYS5, 0, 0},
- {"system.cpu.sys15", 0, SYSTEM_CPU_SYS15, 0, 0},
- {"system.cpu.user1", 0, SYSTEM_CPU_USER1, 0, 0},
- {"system.cpu.user5", 0, SYSTEM_CPU_USER5, 0, 0},
- {"system.cpu.user15", 0, SYSTEM_CPU_USER15, 0, 0},
-*/
-/*
- {"vm.memory.total", 0, VM_MEMORY_TOTAL, 0, 0},
- {"vm.memory.shared", 0, VM_MEMORY_SHARED, 0, 0},
- {"vm.memory.buffers", 0, VM_MEMORY_BUFFERS, 0, 0},
- {"vm.memory.cached", 0, VM_MEMORY_CACHED, 0, 0},
- {"vm.memory.free", 0, VM_MEMORY_FREE, 0, 0},
-*/
-/*
- {"vfs.fs.free", CF_USEUPARAM, VFS_FS_FREE, 0, "/"},
- {"vfs.fs.total", CF_USEUPARAM, VFS_FS_TOTAL, 0, "/"},
- {"vfs.fs.used", CF_USEUPARAM, VFS_FS_USED, 0, "/"},
- {"vfs.fs.pfree", CF_USEUPARAM, VFS_FS_PFREE, 0, "/"},
- {"vfs.fs.pused", CF_USEUPARAM, VFS_FS_PUSED, 0, "/"},
-*/
-/*
- {"vfs.fs.inode.free", CF_USEUPARAM, VFS_FS_INODE_FREE, 0, "/"},
- {"vfs.fs.inode.total", CF_USEUPARAM, VFS_FS_INODE_TOTAL, 0, "/"},
- {"vfs.fs.inode.pfree", CF_USEUPARAM, VFS_FS_INODE_PFREE, 0, "/"},
-*/
-/*
- {"net.if.ibytes1", CF_USEUPARAM, NET_IF_IBYTES1, 0, "lo"},
- {"net.if.ibytes5", CF_USEUPARAM, NET_IF_IBYTES5, 0, "lo"},
- {"net.if.ibytes15", CF_USEUPARAM, NET_IF_IBYTES15,0, "lo"},
-
- {"net.if.obytes1", CF_USEUPARAM, NET_IF_OBYTES1, 0, "lo"},
- {"net.if.obytes5", CF_USEUPARAM, NET_IF_OBYTES5, 0, "lo"},
- {"net.if.obytes15", CF_USEUPARAM, NET_IF_OBYTES15,0, "lo"},
-*/
-/*
- {"disk_read_ops1", CF_USEUPARAM, DISKREADOPS1, 0, "hda"},
- {"disk_read_ops5", CF_USEUPARAM, DISKREADOPS5, 0, "hda"},
- {"disk_read_ops15", CF_USEUPARAM, DISKREADOPS15, 0, "hda"},
-
- {"disk_read_blks1", CF_USEUPARAM, DISKREADBLKS1, 0, "hda"},
- {"disk_read_blks5", CF_USEUPARAM, DISKREADBLKS5, 0, "hda"},
- {"disk_read_blks15", CF_USEUPARAM, DISKREADBLKS15, 0, "hda"},
-
- {"disk_write_ops1", CF_USEUPARAM, DISKWRITEOPS1, 0, "hda"},
- {"disk_write_ops5", CF_USEUPARAM, DISKWRITEOPS5, 0, "hda"},
- {"disk_write_ops15", CF_USEUPARAM, DISKWRITEOPS15, 0, "hda"},
-
- {"disk_write_blks1", CF_USEUPARAM, DISKWRITEBLKS1, 0, "hda"},
- {"disk_write_blks5", CF_USEUPARAM, DISKWRITEBLKS5, 0, "hda"},
- {"disk_write_blks15", CF_USEUPARAM, DISKWRITEBLKS15,0, "hda"},
-*/
-/*
- {"system.cpu.load1", 0, SYSTEM_CPU_LOAD1, 0, 0},
- {"system.cpu.load5", 0, SYSTEM_CPU_LOAD5, 0, 0},
- {"system.cpu.load15", 0, SYSTEM_CPU_LOAD15, 0, 0},
-*/
-
-/****************************************
- All these perameters require more than 1 second to retrieve.
-
- {"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
- {"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
- {"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
-***************************************/
-
-/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
-/*
- {"check_port", CF_USEUPARAM, CHECK_PORT, 0, "80"},
- {"check_service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
- {"check_service_perf", CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
-*/
-/*
- {"dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-*/
{"agent.ping", 0, AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0, 0},
{"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "/etc/passwd"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "/etc/passwd,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "/etc/passwd"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"},
{"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "/etc/services"},
{"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "/etc/services"},
-/************************************
- * NEW FUNCTIONS *
- ************************************/
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
- {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
- {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
{"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
-
{"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
-
{"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
{"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
{"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
@@ -240,19 +56,14 @@ ZBX_METRIC parameters_specific[]=
{"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
{"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
- {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "/,free"},
- {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "/,free"},
-
- {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
- {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
-
{"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
{"proc.num", CF_USEUPARAM, PROC_NUM, 0, "inetd,,"},
{"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "inetd,,"},
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
{"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,user,avg1"},
-
{"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
{"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
diff --git a/src/libs/zbxsysinfo/win32/cpu.c b/src/libs/zbxsysinfo/win32/cpu.c
new file mode 100755
index 00000000..6d720071
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/cpu.c
@@ -0,0 +1,209 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+#include "stats.h"
+
+int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ /* SKIP REALIZATION */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+ char cpuname[MAX_STRING_LEN];
+ char type[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int cpu_num = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
+ {
+ cpuname[0] = '\0';
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
+ }
+
+ if(get_param(param, 2, type, sizeof(type)) != 0)
+ {
+ type[0] = '\0';
+ }
+ if(type[0] == '\0')
+ {
+ /* default parameter */
+ zbx_snprintf(type, sizeof(type), "system");
+ }
+ if(strncmp(type, "system", sizeof(type)))
+ { /* only 'system' parameter supported */
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 3, mode, sizeof(mode)) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ zbx_snprintf(mode, sizeof(mode), "avg1");
+ }
+
+ if(NULL == collector)
+ {
+ SET_MSG_RESULT(result, strdup("Collector is not started!"));
+ return SYSINFO_RET_OK;
+ }
+
+ if(strcmp(cpuname,"all") == 0)
+ {
+ cpu_num = 0;
+ }
+ else
+ {
+ cpu_num = atoi(cpuname)+1;
+ if ((cpu_num < 1) || (cpu_num > collector->cpus.count))
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(type,"system"))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(mode,"avg1") == 0)
+ {
+ SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].util1);
+ }
+ else if(strcmp(mode,"avg5") == 0)
+ {
+ SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].util5);
+ }
+ else if(strcmp(mode,"avg15") == 0)
+ {
+ SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].util15);
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+}
+
+
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char cpuname[10],
+ mode[10];
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, sizeof(cpuname)) != 0)
+ {
+ cpuname[0] = '\0';
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ zbx_snprintf(cpuname, sizeof(cpuname), "all");
+ }
+
+
+ if(get_param(param, 2, mode, sizeof(mode)) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ zbx_snprintf(mode, sizeof(mode), "avg1");
+ }
+
+ if(strcmp(cpuname,"all") != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(NULL == collector)
+ {
+ SET_MSG_RESULT(result, strdup("Collector is not started!"));
+ return SYSINFO_RET_OK;
+ }
+
+ if(strcmp(mode,"avg1") == 0)
+ {
+ SET_DBL_RESULT(result, collector->cpus.load1);
+ }
+ else if(strcmp(mode,"avg5") == 0)
+ {
+ SET_DBL_RESULT(result, collector->cpus.load5);
+ }
+ else if(strcmp(mode,"avg15") == 0)
+ {
+ SET_DBL_RESULT(result, collector->cpus.load15);
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+
+}
+
+int SYSTEM_CPU_SWITCHES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+
+}
+
+int SYSTEM_CPU_INTR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+
+}
+
diff --git a/src/libs/zbxsysinfo/win32/diskio.c b/src/libs/zbxsysinfo/win32/diskio.c
new file mode 100755
index 00000000..e15e7028
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/diskio.c
@@ -0,0 +1,94 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ /* SKIP REALIZATION */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/diskspace.c b/src/libs/zbxsysinfo/win32/diskspace.c
new file mode 100755
index 00000000..a9946c18
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/diskspace.c
@@ -0,0 +1,34 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/inodes.c b/src/libs/zbxsysinfo/win32/inodes.c
new file mode 100755
index 00000000..074b28b3
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/inodes.c
@@ -0,0 +1,35 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+int VFS_FS_INODE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/kernel.c b/src/libs/zbxsysinfo/win32/kernel.c
new file mode 100755
index 00000000..f4c1974b
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/kernel.c
@@ -0,0 +1,48 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+int KERNEL_MAXFILES(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int KERNEL_MAXPROC(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_KERNEL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ /* SKIP REALIZATEION */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/memory.c b/src/libs/zbxsysinfo/win32/memory.c
new file mode 100755
index 00000000..4a778c65
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/memory.c
@@ -0,0 +1,34 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/net.c b/src/libs/zbxsysinfo/win32/net.c
new file mode 100755
index 00000000..f2c44b77
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/net.c
@@ -0,0 +1,70 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int NET_IF_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int NET_IF_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int NET_TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/proc.c b/src/libs/zbxsysinfo/win32/proc.c
new file mode 100755
index 00000000..db66a889
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/proc.c
@@ -0,0 +1,163 @@
+/*
+ * ** ZABBIX
+ * ** Copyright (C) 2000-2005 SIA Zabbix
+ * **
+ * ** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * **/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+
+static int GetProcessUsername(HANDLE hProcess, char *userName, int userNameLen) {
+ HANDLE tok = 0;
+ TOKEN_USER *ptu;
+
+ DWORD
+ nlen,
+ dlen;
+
+ char
+ name[300],
+ dom[300],
+ tubuf[300];
+
+ int iUse;
+
+ assert(userName);
+
+ //clean result;
+ *userName = '\0';
+
+ //open the processes token
+ if (!OpenProcessToken(hProcess,TOKEN_QUERY,&tok)) goto lbl_err;;
+
+ //get the SID of the token
+ ptu = (TOKEN_USER*)tubuf;
+ if (!GetTokenInformation(tok,(TOKEN_INFORMATION_CLASS)1,ptu,300,&nlen)) goto lbl_err;
+
+ //get the account/domain name of the SID
+ dlen = 300; nlen = 300;
+ if (!LookupAccountSid(0, ptu->User.Sid, name, &nlen, dom, &dlen, (PSID_NAME_USE)&iUse)) goto lbl_err;
+
+ nlen = min(userNameLen-1,(int)nlen);
+
+ strncpy(userName, name, nlen);
+ userName[nlen] = 0;
+
+ return 1;
+
+lbl_err:
+ if (tok) CloseHandle(tok);
+ return 0;
+}
+
+
+int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{ /* usage: <function name>[ <process name>, <user name>, <mode>, <command> ] */
+ #ifdef TODO
+ # error Realize function!!!
+ #endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+#define MAX_PROCESSES 4096
+
+int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{ /* usage: <function name>[ <process name>, <user name>] */
+ HANDLE hProcess;
+ HMODULE hMod;
+ DWORD procList[MAX_PROCESSES];
+
+ DWORD dwSize=0;
+
+ int
+ i = 0,
+ proccount = 0,
+ max_proc_cnt = 0,
+ proc_ok = 0,
+ user_ok = 0;
+
+ char
+ procName[MAX_PATH],
+ userName[MAX_PATH],
+ baseName[MAX_PATH],
+ uname[300];
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procName, MAX_PATH) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, userName, MAX_PATH) != 0)
+ {
+ userName[0] = '\0';
+ }
+
+
+ EnumProcesses(procList,sizeof(DWORD)*MAX_PROCESSES,&dwSize);
+
+ for(i=0,proccount=0,max_proc_cnt=dwSize/sizeof(DWORD); i < max_proc_cnt; i++)
+ {
+ proc_ok = 0;
+ user_ok = 0;
+
+ hProcess=OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,procList[i]);
+ if (hProcess!=NULL)
+ {
+ if (procName[0] != 0)
+ {
+ if (EnumProcessModules(hProcess,&hMod,sizeof(hMod),&dwSize))
+ {
+ GetModuleBaseName(hProcess,hMod,baseName,sizeof(baseName));
+ if (stricmp(baseName,procName) == 0)
+ {
+ proc_ok = 1;
+ }
+ }
+ } else {
+ proc_ok = 1;
+ }
+
+ if(userName[0] != '\0')
+ {
+ if(GetProcessUsername(hProcess, uname, 300))
+ {
+ if (stricmp(uname,userName) == 0)
+ user_ok = 1;
+ }
+ } else {
+ user_ok = 1;
+ }
+
+ if(user_ok && proc_ok) proccount++;
+
+ CloseHandle(hProcess);
+ }
+ }
+
+ SET_UI64_RESULT(result, proccount);
+
+ return SYSINFO_RET_OK;
+}
diff --git a/src/libs/zbxsysinfo/win32/sensors.c b/src/libs/zbxsysinfo/win32/sensors.c
new file mode 100755
index 00000000..8c724913
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/sensors.c
@@ -0,0 +1,36 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+#include "md5.h"
+
+
+int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/swap.c b/src/libs/zbxsysinfo/win32/swap.c
new file mode 100755
index 00000000..b78fe622
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/swap.c
@@ -0,0 +1,64 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+#include "md5.h"
+
+
+int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int SYSTEM_SWAP_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
+int SYSTEM_SWAP_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/win32/system_w32.c b/src/libs/zbxsysinfo/win32/system_w32.c
new file mode 100755
index 00000000..8d5fdb02
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/system_w32.c
@@ -0,0 +1,141 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+int SYSTEM_HOSTNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ DWORD dwSize;
+ char buffer[MAX_COMPUTERNAME_LENGTH];
+
+
+ dwSize = MAX_COMPUTERNAME_LENGTH;
+ GetComputerName(buffer, &dwSize);
+
+ SET_TEXT_RESULT(result, strdup(buffer));
+
+ return SYSINFO_RET_OK;
+}
+
+int SYSTEM_UNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ DWORD dwSize;
+ char *cpuType,
+ computerName[MAX_COMPUTERNAME_LENGTH],
+ osVersion[256],
+ buffer[MAX_STRING_LEN];
+ SYSTEM_INFO
+ sysInfo;
+ OSVERSIONINFO
+ versionInfo;
+
+ dwSize = MAX_COMPUTERNAME_LENGTH;
+ GetComputerName(computerName,&dwSize);
+
+ versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&versionInfo);
+ switch(versionInfo.dwPlatformId)
+ {
+ case VER_PLATFORM_WIN32_WINDOWS:
+ zbx_snprintf(
+ osVersion,
+ sizeof(osVersion),
+ "Windows %s-%s",
+ versionInfo.dwMinorVersion==0 ? "95" :
+ (versionInfo.dwMinorVersion==10 ? "98" :
+ (versionInfo.dwMinorVersion==90 ? "Me" : "Unknown")),
+ versionInfo.szCSDVersion);
+ break;
+ case VER_PLATFORM_WIN32_NT:
+ if (versionInfo.dwMajorVersion!=5)
+ {
+ zbx_snprintf(
+ osVersion,
+ sizeof(osVersion),
+ "Windows NT %d.%d %s",
+ versionInfo.dwMajorVersion,
+ versionInfo.dwMinorVersion,
+ versionInfo.szCSDVersion
+ );
+ }
+ else // Windows 2000, Windows XP or Windows Server 2003
+ {
+ zbx_snprintf(
+ osVersion,
+ sizeof(osVersion),
+ "Windows %s%s%s",
+ (versionInfo.dwMinorVersion == 0) ? "2000" :
+ ((versionInfo.dwMinorVersion == 1) ? "XP" : "Server 2003"),
+ versionInfo.szCSDVersion[0]==0 ? "" : " ",
+ versionInfo.szCSDVersion);
+ }
+ break;
+ default:
+ zbx_snprintf(osVersion, sizeof(osVersion), "Windows [Unknown Version]");
+ break;
+ }
+
+ GetSystemInfo(&sysInfo);
+ switch(sysInfo.wProcessorArchitecture)
+ {
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ cpuType="Intel IA-32";
+ break;
+ case PROCESSOR_ARCHITECTURE_MIPS:
+ cpuType="MIPS";
+ break;
+ case PROCESSOR_ARCHITECTURE_ALPHA:
+ cpuType="Alpha";
+ break;
+ case PROCESSOR_ARCHITECTURE_PPC:
+ cpuType="PowerPC";
+ break;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ cpuType="Intel IA-64";
+ break;
+ case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
+ cpuType="IA-32 on IA-64";
+ break;
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ cpuType="AMD-64";
+ break;
+ default:
+ cpuType="unknown";
+ break;
+ }
+
+ zbx_snprintf(
+ buffer,
+ sizeof(buffer),
+ "Windows %s %d.%d.%d %s %s",
+ computerName,
+ versionInfo.dwMajorVersion,
+ versionInfo.dwMinorVersion,
+ versionInfo.dwBuildNumber,
+ osVersion,
+ cpuType
+ );
+
+ SET_TEXT_RESULT(result, strdup(buffer));
+
+ return SYSINFO_RET_OK;
+}
diff --git a/src/libs/zbxsysinfo/win32/uptime.c b/src/libs/zbxsysinfo/win32/uptime.c
new file mode 100755
index 00000000..d93182a2
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/uptime.c
@@ -0,0 +1,32 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+#ifdef TODO
+#error Realize function!!!
+#endif /* todo */
+
+ return SYSINFO_RET_FAIL;
+}
diff --git a/src/libs/zbxsysinfo/win32/win32.c b/src/libs/zbxsysinfo/win32/win32.c
new file mode 100755
index 00000000..8d9e2d16
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/win32.c
@@ -0,0 +1,79 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "sysinfo.h"
+
+ZBX_METRIC parameters_specific[]=
+/* KEY FLAG FUNCTION ADD_PARAM TEST_PARAM */
+ {
+
+ {"agent.ping", 0, AGENT_PING, 0, 0},
+ {"agent.version", 0, AGENT_VERSION, 0, 0},
+
+ {"kernel.maxfiles", 0, KERNEL_MAXFILES, 0, 0},
+ {"kernel.maxproc", 0, KERNEL_MAXPROC, 0, 0},
+
+ {"vfs.file.exists", CF_USEUPARAM, VFS_FILE_EXISTS, 0, "c:\\windows\\win.ini"},
+ {"vfs.file.time", CF_USEUPARAM, VFS_FILE_TIME, 0, "c:\\windows\\win.ini,modify"},
+ {"vfs.file.size", CF_USEUPARAM, VFS_FILE_SIZE, 0, "c:\\windows\\win.ini"},
+ {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "c:\\windows\\win.ini,fonts"},
+ {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "c:\\windows\\win.ini,fonts"},
+ {"vfs.file.cksum", CF_USEUPARAM, VFS_FILE_CKSUM, 0, "c:\\windows\\win.ini"},
+ {"vfs.file.md5sum", CF_USEUPARAM, VFS_FILE_MD5SUM, 0, "c:\\windows\\win.ini"},
+
+ {"vfs.fs.size", CF_USEUPARAM, VFS_FS_SIZE, 0, "c:,free"},
+ {"vfs.fs.inode", CF_USEUPARAM, VFS_FS_INODE, 0, "c:,free"},
+
+ {"vfs.dev.read", CF_USEUPARAM, VFS_DEV_READ, 0, "hda,ops,avg1"},
+ {"vfs.dev.write", CF_USEUPARAM, VFS_DEV_WRITE, 0, "hda,ops,avg1"},
+
+ {"net.tcp.dns", CF_USEUPARAM, CHECK_DNS, 0, "127.0.0.1,localhost"},
+ {"net.tcp.listen", CF_USEUPARAM, NET_TCP_LISTEN, 0, "80"},
+ {"net.tcp.port", CF_USEUPARAM, CHECK_PORT, 0, ",80"},
+ {"net.tcp.service", CF_USEUPARAM, CHECK_SERVICE, 0, "ssh,127.0.0.1,22"},
+ {"net.tcp.service.perf",CF_USEUPARAM, CHECK_SERVICE_PERF, 0, "ssh,127.0.0.1,22"},
+
+ {"net.if.in", CF_USEUPARAM, NET_IF_IN, 0, "lo,bytes"},
+ {"net.if.out", CF_USEUPARAM, NET_IF_OUT, 0, "lo,bytes"},
+ {"net.if.total", CF_USEUPARAM, NET_IF_TOTAL, 0, "lo,bytes"},
+ {"net.if.collisions", CF_USEUPARAM, NET_IF_COLLISIONS, 0, "lo"},
+
+ {"vm.memory.size", CF_USEUPARAM, VM_MEMORY_SIZE, 0, "free"},
+
+ {"proc.num", CF_USEUPARAM, PROC_NUM, 0, "svchost.exe,"},
+ {"proc.mem", CF_USEUPARAM, PROC_MEMORY, 0, "svchost.exe,,"},
+
+ {"system.cpu.switches", 0, SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr", 0, SYSTEM_CPU_INTR, 0, 0},
+ {"system.cpu.util", CF_USEUPARAM, SYSTEM_CPU_UTIL, 0, "all,system,avg1"},
+ {"system.cpu.load", CF_USEUPARAM, SYSTEM_CPU_LOAD, 0, "all,avg1"},
+
+ {"system.swap.size", CF_USEUPARAM, SYSTEM_SWAP_SIZE, 0, "all,free"},
+ {"system.swap.in", CF_USEUPARAM, SYSTEM_SWAP_IN, 0, "all"},
+ {"system.swap.out", CF_USEUPARAM, SYSTEM_SWAP_OUT, 0, "all,count"},
+
+ {"system.hostname", 0, SYSTEM_HOSTNAME, 0, 0},
+
+ {"system.uname", 0, SYSTEM_UNAME, 0, 0},
+ {"system.uptime", 0, SYSTEM_UPTIME, 0, 0},
+ {"system.users.num", 0, SYSTEM_UNUM, 0, 0},
+
+ {0}
+ };
diff --git a/src/libs/zbxwin32/perfmon.c b/src/libs/zbxwin32/perfmon.c
new file mode 100755
index 00000000..0a4e4636
--- /dev/null
+++ b/src/libs/zbxwin32/perfmon.c
@@ -0,0 +1,75 @@
+/*
+** ZabbixW32 - Win32 agent for Zabbix
+** Copyright (C) 2002 Victor Kirhenshtein
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** $module: service.cpp
+**
+**/
+
+#include "common.h"
+#include "perfmon.h"
+
+#include "log.h"
+
+PERFCOUNTER *PerfCounterList = NULL;
+
+//
+// Get performance counter name by index
+//
+
+char *GetCounterName(DWORD index)
+{
+ PERFCOUNTER *counterName;
+ DWORD dwSize;
+ char hostname[MAX_COMPUTERNAME_LENGTH];
+
+ counterName = PerfCounterList;
+ while(counterName!=NULL)
+ {
+ if (counterName->pdhIndex == index)
+ break;
+ counterName = counterName->next;
+ }
+ if (counterName == NULL)
+ {
+ counterName = (PERFCOUNTER *)malloc(sizeof(PERFCOUNTER));
+ memset(counterName, 0, sizeof(PERFCOUNTER));
+ counterName->pdhIndex = index;
+ counterName->next = PerfCounterList;
+
+ hostname[0] = hostname[1] = '\\';
+ dwSize = sizeof(hostname) - 2;
+ if(GetComputerName(hostname + 2, &dwSize)==0)
+ {
+ zabbix_log(LOG_LEVEL_ERR, "GetComputerName failed: %s", strerror_from_system(GetLastError()));
+ }
+
+ dwSize = sizeof(counterName->name);
+ if(PdhLookupPerfNameByIndex(hostname, index, counterName->name, &dwSize) == ERROR_SUCCESS)
+ {
+ PerfCounterList = counterName;
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_ERR, "PdhLookupPerfNameByIndex failed: %s", strerror_from_system(GetLastError()));
+ free(counterName);
+ return "UnknownPerformanceCounter";
+ }
+ }
+
+ return (char *)&counterName->name;
+}
diff --git a/src/libs/zbxwin32/service.c b/src/libs/zbxwin32/service.c
new file mode 100755
index 00000000..6097c4b7
--- /dev/null
+++ b/src/libs/zbxwin32/service.c
@@ -0,0 +1,441 @@
+/*
+** ZabbixW32 - Win32 agent for Zabbix
+** Copyright (C) 2002 Victor Kirhenshtein
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** $module: service.cpp
+**
+**/
+
+#include "common.h"
+#include "service.h"
+
+#include "cfg.h"
+#include "log.h"
+#include "alias.h"
+#include "zbxconf.h"
+#include "perfmon.h"
+
+static int ZabbixRemoveEventSource(void);
+static int ZabbixInstallEventSource(char *path);
+
+//
+// Static data
+//
+
+static SERVICE_STATUS serviceStatus;
+static SERVICE_STATUS_HANDLE serviceHandle;
+
+int application_is_runned = ZBX_APP_RUNNED;
+
+//
+// ZABBIX service control handler
+//
+
+static VOID WINAPI ServiceCtrlHandler(DWORD ctrlCode)
+{
+ int do_exit = 0;
+
+ serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ serviceStatus.dwCurrentState = SERVICE_RUNNING;
+ serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+ serviceStatus.dwWin32ExitCode = 0;
+ serviceStatus.dwServiceSpecificExitCode = 0;
+ serviceStatus.dwCheckPoint = 0;
+ serviceStatus.dwWaitHint = 0;
+
+ switch(ctrlCode)
+ {
+ case SERVICE_CONTROL_STOP:
+ case SERVICE_CONTROL_SHUTDOWN:
+ serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
+ serviceStatus.dwWaitHint = 4000;
+ SetServiceStatus(serviceHandle,&serviceStatus);
+
+ ZBX_DO_EXIT();
+
+ /* Allow other threads to terminate */
+ zbx_sleep(1);
+
+ serviceStatus.dwCurrentState = SERVICE_STOPPED;
+ serviceStatus.dwWaitHint = 0;
+ serviceStatus.dwCheckPoint = 0;
+ serviceStatus.dwWin32ExitCode = 0;
+ break;
+ default:
+ break;
+ }
+
+ SetServiceStatus(serviceHandle, &serviceStatus);
+}
+
+//
+// The entry point for a ZABBIX service.
+//
+
+static VOID WINAPI ServiceEntry(DWORD argc,LPTSTR *argv)
+{
+ WSADATA sockInfo;
+ char counterPath[MAX_COUNTER_PATH * 2 + 50];
+
+ serviceHandle = RegisterServiceCtrlHandler(ZABBIX_SERVICE_NAME, ServiceCtrlHandler);
+
+ // Now we start service initialization
+ serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ serviceStatus.dwCurrentState = SERVICE_START_PENDING;
+ serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+ serviceStatus.dwWin32ExitCode = 0;
+ serviceStatus.dwServiceSpecificExitCode = 0;
+ serviceStatus.dwCheckPoint = 0;
+ serviceStatus.dwWaitHint = 2000;
+
+ SetServiceStatus(serviceHandle, &serviceStatus);
+
+ // Initialize Windows Sockets API
+ WSAStartup(0x0002,&sockInfo);
+
+ // Internal command aliases
+ zbx_snprintf(counterPath, sizeof(counterPath), "perf_counter[\\%s\\%s]",GetCounterName(PCI_SYSTEM),GetCounterName(PCI_SYSTEM_UP_TIME));
+ add_alias("system.uptime",counterPath);
+
+ // Now service is running
+ serviceStatus.dwCurrentState = SERVICE_RUNNING;
+ serviceStatus.dwWaitHint = 0;
+ SetServiceStatus(serviceHandle, &serviceStatus);
+
+ MAIN_ZABBIX_ENTRY();
+}
+
+
+//
+// Initialize service
+//
+
+void service_start(void)
+{
+ int c = 0;
+ static SERVICE_TABLE_ENTRY serviceTable[] = {
+ { ZABBIX_SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)ServiceEntry },
+ { NULL,NULL }
+ };
+
+ WSADATA sockInfo;
+
+ // Initialize Windows Sockets API
+ switch(WSAStartup(0x0002,&sockInfo))
+ {
+ case WSASYSNOTREADY:
+ zbx_error("Underlying network subsystem is not ready for network communication.");
+ return;
+ case WSAVERNOTSUPPORTED:
+ zbx_error("The version of Windows Sockets support requested is not provided.");
+ return;
+ case WSAEINPROGRESS:
+ zbx_error("A blocking Windows Sockets 1.1 operation is in progress.");
+ return;
+ case WSAEPROCLIM:
+ zbx_error("Limit on the number of tasks supported by the Windows Sockets implementation has been reached.");
+ return;
+ case WSAEFAULT:
+ zbx_error("The lpWSAData is not a valid pointer.");
+ return;
+ }
+
+ // Create synchronization stuff
+// eventShutdown = CreateEvent(NULL,TRUE,FALSE,NULL);
+
+ if (!StartServiceCtrlDispatcher(serviceTable))
+ {
+ if(ERROR_FAILED_SERVICE_CONTROLLER_CONNECT == GetLastError())
+ {
+ zbx_error("\n\n\t!!!ATTENTION!!! ZABBIX Agent runned as a console application. !!!ATTENTION!!!\n");
+ MAIN_ZABBIX_ENTRY();
+ }
+ else
+ {
+ zbx_error("StartServiceCtrlDispatcher() failed: %s", strerror_from_system(GetLastError()));
+ }
+
+ }
+
+// CloseHandle(eventShutdown);
+}
+
+
+//
+// Create service
+//
+
+int ZabbixCreateService(char *path)
+{
+#define MAX_CMD_LEN MAX_PATH*2
+
+ SC_HANDLE mgr,service;
+ char execName[MAX_PATH];
+ char configFile[MAX_PATH];
+ char cmdLine[MAX_CMD_LEN];
+ int ret = SUCCEED;
+
+ _fullpath(execName, path, MAX_PATH);
+
+ mgr = OpenSCManager(NULL,NULL,GENERIC_WRITE);
+ if ( NULL == mgr )
+ {
+ zbx_error("ERROR: Cannot connect to Service Manager [%s]",strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ if(NULL == CONFIG_FILE)
+ {
+ zbx_snprintf(cmdLine, sizeof(cmdLine), "\"%s\"", execName);
+ }
+ else
+ {
+ _fullpath(configFile, CONFIG_FILE, MAX_PATH);
+ zbx_snprintf(cmdLine, sizeof(cmdLine), "\"%s\" --config \"%s\"", execName, configFile);
+ }
+
+ service = CreateService(mgr,
+ ZABBIX_SERVICE_NAME,
+ ZABBIX_EVENT_SOURCE,
+ GENERIC_READ,
+ SERVICE_WIN32_OWN_PROCESS,
+ SERVICE_AUTO_START,
+ SERVICE_ERROR_NORMAL,
+ cmdLine,NULL,NULL,NULL,NULL,NULL);
+
+ if (service == NULL)
+ {
+ DWORD code = GetLastError();
+
+ if (ERROR_SERVICE_EXISTS == code)
+ {
+ zbx_error("ERROR: Service named '" ZABBIX_SERVICE_NAME "' already exist");
+ }
+ else
+ {
+ zbx_error("ERROR: Cannot create service [%s]",strerror_from_system(code));
+ }
+ ret = FAIL;
+ }
+ else
+ {
+ zbx_error("Zabbix Win32 Agent service created successfully.");
+ CloseServiceHandle(service);
+ }
+
+ CloseServiceHandle(mgr);
+
+ if(ret != SUCCEED)
+ {
+ return FAIL;
+ }
+
+ return ZabbixInstallEventSource(execName);
+}
+
+
+//
+// Remove service
+//
+
+int ZabbixRemoveService(void)
+{
+ SC_HANDLE mgr,service;
+ int ret = SUCCEED;
+
+ mgr=OpenSCManager(NULL,NULL,GENERIC_WRITE);
+ if (mgr==NULL)
+ {
+ zbx_error("ERROR: Cannot connect to Service Manager [%s]",strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ service=OpenService(mgr,ZABBIX_SERVICE_NAME,DELETE);
+ if (service==NULL)
+ {
+ zbx_error("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ ret = FAIL;
+ }
+ else
+ {
+ if (DeleteService(service))
+ {
+ zbx_error(ZABBIX_EVENT_SOURCE "service deleted successfully");
+ }
+ else
+ {
+ zbx_error("ERROR: Cannot remove service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ ret = FAIL;
+ }
+
+ CloseServiceHandle(service);
+ }
+
+ CloseServiceHandle(mgr);
+
+ if(ret == SUCCEED)
+ {
+ ret = ZabbixRemoveEventSource();
+ }
+
+ return ret;
+}
+
+
+//
+// Start service
+//
+
+int ZabbixStartService(void)
+{
+ SC_HANDLE mgr,service;
+ int ret = SUCCEED;
+
+ mgr=OpenSCManager(NULL,NULL,GENERIC_WRITE);
+
+ if (mgr==NULL)
+ {
+ zbx_error("ERROR: Cannot connect to Service Manager [%s]",strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ service=OpenService(mgr,ZABBIX_SERVICE_NAME,SERVICE_START);
+
+ if (service==NULL)
+ {
+ zbx_error("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ ret = FAIL;
+ }
+ else
+ {
+ if (StartService(service,0,NULL))
+ {
+ zbx_error("Zabbix Win32 Agent service started successfully.");
+ }
+ else
+ {
+ zbx_error("ERROR: Cannot start service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ ret = FAIL;
+ }
+
+ CloseServiceHandle(service);
+ }
+
+ CloseServiceHandle(mgr);
+ return ret;
+}
+
+
+//
+// Stop service
+//
+
+int ZabbixStopService(void)
+{
+ SC_HANDLE mgr,service;
+ int ret = SUCCEED;
+
+ mgr=OpenSCManager(NULL,NULL,GENERIC_WRITE);
+ if (mgr==NULL)
+ {
+ zbx_error("ERROR: Cannot connect to Service Manager [%s]",strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ service=OpenService(mgr,ZABBIX_SERVICE_NAME,SERVICE_STOP);
+ if (service==NULL)
+ {
+ zbx_error("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ ret = FAIL;
+ }
+ else
+ {
+ SERVICE_STATUS status;
+
+ if (ControlService(service,SERVICE_CONTROL_STOP,&status))
+ {
+ zbx_error("Zabbix Win32 Agent service stopped successfully.");
+ }
+ else
+ {
+ zbx_error("ERROR: Cannot stop service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ ret = FAIL;
+ }
+
+ CloseServiceHandle(service);
+ }
+
+ CloseServiceHandle(mgr);
+ return ret;
+}
+
+
+//
+// Install event source
+//
+static int ZabbixInstallEventSource(char *path)
+{
+ HKEY hKey;
+ DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+ char execName[MAX_PATH];
+
+ _fullpath(execName, path, MAX_PATH);
+
+ if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_LOCAL_MACHINE,
+ "System\\CurrentControlSet\\Services\\EventLog\\System\\" ZABBIX_EVENT_SOURCE,
+ 0,
+ NULL,
+ REG_OPTION_NON_VOLATILE,
+ KEY_SET_VALUE,
+ NULL,
+ &hKey,
+ NULL))
+ {
+ zbx_error("Unable to create registry key: %s",strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ RegSetValueEx(hKey,"TypesSupported",0,REG_DWORD,(BYTE *)&dwTypes,sizeof(DWORD));
+ RegSetValueEx(hKey,"EventMessageFile",0,REG_EXPAND_SZ,(BYTE *)execName,strlen(execName)+1);
+
+ RegCloseKey(hKey);
+ zbx_error("Event source \"" ZABBIX_EVENT_SOURCE "\" installed successfully.");
+
+ return SUCCEED;
+}
+
+
+//
+// Remove event source
+//
+
+static int ZabbixRemoveEventSource(void)
+{
+
+ if (ERROR_SUCCESS == RegDeleteKey(HKEY_LOCAL_MACHINE,
+ "System\\CurrentControlSet\\Services\\EventLog\\System\\" ZABBIX_EVENT_SOURCE))
+ {
+ zbx_error("Event source \"" ZABBIX_EVENT_SOURCE "\" uninstalled successfully.");
+ }
+ else
+ {
+ zbx_error("Unable to uninstall event source \"" ZABBIX_EVENT_SOURCE "\": [%s]", strerror_from_system(GetLastError()));
+ return FAIL;
+ }
+
+ return SUCCEED;
+}
diff --git a/src/zabbix_agent/Makefile.am b/src/zabbix_agent/Makefile.am
index 631f0910..8e103b3c 100644
--- a/src/zabbix_agent/Makefile.am
+++ b/src/zabbix_agent/Makefile.am
@@ -1,13 +1,13 @@
SUBDIRS =
bin_PROGRAMS = zabbix_agent zabbix_agentd
-zabbix_agent_SOURCES = zabbix_agent.c
+zabbix_agent_SOURCES = zabbix_agent.c zbxconf.c
zabbix_agent_LDFLAGS = @LDAP_LFLAGS@
zabbix_agent_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxsysinfo/@ARCH@/libzbxsysinfo2.a \
-../libs/zbxlog/libzbxlog.a \
-../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxnet/libzbxnet.a ../libs/zbxconf/libzbxconf.a \
-../libs/zbxcommon/libzbxcommon.a @LDAP_LIBS@
-zabbix_agentd_SOURCES = active.c cpustat.c diskdevices.c interfaces.c logfiles.c stats.c zabbix_agentd.c
+../libs/zbxlog/libzbxlog.a ../libs/zbxsys/libzbxsys.a ../libs/zbxnix/libzbxnix.a ../libs/zbxnet/libzbxnet.a \
+../libs/zbxconf/libzbxconf.a ../libs/zbxcommon/libzbxcommon.a ../libs/zbxcrypto/libzbxcrypto.a @LDAP_LIBS@
+zabbix_agentd_SOURCES = active.c stats.c cpustat.c diskdevices.c interfaces.c logfiles.c zabbix_agentd.c zbxconf.c listener.c
+zabbix_agentd_CPPFLAGS = -DZABBIX_DAEMON
zabbix_agentd_LDFLAGS = @LDAP_LFLAGS@
-zabbix_agentd_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxsysinfo/@ARCH@/libzbxsysinfo2.a ../libs/zbxlog/libzbxlog.a ../libs/zbxcrypto/libzbxcrypto.a \
-../libs/zbxpid/libzbxpid.a ../libs/zbxnet/libzbxnet.a ../libs/zbxconf/libzbxconf.a \
-../libs/zbxcommon/libzbxcommon.a @LDAP_LIBS@
+zabbix_agentd_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxsysinfo/@ARCH@/libzbxsysinfo2.a ../libs/zbxlog/libzbxlog.a \
+../libs/zbxnix/libzbxnix.a ../libs/zbxsys/libzbxsys.a ../libs/zbxnet/libzbxnet.a ../libs/zbxconf/libzbxconf.a \
+../libs/zbxcommon/libzbxcommon.a ../libs/zbxcrypto/libzbxcrypto.a @LDAP_LIBS@
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c
index 4dce3710..02b0334c 100644
--- a/src/zabbix_agent/active.c
+++ b/src/zabbix_agent/active.c
@@ -17,406 +17,425 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
-
-#include <netdb.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <unistd.h>
-#include <signal.h>
-
-#include <time.h>
-
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-/* No warning for bzero */
-#include <string.h>
-#include <strings.h>
-
-/* For config file operations */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-/* For setpriority */
-#include <sys/time.h>
-#include <sys/resource.h>
-
-/* Required for getpwuid */
-#include <pwd.h>
-
#include "common.h"
-#include "sysinfo.h"
+#include "active.h"
-#include "pid.h"
-#include "log.h"
#include "cfg.h"
-#include "stats.h"
-#include "active.h"
+#include "log.h"
+#include "sysinfo.h"
#include "logfiles.h"
+#include "zbxsock.h"
+#include "threads.h"
-METRIC *metrics=NULL;
+#if defined(ZABBIX_SERVICE)
+# include "service.h"
+#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */
+# include "daemon.h"
+#endif /* ZABBIX_DAEMON */
-void init_list()
+static ZBX_ACTIVE_METRIC *active_metrics = NULL;
+
+static void init_active_metrics()
{
- zabbix_log( LOG_LEVEL_DEBUG, "In init_list()");
+ zabbix_log( LOG_LEVEL_DEBUG, "In init_active_metrics()");
- if(metrics==NULL)
+ if(NULL == active_metrics)
{
- metrics=malloc(sizeof(METRIC));
- metrics[0].key=NULL;
+ active_metrics = calloc(sizeof(ZBX_ACTIVE_METRIC), 1);
}
else
{
- zabbix_log( LOG_LEVEL_WARNING, "Metrics are already initialised");
+ zabbix_log(LOG_LEVEL_WARNING, "Metrics are already initialised.");
}
}
-void disable_all_metrics()
+
+static void disable_all_metrics()
{
int i;
- zabbix_log( LOG_LEVEL_DEBUG, "In delete_all_metrics()");
- for(i=0;;i++)
+ zabbix_log( LOG_LEVEL_DEBUG, "In disable_all_metrics()");
+
+ if(NULL == active_metrics)
{
- if(metrics[i].key == NULL) break;
+ zabbix_log(LOG_LEVEL_DEBUG, "No meters to desabling.");
+ return;
+ }
- metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
+ for(i=0; NULL != active_metrics[i].key; i++)
+ {
+ active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
}
}
-int get_min_nextcheck()
+
+static void free_metrics(void)
{
int i;
- int min=-1;
- int nodata=0;
- for(i=0;;i++)
+ zabbix_log( LOG_LEVEL_DEBUG, "In free_metrics()");
+
+ if(NULL == active_metrics)
{
- if(metrics[i].key == NULL) break;
+ zabbix_log(LOG_LEVEL_WARNING, "Metrics are already freed.");
+ return;
+ }
- nodata=1;
- if( (metrics[i].status == ITEM_STATUS_ACTIVE) &&
- ((metrics[i].nextcheck < min) || (min == -1)))
- {
- min=metrics[i].nextcheck;
- }
+ for(i = 0; NULL != active_metrics[i].key;i++)
+ {
+ free(active_metrics[i].key);
+ active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
}
- if(nodata==0)
+ free(active_metrics);
+ active_metrics = NULL;
+}
+
+static int get_min_nextcheck()
+{
+ int i;
+ int min = -1;
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In get_min_nextcheck()");
+
+ for(i = 0; NULL != active_metrics[i].key; i++)
{
- return FAIL;
+ if(ITEM_STATUS_ACTIVE == active_metrics[i].status)
+ continue;
+
+ if(active_metrics[i].nextcheck < min || ((-1) == min))
+ min = active_metrics[i].nextcheck;
}
+
+ if((-1) == min)
+ return FAIL;
+
return min;
}
-void add_check(char *key, int refresh, int lastlogsize)
+static void add_check(char *key, int refresh, int lastlogsize)
{
int i;
- zabbix_log( LOG_LEVEL_DEBUG, "In add check [%s]", key);
+ zabbix_log( LOG_LEVEL_DEBUG, "In add_check('%s', %i, %i)", key, refresh, lastlogsize);
- for(i=0;;i++)
+ for(i=0; NULL != active_metrics[i].key; i++)
{
- if(metrics[i].key == NULL)
- {
- metrics[i].key=strdup(key);
- metrics[i].refresh=refresh;
- metrics[i].nextcheck=0;
- metrics[i].status=ITEM_STATUS_ACTIVE;
- metrics[i].lastlogsize=lastlogsize;
-
- metrics=realloc(metrics,(i+2)*sizeof(METRIC));
- metrics[i+1].key=NULL;
- break;
- }
- else if(strcmp(metrics[i].key,key)==0)
+ if(strcmp(active_metrics[i].key,key) != 0)
+ continue;
+
+ /* replace metric */
+ if(active_metrics[i].refresh != refresh)
{
- if(metrics[i].refresh!=refresh)
- {
- metrics[i].nextcheck=0;
- }
- metrics[i].refresh=refresh;
- metrics[i].lastlogsize=lastlogsize;
- metrics[i].status=ITEM_STATUS_ACTIVE;
- break;
+ active_metrics[i].nextcheck = 0;
}
+ active_metrics[i].refresh = refresh;
+ active_metrics[i].lastlogsize = lastlogsize;
+ active_metrics[i].status = ITEM_STATUS_ACTIVE;
+
+ return;
}
+
+ /* add new metric */
+ active_metrics[i].key = strdup(key);
+ active_metrics[i].refresh = refresh;
+ active_metrics[i].nextcheck = 0;
+ active_metrics[i].status = ITEM_STATUS_ACTIVE;
+ active_metrics[i].lastlogsize = lastlogsize;
+
+ /* move to the last metric */
+ i++;
+
+ /* allocate memory for last metric */
+ active_metrics = realloc(active_metrics, (i+1) * sizeof(ZBX_ACTIVE_METRIC));
+
+ /* inicialize last metric */
+ memset(&active_metrics[i], 0, sizeof(ZBX_ACTIVE_METRIC));
}
-/* Parse list of active checks received from server */
-int parse_list_of_checks(char *str)
+/******************************************************************************
+ * *
+ * Function: parse_list_of_checks *
+ * *
+ * Purpose: Parse list of active checks received from server *
+ * *
+ * Parameters: str - NULL terminated string received from server *
+ * *
+ * Return value: returns SUCCEED on succesfull parsing, *
+ * FAIL on an incoorrect format of string *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * String reprents as "ZBX_EOF" termination list *
+ * With '\n' delimeter between elements. *
+ * Each element represents as: *
+ * <key>:<refresh time>:<last log size> *
+ * *
+ ******************************************************************************/
+
+static int parse_list_of_checks(char *str)
{
- char *line;
- char *key, *refresh, *lastlogsize;
- char *s1, *s2;
+ char
+ *p = NULL,
+ *pstrend = NULL,
+ *key = NULL,
+ *refresh = NULL,
+ *lastlogsize = NULL;
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In parse_list_of_checks('%s')", str);
disable_all_metrics();
- line=(char *)strtok_r(str,"\n",&s1);
- while(line!=NULL)
+ while(str)
{
- zabbix_log( LOG_LEVEL_DEBUG, "Parsed [%s]", line);
+ pstrend = strchr(str,'\n');
+ if(pstrend) *pstrend = '\0'; /* prepare line */
- if(strcmp(line,"ZBX_EOF")==0) break;
+ zabbix_log(LOG_LEVEL_DEBUG, "Parsed [%s]", str);
- key=(char *)strtok_r(line,":",&s2);
- zabbix_log( LOG_LEVEL_DEBUG, "Key [%s]", key);
- refresh=(char *)strtok_r(NULL,":",&s2);
- zabbix_log( LOG_LEVEL_DEBUG, "Refresh [%s]", refresh);
- lastlogsize=(char *)strtok_r(NULL,":",&s2);
- zabbix_log( LOG_LEVEL_DEBUG, "Lastlogsize [%s]", lastlogsize);
+ if(strcmp(str, "ZBX_EOF") == 0) break;
+ if(pstrend == NULL) break;
- add_check(key, atoi(refresh), atoi(lastlogsize));
+ /* parse string from end of line */
- line=(char *)strtok_r(NULL,"\n",&s1);
+ /* Lastlogsize */
+ for(p = str + strlen(str); p != str; p--)
+ {
+ if(*p == ':')
+ {
+ *p = '\0';
+
+ lastlogsize = p+1;
+ break;
+ }
+ }
+
+ /* Refresh */
+ for(; p != str; p--)
+ {
+ if(*p == ':')
+ {
+ *p = '\0';
+
+ refresh = p+1;
+ break;
+ }
+ }
+
+ key = str;
+
+ str = pstrend+1;
+
+ add_check(key, atoi(refresh), atoi(lastlogsize));
}
return SUCCEED;
}
-int get_active_checks(char *server, int port, char *error, int max_error_len)
+static int get_active_checks(char *server, unsigned short port, char *error, int max_error_len)
{
- int s;
- int len,amount_read;
- char c[MAX_BUF_LEN];
+
+ ZBX_SOCKET s;
+ ZBX_SOCKADDR servaddr_in;
struct hostent *hp;
- struct sockaddr_in servaddr_in;
+ char buf[MAX_BUF_LEN];
- zabbix_log( LOG_LEVEL_DEBUG, "get_active_checks: host[%s] port[%d]", server, port);
+ int len;
+ int amount_read;
- servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(server);
+
+ zabbix_log( LOG_LEVEL_DEBUG, "get_active_checks('%s',%u)", server, port);
+
+ servaddr_in.sin_family = AF_INET;
+ hp = gethostbyname(server);
if(hp==NULL)
{
#ifdef HAVE_HSTRERROR
- zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed [%s]", hstrerror(h_errno));
- snprintf(error,max_error_len-1,"gethostbyname() failed [%s]", (char*)hstrerror((int)h_errno));
+ zbx_snprintf(error, max_error_len,"gethostbyname() failed for server '%s' [%s]", server, (char*)hstrerror((int)h_errno));
#else
- zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed [%d]", h_errno);
- snprintf(error,max_error_len-1,"gethostbyname() failed [%d]", h_errno);
+ zbx_snprintf(error, max_error_len,"gethostbyname() failed for server '%s' [%d]", server, h_errno);
#endif
+ zabbix_log( LOG_LEVEL_WARNING, error);
return NETWORK_ERROR;
}
- servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
+ servaddr_in.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
- servaddr_in.sin_port=htons(port);
+ servaddr_in.sin_port = htons(port);
- s=socket(AF_INET,SOCK_STREAM,0);
-
- if(s == -1)
+ if(INVALID_SOCKET == (s = socket(AF_INET,SOCK_STREAM,0)))
{
- zabbix_log(LOG_LEVEL_WARNING, "Cannot create socket [%s]",
- strerror(errno));
- snprintf(error,max_error_len-1,"Cannot create socket [%s]", strerror(errno));
+ zbx_snprintf(error, max_error_len, "Cannot create socket [%s]", strerror_from_system(errno));
+ zabbix_log(LOG_LEVEL_WARNING, error);
return FAIL;
}
- if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
+ if(SOCKET_ERROR == connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)))
{
switch (errno)
{
case EINTR:
- zabbix_log( LOG_LEVEL_WARNING, "Timeout while connecting to [%s:%d]",server,port);
- snprintf(error,max_error_len-1,"Timeout while connecting to [%s:%d]",server,port);
+ zbx_snprintf(error,max_error_len,"Timeout while connecting to [%s:%u]",server,port);
break;
case EHOSTUNREACH:
- zabbix_log( LOG_LEVEL_WARNING, "No route to host [%s:%d]",server,port);
- snprintf(error,max_error_len-1,"No route to host [%s:%d]",server,port);
+ zbx_snprintf(error,max_error_len,"No route to host [%s:%u]",server,port);
break;
default:
- zabbix_log( LOG_LEVEL_WARNING, "Cannot connect to [%s:%d] [%s]",server,port,strerror(errno));
- snprintf(error,max_error_len-1,"Cannot connect to [%s:%d] [%s]",server,port,strerror(errno));
+ zbx_snprintf(error,max_error_len,"Cannot connect to [%s:%u] [%s]",server,port,strerror(errno));
+ break;
}
- close(s);
+ zabbix_log(LOG_LEVEL_WARNING, error);
+ zbx_sock_close(s);
return NETWORK_ERROR;
}
- snprintf(c,sizeof(c)-1,"%s\n%s\n","ZBX_GET_ACTIVE_CHECKS",CONFIG_HOSTNAME);
- zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", c);
- if( write(s,c,strlen(c)) == -1 )
+ zbx_snprintf(buf, sizeof(buf), "%s\n%s\n","ZBX_GET_ACTIVE_CHECKS", CONFIG_HOSTNAME);
+ zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", buf);
+
+ if(SOCKET_ERROR == zbx_sock_write(s, buf, strlen(buf)))
{
switch (errno)
{
case EINTR:
- zabbix_log( LOG_LEVEL_WARNING, "Timeout while sending data to [%s:%d]",server,port);
- snprintf(error,max_error_len-1,"Timeout while sending data to [%s:%d]",server,port);
+ zbx_snprintf(error,max_error_len,"Timeout while sending data to [%s:%u]",server,port);
break;
default:
- zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to [%s:%d] [%s]",server,port,strerror(errno));
- snprintf(error,max_error_len-1,"Error while sending data to [%s:%d] [%s]",server,port,strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error while sending data to [%s:%u] [%s]",server,port,strerror(errno));
+ break;
}
- close(s);
+ zabbix_log(LOG_LEVEL_WARNING, error);
+ zbx_sock_close(s);
return FAIL;
}
- memset(c,0,MAX_BUF_LEN);
zabbix_log(LOG_LEVEL_DEBUG, "Before read");
amount_read = 0;
+ memset(buf, 0, MAX_BUF_LEN);
do
{
- len=read(s,c+amount_read,(MAX_BUF_LEN-1)-amount_read);
- if (len > 0)
- amount_read += len;
- if(len == -1)
- {
- switch (errno)
- {
- case EINTR:
- zabbix_log( LOG_LEVEL_WARNING, "Timeout while receiving data from [%s:%d]",server,port);
- snprintf(error,max_error_len-1,"Timeout while receiving data from [%s:%d]",server,port);
- break;
- case ECONNRESET:
- zabbix_log( LOG_LEVEL_WARNING, "Connection reset by peer.");
- snprintf(error,max_error_len-1,"Connection reset by peer.");
- close(s);
- return NETWORK_ERROR;
- default:
- zabbix_log( LOG_LEVEL_WARNING, "Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
- snprintf(error,max_error_len-1,"Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
- }
- close(s);
- return FAIL;
- }
- }
- while (len > 0);
+ len = zbx_sock_read(s, buf + amount_read, (MAX_BUF_LEN-1) - amount_read, CONFIG_TIMEOUT);
-/* while((len=read(s,tmp,MAX_BUF_LEN-1))>0)
- {
- if(len == -1)
+ if(SOCKET_ERROR == len)
{
switch (errno)
{
case EINTR:
- zabbix_log( LOG_LEVEL_WARNING, "Timeout while receiving data from [%s:%d]",server,port);
- snprintf(error,max_error_len-1,"Timeout while receiving data from [%s:%d]",server,port);
+ zbx_snprintf(error,max_error_len,"Timeout while receiving data from [%s:%u]",server,port);
break;
case ECONNRESET:
- zabbix_log( LOG_LEVEL_WARNING, "Connection reset by peer.");
- snprintf(error,max_error_len-1,"Connection reset by peer.");
- close(s);
- return NETWORK_ERROR;
+ zbx_snprintf(error,max_error_len,"Connection reset by peer.");
+ break;
default:
- zabbix_log( LOG_LEVEL_WARNING, "Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
- snprintf(error,max_error_len-1,"Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error while receiving data from [%s:%u] [%s]",server,port,strerror(errno));
+ break;
}
- close(s);
+ zabbix_log( LOG_LEVEL_WARNING, error);
+ zbx_sock_close(s);
return FAIL;
}
- strncat(c,tmp,len);
- }
- zabbix_log(LOG_LEVEL_DEBUG, "Read [%s]", c);*/
- parse_list_of_checks(c);
-
- if( close(s)!=0 )
- {
- zabbix_log(LOG_LEVEL_WARNING, "Problem with close [%s]", strerror(errno));
+ amount_read += len;
}
+ while (len > 0);
+
+ parse_list_of_checks(buf);
+ zbx_sock_close(s);
+
return SUCCEED;
}
-int send_value(char *server,int port,char *host, char *key,char *value, char *lastlogsize)
+static int send_value(char *server,unsigned short port,char *host, char *key,char *value, char *lastlogsize)
{
- int i,s;
- char tosend[MAX_BUF_LEN];
- char result[MAX_STRING_LEN];
- struct hostent *hp;
+ ZBX_SOCKET s;
+ ZBX_SOCKADDR myaddr_in;
+ ZBX_SOCKADDR servaddr_in;
+
+ char buf[MAX_STRING_LEN];
+ int len;
- struct sockaddr_in myaddr_in;
- struct sockaddr_in servaddr_in;
+ struct hostent *hp;
- zabbix_log( LOG_LEVEL_DEBUG, "In send_value([%s])",value);
+ zabbix_log( LOG_LEVEL_DEBUG, "In send_value('%s',%u,'%s','%s','%s')", server, port, host, key, lastlogsize);
servaddr_in.sin_family=AF_INET;
- hp=gethostbyname(server);
+ hp = gethostbyname(server);
if(hp==NULL)
{
+#ifdef HAVE_HSTRERROR
+ zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed for server '%s' [%d]", server, (char*)hstrerror((int)h_errno));
+#else
+ zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed for server '%s' [%d]", server, h_errno);
+#endif
return FAIL;
}
servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
- servaddr_in.sin_port=htons(port);
+ servaddr_in.sin_port = htons(port);
- s=socket(AF_INET,SOCK_STREAM,0);
- if(s == -1)
+ if(INVALID_SOCKET == (s = socket(AF_INET,SOCK_STREAM,0)))
{
- zabbix_log( LOG_LEVEL_WARNING, "Error in socket() [%s:%d] [%s]",server,port, strerror(errno));
+ zabbix_log( LOG_LEVEL_WARNING, "Error in socket() [%s:%u] [%s]",server, port, strerror(errno));
return FAIL;
}
-
-/* ling.l_onoff=1;*/
-/* ling.l_linger=0;*/
-/* if(setsockopt(s,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling))==-1)*/
-/* {*/
-/* Ignore */
-/* }*/
-
+
myaddr_in.sin_family = AF_INET;
myaddr_in.sin_port=0;
myaddr_in.sin_addr.s_addr=INADDR_ANY;
- if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
+ if(SOCKET_ERROR == connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)))
{
- zabbix_log( LOG_LEVEL_WARNING, "Error in connect() [%s:%d] [%s]",server, port, strerror(errno));
- close(s);
+ zabbix_log( LOG_LEVEL_WARNING, "Error in connect() [%s:%u] [%s]",server, port, strerror(errno));
+ zbx_sock_close(s);
return FAIL;
}
- comms_create_request(host, key, value, lastlogsize, tosend, sizeof(tosend)-1);
-/* snprintf(tosend,sizeof(tosend)-1,"%s:%s\n",shortname,value); */
- zabbix_log( LOG_LEVEL_DEBUG, "XML before sending [%s]",tosend);
+ comms_create_request(host, key, value, lastlogsize, buf, sizeof(buf));
- if( sendto(s,tosend,strlen(tosend),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
+ zabbix_log(LOG_LEVEL_DEBUG, "XML before sending [%s]",buf);
+
+ if(SOCKET_ERROR == zbx_sock_write(s, buf, strlen(buf)))
{
- zabbix_log( LOG_LEVEL_WARNING, "Error in sendto() [%s:%d] [%s]",server, port, strerror(errno));
- close(s);
+ zabbix_log( LOG_LEVEL_WARNING, "Error during sending [%s:%u] [%s]",server, port, strerror(errno));
+ zbx_sock_close(s);
return FAIL;
}
-/* i=sizeof(struct sockaddr_in);
- i=recvfrom(s,result,1023,0,(struct sockaddr *)&servaddr_in,(socklen_t *)&i);*/
- i = read(s,result,MAX_STRING_LEN-1);
- if(s==-1)
+
+ memset(buf, 0, MAX_STRING_LEN);
+
+ if(SOCKET_ERROR == (len = zbx_sock_read(s, buf, MAX_STRING_LEN-1, CONFIG_TIMEOUT)))
{
- zabbix_log( LOG_LEVEL_WARNING, "Error in recvfrom() [%s:%d] [%s]",server,port, strerror(errno));
- close(s);
+ zabbix_log( LOG_LEVEL_WARNING, "Error in recvfrom() [%s:%u] [%s]",server, port, strerror(errno));
+ zbx_sock_close(s);
return FAIL;
}
- result[i-1]=0;
+ /* !!! REMOVE '\n' AT THE AND (always must be present) !!! */
+ buf[len-1] = '\0';
- if(strcmp(result,"OK") == 0)
+ if(strcmp(buf,"OK") == 0)
{
zabbix_log( LOG_LEVEL_DEBUG, "OK");
}
else
{
- zabbix_log( LOG_LEVEL_DEBUG, "NOT OK [%s:%s]", host, key);
+ zabbix_log( LOG_LEVEL_DEBUG, "NOT OK [%s:%s] [%s]", host, key, buf);
}
- if( close(s)!=0 )
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error in close() [%s] [%s]",server, strerror(errno));
- }
+ zbx_sock_close(s);
return SUCCEED;
}
-int process_active_checks(char *server, int port)
+static int process_active_checks(char *server, unsigned short port)
{
char value[MAX_STRING_LEN];
char lastlogsize[MAX_STRING_LEN];
@@ -428,66 +447,65 @@ int process_active_checks(char *server, int port)
AGENT_RESULT result;
- memset(&result, 0, sizeof(AGENT_RESULT));
+ zabbix_log( LOG_LEVEL_DEBUG, "In process_active_checks('%s',%u)",server, port);
- now=time(NULL);
+ init_result(&result);
- for(i=0;;i++)
+ now = time(NULL);
+
+ for(i=0; NULL != active_metrics[i].key; i++)
{
- if(metrics[i].key == NULL) break;
- if(metrics[i].nextcheck>now) continue;
- if(metrics[i].status!=ITEM_STATUS_ACTIVE) continue;
+ if(active_metrics[i].nextcheck > now) continue;
+ if(active_metrics[i].status != ITEM_STATUS_ACTIVE) continue;
/* Special processing for log files */
- if(strncmp(metrics[i].key,"log[",4) == 0)
+ if(strncmp(active_metrics[i].key,"log[",4) == 0)
{
- strscpy(c,metrics[i].key);
+ strscpy(c,active_metrics[i].key);
filename=strtok(c,"[]");
filename=strtok(NULL,"[]");
- count=0;
- while(process_log(filename,&metrics[i].lastlogsize,value) == 0)
+ count = 0;
+ while(process_log(filename,&active_metrics[i].lastlogsize,value) == 0)
{
-/* snprintf(shortname, MAX_STRING_LEN-1,"%s:%s",CONFIG_HOSTNAME,metrics[i].key);
- zabbix_log( LOG_LEVEL_DEBUG, "%s",shortname); */
- snprintf(lastlogsize, MAX_STRING_LEN-1,"%ld",metrics[i].lastlogsize);
+ zbx_snprintf(lastlogsize, sizeof(lastlogsize), "%d", active_metrics[i].lastlogsize);
- if(send_value(server,port,CONFIG_HOSTNAME,metrics[i].key,value,lastlogsize) == FAIL)
+ if(send_value(server,port,CONFIG_HOSTNAME,active_metrics[i].key,value,lastlogsize) == FAIL)
{
ret = FAIL;
break;
}
if(strcmp(value,"ZBX_NOTSUPPORTED\n")==0)
{
- metrics[i].status=ITEM_STATUS_NOTSUPPORTED;
- zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.", metrics[i].key);
+ active_metrics[i].status = ITEM_STATUS_NOTSUPPORTED;
+ zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.", active_metrics[i].key);
break;
}
count++;
/* Do not flood ZABBIX server if file grows too fast */
- if(count >= MAX_LINES_PER_SECOND*metrics[i].refresh) break;
+ if(count >= (MAX_LINES_PER_SECOND * active_metrics[i].refresh)) break;
}
}
else
{
lastlogsize[0]=0;
- process(metrics[i].key, 0, &result);
+ process(active_metrics[i].key, 0, &result);
if(result.type & AR_DOUBLE)
- snprintf(value, MAX_STRING_LEN-1, ZBX_FS_DBL, result.dbl);
+ zbx_snprintf(value, sizeof(value), ZBX_FS_DBL, result.dbl);
else if(result.type & AR_UINT64)
- snprintf(value, MAX_STRING_LEN-1, ZBX_FS_UI64, result.ui64);
+ zbx_snprintf(value, sizeof(value), ZBX_FS_UI64, result.ui64);
else if(result.type & AR_STRING)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.str);
+ zbx_snprintf(value, sizeof(value), "%s", result.str);
else if(result.type & AR_TEXT)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.text);
+ zbx_snprintf(value, sizeof(value), "%s", result.text);
else if(result.type & AR_MESSAGE)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.msg);
+ zbx_snprintf(value, sizeof(value), "%s", result.msg);
free_result(&result);
-/* snprintf(shortname, MAX_STRING_LEN-1,"%s:%s",CONFIG_HOSTNAME,metrics[i].key);
- zabbix_log( LOG_LEVEL_DEBUG, "%s",shortname); */
- if(send_value(server,port,CONFIG_HOSTNAME,metrics[i].key,value,lastlogsize) == FAIL)
+ zabbix_log( LOG_LEVEL_DEBUG, "For key [%s] received value [%s]", active_metrics[i].key, value);
+
+ if(send_value(server,port,CONFIG_HOSTNAME,active_metrics[i].key,value,lastlogsize) == FAIL)
{
ret = FAIL;
break;
@@ -495,109 +513,110 @@ int process_active_checks(char *server, int port)
if(strcmp(value,"ZBX_NOTSUPPORTED\n")==0)
{
- metrics[i].status=ITEM_STATUS_NOTSUPPORTED;
- zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.", metrics[i].key);
+ active_metrics[i].status=ITEM_STATUS_NOTSUPPORTED;
+ zabbix_log( LOG_LEVEL_WARNING, "Active check [%s] is not supported. Disabled.", active_metrics[i].key);
}
}
- metrics[i].nextcheck=time(NULL)+metrics[i].refresh;
+ active_metrics[i].nextcheck = time(NULL)+active_metrics[i].refresh;
}
return ret;
}
-void refresh_metrics(char *server, int port, char *error, int max_error_len)
+static void refresh_metrics(char *server, unsigned short port, char *error, int max_error_len)
{
- zabbix_log( LOG_LEVEL_DEBUG, "In refresh_metrics()");
+ zabbix_log( LOG_LEVEL_DEBUG, "In refresh_metrics('%s',%u)",server, port);
- while(get_active_checks(server, port, error, sizeof(error)) != SUCCEED)
+ while(get_active_checks(server, port, error, max_error_len) != SUCCEED)
{
zabbix_log( LOG_LEVEL_WARNING, "Getting list of active checks failed. Will retry after 60 seconds");
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [sleeping for %d seconds]", 60);
-#endif
- sleep(60);
+
+ zbx_setproctitle("poller [sleeping for %d seconds]", 60);
+
+ zbx_sleep(60);
}
}
-void child_active_main(int i,char *server, int port)
+ZBX_THREAD_ENTRY(active_checks_thread, args)
{
+ ZBX_THREAD_ACTIVECHK_ARGS activechk_args;
+
char error[MAX_STRING_LEN];
int sleeptime, nextcheck;
int nextrefresh;
+ char *p = NULL;
- zabbix_log( LOG_LEVEL_WARNING, "zabbix_agentd %ld started",(long)getpid());
+ activechk_args.host = strdup(((ZBX_THREAD_ACTIVECHK_ARGS *)args)->host);
+ activechk_args.port = ((ZBX_THREAD_ACTIVECHK_ARGS *)args)->port;
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("getting list of active checks");
-#endif
+ assert(activechk_args.host);
+
+ p = strchr(activechk_args.host,',');
+ if(p) *p = '\0';
+
+ zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd active check started [%s:%u]", activechk_args.host, activechk_args.port);
+
+ zbx_setproctitle("getting list of active checks");
- init_list();
+ init_active_metrics();
- refresh_metrics(server, port, error, sizeof(error));
- nextrefresh=time(NULL)+CONFIG_REFRESH_ACTIVE_CHECKS;
+ refresh_metrics(activechk_args.host, activechk_args.port, error, MAX_STRING_LEN);
+ nextrefresh = time(NULL) + CONFIG_REFRESH_ACTIVE_CHECKS;
- for(;;)
+ while(ZBX_IS_RUNNING)
{
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("processing active checks");
-#endif
- if(process_active_checks(server, port) == FAIL)
+
+ zbx_setproctitle("processing active checks");
+
+ if(process_active_checks(activechk_args.host, activechk_args.port) == FAIL)
{
- sleep(60);
+ zbx_sleep(60);
continue;
}
- nextcheck=get_min_nextcheck();
- if( FAIL == nextcheck)
+
+ nextcheck = get_min_nextcheck();
+ if(FAIL == nextcheck)
{
- sleeptime=60;
+ sleeptime = 60;
}
else
{
- sleeptime=nextcheck-time(NULL);
- if(sleeptime<0)
- {
- sleeptime=0;
- }
+ sleeptime = nextcheck - time(NULL);
+
+ sleeptime = MAX(sleeptime, 0);
}
- if(sleeptime>0)
+
+ if(sleeptime > 0)
{
- if(sleeptime > 60)
- {
- sleeptime = 60;
- }
- zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
- sleeptime );
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [sleeping for %d seconds]",
- sleeptime);
-#endif
- sleep( sleeptime );
+ sleeptime = MIN(sleeptime, 60);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds", sleeptime );
+
+ zbx_setproctitle("poller [sleeping for %d seconds]", sleeptime);
+
+ zbx_sleep( sleeptime );
+ continue;
}
else
{
- zabbix_log( LOG_LEVEL_DEBUG, "No sleeping" );
+ zabbix_log(LOG_LEVEL_DEBUG, "No sleeping" );
}
- if(time(NULL)>=nextrefresh)
+ if(time(NULL) >= nextrefresh)
{
- refresh_metrics(server, port, error, sizeof(error));
- nextrefresh=time(NULL)+CONFIG_REFRESH_ACTIVE_CHECKS;
+ refresh_metrics(activechk_args.host, activechk_args.port, error, MAX_STRING_LEN);
+ nextrefresh=time(NULL) + CONFIG_REFRESH_ACTIVE_CHECKS;
}
}
-}
-pid_t child_active_make(int i,char *server, int port)
-{
- pid_t pid;
+ free(activechk_args.host);
+ free_metrics();
- if((pid = fork()) >0)
- {
- return (pid);
- }
+ zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd active check stopped");
- /* never returns */
- child_active_main(i, server, port);
+ ZBX_DO_EXIT();
+
+ zbx_tread_exit(0);
- /* avoid compilator warning */
- return 0;
}
+
diff --git a/src/zabbix_agent/active.h b/src/zabbix_agent/active.h
index 868ed5a2..669c6bc5 100644
--- a/src/zabbix_agent/active.h
+++ b/src/zabbix_agent/active.h
@@ -20,13 +20,14 @@
#ifndef ZABBIX_ACTIVE_H
#define ZABBIX_ACTIVE_H
+#include "threads.h"
+
extern char *CONFIG_HOSTNAME;
extern int CONFIG_REFRESH_ACTIVE_CHECKS;
#define MAX_LINES_PER_SECOND 10
-#define METRIC struct metric_type
-METRIC
+typedef struct zbx_active_metric_type
{
char *key;
int refresh;
@@ -35,8 +36,14 @@ METRIC
/* Must be long for fseek() */
/* int lastlogsize;*/
long lastlogsize;
-};
+} ZBX_ACTIVE_METRIC;
+
+typedef struct active_ckeck_args
+{
+ char *host;
+ unsigned short port;
+} ZBX_THREAD_ACTIVECHK_ARGS;
-pid_t child_active_make(int i,char *server, int port);
+ZBX_THREAD_ENTRY(active_checks_thread, args);
-#endif
+#endif /* ZABBIX_ACTIVE_H */
diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c
index 862b9abb..d27b7281 100644
--- a/src/zabbix_agent/cpustat.c
+++ b/src/zabbix_agent/cpustat.c
@@ -17,333 +17,462 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <unistd.h>
-#include <signal.h>
-
-#include <errno.h>
+#include "common.h"
+#include "cpustat.h"
-#include <time.h>
+#include "log.h"
-/* No warning for bzero */
-#include <string.h>
-#include <strings.h>
+#ifdef WIN32
+
+ #include "perfmon.h"
+
+#else /* not WIN32 */
+
+ static int get_cpustat(
+ int *now,
+ float *cpu_user,
+ float *cpu_system,
+ float *cpu_nice,
+ float *cpu_idle
+ );
+
+ static void apply_cpustat(
+ ZBX_CPUS_STAT_DATA *pcpus,
+ int now,
+ float cpu_user,
+ float cpu_system,
+ float cpu_nice,
+ float cpu_idle
+ );
+
+#endif /* WIN32 */
+
+
+/******************************************************************************
+ * *
+ * Function: init_cpu_collector *
+ * *
+ * Purpose: Initialize statistic structure and prepare state *
+ * for data calculation *
+ * *
+ * Parameters: pcpus - pointer to the structure *
+ * of ZBX_CPUS_STAT_DATA type *
+ * *
+ * Return value: If the function succeeds, the return 0, *
+ * great than 0 on an error *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
+{
+#ifdef WIN32
-/* For config file operations */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+ SYSTEM_INFO sysInfo;
+ PDH_STATUS status;
+ int i;
-/* For setpriority */
-#include <sys/time.h>
-#include <sys/resource.h>
+ char counter_path[MAX_COUNTER_PATH];
-/* Required for getpwuid */
-#include <pwd.h>
+ GetSystemInfo(&sysInfo);
-#include <dirent.h>
+ pcpus->count = sysInfo.dwNumberOfProcessors;
-#include "common.h"
-#include "sysinfo.h"
-#include "security.h"
-#include "zabbix_agent.h"
+ memset(pcpus, 0, sizeof(ZBX_CPUS_STAT_DATA));
-#include "log.h"
-#include "cfg.h"
-#include "cpustat.h"
-
-CPUSTAT cpustat;
-
-void init_stats_cpustat()
-{
- int i;
-
- for(i=0;i<60*15;i++)
+ if (PdhOpenQuery(NULL,0,&pcpus->pdh_query)!=ERROR_SUCCESS)
{
- cpustat.clock[i]=0;
+ zabbix_log( LOG_LEVEL_ERR, "Call to PdhOpenQuery() failed: %s", strerror_from_system(GetLastError()));
+ return 1;
}
-}
-void report_stats_cpustat(FILE *file, int now)
-{
- int time=0,
- time1=0,
- time5=0,
- time15=0;
- float
- cpu_idle=0,
- cpu_idle1=0,
- cpu_idle5=0,
- cpu_idle15=0,
- cpu_user=0,
- cpu_user1=0,
- cpu_user5=0,
- cpu_user15=0,
- cpu_system=0,
- cpu_system1=0,
- cpu_system5=0,
- cpu_system15=0,
- cpu_nice=0,
- cpu_nice1=0,
- cpu_nice5=0,
- cpu_nice15=0,
- cpu_sum=0,
- cpu_sum1=0,
- cpu_sum5=0,
- cpu_sum15=0;
+ zbx_snprintf(counter_path, sizeof(counter_path), "\\%s(_Total)\\%s",GetCounterName(PCI_PROCESSOR),GetCounterName(PCI_PROCESSOR_TIME));
- int i;
-
- time=now+1;
- time1=now+1;
- time5=now+1;
- time15=now+1;
- for(i=0;i<60*15;i++)
+ if (ERROR_SUCCESS != (status = PdhAddCounter(
+ pcpus->pdh_query,
+ counter_path, 0,
+ &pcpus->cpu[0].usage_couter)))
{
- if(cpustat.clock[i]==0)
- {
- continue;
- }
- if(cpustat.clock[i]==now)
- {
- continue;
- }
- if((cpustat.clock[i] >= now-60) && (time1 > cpustat.clock[i]))
- {
- time1=cpustat.clock[i];
- }
- if((cpustat.clock[i] >= now-5*60) && (time5 > cpustat.clock[i]))
- {
- time5=cpustat.clock[i];
- }
- if((cpustat.clock[i] >= now-15*60) && (time15 > cpustat.clock[i]))
- {
- time15=cpustat.clock[i];
- }
+ zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", strerror_from_module(status,"PDH.DLL"));
+ return 2;
}
- for(i=0;i<60*15;i++)
+
+ for(i=1 /* 0 - is Total cpus */; i <= pcpus->count /* "<=" instead of "+ 1" */; i++)
{
- if(cpustat.clock[i]==now)
- {
- cpu_idle=cpustat.cpu_idle[i];
- cpu_user=cpustat.cpu_user[i];
- cpu_nice=cpustat.cpu_nice[i];
- cpu_system=cpustat.cpu_system[i];
- cpu_sum=cpu_idle+cpu_user+cpu_nice+cpu_system;
- }
- if(cpustat.clock[i]==time1)
- {
- cpu_idle1=cpustat.cpu_idle[i];
- cpu_user1=cpustat.cpu_user[i];
- cpu_nice1=cpustat.cpu_nice[i];
- cpu_system1=cpustat.cpu_system[i];
- cpu_sum1=cpu_idle1+cpu_user1+cpu_nice1+cpu_system1;
- }
- if(cpustat.clock[i]==time5)
- {
- cpu_idle5=cpustat.cpu_idle[i];
- cpu_user5=cpustat.cpu_user[i];
- cpu_nice5=cpustat.cpu_nice[i];
- cpu_system5=cpustat.cpu_system[i];
- cpu_sum5=cpu_idle5+cpu_user5+cpu_nice5+cpu_system5;
- }
- if(cpustat.clock[i]==time15)
+ zbx_snprintf(counter_path, sizeof(counter_path),"\\%s(%d)\\%s", GetCounterName(PCI_PROCESSOR), i-1, GetCounterName(PCI_PROCESSOR_TIME));
+
+ if (ERROR_SUCCESS != (status = PdhAddCounter(
+ pcpus->pdh_query,
+ counter_path,0,
+ &pcpus->cpu[i].usage_couter)))
{
- cpu_idle15=cpustat.cpu_idle[i];
- cpu_user15=cpustat.cpu_user[i];
- cpu_nice15=cpustat.cpu_nice[i];
- cpu_system15=cpustat.cpu_system[i];
- cpu_sum15=cpu_idle15+cpu_user15+cpu_nice15+cpu_system15;
+ zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", strerror_from_module(status,"PDH.DLL"));
+ return 2;
}
}
- if((cpu_idle!=0)&&(cpu_idle1!=0))
- {
- fprintf(file,"cpu[idle1] %f\n", 100*(float)((cpu_idle-cpu_idle1)/(cpu_sum-cpu_sum1)));
- }
- else
- {
- fprintf(file,"cpu[idle1] 0\n");
- }
- if((cpu_idle!=0)&&(cpu_idle5!=0))
- {
- fprintf(file,"cpu[idle5] %f\n",100*(float)((cpu_idle-cpu_idle5)/(cpu_sum-cpu_sum5)));
- }
- else
- {
- fprintf(file,"cpu[idle5] 0\n");
- }
- if((cpu_idle!=0)&&(cpu_idle15!=0))
- {
- fprintf(file,"cpu[idle15] %f\n", 100*(float)((cpu_idle-cpu_idle15)/((cpu_sum-cpu_sum15))));
- }
- else
- {
- fprintf(file,"cpu[idle15] 0\n");
- }
- if((cpu_user!=0)&&(cpu_user1!=0))
- {
- fprintf(file,"cpu[user1] %f\n", 100*(float)((cpu_user-cpu_user1)/((cpu_sum-cpu_sum1))));
- }
- else
- {
- fprintf(file,"cpu[user1] 0\n");
- }
- if((cpu_user!=0)&&(cpu_user5!=0))
- {
- fprintf(file,"cpu[user5] %f\n", 100*(float)((cpu_user-cpu_user5)/((cpu_sum-cpu_sum5))));
- }
- else
- {
- fprintf(file,"cpu[user5] 0\n");
- }
- if((cpu_user!=0)&&(cpu_user15!=0))
- {
- fprintf(file,"cpu[user15] %f\n", 100*(float)((cpu_user-cpu_user15)/((cpu_sum-cpu_sum15))));
- }
- else
+ if (ERROR_SUCCESS != (status = PdhCollectQueryData(pcpus->pdh_query)))
{
- fprintf(file,"cpu[user15] 0\n");
+ zabbix_log( LOG_LEVEL_ERR, "Call to PdhCollectQueryData() failed: %s", strerror_from_module(status,"PDH.DLL"));
+ return 3;
}
- if((cpu_nice!=0)&&(cpu_nice1!=0))
+ for(i = 1; i <= pcpus->count; i++)
{
- fprintf(file,"cpu[nice1] %f\n", 100*(float)((cpu_nice-cpu_nice1)/((cpu_sum-cpu_sum1))));
- }
- else
- {
- fprintf(file,"cpu[nice1] 0\n");
- }
- if((cpu_nice!=0)&&(cpu_nice5!=0))
- {
- fprintf(file,"cpu[nice5] %f\n", 100*(float)((cpu_nice-cpu_nice5)/((cpu_sum-cpu_sum5))));
- }
- else
- {
- fprintf(file,"cpu[nice5] 0\n");
- }
- if((cpu_nice!=0)&&(cpu_nice15!=0))
- {
- fprintf(file,"cpu[nice15] %f\n", 100*(float)((cpu_nice-cpu_nice15)/((cpu_sum-cpu_sum15))));
- }
- else
- {
- fprintf(file,"cpu[nice15] 0\n");
+ PdhGetRawCounterValue(pcpus->cpu[i].usage_couter, NULL, &pcpus->cpu[i].usage_old);
}
- if((cpu_system!=0)&&(cpu_system1!=0))
+
+ zbx_snprintf(counter_path, sizeof(counter_path), "\\%s\\%s", GetCounterName(PCI_SYSTEM), GetCounterName(PCI_PROCESSOR_QUEUE_LENGTH));
+
+ // Prepare for CPU execution queue usage collection
+ if (ERROR_SUCCESS != (status = PdhAddCounter(pcpus->pdh_query, counter_path, 0, &pcpus->queue_counter)))
{
- fprintf(file,"cpu[system1] %f\n", 100*(float)((cpu_system-cpu_system1)/((cpu_sum-cpu_sum1))));
+ zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", strerror_from_module(status,"PDH.DLL"));
+ return 2;
}
- else
+
+#else /* not WIN32 */
+
+ memset(pcpus, 0, sizeof(ZBX_CPUS_STAT_DATA));
+
+
+#endif /* WIN32 */
+
+ return 0;
+}
+
+/******************************************************************************
+ * *
+ * Function: close_cpu_collector *
+ * *
+ * Purpose: Cleare state of data calculation *
+ * *
+ * Parameters: pcpus - pointer to the structure *
+ * of ZBX_CPUS_STAT_DATA type *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+void close_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
+{
+#ifdef WIN32
+
+ int i;
+
+ if(pcpus->queue_counter)
{
- fprintf(file,"cpu[system1] 0\n");
+ PdhRemoveCounter(pcpus->queue_counter);
+ pcpus->queue_counter = NULL;
}
- if((cpu_system!=0)&&(cpu_system5!=0))
+
+ for(i=0; i < MAX_CPU; i++)
{
- fprintf(file,"cpu[system5] %f\n", 100*(float)((cpu_system-cpu_system5)/((cpu_sum-cpu_sum5))));
+ if(pcpus->cpu[i].usage_couter)
+ {
+ PdhRemoveCounter(pcpus->cpu[i].usage_couter);
+ pcpus->cpu[i].usage_couter = NULL;
+ }
}
- else
+
+ if(pcpus->pdh_query)
{
- fprintf(file,"cpu[system5] 0\n");
+ PdhCloseQuery(pcpus->pdh_query);
+ pcpus->pdh_query = NULL;
}
- if((cpu_system!=0)&&(cpu_system15!=0))
+
+#endif /* WIN32 */
+
+}
+
+void collect_cpustat(ZBX_CPUS_STAT_DATA *pcpus)
+{
+#ifdef WIN32
+
+ PDH_FMT_COUNTERVALUE
+ value;
+ PDH_STATUS
+ status;
+ LONG sum;
+ int i,
+ j,
+ n;
+
+ if(!pcpus->queue_counter) return;
+
+ if ((status = PdhCollectQueryData(pcpus->pdh_query)) != ERROR_SUCCESS)
{
- fprintf(file,"cpu[system15] %f\n", 100*(float)((cpu_system-cpu_system15)/((cpu_sum-cpu_sum15))));
+ zabbix_log( LOG_LEVEL_ERR, "Call to PdhCollectQueryData() failed: %s", strerror_from_module(status,"PDH.DLL"));
+ return;
}
- else
+
+ // Process CPU utilization data
+ for(i=0; i <= pcpus->count; i++)
{
- fprintf(file,"cpu[system15] 0\n");
- }
-}
+ if(!pcpus->cpu[i].usage_couter)
+ continue;
+ PdhGetRawCounterValue(
+ pcpus->cpu[i].usage_couter,
+ NULL,
+ &pcpus->cpu[i].usage);
-void add_values_cpustat(int now,float cpu_user,float cpu_system,float cpu_nice,float cpu_idle)
-{
- int i;
+ PdhCalculateCounterFromRawValue(
+ pcpus->cpu[i].usage_couter,
+ PDH_FMT_LONG,
+ &pcpus->cpu[i].usage,
+ &pcpus->cpu[i].usage_old,
+ &value);
+
+ pcpus->cpu[i].h_usage[pcpus->cpu[i].h_usage_index] = value.longValue;
+ pcpus->cpu[i].usage_old = pcpus->cpu[i].usage;
+
+ // Calculate average cpu usage
+ for(n = pcpus->cpu[i].h_usage_index, j = 0, sum = 0; j < MAX_CPU_HISTORY; j++, n--)
+ {
+ if(n < 0) n = MAX_CPU_HISTORY - 1;
+
+ sum += pcpus->cpu[i].h_usage[n];
+
+ if(j == 60) /* cpu usage for last minute */
+ {
+ pcpus->cpu[i].util1 = ((double)sum)/(double)j;
+ }
+ else if(j == 300) /* cpu usage for last five minutes */
+ {
+ pcpus->cpu[i].util5 = ((double)sum)/(double)j;
+ }
+ }
+
+ /* cpu usage for last fifteen minutes */
+ pcpus->cpu[i].util15 = ((double)sum)/(double)MAX_CPU_HISTORY;
+
+ pcpus->cpu[i].h_usage_index++;
+ if (pcpus->cpu[i].h_usage_index == MAX_CPU_HISTORY)
+ pcpus->cpu[i].h_usage_index = 0;
+ }
-/* printf("Add_values [%s] [%f] [%f]\n",interface,value_sent,value_received);*/
- for(i=0;i<15*60;i++)
+ if(pcpus->queue_counter)
{
- if(cpustat.clock[i]<now-15*60)
+ // Process CPU queue length data
+ PdhGetRawCounterValue(
+ pcpus->queue_counter,
+ NULL,
+ &pcpus->queue);
+
+ PdhCalculateCounterFromRawValue(
+ pcpus->queue_counter,
+ PDH_FMT_LONG,
+ &pcpus->queue,
+ NULL,
+ &value);
+
+ pcpus->h_queue[pcpus->h_queue_index] = value.longValue;
+
+ // Calculate average cpu usage
+ for(n = pcpus->h_queue_index, j = 0, sum = 0; j < MAX_CPU_HISTORY; j++, n--)
{
- cpustat.clock[i]=now;
- cpustat.cpu_user[i]=cpu_user;;
- cpustat.cpu_system[i]=cpu_system;
- cpustat.cpu_nice[i]=cpu_nice;
- cpustat.cpu_idle[i]=cpu_idle;
- break;
+ if(n < 0) n = MAX_CPU_HISTORY - 1;
+
+ sum += pcpus->h_queue[n];
+
+ if(j == 60) /* processor(s) load for last minute */
+ {
+ pcpus->load1 = ((double)sum)/(double)j;
+ }
+ else if(j == 300) /* processor(s) load for last five minutes */
+ {
+ pcpus->load5 = ((double)sum)/(double)j;
+ }
}
+
+ /* cpu usage for last fifteen minutes */
+ pcpus->load15 = ((double)sum)/(double)MAX_CPU_HISTORY;
+
+ pcpus->h_queue_index++;
+
+ if (pcpus->h_queue_index == MAX_CPU_HISTORY)
+ pcpus->h_queue_index = 0;
}
-}
+#else /* not WIN32 */
-void collect_stats_cpustat(FILE *outfile)
-{
- /* Must be static */
- static int initialised = 0;
int now = 0;
float cpu_user, cpu_nice, cpu_system, cpu_idle;
-#if defined(HAVE_PROC_STAT)
+
+ if(0 != get_cpustat(&now, &cpu_user, &cpu_system, &cpu_nice, &cpu_idle))
+ return;
+
+ apply_cpustat(pcpus, now, cpu_user, cpu_system, cpu_nice, cpu_idle);
+
+#endif /* WIN32 */
+}
+
+#if !defined(WIN32)
+
+static int get_cpustat(int *now,float *cpu_user,float *cpu_system,float *cpu_nice,float *cpu_idle)
+{
+ #if defined(HAVE_PROC_STAT)
FILE *file;
char line[MAX_STRING_LEN];
-#elif defined(HAVE_SYS_PSTAT_H) /* HAVE_PROC_STAT */
+ #elif defined(HAVE_SYS_PSTAT_H) /* not HAVE_PROC_STAT */
struct pst_dynamic stats;
-#else /* HAVE_SYS_PSTAT_H */
+ #else /* not HAVE_SYS_PSTAT_H */
- return;
+ return 1;
-#endif
-
- if(!initialised)
- {
- init_stats_cpustat();
- initialised = 1;
- }
+ #endif /* HAVE_PROC_STAT */
- now = time(NULL);
+ *now = time(NULL);
-#if defined(HAVE_PROC_STAT)
+ #if defined(HAVE_PROC_STAT)
- file = fopen("/proc/stat","r");
- if(NULL == file)
+ if(NULL == (file = fopen("/proc/stat","r") ))
{
- fprintf(stderr, "Cannot open [%s] [%s]\n","/proc/stat", strerror(errno));
- return;
+ zbx_error("Cannot open [%s] [%s]\n","/proc/stat", strerror(errno));
+ return 1;
}
- cpu_user = cpu_nice = cpu_system = cpu_idle = -1;
+
+ *cpu_user = *cpu_nice = *cpu_system = *cpu_idle = -1;
+
while(fgets(line,1024,file) != NULL)
{
if(strstr(line,"cpu ") == NULL) continue;
- sscanf(line, "cpu %f %f %f %f", &cpu_user, &cpu_nice, &cpu_system, &cpu_idle);
+ sscanf(line, "cpu %f %f %f %f", cpu_user, cpu_nice, cpu_system, cpu_idle);
break;
}
- fclose(file);
+ zbx_fclose(file);
- if(cpu_user < 0)
- return;
+ if(*cpu_user < 0)
+ return 1;
-#elif defined(HAVE_SYS_PSTAT_H) /* HAVE_PROC_STAT */
+ #elif defined(HAVE_SYS_PSTAT_H) /* HAVE_PROC_STAT */
pstat_getdynamic(&stats, sizeof( struct pst_dynamic ), 1, 0 );
- cpu_user = (float)stats.psd_cpu_time[CP_USER];
- cpu_nice = (float)stats.psd_cpu_time[CP_SYS];
- cpu_system = (float)stats.psd_cpu_time[CP_NICE];
- cpu_idle = (float)stats.psd_cpu_time[CP_IDLE];
+ *cpu_user = (float)stats.psd_cpu_time[CP_USER];
+ *cpu_nice = (float)stats.psd_cpu_time[CP_SYS];
+ *cpu_system = (float)stats.psd_cpu_time[CP_NICE];
+ *cpu_idle = (float)stats.psd_cpu_time[CP_IDLE];
-#endif /* HAVE_SYS_PSTAT_H */
+ #endif /* HAVE_SYS_PSTAT_H */
+ return 0;
+}
- add_values_cpustat(now,cpu_user, cpu_system, cpu_nice, cpu_idle);
- report_stats_cpustat(outfile, now);
-
+
+#define CALC_CPU_LOAD(now_val, tim_val, now_all_val, tim_all_val) \
+ if((now_val) - (tim_val) > 0 && (now_all_val) - (tim_all_val) > 0) \
+ { \
+ tim_val = 100 * (float)((now_val) - (tim_val)/(now_all_val) - (tim_all_val)); \
+ } \
+ else \
+ { \
+ tim_val = 0; \
+ }
+
+static void apply_cpustat(
+ ZBX_CPUS_STAT_DATA *pcpus,
+ int now,
+ float cpu_user,
+ float cpu_system,
+ float cpu_nice,
+ float cpu_idle
+ )
+{
+ int i = 0,
+ time = 0,
+ time1 = 0,
+ time5 = 0,
+ time15 = 0;
+
+ for(i=0; i < MAX_CPU_HISTORY; i++)
+ {
+ if(pcpus->clock[i] < now - MAX_CPU_HISTORY)
+ {
+ pcpus->clock[i] = now;
+
+ pcpus->user = pcpus->h_user[i] = cpu_user;
+ pcpus->system = pcpus->h_system[i] = cpu_system;
+ pcpus->nice = pcpus->h_nice[i] = cpu_nice;
+ pcpus->idle = pcpus->h_idle[i] = cpu_idle;
+
+ pcpus->all = cpu_idle + cpu_user + cpu_nice + cpu_system;
+ break;
+ }
+ }
+
+ time = time1 = time5 = time15 = now+1;
+
+ for(i=0; i < MAX_CPU_HISTORY; i++)
+ {
+ if(0 == pcpus->clock[i]) continue;
+
+ if(pcpus->clock[i] == now)
+ {
+ pcpus->idle = pcpus->h_idle[i];
+ pcpus->user = pcpus->h_user[i];
+ pcpus->nice = pcpus->h_nice[i];
+ pcpus->system = pcpus->h_system[i];
+ pcpus->all = pcpus->idle + pcpus->user + pcpus->nice + pcpus->system;
+ }
+
+ if((pcpus->clock[i] >= (now - 60)) && (time1 > pcpus->clock[i]))
+ {
+ time1 = pcpus->clock[i];
+ pcpus->idle1 = pcpus->h_idle[i];
+ pcpus->user1 = pcpus->h_user[i];
+ pcpus->nice1 = pcpus->h_nice[i];
+ pcpus->system1 = pcpus->h_system[i];
+ pcpus->all1 = pcpus->idle1 + pcpus->user1 + pcpus->nice1 + pcpus->system1;
+ }
+ if((pcpus->clock[i] >= (now - (5*60))) && (time5 > pcpus->clock[i]))
+ {
+ time5 = pcpus->clock[i];
+ pcpus->idle5 = pcpus->h_idle[i];
+ pcpus->user5 = pcpus->h_user[i];
+ pcpus->nice5 = pcpus->h_nice[i];
+ pcpus->system5 = pcpus->h_system[i];
+ pcpus->all5 = pcpus->idle5 + pcpus->user5 + pcpus->nice5 + pcpus->system5;
+ }
+ if((pcpus->clock[i] >= (now - (15*60))) && (time15 > pcpus->clock[i]))
+ {
+ time15 = pcpus->clock[i];
+ pcpus->idle15 = pcpus->h_idle[i];
+ pcpus->user15 = pcpus->h_user[i];
+ pcpus->nice15 = pcpus->h_nice[i];
+ pcpus->system15 = pcpus->h_system[i];
+ pcpus->all15 = pcpus->idle15 + pcpus->user15 + pcpus->nice15 + pcpus->system15;
+ }
+ }
+
+ CALC_CPU_LOAD(pcpus->idle, pcpus->idle1, pcpus->all, pcpus->all1);
+ CALC_CPU_LOAD(pcpus->idle, pcpus->idle5, pcpus->all, pcpus->all5);
+ CALC_CPU_LOAD(pcpus->idle, pcpus->idle15, pcpus->all, pcpus->all15);
+
+ CALC_CPU_LOAD(pcpus->user, pcpus->user1, pcpus->all, pcpus->all1);
+ CALC_CPU_LOAD(pcpus->user, pcpus->user5, pcpus->all, pcpus->all5);
+ CALC_CPU_LOAD(pcpus->user, pcpus->user15, pcpus->all, pcpus->all15);
+
+ CALC_CPU_LOAD(pcpus->nice, pcpus->nice1, pcpus->all, pcpus->all1);
+ CALC_CPU_LOAD(pcpus->nice, pcpus->nice5, pcpus->all, pcpus->all5);
+ CALC_CPU_LOAD(pcpus->nice, pcpus->nice15, pcpus->all, pcpus->all15);
+
+ CALC_CPU_LOAD(pcpus->system, pcpus->system1, pcpus->all, pcpus->all1);
+ CALC_CPU_LOAD(pcpus->system, pcpus->system5, pcpus->all, pcpus->all5);
+ CALC_CPU_LOAD(pcpus->system, pcpus->system15, pcpus->all, pcpus->all15);
}
+
+#endif /* not WIN32 */
diff --git a/src/zabbix_agent/cpustat.h b/src/zabbix_agent/cpustat.h
index af2a72b1..d36080b2 100644
--- a/src/zabbix_agent/cpustat.h
+++ b/src/zabbix_agent/cpustat.h
@@ -20,19 +20,83 @@
#ifndef ZABBIX_CPUSTAT_H
#define ZABBIX_CPUSTAT_H
-#define CPUSTAT struct cpustat_type
-CPUSTAT
-{
- char *device;
- int major;
- int diskno;
- int clock[60*15];
- float cpu_user[60*15];
- float cpu_system[60*15];
- float cpu_nice[60*15];
- float cpu_idle[60*15];
-};
-
-void collect_stats_cpustat(FILE *outfile);
+#if defined (WIN32)
+
+ #define MAX_CPU 16
+ #define MAX_CPU_HISTORY 900 /* 15 min in seconds */
+
+ typedef struct s_single_cpu_stat_data
+ {
+ PDH_HCOUNTER usage_couter;
+ PDH_RAW_COUNTER usage;
+ PDH_RAW_COUNTER usage_old;
+
+ double util1;
+ double util5;
+ double util15;
+
+ LONG h_usage[MAX_CPU_HISTORY]; /* usage history */
+ int h_usage_index;
+ } ZBX_SINGLE_CPU_STAT_DATA;
+
+ typedef struct s_cpus_stat_data
+ {
+ ZBX_SINGLE_CPU_STAT_DATA cpu[MAX_CPU];
+ int count;
+
+ double load1;
+ double load5;
+ double load15;
+
+ LONG h_queue[MAX_CPU_HISTORY]; /* queue history */
+ int h_queue_index;
+
+ HQUERY pdh_query;
+ PDH_RAW_COUNTER queue;
+ PDH_HCOUNTER queue_counter;
+
+ } ZBX_CPUS_STAT_DATA;
+
+#else /* not WIN32 */
+
+ #define MAX_CPU_HISTORY 900 /* 15 min in seconds */
+
+ typedef struct s_cpus_stat_data
+ {
+ int clock[MAX_CPU_HISTORY];
+ float h_user[MAX_CPU_HISTORY];
+ float h_system[MAX_CPU_HISTORY];
+ float h_nice[MAX_CPU_HISTORY];
+ float h_idle[MAX_CPU_HISTORY];
+
+ float idle;
+ float idle1;
+ float idle5;
+ float idle15;
+ float user;
+ float user1;
+ float user5;
+ float user15;
+ float system;
+ float system1;
+ float system5;
+ float system15;
+ float nice;
+ float nice1;
+ float nice5;
+ float nice15;
+ float all;
+ float all1;
+ float all5;
+ float all15;
+
+ } ZBX_CPUS_STAT_DATA;
+
+#endif /* WIN32 */
+
+
+int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus);
+void collect_cpustat(ZBX_CPUS_STAT_DATA *pcpus);
+void close_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus);
#endif
diff --git a/src/zabbix_agent/diskdevices.c b/src/zabbix_agent/diskdevices.c
index 8b2f91da..d0bae0d6 100644
--- a/src/zabbix_agent/diskdevices.c
+++ b/src/zabbix_agent/diskdevices.c
@@ -17,7 +17,21 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
+#include "common.h"
+#include "diskdevices.h"
+
+
+void collect_stats_diskdevices(ZBX_DISKDEVICES_DATA *pdiskdevices)
+{
+#if defined(TODO)
+#error "Realize function"
+#endif
+}
+
+
+#if 0 && (!defined(WIN32) || (defined(TODO) && defined(WIN32)))
+
+//TODO!!! Make same as cpustat.c
#include <netdb.h>
@@ -57,7 +71,6 @@
#include <dirent.h>
-#include "common.h"
#include "sysinfo.h"
#include "security.h"
#include "zabbix_agent.h"
@@ -124,10 +137,9 @@ void init_stats_diskdevices()
}
}
- file=fopen("/proc/stat","r");
- if(NULL == file)
+ if(NULL == (file = fopen("/proc/stat","r") ))
{
- fprintf(stderr, "Cannot open [%s] [%s]\n","/proc/stat", strerror(errno));
+ zbx_error("Cannot open [%s] [%s].","/proc/stat", strerror(errno));
return;
}
i=0;
@@ -166,7 +178,7 @@ void init_stats_diskdevices()
}
}
- fclose(file);
+ zbx_fclose(file);
}
/*
@@ -187,10 +199,9 @@ void init_stats_diskdevices()
}
}
- file=fopen("/proc/stat","r");
- if(NULL == file)
+ if(NULL == (file = fopen("/proc/stat","r") ))
{
- fprintf(stderr, "Cannot open [%s] [%m]\n","/proc/stat");
+ zbx_error("Cannot open [%s] [%m].","/proc/stat");
return;
}
i=0;
@@ -213,7 +224,7 @@ void init_stats_diskdevices()
i++;
}
- fclose(file);
+ zbx_fclose(file);
}
*/
@@ -470,10 +481,9 @@ void collect_stats_diskdevices(FILE *outfile)
now=time(NULL);
- file=fopen("/proc/stat","r");
- if(NULL == file)
+ if( NULL == (file = fopen("/proc/stat","r") ))
{
- fprintf(stderr, "Cannot open [%s] [%s]\n","/proc/stat", strerror(errno));
+ zbx_error("Cannot open [%s] [%s].","/proc/stat", strerror(errno));
return;
}
i=0;
@@ -505,9 +515,11 @@ void collect_stats_diskdevices(FILE *outfile)
}
}
- fclose(file);
+ zbx_fclose(file);
report_stats_diskdevices(outfile, now);
#endif /* HAVE_PROC_STAT */
}
+
+#endif /* TODO */
diff --git a/src/zabbix_agent/diskdevices.h b/src/zabbix_agent/diskdevices.h
index a8d28704..404c66b5 100644
--- a/src/zabbix_agent/diskdevices.h
+++ b/src/zabbix_agent/diskdevices.h
@@ -20,6 +20,29 @@
#ifndef ZABBIX_DISKDEVICES_H
#define ZABBIX_DISKDEVICES_H
+
+#define MAX_DISKDEVICES 8
+
+typedef struct c_single_diskdevice_data
+{
+ char *name;
+ int major;
+ int diskno;
+ int clock[60*15];
+ float read_io_ops[60*15];
+ float blks_read[60*15];
+ float write_io_ops[60*15];
+ float blks_write[60*15];
+} ZBX_SINGLE_DISKDEVICE_DATA;
+
+typedef struct c_diskdevices_data
+{
+ ZBX_SINGLE_DISKDEVICE_DATA device[MAX_DISKDEVICES];
+} ZBX_DISKDEVICES_DATA;
+
+void collect_stats_diskdevices(ZBX_DISKDEVICES_DATA *pdiskdevices);
+
+/*
#define MAX_DISKDEVICES 8
#define DISKDEVICE struct diskdevice_type
@@ -36,5 +59,5 @@ DISKDEVICE
};
void collect_stats_diskdevices(FILE *outfile);
-
+*/
#endif
diff --git a/src/zabbix_agent/interfaces.c b/src/zabbix_agent/interfaces.c
index 446d0ce0..1a3205a7 100644
--- a/src/zabbix_agent/interfaces.c
+++ b/src/zabbix_agent/interfaces.c
@@ -17,7 +17,21 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
+#include "common.h"
+#include "interfaces.h"
+
+
+void collect_stats_interfaces(ZBX_INTERFACES_DATA *pinterfaces)
+{
+#if defined(TODO)
+#error "Realize function"
+#endif
+}
+
+
+#if 0 && (!defined(WIN32) || (defined(TODO) && defined(WIN32)))
+
+//TODO!!! Make same as cpustat.c
#include <netdb.h>
@@ -50,7 +64,6 @@
/* Required for getpwuid */
#include <pwd.h>
-#include "common.h"
#include "sysinfo.h"
#include "security.h"
#include "zabbix_agent.h"
@@ -106,10 +119,9 @@ void init_stats_interfaces()
}
}
- file=fopen("/proc/net/dev","r");
- if(NULL == file)
+ if( NULL == (file = fopen("/proc/net/dev","r") ))
{
- fprintf(stderr, "Cannot open config file [%s] [%s]\n","/proc/net/dev", strerror(errno));
+ zbx_error("Cannot open statistic file [%s] [%s].","/proc/net/dev", strerror(errno));
return;
}
i=0;
@@ -132,7 +144,7 @@ void init_stats_interfaces()
i++;
}
- fclose(file);
+ zbx_fclose(file);
}
void report_stats_interfaces(FILE *file, int now)
@@ -343,10 +355,9 @@ void collect_stats_interfaces(FILE *outfile)
now=time(NULL);
- file=fopen("/proc/net/dev","r");
- if(NULL == file)
+ if(NULL == (file = fopen("/proc/net/dev","r") ))
{
- fprintf(stderr, "Cannot open config file [%s] [%s]\n","/proc/net/dev", strerror(errno));
+ zbx_error("Cannot open statistic file [%s] [%s].","/proc/net/dev", strerror(errno));
return;
}
@@ -388,9 +399,12 @@ void collect_stats_interfaces(FILE *outfile)
}
i++;
}
- fclose(file);
+ zbx_fclose(file);
report_stats_interfaces(outfile, now);
#endif /* HAVE_PROC_NET_DEV */
}
+
+#endif /* TODO */
+
diff --git a/src/zabbix_agent/interfaces.h b/src/zabbix_agent/interfaces.h
index 75eb723f..0b72074f 100644
--- a/src/zabbix_agent/interfaces.h
+++ b/src/zabbix_agent/interfaces.h
@@ -20,6 +20,25 @@
#ifndef ZABBIX_INTERFACES_H
#define ZABBIX_INTERFACES_H
+
+#define MAX_INTERFACE (16)
+
+typedef struct s_single_interface_data
+{
+ char *name;
+ int clock[60*15];
+ float sent[60*15];
+ float received[60*15];
+} ZBX_SINGLE_INTERFACE_DATA;
+
+typedef struct s_interfaces_data
+{
+ ZBX_SINGLE_INTERFACE_DATA intfs[MAX_INTERFACE];
+} ZBX_INTERFACES_DATA;
+
+void collect_stats_interfaces(ZBX_INTERFACES_DATA *pinterfaces);
+
+/*
#define MAX_INTERFACE 16
#define INTERFACE struct interface_type
@@ -32,5 +51,5 @@ INTERFACE
};
void collect_stats_interfaces(FILE *outfile);
-
+*/
#endif
diff --git a/src/zabbix_agent/listener.c b/src/zabbix_agent/listener.c
new file mode 100755
index 00000000..6a130806
--- /dev/null
+++ b/src/zabbix_agent/listener.c
@@ -0,0 +1,156 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "listener.h"
+
+#include "zbxsock.h"
+#include "cfg.h"
+#include "zbxconf.h"
+#include "stats.h"
+#include "sysinfo.h"
+#include "log.h"
+#include "zbxsecurity.h"
+
+#if defined(ZABBIX_SERVICE)
+# include "service.h"
+#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */
+# include "daemon.h"
+#endif /* ZABBIX_DAEMON */
+
+static void process_listener(ZBX_SOCKET sock)
+{
+ AGENT_RESULT result;
+
+ char command[MAX_STRING_LEN];
+ char value[MAX_STRING_LEN];
+ int ret = 0;
+
+ init_result(&result);
+
+ memset(&command, 0, MAX_STRING_LEN);
+
+ ret = zbx_sock_read(sock, (void *)command, MAX_STRING_LEN, CONFIG_TIMEOUT);
+
+ if(ret == SOCKET_ERROR)
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Error receiving data from socket: %s", strerror(errno));
+ return;
+ }
+ else if(ret == 0)
+ {
+ zabbix_log( LOG_LEVEL_DEBUG, "Read timeout");
+ return;
+ }
+
+ /*command[ret-2] = '\0'; *//* remove '\r\n' sumbols from recived command (WIN32) !!!TODO!!! correct win32 agent !!!TODO!!! */
+ command[ret-1] = '\0'; /* remove '\n' sumbols from recived command (LINUX) !!!TODO!!! */
+
+ zabbix_log(LOG_LEVEL_DEBUG, "Requested [%s]", command);
+
+ process(command, 0, &result);
+
+ if(result.type & AR_DOUBLE) zbx_snprintf(value, sizeof(value), "%f", result.dbl);
+ else if(result.type & AR_UINT64) zbx_snprintf(value, sizeof(value), ZBX_FS_UI64, result.ui64);
+ else if(result.type & AR_STRING) zbx_snprintf(value, sizeof(value), "%s", result.str);
+ else if(result.type & AR_TEXT) zbx_snprintf(value, sizeof(value), "%s", result.text);
+ else if(result.type & AR_MESSAGE) zbx_snprintf(value, sizeof(value), "%s", result.msg);
+
+ free_result(&result);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "Sending back [%s]", value);
+
+ ret = zbx_sock_write(sock, value, strlen(value));
+
+ if(ret == SOCKET_ERROR)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "Error writing to socket [%s]", strerror(errno));
+ }
+}
+
+ZBX_THREAD_ENTRY(listener_thread, pSock)
+{
+ int local_request_failed = 0;
+
+ ZBX_SOCKET sock, accept_sock;
+ ZBX_SOCKADDR serv_addr;
+ int nlen = 0;
+
+ assert(pSock);
+
+ zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd listener started");
+
+ sock = *((ZBX_SOCKET *)pSock);
+
+ while(ZBX_IS_RUNNING)
+ {
+ collector->requests.all++;
+ zbx_setproctitle("waiting for connection. Requests [%d]", collector->requests.all);
+
+ accept_sock = SOCKET_ERROR;
+ nlen = sizeof(ZBX_SOCKADDR);
+ if(SOCKET_ERROR == (accept_sock = accept(sock, (struct sockaddr *)&serv_addr, &nlen)))
+ {
+ if(!ZBX_IS_RUNNING) break;
+
+ if (EINTR != zbx_sock_last_error())
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Unable to accept incoming connection: [%s]", strerror_from_system(zbx_sock_last_error()));
+ }
+
+ local_request_failed++;
+
+ collector->requests.failed++;
+ if (local_request_failed > 1000)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Too many consecutive errors on accept() call.");
+ local_request_failed = 0;
+ }
+ zbx_sleep(1);
+ continue;
+ }
+ if(!ZBX_IS_RUNNING) break;
+
+ local_request_failed = 0; /* Reset consecutive errors counter */
+
+ zbx_setproctitle("processing request");
+
+ zabbix_log(LOG_LEVEL_DEBUG, "Processing request.");
+
+ if(SUCCEED == check_security(accept_sock, CONFIG_HOSTS_ALLOWED, 0))
+ {
+ collector->requests.accepted++;
+ process_listener(accept_sock);
+ }
+ else
+ {
+ collector->requests.rejected++;
+ }
+
+ shutdown(accept_sock,2);
+
+ zbx_sock_close(accept_sock);
+ }
+
+ zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd listener stopped");
+
+ ZBX_DO_EXIT();
+
+ zbx_tread_exit(0);
+}
diff --git a/src/zabbix_agent/listener.h b/src/zabbix_agent/listener.h
new file mode 100755
index 00000000..8d923096
--- /dev/null
+++ b/src/zabbix_agent/listener.h
@@ -0,0 +1,27 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_LISTENER_H
+#define ZABBIX_LISTENER_H
+
+#include "threads.h"
+
+ZBX_THREAD_ENTRY(listener_thread, pSock);
+
+#endif /* ZABBIX_LISTENER_H */
diff --git a/src/zabbix_agent/logfiles.c b/src/zabbix_agent/logfiles.c
index 30aa6d4b..bc248300 100644
--- a/src/zabbix_agent/logfiles.c
+++ b/src/zabbix_agent/logfiles.c
@@ -17,16 +17,6 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
#include "common.h"
#include "log.h"
@@ -34,10 +24,14 @@
int process_log(char *filename,long *lastlogsize, char *value)
{
- FILE *f;
+ FILE *f = NULL;
struct stat buf;
- zabbix_log( LOG_LEVEL_DEBUG, "In process log (%s,%ld)", filename, *lastlogsize);
+ assert(filename);
+ assert(lastlogsize);
+ assert(value);
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In process log (%s,%d)", filename, *lastlogsize);
/* Handling of file shrinking */
if(stat(filename,&buf) == 0)
@@ -50,33 +44,32 @@ int process_log(char *filename,long *lastlogsize, char *value)
else
{
zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
- snprintf(value,MAX_STRING_LEN-1,"%s","ZBX_NOTSUPPORTED\n");
+ zbx_snprintf(value, sizeof(value),"%s","ZBX_NOTSUPPORTED\n");
return 1;
}
- f=fopen(filename,"r");
- if(NULL == f)
+ if(NULL == (f = fopen(filename,"r") ))
{
zabbix_log( LOG_LEVEL_WARNING, "Cannot open [%s] [%s]", filename, strerror(errno));
- snprintf(value,MAX_STRING_LEN-1,"%s","ZBX_NOTSUPPORTED\n");
+ zbx_snprintf(value,sizeof(value),"%s","ZBX_NOTSUPPORTED\n");
return 1;
}
if(-1 == fseek(f,*lastlogsize,SEEK_SET))
{
- zabbix_log( LOG_LEVEL_WARNING, "Cannot set postition to [%ld] for [%s] [%s]", *lastlogsize, filename, strerror(errno));
- snprintf(value,MAX_STRING_LEN-1,"%s","ZBX_NOTSUPPORTED\n");
- fclose(f);
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot set postition to [%d] for [%s] [%s]", *lastlogsize, filename, strerror(errno));
+ zbx_snprintf(value,sizeof(value),"%s","ZBX_NOTSUPPORTED\n");
+ zbx_fclose(f);
return 1;
}
if(NULL == fgets(value, MAX_STRING_LEN-1, f))
{
/* EOF */
- fclose(f);
+ zbx_fclose(f);
return 1;
}
- fclose(f);
+ zbx_fclose(f);
*lastlogsize+=strlen(value);
diff --git a/src/zabbix_agent/messages.mc b/src/zabbix_agent/messages.mc
new file mode 100755
index 00000000..ee31c08b
--- /dev/null
+++ b/src/zabbix_agent/messages.mc
@@ -0,0 +1,17 @@
+;/****************************************************************************
+; Messages for Zabbix Win32 Agent
+;****************************************************************************/
+;
+;#ifndef _messages_h_
+;#define _messages_h_
+;
+
+MessageIdTypedef=DWORD
+
+MessageId=1
+SymbolicName=MSG_ZABBIX_MESSAGE
+Language=English
+ZABBIX LOG: %1
+.
+
+;#endif
diff --git a/src/zabbix_agent/resources.rc b/src/zabbix_agent/resources.rc
new file mode 100755
index 00000000..26a388d9
--- /dev/null
+++ b/src/zabbix_agent/resources.rc
@@ -0,0 +1,82 @@
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// Russian resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
+#ifdef _WIN32
+LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
+#pragma code_page(1251)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // Russian resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// bin
+//
+
+IDR_MESSAGES bin DISCARDABLE "MSG00001.bin"
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/src/zabbix_agent/stats.c b/src/zabbix_agent/stats.c
index 25e01046..f31d3943 100644
--- a/src/zabbix_agent/stats.c
+++ b/src/zabbix_agent/stats.c
@@ -17,84 +17,178 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
+#include "common.h"
+#include "stats.h"
-#include <netdb.h>
+#include "log.h"
+#include "mutexs.h"
+#include "zbxconf.h"
-#include <stdlib.h>
-#include <stdio.h>
+#include "interfaces.h"
+#include "diskdevices.h"
+#include "cpustat.h"
+#include "log.h"
+#include "cfg.h"
-#include <unistd.h>
-#include <signal.h>
+#if defined(ZABBIX_SERVICE)
+# include "service.h"
+#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */
+# include "daemon.h"
+#endif /* ZABBIX_DAEMON */
+
+ZBX_COLLECTOR_DATA *collector = NULL;
+
+#define ZBX_GET_SHM_KEY(smk_key) \
+ {if( -1 == (shm_key = ftok(CONFIG_FILE, (int)'z') )) \
+ { \
+ zbx_error("Can not create IPC key for path '%s', try to create for path '.' [%s]", CONFIG_FILE, strerror(errno)); \
+ if( -1 == (shm_key = ftok(".", (int)'z') )) \
+ { \
+ zbx_error("Can not create IPC key for path '.' [%s]", strerror(errno)); \
+ exit(1); \
+ } \
+ }}
+
+/******************************************************************************
+ * *
+ * Function: init_collector_data *
+ * *
+ * Purpose: Allocate memory for collector *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: Linux version allocate memory as shared. *
+ * *
+ ******************************************************************************/
+
+void init_collector_data(void)
+{
+#if defined (WIN32)
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+ collector = calloc(1, sizeof(ZBX_COLLECTOR_DATA));
-#include <time.h>
+ if(NULL == collector)
+ {
+ zabbix_log(LOG_LEVEL_CRIT, "Can't allocate memory for collector.");
+ exit(1);
-/* No warning for bzero */
-#include <string.h>
-#include <strings.h>
+ }
-/* For config file operations */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#else /* not WIN32 */
-/* For setpriority */
-#include <sys/time.h>
-#include <sys/resource.h>
+ key_t shm_key;
+ int shm_id;
-/* Required for getpwuid */
-#include <pwd.h>
+ ZBX_GET_SHM_KEY(shm_key);
-#include "common.h"
-#include "sysinfo.h"
-#include "security.h"
-#include "zabbix_agent.h"
+ shm_id = shmget(shm_key, sizeof(ZBX_COLLECTOR_DATA), IPC_CREAT | 0666);
-#include "log.h"
-#include "cfg.h"
-#include "stats.h"
+ if (-1 == shm_id)
+ {
+ zabbix_log(LOG_LEVEL_CRIT, "Can't allocate shared memory for collector. [%s]",strerror(errno));
+ exit(1);
+ }
+
+ collector = shmat(shm_id, 0, 0);
+
+ if ((void*)(-1) == collector)
+ {
+ zabbix_log(LOG_LEVEL_CRIT, "Can't attache shared memory for collector. [%s]",strerror(errno));
+ exit(1);
+ }
+
+#endif /* WIN32 */
+}
-/*INTERFACE interfaces[MAX_INTERFACE]=
+/******************************************************************************
+ * *
+ * Function: free_collector_data *
+ * *
+ * Purpose: Free memory aloccated for collector *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: Linux version allocate memory as shared. *
+ * *
+ ******************************************************************************/
+
+void free_collector_data(void)
{
- {0}
-};*/
+ if(NULL == collector) return;
-extern char *CONFIG_STAT_FILE;
+#if defined (WIN32)
-void collect_statistics()
+ free(collector);
+
+#else /* not WIN32 */
+
+ key_t shm_key;
+ int shm_id;
+
+ ZBX_GET_SHM_KEY(shm_key);
+
+ shm_id = shmget(shm_key, sizeof(ZBX_COLLECTOR_DATA), 0);
+
+ if (-1 == shm_id)
+ {
+ zabbix_log(LOG_LEVEL_ERR, "Can't find shared memory for collector. [%s]",strerror(errno));
+ exit(1);
+ }
+
+ shmctl(shm_id, IPC_RMID, 0);
+
+#endif /* WIN32 */
+
+ collector = NULL;
+}
+
+
+/******************************************************************************
+ * *
+ * Function: collector_thread *
+ * *
+ * Purpose: Collect system information *
+ * *
+ * Parameters: args - skipped *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+
+ZBX_THREAD_ENTRY(collector_thread, args)
{
- FILE *file;
+ zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd collector started");
- char tmpname[MAX_STRING_LEN];
+ init_cpu_collector(&(collector->cpus));
- for(;;)
+ while(ZBX_IS_RUNNING)
{
- memset(tmpname, 0, MAX_STRING_LEN);
- strscpy(tmpname, CONFIG_STAT_FILE);
- strncat(tmpname, "2", MAX_STRING_LEN);
- file=fopen(tmpname,"w");
- if(NULL == file)
- {
- zabbix_log( LOG_LEVEL_CRIT, "Cannot open file [%s] [%s]",tmpname, strerror(errno));
- return;
- }
- /* Here is list of functions to call periodically */
- collect_stats_interfaces(file);
- collect_stats_diskdevices(file);
- collect_stats_cpustat(file);
-
- fclose(file);
- if(-1 == rename(tmpname,CONFIG_STAT_FILE))
- {
- zabbix_log( LOG_LEVEL_CRIT, "Cannot rename file [%s] to [%s] [%s]",tmpname,CONFIG_STAT_FILE,strerror(errno));
- return;
- }
-
- sleep(1);
+ collect_cpustat(&(collector->cpus));
+
+ collect_stats_interfaces(&(collector->interfaces));
+ collect_stats_diskdevices(&(collector->diskdevices));
+
+ zbx_sleep(1);
}
+
+ close_cpu_collector(&(collector->cpus));
+
+ zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd collector stopped");
+
+ ZBX_DO_EXIT();
+
+ zbx_tread_exit(0);
}
+
diff --git a/src/zabbix_agent/stats.h b/src/zabbix_agent/stats.h
index ddd01bab..bf3b61fb 100644
--- a/src/zabbix_agent/stats.h
+++ b/src/zabbix_agent/stats.h
@@ -20,10 +20,33 @@
#ifndef ZABBIX_STATS_H
#define ZABBIX_STATS_H
+#include "threads.h"
+#include "cpustat.h"
#include "interfaces.h"
#include "diskdevices.h"
-#include "cpustat.h"
-void collect_statistics();
+typedef struct s_request_stat_data
+{
+ long all;
+ long failed;
+ long accepted;
+ long rejected;
+} ZBX_REQUESTS_DATA;
+
+typedef struct s_collector_data
+{
+ ZBX_REQUESTS_DATA requests;
+ ZBX_CPUS_STAT_DATA cpus;
+ ZBX_INTERFACES_DATA interfaces;
+ ZBX_DISKDEVICES_DATA diskdevices;
+} ZBX_COLLECTOR_DATA;
+
+extern ZBX_COLLECTOR_DATA *collector;
+
+
+ZBX_THREAD_ENTRY(collector_thread, pSemColectorStarted);
+
+void init_collector_data(void);
+void free_collector_data(void);
#endif
diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c
index 4524f4c3..642ae2a9 100644
--- a/src/zabbix_agent/zabbix_agent.c
+++ b/src/zabbix_agent/zabbix_agent.c
@@ -17,14 +17,15 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
-
#include "common.h"
+#include "zabbix_agent.h"
+
#include "cfg.h"
#include "log.h"
#include "sysinfo.h"
#include "security.h"
-#include "zabbix_agent.h"
+#include "zbxconf.h"
+#include "zbxgetopt.h"
char *progname = NULL;
char title_message[] = "ZABBIX Agent";
@@ -51,7 +52,7 @@ char *help_message[] = {
};
#endif
-struct option longopts[] =
+struct zbx_option longopts[] =
{
{"config", 1, 0, 'c'},
{"help", 0, 0, 'h'},
@@ -61,16 +62,14 @@ struct option longopts[] =
{0,0,0,0}
};
-char *CONFIG_FILE = NULL;
static char *CONFIG_HOSTS_ALLOWED = NULL;
-static int CONFIG_TIMEOUT = AGENT_TIMEOUT;
-int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
-void signal_handler( int sig )
+#ifdef TODO
+void child_signal_handler( int sig )
{
if( SIGALRM == sig )
{
- signal( SIGALRM, signal_handler );
+ signal( SIGALRM, child_signal_handler );
}
if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig )
@@ -114,6 +113,8 @@ void init_config(void)
parse_cfg_file(CONFIG_FILE,cfg);
}
+#endif /* TODO */
+
int main(int argc, char **argv)
{
char s[MAX_STRING_LEN];
@@ -121,6 +122,7 @@ int main(int argc, char **argv)
int ch;
int task = ZBX_TASK_START;
char *TEST_METRIC = NULL;
+
AGENT_RESULT result;
memset(&result, 0, sizeof(AGENT_RESULT));
@@ -128,10 +130,10 @@ int main(int argc, char **argv)
progname = argv[0];
/* Parse the command-line. */
- while ((ch = getopt_long(argc, argv, "c:hvpt:", longopts, NULL)) != EOF)
+ while ((ch = zbx_getopt_long(argc, argv, "c:hvpt:", longopts, NULL)) != EOF)
switch ((char) ch) {
case 'c':
- CONFIG_FILE = optarg;
+ CONFIG_FILE = zbx_optarg;
break;
case 'h':
help();
@@ -149,7 +151,7 @@ int main(int argc, char **argv)
if(task == ZBX_TASK_START)
{
task = ZBX_TASK_TEST_METRIC;
- TEST_METRIC = optarg;
+ TEST_METRIC = zbx_optarg;
}
break;
default:
@@ -157,33 +159,37 @@ int main(int argc, char **argv)
break;
}
-/* Must be before init_config() */
- init_metrics();
- init_config();
+ init_metrics(); // Must be before init_config()
-/* Do not create debug files */
+ load_config(1);
+
+ /* Do not create debug files */
zabbix_open_log(LOG_TYPE_SYSLOG,LOG_LEVEL_EMPTY,NULL);
- switch(task)
- {
- case ZBX_TASK_PRINT_SUPPORTED:
- test_parameters();
- exit(-1);
- break;
- case ZBX_TASK_TEST_METRIC:
- test_parameter(TEST_METRIC);
- exit(-1);
- break;
- case ZBX_TASK_SHOW_USAGE:
- usage();
- exit(-1);
- break;
- }
-
- signal( SIGINT, signal_handler );
- signal( SIGQUIT, signal_handler );
- signal( SIGTERM, signal_handler );
- signal( SIGALRM, signal_handler );
+ switch(task)
+ {
+ case ZBX_TASK_PRINT_SUPPORTED:
+ test_parameters();
+ exit(-1);
+ break;
+ case ZBX_TASK_TEST_METRIC:
+ test_parameter(TEST_METRIC);
+ exit(-1);
+ break;
+ case ZBX_TASK_SHOW_USAGE:
+ usage();
+ exit(-1);
+ break;
+ }
+
+#ifdef TODO
+
+ signal( SIGINT, child_signal_handler);
+ signal( SIGQUIT, child_signal_handler );
+ signal( SIGTERM, child_signal_handler );
+ signal( SIGALRM, child_signal_handler );
+
+#endif /* TODO */
alarm(CONFIG_TIMEOUT);
@@ -196,15 +202,15 @@ int main(int argc, char **argv)
process(s, 0, &result);
if(result.type & AR_DOUBLE)
- snprintf(value, MAX_STRING_LEN-1, "%f", result.dbl);
+ zbx_snprintf(value, sizeof(value), "%f", result.dbl);
else if(result.type & AR_UINT64)
- snprintf(value, MAX_STRING_LEN-1, ZBX_FS_UI64, result.ui64);
+ zbx_snprintf(value, sizeof(value), ZBX_FS_UI64, result.ui64);
else if(result.type & AR_STRING)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.str);
+ zbx_snprintf(value, sizeof(value), "%s", result.str);
else if(result.type & AR_TEXT)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.text);
+ zbx_snprintf(value, sizeof(value), "%s", result.text);
else if(result.type & AR_MESSAGE)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.msg);
+ zbx_snprintf(value, sizeof(value), "%s", result.msg);
free_result(&result);
printf("%s\n",value);
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index b06ab585..1367127c 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -17,642 +17,439 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-#include "config.h"
+#include "common.h"
-#include <netdb.h>
+#include "sysinfo.h"
+#include "security.h"
+#include "zabbix_agent.h"
-#include <stdlib.h>
-#include <stdio.h>
+#include "cfg.h"
+#include "log.h"
+#include "zbxconf.h"
+#include "zbxgetopt.h"
+#include "zbxsock.h"
+#include "mutexs.h"
+#include "alias.h"
-#include <unistd.h>
-#include <signal.h>
+#include "stats.h"
+#include "active.h"
+#include "listener.h"
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#if defined(ZABBIX_SERVICE)
+# include "service.h"
+#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */
+# include "daemon.h"
+#endif /* ZABBIX_DAEMON */
-/* No warning for bzero */
-#include <string.h>
-#include <strings.h>
-/* For config file operations */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+char *progname = NULL;
-/* For setpriority */
-#include <sys/time.h>
-#include <sys/resource.h>
-/* Required for getpwuid */
-#include <pwd.h>
+/* application TITLE */
-#include "common.h"
-#include "sysinfo.h"
-#include "security.h"
-#include "zabbix_agent.h"
+char title_message[] = "ZABBIX Agent"
+#if defined(ZABBIX_SERVICE)
+ " (service)"
+#elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */
+ " (daemon)"
+#endif /* ZABBIX_DAEMON */
+ ;
+/* end of application TITLE */
-#include "pid.h"
-#include "log.h"
-#include "cfg.h"
-#include "stats.h"
-#include "active.h"
-#define LISTENQ 1024
-char *progname = NULL;
-char title_message[] = "ZABBIX Agent (daemon)";
-char usage_message[] = "[-vhp] [-c <file>] [-t <metric>]";
-#ifndef HAVE_GETOPT_LONG
-char *help_message[] = {
- "Options:",
- " -c <file> Specify configuration file",
- " -h give this help",
- " -v display version number",
- " -p print supported metrics and exit",
- " -t <metric> test specified metric and exit",
- 0 /* end of text */
-};
-#else
+/* application USAGE message */
+
+char usage_message[] =
+ "[-vhp]"
+#if defined(WIN32)
+ " [-iusx]"
+#endif /* WIN32 */
+ " [-c <file>] [-t <metric>]";
+
+/*end of application USAGE message */
+
+
+
+/* application HELP message */
+
char *help_message[] = {
"Options:",
+ "",
" -c --config <file> Specify configuration file",
" -h --help give this help",
" -v --version display version number",
" -p --print print supported metrics and exit",
" -t --test <metric> test specified metric and exit",
+
+#if defined (WIN32)
+
+ "",
+ "Functions:",
+ "",
+ " -i --install install ZABIX agent as service",
+ " -u --uninstall uninstall ZABIX agent from service",
+
+ " -s --start start ZABIX agent service",
+ " -x --stop stop ZABIX agent service",
+
+#endif /* WIN32 */
+
0 /* end of text */
};
-#endif
-struct option longopts[] =
+/* end of application HELP message */
+
+
+
+/* COMMAND LINE OPTIONS */
+
+/* long options */
+
+static struct zbx_option longopts[] =
{
{"config", 1, 0, 'c'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'v'},
{"print", 0, 0, 'p'},
{"test", 1, 0, 't'},
- {0,0,0,0}
-};
-static pid_t *pids=NULL;
-int parent=0;
-/* Number of processed requests */
-int stats_request=0;
-
-
-char *CONFIG_HOSTS_ALLOWED = NULL;
-char *CONFIG_HOSTNAME = NULL;
-char *CONFIG_FILE = NULL;
-char *CONFIG_PID_FILE = NULL;
-char *CONFIG_STAT_FILE = NULL;
-char *CONFIG_LOG_FILE = NULL;
-int CONFIG_AGENTD_FORKS = AGENTD_FORKS;
-/*int CONFIG_NOTIMEWAIT = 0;*/
-int CONFIG_DISABLE_ACTIVE = 0;
-int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
-int CONFIG_TIMEOUT = AGENT_TIMEOUT;
-int CONFIG_LISTEN_PORT = 10050;
-int CONFIG_SERVER_PORT = 10051;
-int CONFIG_REFRESH_ACTIVE_CHECKS = 120;
-char *CONFIG_LISTEN_IP = NULL;
-int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING;
-
-void init_config(void);
-
-void uninit(void)
-{
- int i;
+#if defined (WIN32)
- if(parent == 1)
- {
- if(pids != NULL)
- {
- for(i = 0; i<CONFIG_AGENTD_FORKS; i++)
- {
- kill(pids[i],SIGTERM);
- }
- }
+ {"install", 0, 0, 'i'},
+ {"uninstall", 0, 0, 'u'},
- if( unlink(CONFIG_STAT_FILE) != 0)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot remove STAT file [%s]",
- CONFIG_STAT_FILE);
- }
+ {"start", 0, 0, 's'},
+ {"stop", 0, 0, 'x'},
- if( unlink(CONFIG_PID_FILE) != 0)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot remove PID file [%s]",
- CONFIG_PID_FILE);
- }
- }
-}
+#endif /* WIN32 */
-void signal_handler( int sig )
-{
- if( SIGALRM == sig )
- {
- signal( SIGALRM, signal_handler );
- zabbix_log( LOG_LEVEL_WARNING, "Timeout while answering request");
- }
- else if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig )
- {
- zabbix_log( LOG_LEVEL_WARNING, "Got signal. Exiting ...");
- uninit();
- exit( FAIL );
- }
-/* parent==1 is mandatory ! EXECUTE sends SIGCHLD as well (?) ... */
- else if( (SIGCHLD == sig) && (parent == 1) )
- {
- zabbix_log( LOG_LEVEL_WARNING, "One child process died. Exiting ...");
- uninit();
- exit( FAIL );
- }
- else if( SIGPIPE == sig)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Got SIGPIPE. Where it came from???");
- }
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "Got signal [%d]. Ignoring ...", sig);
- }
-}
+ {0,0,0,0}
+};
-void daemon_init(void)
-{
- int i;
- pid_t pid;
- struct passwd *pwd;
+/* short options */
- /* running as root ?*/
- if((getuid()==0) || (getgid()==0))
- {
- pwd = getpwnam("zabbix");
- if ( pwd == NULL )
- {
- fprintf(stderr,"User zabbix does not exist.\n");
- fprintf(stderr, "Cannot run as root !\n");
- exit(FAIL);
- }
- if( (setgid(pwd->pw_gid) ==-1) || (setuid(pwd->pw_uid) == -1) )
- {
- fprintf(stderr,"Cannot setgid or setuid to zabbix [%s]\n", strerror(errno));
- exit(FAIL);
- }
+static char shortopts[] =
+ "c:hvpt:"
+#if defined (WIN32)
+ "iusx"
+#endif /* WIN32 */
+ ;
-#ifdef HAVE_FUNCTION_SETEUID
- if( (setegid(pwd->pw_gid) ==-1) || (seteuid(pwd->pw_uid) == -1) )
- {
- fprintf(stderr,"Cannot setegid or seteuid to zabbix [%s]\n", strerror(errno));
- exit(FAIL);
- }
-#endif
+/* end of COMMAND LINE OPTIONS*/
- }
- /* Init log files */
- if(CONFIG_LOG_FILE == NULL)
- zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL);
- else
- zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE);
- if( (pid = fork()) != 0 )
- {
- exit( 0 );
- }
+static char *TEST_METRIC = NULL;
- setsid();
-
- signal( SIGHUP, SIG_IGN );
+static ZBX_THREAD_HANDLE *threads = NULL;
- if( (pid = fork()) !=0 )
- {
- exit( 0 );
- }
+static int parse_commandline(int argc, char **argv)
+{
+ int task = ZBX_TASK_START;
+ char ch = '\0';
- chdir("/");
-/* umask(022);*/
- umask(002);
- for(i=0;i<MAXFD;i++)
- {
- /* Do not close stderr */
- if(i != fileno(stderr)) close(i);
- }
+ /* Parse the command-line. */
+ while ((ch = zbx_getopt_long(argc, argv, shortopts, longopts, NULL)) != EOF)
+ switch ((char) ch) {
+ case 'c':
+ CONFIG_FILE = strdup(zbx_optarg);
+ break;
+ case 'h':
+ help();
+ exit(-1);
+ break;
+ case 'v':
+ version();
+ exit(-1);
+ break;
+ case 'p':
+ if(task == ZBX_TASK_START)
+ task = ZBX_TASK_PRINT_SUPPORTED;
+ break;
+ case 't':
+ if(task == ZBX_TASK_START)
+ {
+ task = ZBX_TASK_TEST_METRIC;
+ TEST_METRIC = strdup(zbx_optarg);
+ }
+ break;
-/* openlog("zabbix_agentd",LOG_LEVEL_PID,LOG_USER);
- setlogmask(LOG_UPTO(LOG_WARNING));*/
+#if defined (WIN32)
+ case 'i':
+ task = ZBX_TASK_INSTALL_SERVICE;
+ break;
+ case 'u':
+ task = ZBX_TASK_UNINSTALL_SERVICE;
+ break;
+ case 's':
+ task = ZBX_TASK_START_SERVICE;
+ break;
+ case 'x':
+ task = ZBX_TASK_STOP_SERVICE;
+ break;
+#endif /* WIN32 */
-#ifdef HAVE_SYS_RESOURCE_SETPRIORITY
- if(setpriority(PRIO_PROCESS,0,5)!=0)
- {
- fprintf(stderr, "Unable to set process priority to 5. Leaving default.\n");
+ default:
+ task = ZBX_TASK_SHOW_USAGE;
+ break;
}
-#endif
+ return task;
}
-int add_parameter(char *value)
+static ZBX_SOCKET connect_to_server(void)
{
- char *value2;
+ ZBX_SOCKET sock;
+ ZBX_SOCKADDR serv_addr;
- value2=strstr(value,",");
- if(NULL == value2)
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
- return FAIL;
- }
- value2[0]=0;
- value2++;
- add_user_parameter(value, value2);
- return SUCCEED;
-}
-
-void init_config(void)
-{
- struct cfg_line cfg[]=
- {
-/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX
-*/
- {"Server",&CONFIG_HOSTS_ALLOWED,0,TYPE_STRING,PARM_MAND,0,0},
- {"Hostname",&CONFIG_HOSTNAME,0,TYPE_STRING,PARM_OPT,0,0},
- {"PidFile",&CONFIG_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0},
- {"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0},
- {"StatFile",&CONFIG_STAT_FILE,0,TYPE_STRING,PARM_OPT,0,0},
- {"DisableActive",&CONFIG_DISABLE_ACTIVE,0,TYPE_INT,PARM_OPT,0,1},
- {"EnableRemoteCommands",&CONFIG_ENABLE_REMOTE_COMMANDS,0,TYPE_INT,PARM_OPT,0,1},
- {"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30},
-/* {"NoTimeWait",&CONFIG_NOTIMEWAIT,0,TYPE_INT,PARM_OPT,0,1},*/
- {"ListenPort",&CONFIG_LISTEN_PORT,0,TYPE_INT,PARM_OPT,1024,32767},
- {"ServerPort",&CONFIG_SERVER_PORT,0,TYPE_INT,PARM_OPT,1024,32767},
- {"ListenIP",&CONFIG_LISTEN_IP,0,TYPE_STRING,PARM_OPT,0,0},
- {"DebugLevel",&CONFIG_LOG_LEVEL,0,TYPE_INT,PARM_OPT,0,4},
- {"StartAgents",&CONFIG_AGENTD_FORKS,0,TYPE_INT,PARM_OPT,1,16},
- {"RefreshActiveChecks",&CONFIG_REFRESH_ACTIVE_CHECKS,0,TYPE_INT,PARM_OPT,60,3600},
- {0}
- };
- AGENT_RESULT result;
-
- memset(&result, 0, sizeof(AGENT_RESULT));
-
- if(CONFIG_FILE == NULL)
- {
- CONFIG_FILE = strdup("/etc/zabbix/zabbix_agentd.conf");
+ zabbix_log( LOG_LEVEL_CRIT, "Unable to create socket. [%s]", strerror_from_system(zbx_sock_last_error()));
+ exit(1);
}
- parse_cfg_file(CONFIG_FILE,cfg);
+ // Create socket // Fill in local address structure
+ memset(&serv_addr, 0, sizeof(ZBX_SOCKADDR));
- if(CONFIG_PID_FILE == NULL)
- {
- CONFIG_PID_FILE=strdup("/tmp/zabbix_agentd.pid");
- }
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = CONFIG_LISTEN_IP ? inet_addr(CONFIG_LISTEN_IP) : htonl(INADDR_ANY);
+ serv_addr.sin_port = htons((unsigned short)CONFIG_LISTEN_PORT);
- if(CONFIG_HOSTNAME == NULL)
+ // Bind socket
+ if (bind(sock,(struct sockaddr *)&serv_addr,sizeof(ZBX_SOCKADDR)) == SOCKET_ERROR)
{
- if(SUCCEED == process("system.hostname", 0, &result))
- {
- if(result.type & AR_STRING)
- {
- CONFIG_HOSTNAME=strdup(result.str);
- }
- }
- free_result(&result);
+ zabbix_log(LOG_LEVEL_CRIT, "Cannot bind to port %u for server %s. Error [%s]. Another zabbix_agentd already running ?",
+ CONFIG_LISTEN_PORT, CONFIG_LISTEN_IP, strerror_from_system(zbx_sock_last_error()));
- if(CONFIG_HOSTNAME == NULL)
- {
- zabbix_log( LOG_LEVEL_CRIT, "Hostname is not defined");
- exit(1);
- }
+ exit(1);
}
- if(CONFIG_STAT_FILE == NULL)
+ if(listen(sock, SOMAXCONN) == SOCKET_ERROR)
{
- CONFIG_STAT_FILE=strdup("/tmp/zabbix_agentd.tmp");
+ zabbix_log( LOG_LEVEL_CRIT, "Listen failed. [%s]", strerror_from_system(zbx_sock_last_error()));
+ exit(1);
}
-}
-void load_user_parameters(void)
-{
- struct cfg_line cfg[]=
- {
-/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX
-*/
- {"UserParameter",0,&add_parameter,0,0,0,0},
- {0}
- };
-
- parse_cfg_file(CONFIG_FILE,cfg);
+ return sock;
}
-void process_child(int sockfd)
+int MAIN_ZABBIX_ENTRY(void)
{
- ssize_t nread;
- char line[MAX_STRING_LEN];
- char value[MAX_STRING_LEN];
- int i;
+ ZBX_THREAD_ACTIVECHK_ARGS activechk_args;
- static struct sigaction phan;
- AGENT_RESULT result;
+ int i = 0;
- memset(&result, 0, sizeof(AGENT_RESULT));
-
- phan.sa_handler = &signal_handler; /* set up sig handler using sigaction() */
- sigemptyset(&phan.sa_mask);
- phan.sa_flags = 0;
- sigaction(SIGALRM, &phan, NULL);
+ ZBX_SOCKET sock;
+ zabbix_open_log(
+#if 1 /* !!! normal case must be 1 !!! */
+ LOG_TYPE_FILE
+#elif 0 /* !!! normal case must be 0 !!! */
+ LOG_TYPE_SYSLOG
+#else /* !!! for debug only, print log with zbx_error !!! */
+ LOG_TYPE_UNDEFINED
+#endif
+ ,
+ CONFIG_LOG_LEVEL,
+ CONFIG_LOG_FILE
+ );
- alarm(CONFIG_TIMEOUT);
+ zabbix_log(LOG_LEVEL_INFORMATION, "zabbix_agentd started. ZABBIX %s.", ZABBIX_VERSION);
- zabbix_log( LOG_LEVEL_DEBUG, "Before read()");
- if( (nread = read(sockfd, line, MAX_STRING_LEN)) < 0)
- {
- if(errno == EINTR)
- {
- zabbix_log( LOG_LEVEL_DEBUG, "Read timeout");
- }
- else
- {
- zabbix_log( LOG_LEVEL_DEBUG, "read() failed.");
- }
- zabbix_log( LOG_LEVEL_DEBUG, "After read() 1");
- alarm(0);
- return;
- }
- zabbix_log( LOG_LEVEL_DEBUG, "After read() 2 [%d]",nread);
-
- line[nread-1]=0;
-
- zabbix_log( LOG_LEVEL_DEBUG, "Got line:%s", line);
-
- process(line, 0, &result);
- if(result.type & AR_DOUBLE)
- snprintf(value, MAX_STRING_LEN-1, "%f", result.dbl);
- else if(result.type & AR_UINT64)
- snprintf(value, MAX_STRING_LEN-1, ZBX_FS_UI64, result.ui64);
- else if(result.type & AR_STRING)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.str);
- else if(result.type & AR_TEXT)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.text);
- else if(result.type & AR_MESSAGE)
- snprintf(value, MAX_STRING_LEN-1, "%s", result.msg);
- free_result(&result);
-
- zabbix_log( LOG_LEVEL_DEBUG, "Sending back:%s", value);
- i=write(sockfd, value, strlen(value));
- if(i == -1)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error writing to socket [%s]",
- strerror(errno));
- }
+ sock = connect_to_server();
- alarm(0);
-}
+ init_collector_data();
-int tcp_listen(const char *host, int port, socklen_t *addrlenp)
-{
- int sockfd;
- struct sockaddr_in serv_addr;
- int on;
+ /* --- START THREADS ---*/
+
+ threads = calloc(CONFIG_ZABBIX_FORKS, sizeof(ZBX_THREAD_HANDLE));
-/* struct linger ling;*/
+ threads[i=0] = zbx_thread_start(collector_thread, NULL);
- if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+ /* start listeners */
+ for(i++; i < CONFIG_ZABBIX_FORKS - ((0 == CONFIG_DISABLE_ACTIVE) ? 1 : 0); i++)
{
- zabbix_log( LOG_LEVEL_CRIT, "Unable to create socket");
- exit(1);
+ threads[i] = zbx_thread_start(listener_thread, &sock);
}
- /* Enable address reuse */
- /* This is to immediately use the address even if it is in TIME_WAIT state */
- /* http://www-128.ibm.com/developerworks/linux/library/l-sockpit/index.html */
- on = 1;
- if( -1 == setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) ))
+ /* start active chack */
+ if(0 == CONFIG_DISABLE_ACTIVE)
{
- zabbix_log(LOG_LEVEL_WARNING, "Cannot setsockopt SO_REUSEADDR [%s]", strerror(errno));
+ activechk_args.host = CONFIG_HOSTS_ALLOWED;
+ activechk_args.port = (unsigned short)CONFIG_SERVER_PORT;
+
+ threads[i] = zbx_thread_start(active_checks_thread, &activechk_args);
}
- /*
- if(CONFIG_NOTIMEWAIT == 1)
- {
- ling.l_onoff=1;
- ling.l_linger=0;
- if(setsockopt(sockfd,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling))==-1)
- {
- zabbix_log(LOG_LEVEL_WARNING, "Cannot setsockopt SO_LINGER [%s]", strerror(errno));
- }
- }*/
+#if !defined(WIN32)
+ /* Must be called after all child processes loading. */
+ init_main_process();
+#endif
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- if(CONFIG_LISTEN_IP == NULL)
- {
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- }
- else
+ /* wait for all threads exiting */
+ for(i = 0; i < CONFIG_ZABBIX_FORKS; i++)
{
- serv_addr.sin_addr.s_addr = inet_addr(CONFIG_LISTEN_IP);
+ if(zbx_thread_wait(threads[i]))
+ {
+ zabbix_log( LOG_LEVEL_DEBUG, "%li: thread is terminated", threads[i]);
+ ZBX_DO_EXIT();
+ }
}
- serv_addr.sin_port = htons(port);
- if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
- {
- zabbix_log( LOG_LEVEL_CRIT, "Cannot bind to port %d. Error [%s]. Another zabbix_agentd already running ?",
- port, strerror(errno));
- exit(1);
- }
+ free_collector_data();
- if(listen(sockfd, LISTENQ) != 0)
- {
- zabbix_log( LOG_LEVEL_CRIT, "Listen failed");
- exit(1);
- }
+ zbx_free(threads);
- *addrlenp = sizeof(serv_addr);
+ zbx_on_exit();
- return sockfd;
+ return SUCCEED;
}
-void child_passive_main(int i,int listenfd, int addrlen)
+void zbx_on_exit()
{
- int connfd;
- socklen_t clilen;
- struct sockaddr cliaddr;
+ zabbix_log(LOG_LEVEL_DEBUG, "zbx_on_exit() called.");
- zabbix_log( LOG_LEVEL_WARNING, "zabbix_agentd %ld started",(long)getpid());
+#if !defined(WIN32)
+
+ int i = 0;
- for(;;)
+ if(threads != NULL)
{
- clilen = addrlen;
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("waiting for connection. Requests [%d]", stats_request++);
-#endif
- connfd=accept(listenfd,&cliaddr, &clilen);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("processing request");
-#endif
- if( check_security(connfd, CONFIG_HOSTS_ALLOWED, 0) == SUCCEED)
+ for(i = 0; i<CONFIG_ZABBIX_FORKS ; i++)
{
- process_child(connfd);
+ if(threads[i]) {
+ kill(threads[i],SIGTERM);
+ threads[i] = (ZBX_THREAD_HANDLE)NULL;
+ }
}
- close(connfd);
}
+
+#endif /* not WIN32 */
+
+#ifdef USE_PID_FILE
+
+ daemon_stop();
+
+#endif /* USE_PID_FILE */
+
+ free_collector_data();
+ alias_list_free();
+
+ zbx_sleep(2); /* wait for all threads closing */
+
+ zabbix_log(LOG_LEVEL_INFORMATION, "ZABBIX Agent stopped");
+ zabbix_close_log();
+
+ exit(SUCCEED);
}
-pid_t child_passive_make(int i,int listenfd, int addrlen)
+static char* get_programm_name(char *path)
{
- pid_t pid;
-
- if((pid = fork()) >0)
- {
- return (pid);
- }
+ char *p;
+ char *filename;
- /* never returns */
- child_passive_main(i, listenfd, addrlen);
+ for(filename = p = path; p && *p; p++)
+ if(*p == '\\' || *p == '/')
+ filename = p+1;
- /* avoid compilator warning */
- return 0;
+ return filename;
}
+#ifndef ZABBIX_TEST
+
int main(int argc, char **argv)
{
- int listenfd;
- socklen_t addrlen;
- int i;
+ int task = ZBX_TASK_START;
- char host[128];
- int ch;
- char *s;
- int task = ZBX_TASK_START;
- char *TEST_METRIC = NULL;
+ progname = get_programm_name(argv[0]);
- static struct sigaction phan;
+ task = parse_commandline(argc, argv);
- progname = argv[0];
+ init_metrics(); // Must be before load_config(). load_config - use metrics!!!
-/* Parse the command-line. */
- while ((ch = getopt_long(argc, argv, "c:hvpt:", longopts, NULL)) != EOF)
- switch ((char) ch) {
- case 'c':
- CONFIG_FILE = optarg;
- break;
- case 'h':
- help();
- exit(-1);
- break;
- case 'v':
- version();
- exit(-1);
+ load_config(task == 0);
+
+ load_user_parameters();
+
+ switch(task)
+ {
+
+#if defined (WIN32)
+ case ZBX_TASK_INSTALL_SERVICE:
+ exit(ZabbixCreateService(argv[0]));
break;
- case 'p':
- if(task == ZBX_TASK_START)
- task = ZBX_TASK_PRINT_SUPPORTED;
+ case ZBX_TASK_UNINSTALL_SERVICE:
+ exit(ZabbixRemoveService());
break;
- case 't':
- if(task == ZBX_TASK_START)
- {
- task = ZBX_TASK_TEST_METRIC;
- TEST_METRIC = optarg;
- }
+ case ZBX_TASK_START_SERVICE:
+ exit(ZabbixStartService());
break;
- default:
- task = ZBX_TASK_SHOW_USAGE;
+ case ZBX_TASK_STOP_SERVICE:
+ exit(ZabbixStopService());
break;
- }
+#endif /* WIN32 */
-/* Must be before init_config() */
- init_metrics();
- init_config();
-
-/* Moved to daemon_init(), otherwise log files can be created as root */
-/* if(CONFIG_LOG_FILE == NULL)
- zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL);
- else
- zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE);*/
-
- load_user_parameters();
-
- switch(task)
- {
case ZBX_TASK_PRINT_SUPPORTED:
test_parameters();
- exit(-1);
+ exit(SUCCEED);
break;
case ZBX_TASK_TEST_METRIC:
test_parameter(TEST_METRIC);
- exit(-1);
+ exit(SUCCEED);
break;
case ZBX_TASK_SHOW_USAGE:
usage();
- exit(-1);
+ exit(FAIL);
break;
}
-
- daemon_init();
-
- phan.sa_handler = &signal_handler;
- sigemptyset(&phan.sa_mask);
- phan.sa_flags = 0;
- sigaction(SIGINT, &phan, NULL);
- sigaction(SIGQUIT, &phan, NULL);
- sigaction(SIGTERM, &phan, NULL);
- sigaction(SIGPIPE, &phan, NULL);
- if( FAIL == create_pid_file(CONFIG_PID_FILE))
- {
- return -1;
- }
+#if defined(WIN32)
+
+ service_start();
+
+#else /* not WIN32 */
+
+ daemon_start(CONFIG_ALLOW_ROOT_PERMISSION);
+
+#endif /* WIN32 */
- zabbix_log( LOG_LEVEL_WARNING, "zabbix_agentd started. ZABBIX %s.", ZABBIX_VERSION);
+ return SUCCEED;
+}
- if(gethostname(host,127) != 0)
- {
- zabbix_log( LOG_LEVEL_CRIT, "gethostname() failed");
- exit(FAIL);
- }
+#else /* ZABBIX_TEST */
- listenfd = tcp_listen(host,CONFIG_LISTEN_PORT,&addrlen);
+int main()
+{
+#if 0
+ char buffer[100*1024];
- pids = calloc(CONFIG_AGENTD_FORKS, sizeof(pid_t));
+ get_http_page("www.zabbix.com", "", 80, buffer, 100*1024);
- for(i = 0; i<CONFIG_AGENTD_FORKS-1; i++)
- {
- pids[i] = child_passive_make(i, listenfd, addrlen);
- }
+ printf("Back [%d] [%s]\n", strlen(buffer), buffer);
+
+#elif 1
- /* Initialize thread for active checks */
- if(CONFIG_DISABLE_ACTIVE==0)
- {
- s=strtok(CONFIG_HOSTS_ALLOWED,",");
- pids[CONFIG_AGENTD_FORKS-1] = child_active_make(CONFIG_AGENTD_FORKS-1, s, CONFIG_SERVER_PORT);
- }
+ char s[] = "ABCDEFGH";
+ char p[] = "D(.){0,}E";
+ int len=2;
- parent=1;
+ printf("String: \t %s\n", s);
+ printf("Pattern:\t %s\n", p);
+ printf("Result: \t [%s] [%d]\n", zbx_regexp_match(s, p, &len), len);
+/*
+#elif 1 // 0 - off; 1 - on;
-/* For parent only. To avoid problems with EXECUTE */
- sigaction(SIGCHLD, &phan, NULL);
+ Place your test code HERE!!!
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("main process");
-#endif
+*/
- collect_statistics();
+#endif /* 0 */
- uninit();
+}
-/*
-#ifdef HAVE_PROC_NET_DEV
- collect_statistics();
-#else
- for(;;)
- {
- pause();
- }
-#endif
-*/
+#endif /* not ZABBIX_TEST */
- return SUCCEED;
-}
diff --git a/src/zabbix_agent/zbxconf.c b/src/zabbix_agent/zbxconf.c
new file mode 100755
index 00000000..1a4a8d39
--- /dev/null
+++ b/src/zabbix_agent/zbxconf.c
@@ -0,0 +1,168 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+#include "zbxconf.h"
+
+#include "cfg.h"
+#include "log.h"
+#include "alias.h"
+#include "sysinfo.h"
+
+#if defined(ZABBIX_DAEMON)
+/* use pid file configureation */
+# include "daemon.h"
+#endif /* ZABBIX_DAEMON */
+
+#if defined(WITH_PLUGINS)
+/* use ZABBIX plugins configurations */
+# include "zbxplugin.h"
+#endif /* WITH_PLUGINS */
+
+#ifdef WIN32
+ static char DEFAULT_CONFIG_FILE[] = "C:\\zabbix_agentd.conf";
+#else /* not WIN32 */
+ static char DEFAULT_CONFIG_FILE[] = "/etc/zabbix/zabbix_agentd.conf";
+#endif /* WIN32 */
+
+#ifdef USE_PID_FILE
+ static char DEFAULT_PID_FILE[] = "/tmp/zabbix_agentd.pid";
+#endif /* USE_PID_FILE */
+
+char *CONFIG_HOSTS_ALLOWED = NULL;
+char *CONFIG_HOSTNAME = NULL;
+
+
+int CONFIG_DISABLE_ACTIVE = 0;
+int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
+int CONFIG_LISTEN_PORT = 10050;
+int CONFIG_SERVER_PORT = 10051;
+int CONFIG_REFRESH_ACTIVE_CHECKS = 120;
+char *CONFIG_LISTEN_IP = NULL;
+int CONFIG_LOG_LEVEL = LOG_LEVEL_INFORMATION;
+char CONFIG_LOG_UNRES_SYMB = 0;
+
+
+void load_config(int exit_on_error)
+{
+ struct cfg_line cfg[]=
+ {
+/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s), MANDATORY, MIN, MAX
+*/
+ {"Server", &CONFIG_HOSTS_ALLOWED, 0,TYPE_STRING, PARM_MAND, 0,0},
+ {"Hostname", &CONFIG_HOSTNAME, 0,TYPE_STRING, PARM_OPT, 0,0},
+
+#ifdef USE_PID_FILE
+ {"PidFile", &APP_PID_FILE, 0,TYPE_STRING, PARM_OPT, 0,0},
+#endif /* USE_PID_FILE */
+
+ {"LogFile", &CONFIG_LOG_FILE, 0,TYPE_STRING, PARM_OPT, 0,0},
+ {"DisableActive", &CONFIG_DISABLE_ACTIVE, 0,TYPE_INT, PARM_OPT, 0,1},
+ {"Timeout", &CONFIG_TIMEOUT, 0,TYPE_INT, PARM_OPT, 1,30},
+ {"ListenPort", &CONFIG_LISTEN_PORT, 0,TYPE_INT, PARM_OPT, 1024,32767},
+ {"ServerPort", &CONFIG_SERVER_PORT, 0,TYPE_INT, PARM_OPT, 1024,32767},
+ {"ListenIP", &CONFIG_LISTEN_IP, 0,TYPE_STRING, PARM_OPT, 0,0},
+
+ {"DebugLevel", &CONFIG_LOG_LEVEL, 0,TYPE_INT, PARM_OPT, 0,5},
+
+ {"StartAgents", &CONFIG_ZABBIX_FORKS, 0,TYPE_INT, PARM_OPT, 1,16},
+ {"RefreshActiveChecks", &CONFIG_REFRESH_ACTIVE_CHECKS, 0,TYPE_INT, PARM_OPT,60,3600},
+ {"EnableRemoteCommands",&CONFIG_ENABLE_REMOTE_COMMANDS, 0,TYPE_INT, PARM_OPT,0,1},
+ {"AllowRootPermission", &CONFIG_ALLOW_ROOT_PERMISSION, 0,TYPE_INT, PARM_OPT,0,1},
+
+// {"PerfCounter", &CONFIG_PERF_COUNTER, 0, TYPE_STRING,PARM_OPT,0,0},
+
+ {"LogUnresolvedSymbols",&CONFIG_LOG_UNRES_SYMB, 0, TYPE_STRING,PARM_OPT,0,1},
+
+ {"Alias", 0, &add_alias_from_config, TYPE_STRING,PARM_OPT,0,0},
+
+#if defined(WITH_PLUGINS)
+ {"Plugin", 0, &add_plugin, TYPE_STRING,PARM_OPT,0,0},
+#endif /* ZABBIX_DAEMON */
+
+ {0}
+ };
+
+ AGENT_RESULT result;
+
+ memset(&result, 0, sizeof(AGENT_RESULT));
+
+ if(CONFIG_FILE == NULL)
+ {
+ CONFIG_FILE = DEFAULT_CONFIG_FILE;
+ }
+
+ parse_cfg_file(CONFIG_FILE, cfg);
+
+#ifdef USE_PID_FILE
+ if(APP_PID_FILE == NULL)
+ {
+ APP_PID_FILE = DEFAULT_PID_FILE;
+ }
+#endif /* USE_PID_FILE */
+
+ if(CONFIG_HOSTNAME == NULL)
+ {
+ if(SUCCEED == process("system.hostname", 0, &result))
+ {
+ if(result.type & AR_STRING)
+ {
+ CONFIG_HOSTNAME = strdup(result.str);
+ }
+ }
+ free_result(&result);
+
+ if(CONFIG_HOSTNAME == NULL)
+ {
+ zabbix_log( LOG_LEVEL_CRIT, "Hostname is not defined");
+ if(exit_on_error)
+ {
+ exit(1);
+ }
+ }
+ }
+}
+
+static int add_parameter(char *key)
+{
+ char *command;
+
+ command = strstr(key,",");
+ if(NULL == command)
+ {
+ return FAIL;
+ }
+ command[0]=0;
+ command++;
+ add_user_parameter(key, command);
+ return SUCCEED;
+}
+
+void load_user_parameters(void)
+{
+ struct cfg_line cfg[]=
+ {
+/* PARAMETER, VAR, FUNC, TYPE(0i,1s), MANDATORY,MIN,MAX
+*/
+ {"UserParameter", 0, &add_parameter, 0, 0, 0, 0},
+ {0}
+ };
+
+ parse_cfg_file(CONFIG_FILE,cfg);
+}
diff --git a/src/zabbix_agent/zbxconf.h b/src/zabbix_agent/zbxconf.h
new file mode 100755
index 00000000..8602d9cf
--- /dev/null
+++ b/src/zabbix_agent/zbxconf.h
@@ -0,0 +1,38 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_ZBXCONF_H
+#define ZABBIX_ZBXCONF_H
+
+extern char *CONFIG_HOSTS_ALLOWED;
+extern char *CONFIG_HOSTNAME;
+/* extern int CONFIG_NOTIMEWAIT; */
+extern int CONFIG_DISABLE_ACTIVE;
+extern int CONFIG_ENABLE_REMOTE_COMMANDS;
+extern int CONFIG_LISTEN_PORT;
+extern int CONFIG_SERVER_PORT;
+extern int CONFIG_REFRESH_ACTIVE_CHECKS;
+extern char *CONFIG_LISTEN_IP;
+extern int CONFIG_LOG_LEVEL;
+extern char CONFIG_LOG_UNRES_SYMB;
+
+void load_config(int exit_on_error);
+void load_user_parameters(void);
+
+#endif /* ZABBIX_ZBXCONF_H */
diff --git a/src/zabbix_agent_win32/active.cpp b/src/zabbix_agent_win32/active.cpp
index 2740147b..08bbaabe 100755
--- a/src/zabbix_agent_win32/active.cpp
+++ b/src/zabbix_agent_win32/active.cpp
@@ -398,16 +398,16 @@ LOG_FUNC_CALL("In get_active_checks()");
{
case WSAETIMEDOUT:
zabbix_log( LOG_LEVEL_WARNING, "Timeout while receiving data from [%s:%d]",server,port);
- snprintf(error,max_error_len-1,"Timeout while receiving data from [%s:%d]",server,port);
+ zbx_snprintf(error,max_error_len,"Timeout while receiving data from [%s:%d]",server,port);
break;
case ECONNRESET:
zabbix_log( LOG_LEVEL_WARNING, "Connection reset by peer.");
- snprintf(error,max_error_len-1,"Connection reset by peer.");
+ zbx_snprintf(error,max_error_len,"Connection reset by peer.");
close(s);
return NETWORK_ERROR;
default:
zabbix_log( LOG_LEVEL_WARNING, "Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
- snprintf(error,max_error_len-1,"Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error while receiving data from [%s:%d] [%s]",server,port,strerror(errno));
}
close(s);
return FAIL;
@@ -696,9 +696,9 @@ LOG_FUNC_CALL("In refresh_metrics()");
while(get_active_checks(server, port, error, max_error_len) != SUCCEED)
{
LOG_DEBUG_INFO("s","Getting list of active checks failed. Will retry after 60 seconds");
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [sleeping for %d seconds]", 60*1000);
-#endif
+
+ zbx_setproctitle("poller [sleeping for %d seconds]", 60*1000);
+
Sleep(60*1000);
}
LOG_DEBUG_INFO("s","Out of refresh_metrics()");
diff --git a/src/zabbix_get/Makefile.am b/src/zabbix_get/Makefile.am
index b64c0978..b38e4ff8 100644
--- a/src/zabbix_get/Makefile.am
+++ b/src/zabbix_get/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS =
bin_PROGRAMS = zabbix_get
zabbix_get_SOURCES = zabbix_get.c
-zabbix_get_LDADD = ../libs/zbxcommon/libzbxcommon.a
+zabbix_get_LDADD = ../libs/zbxlog/libzbxlog.a ../libs/zbxcommon/libzbxcommon.a ../libs/zbxsys/libzbxsys.a
diff --git a/src/zabbix_get/zabbix_get.c b/src/zabbix_get/zabbix_get.c
index aa4ce152..595eef5d 100644
--- a/src/zabbix_get/zabbix_get.c
+++ b/src/zabbix_get/zabbix_get.c
@@ -103,12 +103,12 @@ static void signal_handler( int sig )
if( SIGALRM == sig )
{
signal( SIGALRM, signal_handler );
- fprintf(stderr,"Timeout while executing operation.\n");
+ zbx_error("Timeout while executing operation.");
}
if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig )
{
-/* fprintf(stderr,"\nGot QUIT or INT or TERM signal. Exiting..." ); */
+/* zbx_error("\nGot QUIT or INT or TERM signal. Exiting..." ); */
}
exit( FAIL );
}
@@ -149,7 +149,7 @@ static int get_value(char *server,int port,char *key,char *value)
if(hp==NULL)
{
- fprintf(stderr, "Error: %s\n", strerror(errno));
+ zbx_error("Error on gethostbyname. [%s]", strerror(errno));
return FAIL;
}
@@ -175,7 +175,7 @@ static int get_value(char *server,int port,char *key,char *value)
return FAIL;
}
- snprintf(tosend,sizeof(tosend)-1,"%s\n",key);
+ zbx_snprintf(tosend,sizeof(tosend),"%s\n",key);
if(write(s,tosend,strlen(tosend)) == -1)
/* if( sendto(s,tosend,strlen(tosend),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )*/
diff --git a/src/zabbix_sender/Makefile.am b/src/zabbix_sender/Makefile.am
index 9a868152..5d98d9f0 100644
--- a/src/zabbix_sender/Makefile.am
+++ b/src/zabbix_sender/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS =
bin_PROGRAMS = zabbix_sender
zabbix_sender_SOURCES = zabbix_sender.c
-zabbix_sender_LDADD = ../libs/zbxcommon/libzbxcommon.a
+zabbix_sender_LDADD = ../libs/zbxlog/libzbxlog.a ../libs/zbxcommon/libzbxcommon.a ../libs/zbxsys/libzbxsys.a ../libs/zbxcrypto/libzbxcrypto.a
diff --git a/src/zabbix_sender/zabbix_sender.c b/src/zabbix_sender/zabbix_sender.c
index a47bf9c2..c3f81c80 100644
--- a/src/zabbix_sender/zabbix_sender.c
+++ b/src/zabbix_sender/zabbix_sender.c
@@ -119,8 +119,8 @@ static int send_value(char *server,int port,char *hostname, char *key,char *valu
comms_create_request(hostname, key, value, lastlogsize, tosend, sizeof(tosend)-1);
-/* snprintf(tosend,sizeof(tosend)-1,"%s:%s\n",shortname,value);
- snprintf(tosend,sizeof(tosend)-1,"<req><host>%s</host><key>%s</key><data>%s</data></req>",hostname_b64,key_b64,value_b64); */
+/* zbx_snprintf(tosend,sizeof(tosend),"%s:%s\n",shortname,value);
+ zbx_snprintf(tosend,sizeof(tosend),"<req><host>%s</host><key>%s</key><data>%s</data></req>",hostname_b64,key_b64,value_b64); */
if(write(s, tosend,strlen(tosend)) == -1)
/* if( sendto(s,tosend,strlen(tosend),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )*/
diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am
index 58964430..8c168160 100644
--- a/src/zabbix_server/Makefile.am
+++ b/src/zabbix_server/Makefile.am
@@ -3,6 +3,11 @@ INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @SNMP_INCLUDE@
bin_PROGRAMS = zabbix_server
zabbix_server_SOURCES = evalfunc.c expression.c actions.c zlog.c functions.c server.c
+zabbix_server_CPPFLAGS = -DZABBIX_DAEMON
zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxsysinfo/@ARCH@/libzbxsysinfo2.a \
-../libs/zbxlog/libzbxlog.a ../libs/zbxpid/libzbxpid.a ../libs/zbxconf/libzbxconf.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a poller/libzbxpoller.a housekeeper/libzbxhousekeeper.a alerter/libzbxalerter.a timer/libzbxtimer.a trapper/libzbxtrapper.a ../libs/zbxemail/libzbxemail.a ../libs/zbxsms/libzbxsms.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxcommon/libzbxcommon.a @MYSQL_LIBS@ @PGSQL_LIBS@ @ORACLE_LIBS@ @LDAP_LIBS@ @SNMP_LIBS@
-zabbix_server_LDFLAGS=@MYSQL_LFLAGS@ @PGSQL_LFLAGS@ @ORACLE_LFLAGS@ @LDAP_LFLAGS@ @SNMP_LFLAGS@
+../libs/zbxlog/libzbxlog.a ../libs/zbxnix/libzbxnix.a ../libs/zbxsys/libzbxsys.a ../libs/zbxconf/libzbxconf.a \
+../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a poller/libzbxpoller.a housekeeper/libzbxhousekeeper.a \
+alerter/libzbxalerter.a timer/libzbxtimer.a trapper/libzbxtrapper.a ../libs/zbxemail/libzbxemail.a \
+../libs/zbxsms/libzbxsms.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxcommon/libzbxcommon.a \
+../libs/zbxcrypto/libzbxcrypto.a @MYSQL_LIBS@ @PGSQL_LIBS@ @ORACLE_LIBS@ @LDAP_LIBS@ @SNMP_LIBS@
+zabbix_server_LDFLAGS=@MYSQL_LFLAGS@ @PGSQL_LFLAGS@ @ORACLE_LFLAGS@ @LDAP_LFLAGS@ @SNMP_LFLAGS@ -DZABBIX_DEAMON
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index 4acc5f1e..5f1be76e 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -135,7 +135,7 @@ static void send_to_user_medias(DB_TRIGGER *trigger,DB_ACTION *action, int useri
DB_RESULT result;
DB_ROW row;
- snprintf(sql,sizeof(sql)-1,"select mediatypeid,sendto,active,severity,period from media where active=%d and userid=%d",MEDIA_STATUS_ACTIVE,userid);
+ zbx_snprintf(sql,sizeof(sql),"select mediatypeid,sendto,active,severity,period from media where active=%d and userid=%d",MEDIA_STATUS_ACTIVE,userid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -191,7 +191,7 @@ static void send_to_user(DB_TRIGGER *trigger,DB_ACTION *action)
}
else if(action->recipient == RECIPIENT_TYPE_GROUP)
{
- snprintf(sql,sizeof(sql)-1,"select u.userid from users u, users_groups ug where ug.usrgrpid=%d and ug.userid=u.userid", action->userid);
+ zbx_snprintf(sql,sizeof(sql),"select u.userid from users u, users_groups ug where ug.usrgrpid=%d and ug.userid=u.userid", action->userid);
result = DBselect(sql);
while((row=DBfetch(result)))
{
@@ -240,7 +240,7 @@ static void run_remote_command(char* host_name, char* command)
zabbix_log(LOG_LEVEL_DEBUG, "run_remote_command START [hostname: '%s', command: '%s']", host_name, command);
- snprintf(sql,sizeof(sql)-1,"select distinct host,ip,useip,port from hosts where host='%s'", host_name);
+ zbx_snprintf(sql,sizeof(sql),"select distinct host,ip,useip,port from hosts where host='%s'", host_name);
result = DBselect(sql);
row = DBfetch(result);
if(row)
@@ -250,7 +250,7 @@ static void run_remote_command(char* host_name, char* command)
item.useip=atoi(row[2]);
item.port=atoi(row[3]);
- snprintf(item.key,ITEM_KEY_LEN_MAX-1,"system.run[%s,nowait]",command);
+ zbx_snprintf(item.key,ITEM_KEY_LEN_MAX,"system.run[%s,nowait]",command);
alarm(CONFIG_TIMEOUT);
@@ -388,7 +388,7 @@ static int get_next_command(char** command_list, char** alias, int* is_group, ch
if(alias == '\0' || command == '\0') continue;
if(is_group)
{
- snprintf(sql,sizeof(sql)-1,"select distinct h.host from hosts_groups hg,hosts h, groups g where hg.hostid=h.hostid and hg.groupid=g.groupid and g.name='%s'", alias);
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.host from hosts_groups hg,hosts h, groups g where hg.hostid=h.hostid and hg.groupid=g.groupid and g.name='%s'", alias);
result = DBselect(sql);
while((row=DBfetch(result)))
{
@@ -418,7 +418,7 @@ static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigge
if(condition->conditiontype == CONDITION_TYPE_HOST_GROUP)
{
- snprintf(sql,sizeof(sql)-1,"select distinct hg.groupid from hosts_groups hg,hosts h, items i, functions f, triggers t where hg.hostid=h.hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct hg.groupid from hosts_groups hg,hosts h, items i, functions f, triggers t where hg.hostid=h.hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", trigger->triggerid);
result = DBselect(sql);
while((row=DBfetch(result)))
{
@@ -448,7 +448,7 @@ static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigge
}
else if(condition->conditiontype == CONDITION_TYPE_HOST)
{
- snprintf(sql,sizeof(sql)-1,"select distinct h.hostid from hosts h, items i, functions f, triggers t where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.hostid from hosts h, items i, functions f, triggers t where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", trigger->triggerid);
result = DBselect(sql);
while((row=DBfetch(result)))
{
@@ -605,7 +605,7 @@ static int check_action_conditions(DB_TRIGGER *trigger,int alarmid,int new_trigg
zabbix_log( LOG_LEVEL_DEBUG, "In check_action_conditions [actionid:%d]", actionid);
- snprintf(sql,sizeof(sql)-1,"select conditionid,actionid,conditiontype,operator,value from conditions where actionid=%d order by conditiontype", actionid);
+ zbx_snprintf(sql,sizeof(sql),"select conditionid,actionid,conditiontype,operator,value from conditions where actionid=%d order by conditiontype", actionid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -664,7 +664,7 @@ void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value)
{
zabbix_log( LOG_LEVEL_DEBUG, "Check dependencies");
- snprintf(sql,sizeof(sql)-1,"select count(*) from trigger_depends d,triggers t where d.triggerid_down=%d and d.triggerid_up=t.triggerid and t.value=%d",trigger->triggerid, TRIGGER_VALUE_TRUE);
+ zbx_snprintf(sql,sizeof(sql),"select count(*) from trigger_depends d,triggers t where d.triggerid_down=%d and d.triggerid_up=t.triggerid and t.value=%d",trigger->triggerid, TRIGGER_VALUE_TRUE);
result = DBselect(sql);
row=DBfetch(result);
if(row && DBis_null(row[0]) != SUCCEED)
@@ -683,11 +683,11 @@ void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value)
/* now = time(NULL);*/
-/* snprintf(sql,sizeof(sql)-1,"select actionid,userid,delay,subject,message,scope,severity,recipient,good from actions where (scope=%d and triggerid=%d and good=%d and nextcheck<=%d) or (scope=%d and good=%d) or (scope=%d and good=%d)",ACTION_SCOPE_TRIGGER,trigger->triggerid,trigger_value,now,ACTION_SCOPE_HOST,trigger_value,ACTION_SCOPE_HOSTS,trigger_value);*/
-/* snprintf(sql,sizeof(sql)-1,"select actionid,userid,delay,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where nextcheck<=%d and status=%d", now, ACTION_STATUS_ACTIVE);*/
+/* zbx_snprintf(sql,sizeof(sql),"select actionid,userid,delay,subject,message,scope,severity,recipient,good from actions where (scope=%d and triggerid=%d and good=%d and nextcheck<=%d) or (scope=%d and good=%d) or (scope=%d and good=%d)",ACTION_SCOPE_TRIGGER,trigger->triggerid,trigger_value,now,ACTION_SCOPE_HOST,trigger_value,ACTION_SCOPE_HOSTS,trigger_value);*/
+/* zbx_snprintf(sql,sizeof(sql),"select actionid,userid,delay,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where nextcheck<=%d and status=%d", now, ACTION_STATUS_ACTIVE);*/
/* No support of action delay anymore */
- snprintf(sql,sizeof(sql)-1,"select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where status=%d", ACTION_STATUS_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where status=%d", ACTION_STATUS_ACTIVE);
result = DBselect(sql);
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql);
@@ -716,7 +716,7 @@ void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value)
else
run_commands(trigger,&action);
-/* snprintf(sql,sizeof(sql)-1,"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid);
+/* zbx_snprintf(sql,sizeof(sql),"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid);
DBexecute(sql);*/
}
else
diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c
index e36519af..54c854a7 100644
--- a/src/zabbix_server/alerter/alerter.c
+++ b/src/zabbix_server/alerter/alerter.c
@@ -53,26 +53,7 @@
#include "sms.h"
#include "alerter.h"
-
-/******************************************************************************
- * *
- * Function: signal_handler *
- * *
- * Purpose: dummy signal handler *
- * *
- * Parameters: sign - signal id *
- * *
- * Return value: *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: *
- * *
- ******************************************************************************/
-static void signal_handler2( int sig )
-{
- zabbix_log( LOG_LEVEL_DEBUG, "Got signal [%d]", sig);
-}
+#include "daemon.h"
/******************************************************************************
* *
@@ -93,8 +74,7 @@ static void signal_handler2( int sig )
******************************************************************************/
static int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max_error_len)
{
- int res=FAIL;
- struct sigaction phan;
+ int res=FAIL;
int pid;
char full_path[MAX_STRING_LEN];
@@ -115,14 +95,6 @@ static int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error,
/* if(-1 == execl(CONFIG_ALERT_SCRIPTS_PATH,mediatype->exec_path,alert->sendto,alert->subject,alert->message))*/
zabbix_log( LOG_LEVEL_DEBUG, "Before execl([%s],[%s])",CONFIG_ALERT_SCRIPTS_PATH,mediatype->exec_path);
- phan.sa_handler = &signal_handler2;
- phan.sa_handler = SIG_IGN;
-/* signal( SIGCHLD, SIG_IGN );*/
-
- sigemptyset(&phan.sa_mask);
- phan.sa_flags = 0;
- sigaction(SIGCHLD, &phan, NULL);
-
/* if(-1 == execl("/home/zabbix/bin/lmt.sh","lmt.sh",alert->sendto,alert->subject,alert->message,(char *)0))*/
pid=fork();
@@ -140,7 +112,7 @@ static int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error,
{
zabbix_log( LOG_LEVEL_ERR, "Error executing [%s] [%s]", full_path, strerror(errno));
zabbix_syslog("Error executing [%s] [%s]", full_path, strerror(errno));
- snprintf(error,max_error_len-1,"Error executing [%s] [%s]", full_path, strerror(errno));
+ zbx_snprintf(error,max_error_len,"Error executing [%s] [%s]", full_path, strerror(errno));
res = FAIL;
}
else
@@ -157,7 +129,7 @@ static int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error,
{
zabbix_log( LOG_LEVEL_ERR, "Unsupported media type [%d] for alert ID [%d]", mediatype->type,alert->alertid);
zabbix_syslog("Unsupported media type [%d] for alert ID [%d]", mediatype->type,alert->alertid);
- snprintf(error,max_error_len-1,"Unsupported media type [%d]", mediatype->type);
+ zbx_snprintf(error,max_error_len,"Unsupported media type [%d]", mediatype->type);
res=FAIL;
}
@@ -198,16 +170,15 @@ int main_alerter_loop()
for(;;)
{
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("connecting to the database");
-#endif
+
+ zbx_setproctitle("connecting to the database");
DBconnect();
now = time(NULL);
-/* snprintf(sql,sizeof(sql)-1,"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path from alerts a,media_type mt where a.status=0 and a.retries<3 and a.mediatypeid=mt.mediatypeid order by a.clock"); */
- snprintf(sql,sizeof(sql)-1,"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem from alerts a,media_type mt where a.status=%d and a.retries<3 and (a.repeats<a.maxrepeats or a.maxrepeats=0) and a.nextcheck<=%d and a.mediatypeid=mt.mediatypeid order by a.clock", ALERT_STATUS_NOT_SENT, now);
+/* zbx_snprintf(sql,sizeof(sql),"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path from alerts a,media_type mt where a.status=0 and a.retries<3 and a.mediatypeid=mt.mediatypeid order by a.clock"); */
+ zbx_snprintf(sql,sizeof(sql),"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem from alerts a,media_type mt where a.status=%d and a.retries<3 and (a.repeats<a.maxrepeats or a.maxrepeats=0) and a.nextcheck<=%d and a.mediatypeid=mt.mediatypeid order by a.clock", ALERT_STATUS_NOT_SENT, now);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -232,7 +203,7 @@ int main_alerter_loop()
mediatype.gsm_modem=row[15];
- phan.sa_handler = &signal_handler;
+ phan.sa_handler = child_signal_handler;
sigemptyset(&phan.sa_mask);
phan.sa_flags = 0;
sigaction(SIGALRM, &phan, NULL);
@@ -246,9 +217,9 @@ int main_alerter_loop()
if(res==SUCCEED)
{
zabbix_log( LOG_LEVEL_DEBUG, "Alert ID [%d] was sent successfully", alert.alertid);
- snprintf(sql,sizeof(sql)-1,"update alerts set repeats=repeats+1, nextcheck=%d where alertid=%d", now+alert.delay, alert.alertid);
+ zbx_snprintf(sql,sizeof(sql),"update alerts set repeats=repeats+1, nextcheck=%d where alertid=%d", now+alert.delay, alert.alertid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"update alerts set status=%d where alertid=%d and repeats>=maxrepeats and status=%d and retries<3", ALERT_STATUS_SENT, alert.alertid, ALERT_STATUS_NOT_SENT);
+ zbx_snprintf(sql,sizeof(sql),"update alerts set status=%d where alertid=%d and repeats>=maxrepeats and status=%d and retries<3", ALERT_STATUS_SENT, alert.alertid, ALERT_STATUS_NOT_SENT);
DBexecute(sql);
}
else
@@ -256,7 +227,7 @@ int main_alerter_loop()
zabbix_log( LOG_LEVEL_DEBUG, "Error sending alert ID [%d]", alert.alertid);
zabbix_syslog("Error sending alert ID [%d]", alert.alertid);
DBescape_string(error,error_esc,MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"update alerts set retries=retries+1,error='%s' where alertid=%d", error_esc, alert.alertid);
+ zbx_snprintf(sql,sizeof(sql),"update alerts set retries=retries+1,error='%s' where alertid=%d", error_esc, alert.alertid);
DBexecute(sql);
}
@@ -264,9 +235,8 @@ int main_alerter_loop()
DBfree_result(result);
DBclose();
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("sender [sleeping for %d seconds]", CONFIG_SENDER_FREQUENCY);
-#endif
+
+ zbx_setproctitle("sender [sleeping for %d seconds]", CONFIG_SENDER_FREQUENCY);
sleep(CONFIG_SENDER_FREQUENCY);
}
diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c
index 7a6157e8..44f0100d 100644
--- a/src/zabbix_server/evalfunc.c
+++ b/src/zabbix_server/evalfunc.c
@@ -79,7 +79,7 @@ static int evaluate_LOGSOURCE(char *value, DB_ITEM *item, char *parameter)
now=time(NULL);
- snprintf(sql,sizeof(sql)-1,"select source from history_log where itemid=%d order by clock desc",item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select source from history_log where itemid=%d order by clock desc",item->itemid);
result = DBselectN(sql,1);
row = DBfetch(result);
@@ -138,7 +138,7 @@ static int evaluate_LOGSEVERITY(char *value, DB_ITEM *item, char *parameter)
now=time(NULL);
- snprintf(sql,sizeof(sql)-1,"select severity from history_log where itemid=%d order by clock desc",item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select severity from history_log where itemid=%d order by clock desc",item->itemid);
result = DBselectN(sql,1);
row = DBfetch(result);
@@ -198,7 +198,7 @@ static int evaluate_COUNT(char *value, DB_ITEM *item, int parameter)
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select count(value) from %s where clock>%d and itemid=%d",table,now-parameter,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select count(value) from %s where clock>%d and itemid=%d",table,now-parameter,item->itemid);
result = DBselect(sql);
row = DBfetch(result);
@@ -263,7 +263,7 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag)
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select sum(value) from %s where clock>%d and itemid=%d",table, now-parameter,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select sum(value) from %s where clock>%d and itemid=%d",table, now-parameter,item->itemid);
result = DBselect(sql);
row = DBfetch(result);
@@ -287,7 +287,7 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag)
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select value from %s where itemid=%d order by clock desc",table,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=%d order by clock desc",table,item->itemid);
result = DBselectN(sql, parameter);
row = DBfetch(result);
if(!row || DBis_null(row[0])==SUCCEED)
@@ -305,12 +305,12 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag)
#else
sum_uint64+=atol(row[0]);
#endif
- snprintf(value,MAX_STRING_LEN-1,ZBX_FS_UI64, sum_uint64);
+ zbx_snprintf(value,MAX_STRING_LEN,ZBX_FS_UI64, sum_uint64);
}
else
{
while((row=DBfetch(result))) sum+=atof(row[0]);
- snprintf(value,MAX_STRING_LEN-1,"%f", sum);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f", sum);
}
}
}
@@ -362,7 +362,7 @@ static int evaluate_AVG(char *value,DB_ITEM *item,int parameter,int flag)
if(flag == ZBX_FLAG_SEC)
{
- snprintf(sql,sizeof(sql)-1,"select avg(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select avg(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid);
result = DBselect(sql);
row = DBfetch(result);
@@ -380,7 +380,7 @@ static int evaluate_AVG(char *value,DB_ITEM *item,int parameter,int flag)
}
else if(flag == ZBX_FLAG_VALUES)
{
- snprintf(sql,sizeof(sql)-1,"select value from history where itemid=%d order by clock desc",item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select value from history where itemid=%d order by clock desc",item->itemid);
result = DBselectN(sql, parameter);
rows=0;
while((row=DBfetch(result)))
@@ -395,7 +395,7 @@ static int evaluate_AVG(char *value,DB_ITEM *item,int parameter,int flag)
}
else
{
- snprintf(value,MAX_STRING_LEN-1,"%f", sum/(double)rows);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f", sum/(double)rows);
}
}
else
@@ -460,7 +460,7 @@ static int evaluate_MIN(char *value,DB_ITEM *item,int parameter, int flag)
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select min(value) from %s where clock>%d and itemid=%d",table, now-parameter,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select min(value) from %s where clock>%d and itemid=%d",table, now-parameter,item->itemid);
result = DBselect(sql);
row = DBfetch(result);
if(!row || DBis_null(row[0])==SUCCEED)
@@ -484,7 +484,7 @@ static int evaluate_MIN(char *value,DB_ITEM *item,int parameter, int flag)
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select value from %s where itemid=%d order by clock desc",table,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=%d order by clock desc",table,item->itemid);
result = DBselectN(sql,parameter);
rows=0;
@@ -518,11 +518,11 @@ static int evaluate_MIN(char *value,DB_ITEM *item,int parameter, int flag)
{
if(item->value_type == ITEM_VALUE_TYPE_UINT64)
{
- snprintf(value,MAX_STRING_LEN-1,ZBX_FS_UI64, min_uint64);
+ zbx_snprintf(value,MAX_STRING_LEN,ZBX_FS_UI64, min_uint64);
}
else
{
- snprintf(value,MAX_STRING_LEN-1,"%f", min);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f", min);
}
}
}
@@ -589,7 +589,7 @@ static int evaluate_MAX(char *value,DB_ITEM *item,int parameter,int flag)
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select max(value) from %s where clock>%d and itemid=%d",table,now-parameter,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select max(value) from %s where clock>%d and itemid=%d",table,now-parameter,item->itemid);
zabbix_log(LOG_LEVEL_DEBUG, "DBselect" );
result = DBselect(sql);
@@ -620,7 +620,7 @@ zabbix_log(LOG_LEVEL_DEBUG, "del_zeroes" );
{
strscpy(table,"history");
}
- snprintf(sql,sizeof(sql)-1,"select value from %s where itemid=%d order by clock desc",table,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=%d order by clock desc",table,item->itemid);
result = DBselectN(sql,parameter);
rows=0;
while((row=DBfetch(result)))
@@ -652,11 +652,11 @@ zabbix_log(LOG_LEVEL_DEBUG, "del_zeroes" );
{
if(item->value_type == ITEM_VALUE_TYPE_UINT64)
{
- snprintf(value,MAX_STRING_LEN-1,ZBX_FS_UI64, max_uint64);
+ zbx_snprintf(value,MAX_STRING_LEN,ZBX_FS_UI64, max_uint64);
}
else
{
- snprintf(value,MAX_STRING_LEN-1,"%f", max);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f", max);
}
}
}
@@ -713,7 +713,7 @@ static int evaluate_DELTA(char *value,DB_ITEM *item,int parameter, int flag)
if(flag == ZBX_FLAG_SEC)
{
- snprintf(sql,sizeof(sql)-1,"select max(value)-min(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select max(value)-min(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid);
result = DBselect(sql);
row = DBfetch(result);
@@ -730,7 +730,7 @@ static int evaluate_DELTA(char *value,DB_ITEM *item,int parameter, int flag)
}
else if(flag == ZBX_FLAG_VALUES)
{
- snprintf(sql,sizeof(sql)-1,"select value from history where itemid=%d order by clock desc",item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"select value from history where itemid=%d order by clock desc",item->itemid);
result = DBselectN(sql,parameter);
rows=0;
while((row=DBfetch(result)))
@@ -754,7 +754,7 @@ static int evaluate_DELTA(char *value,DB_ITEM *item,int parameter, int flag)
}
else
{
- snprintf(value,MAX_STRING_LEN-1,"%f", max-min);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f", max-min);
}
}
else
@@ -850,7 +850,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
if( (item->value_type==ITEM_VALUE_TYPE_FLOAT) || (item->value_type==ITEM_VALUE_TYPE_UINT64))
{
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 1");
- snprintf(value,MAX_STRING_LEN-1,"%f",item->lastvalue);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f",item->lastvalue);
del_zeroes(value);
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 2 value [%s]", value);
}
@@ -873,7 +873,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
{
if( (item->value_type==ITEM_VALUE_TYPE_FLOAT) || (item->value_type==ITEM_VALUE_TYPE_UINT64))
{
- snprintf(value,MAX_STRING_LEN-1,"%f",item->prevvalue);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f",item->prevvalue);
del_zeroes(value);
}
else
@@ -929,7 +929,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
{
now=time(NULL);
tm=localtime(&now);
- snprintf(value,MAX_STRING_LEN-1,"%.4d%.2d%.2d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday);
+ zbx_snprintf(value,MAX_STRING_LEN,"%.4d%.2d%.2d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday);
}
else if(strcmp(function,"dayofweek")==0)
{
@@ -938,13 +938,13 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
/* The number of days since Sunday, in the range 0 to 6. */
day=tm->tm_wday;
if(0 == day) day=7;
- snprintf(value,MAX_STRING_LEN-1,"%d", day);
+ zbx_snprintf(value,MAX_STRING_LEN,"%d", day);
}
else if(strcmp(function,"time")==0)
{
now=time(NULL);
tm=localtime(&now);
- snprintf(value,MAX_STRING_LEN-1,"%.2d%.2d%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
+ zbx_snprintf(value,MAX_STRING_LEN,"%.2d%.2d%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
}
else if(strcmp(function,"abschange")==0)
{
@@ -956,7 +956,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
{
if( (item->value_type==ITEM_VALUE_TYPE_FLOAT) || (item->value_type==ITEM_VALUE_TYPE_UINT64))
{
- snprintf(value,MAX_STRING_LEN-1,"%f",(float)abs(item->lastvalue-item->prevvalue));
+ zbx_snprintf(value,MAX_STRING_LEN,"%f",(float)abs(item->lastvalue-item->prevvalue));
del_zeroes(value);
}
else
@@ -982,7 +982,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
{
if(item->value_type==ITEM_VALUE_TYPE_FLOAT)
{
- snprintf(value,MAX_STRING_LEN-1,"%f",item->lastvalue-item->prevvalue);
+ zbx_snprintf(value,MAX_STRING_LEN,"%f",item->lastvalue-item->prevvalue);
del_zeroes(value);
}
else
@@ -1071,7 +1071,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter)
else if(strcmp(function,"now")==0)
{
now=time(NULL);
- snprintf(value,MAX_STRING_LEN-1,"%d",(int)now);
+ zbx_snprintf(value,MAX_STRING_LEN,"%d",(int)now);
}
else if(strcmp(function,"fuzzytime")==0)
{
@@ -1186,11 +1186,11 @@ int add_value_suffix(char *value, DB_ITEM *item)
/* if(cmp_double((double)round(value_float), value_float) == 0) */
if(cmp_double((int)(value_float+0.5), value_float) == 0)
{
- snprintf(value, MAX_STRING_LEN-1, "%.0f %s%s", value_float, suffix, item->units);
+ zbx_snprintf(value, MAX_STRING_LEN, "%.0f %s%s", value_float, suffix, item->units);
}
else
{
- snprintf(value, MAX_STRING_LEN-1, "%.2f %s%s", value_float, suffix, item->units);
+ zbx_snprintf(value, MAX_STRING_LEN, "%.2f %s%s", value_float, suffix, item->units);
}
zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] [%f] Suffix [%s] Units [%s]",value,value_float,suffix,item->units);
@@ -1227,7 +1227,7 @@ int replace_value_by_map(char *value, int valuemapid)
if(valuemapid == 0) return FAIL;
- snprintf(sql,sizeof(sql)-1,"select newvalue from mappings where valuemapid=%d and value='%s'",
+ zbx_snprintf(sql,sizeof(sql),"select newvalue from mappings where valuemapid=%d and value='%s'",
valuemapid, value);
result = DBselect(sql);
row = DBfetch(result);
@@ -1241,7 +1241,7 @@ int replace_value_by_map(char *value, int valuemapid)
or_value = sql; /* sql variarbvle used as tmp - original value */
strncpy(sql,value,MAX_STRING_LEN);
- snprintf(value, MAX_STRING_LEN-1, "%s (%s)", new_value, or_value);
+ zbx_snprintf(value, MAX_STRING_LEN, "%s (%s)", new_value, or_value);
zabbix_log(LOG_LEVEL_DEBUG, "Value: $s", value);
return SUCCEED;
@@ -1277,7 +1277,7 @@ int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *par
zabbix_log(LOG_LEVEL_DEBUG, "In evaluate_FUNCTION2()" );
- snprintf(sql,sizeof(sql)-1,"select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", ZBX_SQL_ITEM_SELECT, host, key );
+ zbx_snprintf(sql,sizeof(sql),"select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", ZBX_SQL_ITEM_SELECT, host, key );
result = DBselect(sql);
row = DBfetch(result);
diff --git a/src/zabbix_server/expression.c b/src/zabbix_server/expression.c
index f23ddc50..5e5e2237 100644
--- a/src/zabbix_server/expression.c
+++ b/src/zabbix_server/expression.c
@@ -324,7 +324,7 @@ int evaluate_simple (double *result,char *exp,char *error,int maxerrlen)
}
if(cmp_double(value2,0) == 0)
{
- snprintf(error,maxerrlen-1,"Division by zero. Cannot evaluate expression [%s/%s]", first,second);
+ zbx_snprintf(error,maxerrlen,"Division by zero. Cannot evaluate expression [%s/%s]", first,second);
zabbix_log(LOG_LEVEL_WARNING, error);
zabbix_syslog(error);
return FAIL;
@@ -443,7 +443,7 @@ int evaluate_simple (double *result,char *exp,char *error,int maxerrlen)
}
else
{
- snprintf(error,maxerrlen-1,"Format error or unsupported operator. Exp: [%s]", exp);
+ zbx_snprintf(error,maxerrlen,"Format error or unsupported operator. Exp: [%s]", exp);
zabbix_log(LOG_LEVEL_WARNING, error);
zabbix_syslog(error);
return FAIL;
@@ -492,7 +492,7 @@ int evaluate(int *result,char *exp, char *error, int maxerrlen)
}
if( r == -1 )
{
- snprintf(error, maxerrlen-1, "Cannot find left bracket [(]. Expression:[%s]", exp);
+ zbx_snprintf(error, maxerrlen, "Cannot find left bracket [(]. Expression:[%s]", exp);
zabbix_log(LOG_LEVEL_WARNING, error);
zabbix_syslog(error);
return FAIL;
@@ -522,7 +522,7 @@ int evaluate(int *result,char *exp, char *error, int maxerrlen)
for(i=l+3;i<=r;i++) exp[i]=' ';
- snprintf(res,sizeof(res)-1,exp,value);
+ zbx_snprintf(res,sizeof(res),exp,value);
strcpy(exp,res);
delete_spaces(res);
zabbix_log(LOG_LEVEL_DEBUG, "Expression4:[%s]", res );
@@ -588,8 +588,8 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data
}
else if( (s = strstr(str,"{HOSTNAME}")) != NULL )
{
-/* snprintf(sql,sizeof(sql)-1,"select distinct t.description,h.host from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", trigger->triggerid);*/
- snprintf(sql,sizeof(sql)-1,"select distinct h.host from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", trigger->triggerid);
+/* zbx_snprintf(sql,sizeof(sql),"select distinct t.description,h.host from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", trigger->triggerid);*/
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.host from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", trigger->triggerid);
result = DBselect(sql);
row=DBfetch(result);
@@ -614,7 +614,7 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data
}
else if( (s = strstr(str,"{TRIGGER.KEY}")) != NULL )
{
- snprintf(sql,sizeof(sql)-1,"select distinct i.key_ from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid order by i.key_", trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct i.key_ from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid order by i.key_", trigger->triggerid);
result = DBselect(sql);
row=DBfetch(result);
@@ -639,7 +639,7 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data
}
else if( (s = strstr(str,"{IPADDRESS}")) != NULL )
{
- snprintf(sql,sizeof(sql)-1,"select distinct h.ip from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.useip=1", trigger->triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.ip from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.useip=1", trigger->triggerid);
result = DBselect(sql);
row = DBfetch(result);
@@ -666,7 +666,7 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data
{
now=time(NULL);
tm=localtime(&now);
- snprintf(tmp,sizeof(tmp)-1,"%.4d.%.2d.%.2d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday);
+ zbx_snprintf(tmp,sizeof(tmp),"%.4d.%.2d.%.2d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday);
s[0]=0;
strcpy(data, str);
@@ -677,7 +677,7 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data
{
now=time(NULL);
tm=localtime(&now);
- snprintf(tmp,sizeof(tmp)-1,"%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
+ zbx_snprintf(tmp,sizeof(tmp),"%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
s[0]=0;
strcpy(data, str);
@@ -689,11 +689,11 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data
/* This is old value */
if(trigger->value == TRIGGER_VALUE_TRUE)
{
- snprintf(tmp,sizeof(tmp)-1,"OFF");
+ zbx_snprintf(tmp,sizeof(tmp),"OFF");
}
else
{
- snprintf(tmp,sizeof(tmp)-1,"ON");
+ zbx_snprintf(tmp,sizeof(tmp),"ON");
}
s[0]=0;
@@ -840,7 +840,7 @@ int substitute_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data)
zabbix_log( LOG_LEVEL_DEBUG, "Value5 [%s]", data );
- snprintf(res,sizeof(res)-1,data,value);
+ zbx_snprintf(res,sizeof(res),data,value);
strcpy(data,res);
/* delete_spaces(data); */
zabbix_log( LOG_LEVEL_DEBUG, "Expression4:[%s]", data );
@@ -884,14 +884,14 @@ int substitute_functions(char *exp, char *error, int maxerrlen)
r=find_char(exp,'}');
if( r == FAIL )
{
- snprintf(error,maxerrlen-1,"Cannot find right bracket. Expression:[%s]", exp);
+ zbx_snprintf(error,maxerrlen,"Cannot find right bracket. Expression:[%s]", exp);
zabbix_log( LOG_LEVEL_WARNING, error);
zabbix_syslog(error);
return FAIL;
}
if( r < l )
{
- snprintf(error,maxerrlen-1, "Right bracket is before left one. Expression:[%s]", exp);
+ zbx_snprintf(error,maxerrlen, "Right bracket is before left one. Expression:[%s]", exp);
zabbix_log( LOG_LEVEL_WARNING, error);
zabbix_syslog(error);
return FAIL;
@@ -906,7 +906,7 @@ int substitute_functions(char *exp, char *error, int maxerrlen)
if( DBget_function_result( &value, functionid ) != SUCCEED )
{
/* It may happen because of functions.lastvalue is NULL, so this is not warning */
- snprintf(error,maxerrlen-1, "Unable to get value for functionid [%s]", functionid);
+ zbx_snprintf(error,maxerrlen, "Unable to get value for functionid [%s]", functionid);
zabbix_log( LOG_LEVEL_DEBUG, error);
zabbix_syslog(error);
return FAIL;
@@ -928,7 +928,7 @@ int substitute_functions(char *exp, char *error, int maxerrlen)
zabbix_log( LOG_LEVEL_DEBUG, "Expression3:[%s]", exp );
- snprintf(res,sizeof(res)-1,exp,value);
+ zbx_snprintf(res,sizeof(res),exp,value);
strcpy(exp,res);
delete_spaces(exp);
zabbix_log( LOG_LEVEL_DEBUG, "Expression4:[%s]", exp );
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index 5b53833e..2ce902bf 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -81,8 +81,8 @@ void update_functions(DB_ITEM *item)
zabbix_log( LOG_LEVEL_DEBUG, "In update_functions(%d)",item->itemid);
/* Oracle does'n support this */
-/* snprintf(sql,sizeof(sql)-1,"select function,parameter,itemid,lastvalue from functions where itemid=%d group by function,parameter,itemid order by function,parameter,itemid",item->itemid);*/
- snprintf(sql,sizeof(sql)-1,"select distinct function,parameter,itemid,lastvalue from functions where itemid=%d",item->itemid);
+/* zbx_snprintf(sql,sizeof(sql),"select function,parameter,itemid,lastvalue from functions where itemid=%d group by function,parameter,itemid order by function,parameter,itemid",item->itemid);*/
+ zbx_snprintf(sql,sizeof(sql),"select distinct function,parameter,itemid,lastvalue from functions where itemid=%d",item->itemid);
result = DBselect(sql);
@@ -93,22 +93,22 @@ void update_functions(DB_ITEM *item)
function.itemid=atoi(row[2]);
lastvalue=row[3];
- zabbix_log( LOG_LEVEL_DEBUG, "ItemId:%d Evaluating %s(%d)\n",function.itemid,function.function,function.parameter);
+ zabbix_log( LOG_LEVEL_DEBUG, "ItemId:%d Evaluating %s(%d)",function.itemid,function.function,function.parameter);
ret = evaluate_FUNCTION(value,item,function.function,function.parameter);
if( FAIL == ret)
{
- zabbix_log( LOG_LEVEL_DEBUG, "Evaluation failed for function:%s\n",function.function);
+ zabbix_log( LOG_LEVEL_DEBUG, "Evaluation failed for function:%s",function.function);
continue;
}
- zabbix_log( LOG_LEVEL_DEBUG, "Result of evaluate_FUNCTION [%s]\n",value);
+ zabbix_log( LOG_LEVEL_DEBUG, "Result of evaluate_FUNCTION [%s]",value);
if (ret == SUCCEED)
{
/* Update only if lastvalue differs from new one */
if( (lastvalue == NULL) || (strcmp(lastvalue,value) != 0))
{
DBescape_string(value,value_esc,MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='%s' where itemid=%d and function='%s' and parameter='%s'", value_esc, function.itemid, function.function, function.parameter );
+ zbx_snprintf(sql,sizeof(sql),"update functions set lastvalue='%s' where itemid=%d and function='%s' and parameter='%s'", value_esc, function.itemid, function.function, function.parameter );
DBexecute(sql);
}
else
@@ -148,7 +148,7 @@ void update_services_rec(int serviceid)
DB_ROW row;
DB_ROW row2;
- snprintf(sql,sizeof(sql)-1,"select l.serviceupid,s.algorithm from services_links l,services s where s.serviceid=l.serviceupid and l.servicedownid=%d",serviceid);
+ zbx_snprintf(sql,sizeof(sql),"select l.serviceupid,s.algorithm from services_links l,services s where s.serviceid=l.serviceupid and l.servicedownid=%d",serviceid);
result=DBselect(sql);
status=0;
while((row=DBfetch(result)))
@@ -164,7 +164,7 @@ void update_services_rec(int serviceid)
(SERVICE_ALGORITHM_MIN == algorithm))
{
/* Why it was so complex ?
- sprintf(sql,"select status from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid);
+ zbx_snprintf(sql, sizeof(sql), "select status from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid);
result2=DBselect(sql);
for(j=0;j<DBnum_rows(result2);j++)
{
@@ -177,12 +177,12 @@ void update_services_rec(int serviceid)
if(SERVICE_ALGORITHM_MAX == algorithm)
{
- snprintf(sql,sizeof(sql)-1,"select count(*),max(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid);
+ zbx_snprintf(sql,sizeof(sql),"select count(*),max(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid);
}
/* MIN otherwise */
else
{
- snprintf(sql,sizeof(sql)-1,"select count(*),min(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid);
+ zbx_snprintf(sql,sizeof(sql),"select count(*),min(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid);
}
result2=DBselect(sql);
row2=DBfetch(result2);
@@ -197,7 +197,7 @@ void update_services_rec(int serviceid)
now=time(NULL);
DBadd_service_alarm(atoi(row[0]),status,now);
- snprintf(sql,sizeof(sql)-1,"update services set status=%d where serviceid=%d",status,atoi(row[0]));
+ zbx_snprintf(sql,sizeof(sql),"update services set status=%d where serviceid=%d",status,atoi(row[0]));
DBexecute(sql);
}
else
@@ -208,7 +208,7 @@ void update_services_rec(int serviceid)
}
DBfree_result(result);
- snprintf(sql,sizeof(sql)-1,"select serviceupid from services_links where servicedownid=%d",serviceid);
+ zbx_snprintf(sql,sizeof(sql),"select serviceupid from services_links where servicedownid=%d",serviceid);
result=DBselect(sql);
while((row=DBfetch(result)))
@@ -241,10 +241,10 @@ void update_services(int triggerid, int status)
DB_RESULT result;
- snprintf(sql,sizeof(sql)-1,"update services set status=%d where triggerid=%d",status,triggerid);
+ zbx_snprintf(sql,sizeof(sql),"update services set status=%d where triggerid=%d",status,triggerid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"select serviceid from services where triggerid=%d", triggerid);
+ zbx_snprintf(sql,sizeof(sql),"select serviceid from services where triggerid=%d", triggerid);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -285,9 +285,9 @@ void update_triggers(int itemid)
zabbix_log( LOG_LEVEL_DEBUG, "In update_triggers [%d]", itemid);
/* Does not work for PostgreSQL */
-/* sprintf(sql,"select t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value from triggers t,functions f,items i where i.status<>3 and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=%d group by t.triggerid,t.expression,t.dep_level",TRIGGER_STATUS_ENABLED,server_num);*/
+/* zbx_snprintf(sql, sizeof(sql), "select t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value from triggers t,functions f,items i where i.status<>3 and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=%d group by t.triggerid,t.expression,t.dep_level",TRIGGER_STATUS_ENABLED,server_num);*/
/* Is it correct SQL? */
- snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value,t.description from triggers t,functions f,items i where i.status<>%d and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=%d",ITEM_STATUS_NOTSUPPORTED, TRIGGER_STATUS_ENABLED, itemid);
+ zbx_snprintf(sql,sizeof(sql),"select distinct t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value,t.description from triggers t,functions f,items i where i.status<>%d and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=%d",ITEM_STATUS_NOTSUPPORTED, TRIGGER_STATUS_ENABLED, itemid);
result = DBselect(sql);
@@ -424,12 +424,12 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
init_result(&agent);
-/* snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula,i.logtimefmt from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d)", HOST_STATUS_MONITORED, server, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE);*/
+/* zbx_snprintf(sql,sizeof(sql),"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula,i.logtimefmt from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d)", HOST_STATUS_MONITORED, server, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE);*/
DBescape_string(server, server_esc, MAX_STRING_LEN);
DBescape_string(key, key_esc, MAX_STRING_LEN);
- snprintf(sql,sizeof(sql)-1,"select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d)", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d)", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE);
result = DBselect(sql);
@@ -628,7 +628,7 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now)
{
if(value->type & AR_STRING)
DBadd_history_log(item->itemid,value->str,now,item->timestamp,item->eventlog_source,item->eventlog_severity);
- snprintf(sql,sizeof(sql)-1,"update items set lastlogsize=%d where itemid=%d",item->lastlogsize,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"update items set lastlogsize=%d where itemid=%d",item->lastlogsize,item->itemid);
DBexecute(sql);
}
else if(item->value_type==ITEM_VALUE_TYPE_TEXT)
@@ -679,12 +679,12 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
if(value->type & AR_UINT64)
{
- snprintf(value_str,MAX_STRING_LEN-1,ZBX_FS_UI64, value->ui64);
+ zbx_snprintf(value_str, sizeof(value_str),ZBX_FS_UI64, value->ui64);
value_double = (double)value->ui64;
}
if(value->type & AR_DOUBLE)
{
- snprintf(value_str,MAX_STRING_LEN-1,"%f", value->dbl);
+ zbx_snprintf(value_str,sizeof(value_str),"%f", value->dbl);
value_double = value->dbl;
}
if(value->type & AR_STRING)
@@ -705,8 +705,8 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
(strcmp(item->prevvalue_str,item->lastvalue_str) != 0)))
{
DBescape_string(value_str,value_esc,MAX_STRING_LEN);
-/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value_esc,now,item->itemid);*/
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_esc,(int)now,item->itemid);
+/* zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value_esc,now,item->itemid);*/
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_esc,(int)now,item->itemid);
item->prevvalue=item->lastvalue;
item->lastvalue=value_double;
item->prevvalue_str=item->lastvalue_str;
@@ -717,8 +717,8 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
}
else
{
-/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,lastclock=%d where itemid=%d",now+item->delay,now,item->itemid);*/
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),(int)now,item->itemid);
+/* zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,lastclock=%d where itemid=%d",now+item->delay,now,item->itemid);*/
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),(int)now,item->itemid);
}
}
/* Logic for delta as speed of change */
@@ -726,13 +726,13 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
{
if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) )
{
-/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",now+item->delay,value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),now,item->itemid);*/
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),(int)now,item->itemid);
+/* zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",now+item->delay,value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),now,item->itemid);*/
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),(int)now,item->itemid);
}
else
{
-/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",now+item->delay,value_double,now,item->itemid);*/
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(int)now,item->itemid);
+/* zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",now+item->delay,value_double,now,item->itemid);*/
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(int)now,item->itemid);
}
item->prevvalue=item->lastvalue;
@@ -748,11 +748,11 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
{
if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) )
{
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid);
}
else
{
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(int)now,item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->delay,now),value_double,(int)now,item->itemid);
}
item->prevvalue=item->lastvalue;
@@ -771,7 +771,7 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] became supported by agent on host [%s]", item->key, item->host );
zabbix_syslog("Parameter [%s] became supported by agent on host [%s]", item->key, item->host );
item->status = ITEM_STATUS_ACTIVE;
- snprintf(sql,sizeof(sql)-1,"update items set status=%d where itemid=%d", ITEM_STATUS_ACTIVE, item->itemid);
+ zbx_snprintf(sql,sizeof(sql),"update items set status=%d where itemid=%d", ITEM_STATUS_ACTIVE, item->itemid);
DBexecute(sql);
}
diff --git a/src/zabbix_server/housekeeper/housekeeper.c b/src/zabbix_server/housekeeper/housekeeper.c
index 88147187..6f01694f 100644
--- a/src/zabbix_server/housekeeper/housekeeper.c
+++ b/src/zabbix_server/housekeeper/housekeeper.c
@@ -80,7 +80,7 @@ static int housekeeping_process_log()
zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_process_log()");
/* order by tablename to effectively use DB cache */
- snprintf(sql,sizeof(sql)-1,"select housekeeperid, tablename, field, value from housekeeper order by tablename");
+ zbx_snprintf(sql,sizeof(sql),"select housekeeperid, tablename, field, value from housekeeper order by tablename");
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -91,13 +91,13 @@ static int housekeeping_process_log()
housekeeper.value=atoi(row[3]);
#ifdef HAVE_ORACLE
- snprintf(sql,sizeof(sql)-1,"delete from %s where %s=%d and rownum<500",housekeeper.tablename, housekeeper.field,housekeeper.value);
+ zbx_snprintf(sql,sizeof(sql),"delete from %s where %s=%d and rownum<500",housekeeper.tablename, housekeeper.field,housekeeper.value);
#else
- snprintf(sql,sizeof(sql)-1,"delete from %s where %s=%d limit 500",housekeeper.tablename, housekeeper.field,housekeeper.value);
+ zbx_snprintf(sql,sizeof(sql),"delete from %s where %s=%d limit 500",housekeeper.tablename, housekeeper.field,housekeeper.value);
#endif
if(( deleted = DBexecute(sql)) == 0)
{
- snprintf(sql,sizeof(sql)-1,"delete from housekeeper where housekeeperid=%d",housekeeper.housekeeperid);
+ zbx_snprintf(sql,sizeof(sql),"delete from housekeeper where housekeeperid=%d",housekeeper.housekeeperid);
DBexecute(sql);
}
else
@@ -117,7 +117,7 @@ static int housekeeping_sessions(int now)
zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_sessions(%d)", now);
- snprintf(sql,sizeof(sql)-1,"delete from sessions where lastaccess<%d",now-24*3600);
+ zbx_snprintf(sql,sizeof(sql),"delete from sessions where lastaccess<%d",now-24*3600);
zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [sessions]", DBexecute(sql));
@@ -134,7 +134,7 @@ static int housekeeping_alerts(int now)
zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_alerts(%d)", now);
- snprintf(sql,sizeof(sql)-1,"select alert_history from config");
+ zbx_snprintf(sql,sizeof(sql),"select alert_history from config");
result = DBselect(sql);
row=DBfetch(result);
@@ -148,7 +148,7 @@ static int housekeeping_alerts(int now)
{
alert_history=atoi(row[0]);
- snprintf(sql,sizeof(sql)-1,"delete from alerts where clock<%d",now-24*3600*alert_history);
+ zbx_snprintf(sql,sizeof(sql),"delete from alerts where clock<%d",now-24*3600*alert_history);
zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [alerts]", DBexecute(sql));
}
@@ -169,7 +169,7 @@ static int housekeeping_alarms(int now)
zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_alarms(%d)", now);
- snprintf(sql,sizeof(sql)-1,"select alarm_history from config");
+ zbx_snprintf(sql,sizeof(sql),"select alarm_history from config");
result = DBselect(sql);
row1=DBfetch(result);
@@ -182,16 +182,16 @@ static int housekeeping_alarms(int now)
{
alarm_history=atoi(row1[0]);
- snprintf(sql,sizeof(sql)-1,"select alarmid from alarms where clock<%d", now-24*3600*alarm_history);
+ zbx_snprintf(sql,sizeof(sql),"select alarmid from alarms where clock<%d", now-24*3600*alarm_history);
result2 = DBselect(sql);
while((row2=DBfetch(result2)))
{
alarmid=atoi(row2[0]);
- snprintf(sql,sizeof(sql)-1,"delete from acknowledges where alarmid=%d",alarmid);
+ zbx_snprintf(sql,sizeof(sql),"delete from acknowledges where alarmid=%d",alarmid);
DBexecute(sql);
- snprintf(sql,sizeof(sql)-1,"delete from alarms where alarmid=%d",alarmid);
+ zbx_snprintf(sql,sizeof(sql),"delete from alarms where alarmid=%d",alarmid);
zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [alarms]", DBexecute(sql));
}
DBfree_result(result2);
@@ -211,9 +211,8 @@ int main_housekeeper_loop()
for(;;)
{
/* Do nothing */
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("do nothing");
-#endif
+ zbx_setproctitle("do nothing");
+
sleep(3600);
}
}
@@ -221,62 +220,47 @@ int main_housekeeper_loop()
for(;;)
{
now = time(NULL);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("connecting to the database");
-#endif
+
+ zbx_setproctitle("connecting to the database");
+
DBconnect();
-#ifdef HAVE_FUNCTION_SETPROCTITLE
-/* setproctitle("housekeeper [removing deleted hosts]");*/
-#endif
+
+/* zbx_setproctitle("housekeeper [removing deleted hosts]");*/
+
/* housekeeping_hosts();*/
-#ifdef HAVE_FUNCTION_SETPROCTITLE
-/* setproctitle("housekeeper [removing deleted items]");*/
-#endif
+/* zbx_setproctitle("housekeeper [removing deleted items]");*/
/* housekeeping_items();*/
-#ifdef HAVE_FUNCTION_SETPROCTITLE
-/* setproctitle("housekeeper [removing old history]");*/
-#endif
+/* zbx_setproctitle("housekeeper [removing old history]");*/
/* housekeeping_history_and_trends(now);*/
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [removing old history]");
-#endif
+ zbx_setproctitle("housekeeper [removing old history]");
housekeeping_process_log(now);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [removing old alarms]");
-#endif
+ zbx_setproctitle("housekeeper [removing old alarms]");
housekeeping_alarms(now);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [removing old alerts]");
-#endif
+ zbx_setproctitle("housekeeper [removing old alerts]");
housekeeping_alerts(now);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [removing old sessions]");
-#endif
+ zbx_setproctitle("housekeeper [removing old sessions]");
housekeeping_sessions(now);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [vacuuming database]");
-#endif
+ zbx_setproctitle("housekeeper [vacuuming database]");
+
DBvacuum();
zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d hours", CONFIG_HOUSEKEEPING_FREQUENCY);
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("housekeeper [sleeping for %d hour(s)]", CONFIG_HOUSEKEEPING_FREQUENCY);
-#endif
+ zbx_setproctitle("housekeeper [sleeping for %d hour(s)]", CONFIG_HOUSEKEEPING_FREQUENCY);
DBclose();
sleep(3660*CONFIG_HOUSEKEEPING_FREQUENCY);
diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c
index d27654e4..61c9344d 100644
--- a/src/zabbix_server/pinger/pinger.c
+++ b/src/zabbix_server/pinger/pinger.c
@@ -134,11 +134,11 @@ static int process_value(char *key, char *host, AGENT_RESULT *value)
/* IP address? */
if(is_ip(host) == SUCCEED)
{
- snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.ip='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE);
+ zbx_snprintf(sql,sizeof(sql),"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.ip='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE);
}
else
{
- snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE);
+ zbx_snprintf(sql,sizeof(sql),"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE);
}
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql);
result = DBselect(sql);
@@ -229,9 +229,7 @@ static int create_host_file(void)
zabbix_log( LOG_LEVEL_DEBUG, "In create_host_file()");
- f = fopen("/tmp/zabbix_server.pinger", "w");
-
- if( f == NULL)
+ if(NULL == (f = fopen("/tmp/zabbix_server.pinger", "w") ))
{
zabbix_log( LOG_LEVEL_ERR, "Cannot open file [%s] [%s]", "/tmp/zabbix_server.pinger", strerror(errno));
zabbix_syslog("Cannot open file [%s] [%s]", "/tmp/zabbix_server.pinger", strerror(errno));
@@ -240,7 +238,7 @@ static int create_host_file(void)
now=time(NULL);
/* Select hosts monitored by IP */
- snprintf(sql,sizeof(sql)-1,"select distinct h.ip from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.ip from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -255,7 +253,7 @@ static int create_host_file(void)
DBfree_result(result);
/* Select hosts monitored by hostname */
- snprintf(sql,sizeof(sql)-1,"select distinct h.host from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select distinct h.host from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE);
result = DBselect(sql);
while((row=DBfetch(result)))
@@ -268,7 +266,7 @@ static int create_host_file(void)
}
DBfree_result(result);
- fclose(f);
+ zbx_fclose(f);
return SUCCEED;
}
@@ -303,7 +301,7 @@ static int do_ping(void)
zabbix_log( LOG_LEVEL_DEBUG, "In do_ping()");
- snprintf(str,sizeof(str)-1,"cat /tmp/zabbix_server.pinger | %s -e 2>/dev/null",CONFIG_FPING_LOCATION);
+ zbx_snprintf(str,sizeof(str),"cat /tmp/zabbix_server.pinger | %s -e 2>/dev/null",CONFIG_FPING_LOCATION);
f=popen(str,"r");
if(f==0)
@@ -399,9 +397,7 @@ void main_pinger_loop()
{
for(;;)
{
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("connecting to the database");
-#endif
+ zbx_setproctitle("connecting to the database");
DBconnect();
@@ -411,9 +407,7 @@ void main_pinger_loop()
if( SUCCEED == ret)
{
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("pinging hosts");
-#endif
+ zbx_setproctitle("pinging hosts");
ret = do_ping();
}
@@ -423,9 +417,8 @@ void main_pinger_loop()
DBclose();
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("pinger [sleeping for %d seconds]", CONFIG_PINGER_FREQUENCY);
-#endif
+ zbx_setproctitle("pinger [sleeping for %d seconds]", CONFIG_PINGER_FREQUENCY);
+
sleep(CONFIG_PINGER_FREQUENCY);
}
}
diff --git a/src/zabbix_server/poller/checks_agent.c b/src/zabbix_server/poller/checks_agent.c
index 3e37c39a..693d459a 100644
--- a/src/zabbix_server/poller/checks_agent.c
+++ b/src/zabbix_server/poller/checks_agent.c
@@ -69,11 +69,11 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
if(hp==NULL)
{
#ifdef HAVE_HSTRERROR
- snprintf(error,MAX_STRING_LEN-1,"gethostbyname() failed [%s]", hstrerror(h_errno));
+ zbx_snprintf(error,sizeof(error),"gethostbyname() failed [%s]", hstrerror(h_errno));
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
#else
- snprintf(error,MAX_STRING_LEN-1,"gethostbyname() failed [%d]", h_errno);
+ zbx_snprintf(error,sizeof(error),"gethostbyname() failed [%d]", h_errno);
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
#endif
@@ -97,7 +97,7 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
}*/
if(s == -1)
{
- snprintf(error,MAX_STRING_LEN-1,"Cannot create socket [%s]", strerror(errno));
+ zbx_snprintf(error,sizeof(error),"Cannot create socket [%s]", strerror(errno));
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
return FAIL;
@@ -108,17 +108,17 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
switch (errno)
{
case EINTR:
- snprintf(error,MAX_STRING_LEN-1,"Timeout while connecting to [%s]",item->host);
+ zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]",item->host);
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
break;
case EHOSTUNREACH:
- snprintf(error,MAX_STRING_LEN-1,"No route to host [%s]",item->host);
+ zbx_snprintf(error,sizeof(error),"No route to host [%s]",item->host);
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
break;
default:
- snprintf(error,MAX_STRING_LEN-1,"Cannot connect to [%s] [%s]",item->host, strerror(errno));
+ zbx_snprintf(error,sizeof(error),"Cannot connect to [%s] [%s]",item->host, strerror(errno));
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
}
@@ -126,19 +126,19 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
return NETWORK_ERROR;
}
- snprintf(c, MAX_STRING_LEN - 1, "%s\n",item->key);
+ zbx_snprintf(c, sizeof(c), "%s\n",item->key);
zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", c);
if( write(s,c,strlen(c)) == -1 )
{
switch (errno)
{
case EINTR:
- snprintf(error,MAX_STRING_LEN-1,"Timeout while sending data to [%s]",item->host);
+ zbx_snprintf(error,sizeof(error),"Timeout while sending data to [%s]",item->host);
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
break;
default:
- snprintf(error,MAX_STRING_LEN-1,"Error while sending data to [%s] [%s]",item->host, strerror(errno));
+ zbx_snprintf(error,sizeof(error),"Error while sending data to [%s] [%s]",item->host, strerror(errno));
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
}
@@ -153,18 +153,18 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
switch (errno)
{
case EINTR:
- snprintf(error,MAX_STRING_LEN-1,"Timeout while receiving data from [%s]",item->host);
+ zbx_snprintf(error,sizeof(error),"Timeout while receiving data from [%s]",item->host);
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
break;
case ECONNRESET:
- snprintf(error,MAX_STRING_LEN-1,"Connection reset by peer.");
+ zbx_snprintf(error,sizeof(error),"Connection reset by peer.");
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
close(s);
return NETWORK_ERROR;
default:
- snprintf(error,MAX_STRING_LEN-1,"Error while receiving data from [%s] [%s]",item->host, strerror(errno));
+ zbx_snprintf(error,sizeof(error),"Error while receiving data from [%s] [%s]",item->host, strerror(errno));
zabbix_log(LOG_LEVEL_WARNING, error);
result->msg=strdup(error);
}
@@ -190,20 +190,20 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
if( strcmp(c,"ZBX_NOTSUPPORTED") == 0)
{
- snprintf(error,MAX_STRING_LEN-1,"Not supported by ZABBIX agent");
+ zbx_snprintf(error,sizeof(error),"Not supported by ZABBIX agent");
result->msg=strdup(error);
return NOTSUPPORTED;
}
else if( strcmp(c,"ZBX_ERROR") == 0)
{
- snprintf(error,MAX_STRING_LEN-1,"ZABBIX agent non-critical error");
+ zbx_snprintf(error,sizeof(error),"ZABBIX agent non-critical error");
result->msg=strdup(error);
return AGENT_ERROR;
}
/* The section should be improved */
else if(c[0]==0)
{
- snprintf(error,MAX_STRING_LEN-1,"Got empty string from [%s] IP [%s] Parameter [%s]", item->host, item->ip, item->key);
+ zbx_snprintf(error,sizeof(error),"Got empty string from [%s] IP [%s] Parameter [%s]", item->host, item->ip, item->key);
zabbix_log( LOG_LEVEL_WARNING, error);
zabbix_log( LOG_LEVEL_WARNING, "Assuming that agent dropped connection because of access permissions");
result->msg=strdup(error);
@@ -212,7 +212,7 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result)
if(set_result_type(result, item->value_type, c) == FAIL)
{
- snprintf(error,MAX_STRING_LEN-1, "Type of received value [%s] is not sutable for [%s@%s] having type [%d]", c, item->key, item->host, item->value_type);
+ zbx_snprintf(error,sizeof(error), "Type of received value [%s] is not sutable for [%s@%s] having type [%d]", c, item->key, item->host, item->value_type);
zabbix_log( LOG_LEVEL_WARNING, error);
zabbix_log( LOG_LEVEL_WARNING, "Returning NOTSUPPORTED");
result->msg=strdup(error);
diff --git a/src/zabbix_server/poller/checks_aggregate.c b/src/zabbix_server/poller/checks_aggregate.c
index 44412944..2faf1ee0 100644
--- a/src/zabbix_server/poller/checks_aggregate.c
+++ b/src/zabbix_server/poller/checks_aggregate.c
@@ -110,12 +110,12 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup,
DBescape_string(hostgroup,hostgroup_esc,MAX_STRING_LEN);
/* Get list of affected item IDs */
strscpy(items,"0");
- snprintf(sql,sizeof(sql)-1,"select itemid from items,hosts_groups,hosts,groups where hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and items.status=%d and hosts.status=%d",hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, HOST_STATUS_MONITORED);
+ zbx_snprintf(sql,sizeof(sql),"select itemid from items,hosts_groups,hosts,groups where hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and items.status=%d and hosts.status=%d",hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, HOST_STATUS_MONITORED);
result = DBselect(sql);
while((row=DBfetch(result)))
{
- snprintf(items2,sizeof(items2)-1,"%s,%s",items, row[0]);
+ zbx_snprintf(items2,sizeof(items2),"%s,%s",items, row[0]);
/* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items2[%s])",items2);*/
strscpy(items,items2);
/* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items[%s])",items2);*/
@@ -124,11 +124,11 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup,
if(strcmp(itemfunc,"last") == 0)
{
- snprintf(sql,sizeof(sql)-1,"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)",items);
- snprintf(sql2,sizeof(sql2)-1,"select itemid,value_type,lastvalue from items where 0=1");
+ zbx_snprintf(sql,sizeof(sql),"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)",items);
+ zbx_snprintf(sql2,sizeof(sql2),"select itemid,value_type,lastvalue from items where 0=1");
}
/* The SQL works very very slow on MySQL 4.0. That's why it has been split into two. */
-/* snprintf(sql,sizeof(sql)-1,"select items.itemid,items.value_type,min(history.value) from items,hosts_groups,hosts,groups,history where history.itemid=items.itemid and hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and history.clock>%d group by 1,2",hostgroup_esc, itemkey_esc, now - atoi(param));*/
+/* zbx_snprintf(sql,sizeof(sql),"select items.itemid,items.value_type,min(history.value) from items,hosts_groups,hosts,groups,history where history.itemid=items.itemid and hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and history.clock>%d group by 1,2",hostgroup_esc, itemkey_esc, now - atoi(param));*/
else if( (strcmp(itemfunc,"min") == 0) ||
(strcmp(itemfunc,"max") == 0) ||
(strcmp(itemfunc,"avg") == 0) ||
@@ -136,8 +136,8 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup,
(strcmp(itemfunc,"sum") == 0)
)
{
- snprintf(sql,sizeof(sql)-1,"select h.itemid,i.value_type,%s(h.value) from items i,history h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by 1,2",itemfunc, items, now - atoi(param));
- snprintf(sql2,sizeof(sql)-1,"select h.itemid,i.value_type,%s(h.value) from items i,history_uint h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by 1,2",itemfunc, items, now - atoi(param));
+ zbx_snprintf(sql,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by 1,2",itemfunc, items, now - atoi(param));
+ zbx_snprintf(sql2,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history_uint h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by 1,2",itemfunc, items, now - atoi(param));
}
else
{
diff --git a/src/zabbix_server/poller/checks_internal.c b/src/zabbix_server/poller/checks_internal.c
index 18533ff8..570b07e3 100644
--- a/src/zabbix_server/poller/checks_internal.c
+++ b/src/zabbix_server/poller/checks_internal.c
@@ -81,7 +81,7 @@ int get_value_internal(DB_ITEM *item, AGENT_RESULT *result)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Internal check [%s] is not supported", item->key);
+ zbx_snprintf(error,sizeof(error),"Internal check [%s] is not supported", item->key);
zabbix_log( LOG_LEVEL_WARNING, error);
SET_STR_RESULT(result, strdup(error));
return NOTSUPPORTED;
diff --git a/src/zabbix_server/poller/checks_simple.c b/src/zabbix_server/poller/checks_simple.c
index f7fb911f..abd0a9ba 100644
--- a/src/zabbix_server/poller/checks_simple.c
+++ b/src/zabbix_server/poller/checks_simple.c
@@ -43,18 +43,18 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
l=strstr(item->key,"[");
r=strstr(item->key,"]");
if(l==NULL || r==NULL)
- snprintf(c,sizeof(c)-1,"net.tcp.service[%s]",item->key);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service[%s]",item->key);
else
{
strncpy( param,l+1, r-l-1);
param[r-l-1]=0;
if(item->useip==1)
{
- snprintf(c,sizeof(c)-1,"net.tcp.service[%s,%s]",item->key,item->ip);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->ip);
}
else
{
- snprintf(c,sizeof(c)-1,"net.tcp.service[%s,%s]",item->key,item->host);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->host);
}
}
}
@@ -65,18 +65,18 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
l=strstr(item->key,"[");
r=strstr(item->key,"]");
if(l==NULL || r==NULL)
- snprintf(c,sizeof(c)-1,"%s",item->key);
+ zbx_snprintf(c,sizeof(c),"%s",item->key);
else
{
strncpy( param,l+1, r-l-1);
param[r-l-1]=0;
-/* snprintf(c,sizeof(c)-1,"dns[%s,%s]",item->ip,param);*/
- snprintf(c,sizeof(c)-1,"dns[%s]",param);
+/* zbx_snprintf(c,sizeof(c),"dns[%s,%s]",item->ip,param);*/
+ zbx_snprintf(c,sizeof(c),"dns[%s]",param);
}
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"You must use IP address in Host %s definition", item->host);
+ zbx_snprintf(error,sizeof(error),"You must use IP address in Host %s definition", item->host);
zabbix_log( LOG_LEVEL_WARNING, error);
result->str=strdup(error);
return NOTSUPPORTED;
@@ -110,7 +110,7 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Port number must be numeric in [%s]", item->key);
+ zbx_snprintf(error,sizeof(error),"Port number must be numeric in [%s]", item->key);
zabbix_log( LOG_LEVEL_WARNING, error);
result->str=strdup(error);
ret = NOTSUPPORTED;
@@ -118,7 +118,7 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Too many parameters in [%s]", item->key);
+ zbx_snprintf(error,sizeof(error),"Too many parameters in [%s]", item->key);
zabbix_log( LOG_LEVEL_WARNING, error);
result->str=strdup(error);
ret = NOTSUPPORTED;
@@ -145,11 +145,11 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
if(port_int == 0)
{
- snprintf(c,sizeof(c)-1,"%s[%s,%s]",service_sysinfo,service,ip);
+ zbx_snprintf(c,sizeof(c),"%s[%s,%s]",service_sysinfo,service,ip);
}
else
{
- snprintf(c,sizeof(c)-1,"%s[%s,%s,%d]",service_sysinfo,service,ip,port_int);
+ zbx_snprintf(c,sizeof(c),"%s[%s,%s,%d]",service_sysinfo,service,ip,port_int);
}
zabbix_log( LOG_LEVEL_DEBUG, "Sysinfo [%s]", c);
}
@@ -163,11 +163,11 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
{
if(item->useip==1)
{
- snprintf(c,sizeof(c)-1,"net.tcp.service[%s,%s]",item->key,item->ip);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->ip);
}
else
{
- snprintf(c,sizeof(c)-1,"net.tcp.service[%s,%s]",item->key,item->host);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->host);
}
}
else
@@ -178,18 +178,18 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result)
if(item->useip==1)
{
- snprintf(c,sizeof(c)-1,"net.tcp.service.perf[%s,%s]",s,item->ip);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service.perf[%s,%s]",s,item->ip);
}
else
{
- snprintf(c,sizeof(c)-1,"net.tcp.service.perf[%s,%s]",s,item->host);
+ zbx_snprintf(c,sizeof(c),"net.tcp.service.perf[%s,%s]",s,item->host);
}
}
*/
if(process(c, 0, result) == NOTSUPPORTED)
{
- snprintf(error,MAX_STRING_LEN-1,"Simple check [%s] is not supported", c);
+ zbx_snprintf(error,sizeof(error),"Simple check [%s] is not supported", c);
zabbix_log( LOG_LEVEL_WARNING, error);
result->str=strdup(error);
ret = NOTSUPPORTED;
diff --git a/src/zabbix_server/poller/checks_snmp.c b/src/zabbix_server/poller/checks_snmp.c
index 4c821b35..a0b755dc 100644
--- a/src/zabbix_server/poller/checks_snmp.c
+++ b/src/zabbix_server/poller/checks_snmp.c
@@ -71,7 +71,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Error in get_value_SNMP. Wrong item type [%d]. Must be SNMP.", item->type);
+ zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Wrong item type [%d]. Must be SNMP.", item->type);
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -83,7 +83,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
if(item->useip == 1)
{
#ifdef NEW_APPROACH
- snprintf(temp,sizeof(temp)-1,"%s:%d", item->ip, item->snmp_port);
+ zbx_snprintf(temp,sizeof(temp),"%s:%d", item->ip, item->snmp_port);
session.peername = temp;
session.remote_port = item->snmp_port;
#else
@@ -94,7 +94,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
else
{
#ifdef NEW_APPROACH
- snprintf(temp, sizeof(temp)-1, "%s:%d", item->host, item->snmp_port);
+ zbx_snprintf(temp, sizeof(temp), "%s:%d", item->host, item->snmp_port);
session.peername = temp;
session.remote_port = item->snmp_port;
#else
@@ -136,7 +136,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
session.securityAuthKey,
&session.securityAuthKeyLen) != SNMPERR_SUCCESS)
{
- snprintf(error,MAX_STRING_LEN-1,"Error generating Ku from authentication pass phrase.");
+ zbx_snprintf(error,sizeof(error),"Error generating Ku from authentication pass phrase.");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -159,7 +159,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
session.securityAuthKey,
&session.securityAuthKeyLen) != SNMPERR_SUCCESS)
{
- snprintf(error,MAX_STRING_LEN-1,"Error generating Ku from authentication pass phrase.");
+ zbx_snprintf(error,sizeof(error),"Error generating Ku from authentication pass phrase.");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -178,7 +178,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
session.securityPrivKey,
&session.securityPrivKeyLen) != SNMPERR_SUCCESS)
{
- snprintf(error,MAX_STRING_LEN-1,"Error generating Ku from priv pass phrase.");
+ zbx_snprintf(error,sizeof(error),"Error generating Ku from priv pass phrase.");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -190,7 +190,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Error in get_value_SNMP. Unsupported session.version [%d]",(int)session.version);
+ zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Unsupported session.version [%d]",(int)session.version);
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -206,7 +206,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
{
SOCK_CLEANUP;
- snprintf(error,MAX_STRING_LEN-1,"Error doing snmp_open()");
+ zbx_snprintf(error,sizeof(error),"Error doing snmp_open()");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -263,8 +263,8 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
* This solves situation when large numbers are stored as negative values
* http://sourceforge.net/tracker/index.php?func=detail&aid=700145&group_id=23494&atid=378683
*/
- /*sprintf(result_str,"%ld",(long)*vars->val.integer);*/
-/* snprintf(result_str,MAX_STRING_LEN-1,"%lu",(long)*vars->val.integer);*/
+ /*zbx_snprintf(result_str,sizeof(result_str),"%ld",(long)*vars->val.integer);*/
+/* zbx_snprintf(result_str,sizeof(result_str),"%lu",(long)*vars->val.integer);*/
/* Not correct. Returns huge values. */
/* SET_UI64_RESULT(value, (zbx_uint64_t)*vars->val.integer);*/
@@ -288,20 +288,20 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
{
SET_UI64_RESULT(value, (zbx_uint64_t)*vars->val.integer);
/* *result=(long)*vars->val.integer;
- snprintf(result_str,MAX_STRING_LEN-1,"%ld",(long)*vars->val.integer);*/
+ zbx_snprintf(result_str,sizeof(result_str),"%ld",(long)*vars->val.integer);*/
}
#ifdef OPAQUE_SPECIAL_TYPES
else if(vars->type == ASN_FLOAT)
{
/* *result=(double)*vars->val.floatVal;
- snprintf(result_str,MAX_STRING_LEN-1,"%f",(double)*vars->val.floatVal);*/
+ zbx_snprintf(result_str,sizeof(result_str),"%f",(double)*vars->val.floatVal);*/
SET_DBL_RESULT(value, *vars->val.floatVal);
}
else if(vars->type == ASN_DOUBLE)
{
/* *result=(double)*vars->val.doubleVal;
- snprintf(result_str,MAX_STRING_LEN-1,"%lf",(double)*vars->val.doubleVal);*/
+ zbx_snprintf(result_str,sizeof(result_str),"%lf",(double)*vars->val.doubleVal);*/
SET_DBL_RESULT(value, *vars->val.doubleVal);
}
#endif
@@ -322,14 +322,14 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Cannot allocate required memory");
+ zbx_snprintf(error,sizeof(error),"Cannot allocate required memory");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
}
}
else if(item->value_type != ITEM_VALUE_TYPE_STR)
{
- snprintf(error,MAX_STRING_LEN-1,"Cannot store SNMP string value (ASN_OCTET_STR) in item having numeric type");
+ zbx_snprintf(error,sizeof(error),"Cannot store SNMP string value (ASN_OCTET_STR) in item having numeric type");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -347,7 +347,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Cannot allocate required memory");
+ zbx_snprintf(error,sizeof(error),"Cannot allocate required memory");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
}
@@ -356,14 +356,14 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
else if(vars->type == ASN_IPADDRESS)
{
/* ip = vars->val.string;
- snprintf(result_str,MAX_STRING_LEN-1,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);*/
+ zbx_snprintf(result_str,sizeof(result_str),"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);*/
/* if(item->type == 0)
{
ret = NOTSUPPORTED;
}*/
if(item->value_type != ITEM_VALUE_TYPE_STR)
{
- snprintf(error,MAX_STRING_LEN-1,"Cannot store SNMP string value (ASN_IPADDRESS) in item having numeric type");
+ zbx_snprintf(error,sizeof(error),"Cannot store SNMP string value (ASN_IPADDRESS) in item having numeric type");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
ret = NOTSUPPORTED;
@@ -373,13 +373,13 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
p = malloc(16);
if(p)
{
- snprintf(p,MAX_STRING_LEN-1,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);
+ zbx_snprintf(p,16,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);
SET_STR_RESULT(value, p);
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"Cannot allocate required memory");
+ zbx_snprintf(error,sizeof(error),"Cannot allocate required memory");
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
}
@@ -390,7 +390,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
/* count is not really used. Has to be removed */
count++;
- snprintf(error,MAX_STRING_LEN-1,"OID [%s] value #%d has unknow type [%X]",item->snmp_oid, count,vars->type);
+ zbx_snprintf(error,sizeof(error),"OID [%s] value #%d has unknow type [%X]",item->snmp_oid, count,vars->type);
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -407,7 +407,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
snmp_errstring(response->errstat));
if(response->errstat == SNMP_ERR_NOSUCHNAME)
{
- snprintf(error,MAX_STRING_LEN-1,"SNMP error [%s]", snmp_errstring(response->errstat));
+ zbx_snprintf(error,sizeof(error),"SNMP error [%s]", snmp_errstring(response->errstat));
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -416,7 +416,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"SNMP error [%s]", snmp_errstring(response->errstat));
+ zbx_snprintf(error,sizeof(error),"SNMP error [%s]", snmp_errstring(response->errstat));
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
@@ -426,7 +426,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else if(status == STAT_TIMEOUT)
{
- snprintf(error,MAX_STRING_LEN-1,"Timeout while connecting to [%s]",session.peername);
+ zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]",session.peername);
/* snmp_sess_perror("snmpget", ss);*/
zabbix_log( LOG_LEVEL_ERR, error);
@@ -436,7 +436,7 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value)
}
else
{
- snprintf(error,MAX_STRING_LEN-1,"SNMP error [%d]",status);
+ zbx_snprintf(error,sizeof(error),"SNMP error [%d]",status);
zabbix_log( LOG_LEVEL_ERR, error);
SET_MSG_RESULT(value, strdup(error));
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index 35435e43..20377bd3 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -53,15 +53,19 @@
#include "checks_simple.h"
#include "checks_snmp.h"
+#include "daemon.h"
+
AGENT_RESULT result;
+static int my_server_num = 0;
+
int get_value(DB_ITEM *item, AGENT_RESULT *result)
{
int res=FAIL;
struct sigaction phan;
- phan.sa_handler = &signal_handler;
+ phan.sa_handler = &child_signal_handler;
sigemptyset(&phan.sa_mask);
phan.sa_flags = 0;
sigaction(SIGALRM, &phan, NULL);
@@ -117,19 +121,19 @@ static int get_minnextcheck(int now)
/* Host status 0 == MONITORED
1 == NOT MONITORED
2 == UNREACHABLE */
- if(server_num == 4)
+ if(my_server_num == 4)
{
- snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select count(*),min(nextcheck) from items i,hosts h where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
}
else
{
if(CONFIG_REFRESH_UNSUPPORTED != 0)
{
- snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
}
else
{
- snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
}
}
@@ -170,7 +174,7 @@ static void update_key_status(int hostid,int host_status)
zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(%d,%d)",hostid,host_status);
- snprintf(sql,sizeof(sql)-1,"select %s where h.hostid=i.hostid and h.hostid=%d and i.key_='%s'", ZBX_SQL_ITEM_SELECT, hostid,SERVER_STATUS_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select %s where h.hostid=i.hostid and h.hostid=%d and i.key_='%s'", ZBX_SQL_ITEM_SELECT, hostid,SERVER_STATUS_KEY);
zabbix_log(LOG_LEVEL_DEBUG, "SQL [%s]", sql);
result = DBselect(sql);
@@ -231,19 +235,19 @@ int get_values(void)
now = time(NULL);
/* Poller for unreachable hosts */
- if(server_num == 4)
+ if(my_server_num == 4)
{
- snprintf(sql,sizeof(sql)-1,"select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
}
else
{
if(CONFIG_REFRESH_UNSUPPORTED != 0)
{
- snprintf(sql,sizeof(sql)-1,"select %s where i.nextcheck<=%d and i.status in (%d,%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select %s where i.nextcheck<=%d and i.status in (%d,%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
}
else
{
- snprintf(sql,sizeof(sql)-1,"select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ zbx_snprintf(sql,sizeof(sql),"select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
}
}
result = DBselect(sql);
@@ -273,7 +277,7 @@ int get_values(void)
}
if(item.host_errors_from!=0)
{
- snprintf(sql,sizeof(sql)-1,"update hosts set errors_from=0 where hostid=%d", item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set errors_from=0 where hostid=%d", item.hostid);
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql);
DBexecute(sql);
@@ -285,7 +289,7 @@ int get_values(void)
{
if(item.status == ITEM_STATUS_NOTSUPPORTED)
{
- snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d, lastclock=%d where itemid=%d",calculate_item_nextcheck(CONFIG_REFRESH_UNSUPPORTED,now), now, item.itemid);
+ zbx_snprintf(sql,sizeof(sql),"update items set nextcheck=%d, lastclock=%d where itemid=%d",calculate_item_nextcheck(CONFIG_REFRESH_UNSUPPORTED,now), now, item.itemid);
DBexecute(sql);
}
else
@@ -315,7 +319,7 @@ int get_values(void)
zabbix_syslog("Host [%s]: first network error, wait for %d seconds", item.host, CONFIG_UNREACHABLE_DELAY);
item.host_errors_from=now;
- snprintf(sql,sizeof(sql)-1,"update hosts set errors_from=%d,disable_until=%d where hostid=%d", now, now+CONFIG_UNREACHABLE_DELAY, item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set errors_from=%d,disable_until=%d where hostid=%d", now, now+CONFIG_UNREACHABLE_DELAY, item.hostid);
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql);
DBexecute(sql);
}
@@ -330,7 +334,7 @@ int get_values(void)
update_key_status(item.hostid,HOST_AVAILABLE_FALSE); /* 2 */
item.host_available=HOST_AVAILABLE_FALSE;
- snprintf(sql,sizeof(sql)-1,"update hosts set disable_until=%d where hostid=%d", now+CONFIG_UNAVAILABLE_DELAY, item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set disable_until=%d where hostid=%d", now+CONFIG_UNAVAILABLE_DELAY, item.hostid);
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql);
DBexecute(sql);
}
@@ -340,7 +344,7 @@ int get_values(void)
zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", item.host, CONFIG_UNREACHABLE_DELAY);
zabbix_syslog("Host [%s]: another network error, wait for %d seconds", item.host, CONFIG_UNREACHABLE_DELAY);
- snprintf(sql,sizeof(sql)-1,"update hosts set disable_until=%d where hostid=%d", now+CONFIG_UNREACHABLE_DELAY, item.hostid);
+ zbx_snprintf(sql,sizeof(sql),"update hosts set disable_until=%d where hostid=%d", now+CONFIG_UNREACHABLE_DELAY, item.hostid);
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql);
DBexecute(sql);
}
@@ -370,18 +374,19 @@ int get_values(void)
return SUCCEED;
}
-void main_poller_loop()
+void main_poller_loop(int _server_num)
{
int now;
int nextcheck,sleeptime;
+ my_server_num = _server_num;
+
DBconnect();
for(;;)
{
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [getting values]");
-#endif
+ zbx_setproctitle("poller [getting values]");
+
now=time(NULL);
get_values();
@@ -410,10 +415,10 @@ void main_poller_loop()
}
zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
sleeptime );
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [sleeping for %d seconds]",
+
+ zbx_setproctitle("poller [sleeping for %d seconds]",
sleeptime);
-#endif
+
sleep( sleeptime );
}
else
diff --git a/src/zabbix_server/poller/poller.h b/src/zabbix_server/poller/poller.h
index 2a04e1d3..10fe6af4 100644
--- a/src/zabbix_server/poller/poller.h
+++ b/src/zabbix_server/poller/poller.h
@@ -30,6 +30,6 @@ extern int CONFIG_UNAVAILABLE_DELAY;
extern int CONFIG_UNREACHABLE_PERIOD;
extern int CONFIG_UNREACHABLE_DELAY;
-void main_poller_loop();
+void main_poller_loop(int _servernum);
#endif
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 043a07e6..3c714591 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -51,6 +51,8 @@
#include "expression.h"
#include "sysinfo.h"
+#include "daemon.h"
+
#include "alerter/alerter.h"
#include "housekeeper/housekeeper.h"
#include "pinger/pinger.h"
@@ -92,9 +94,8 @@ struct option longopts[] =
};
-pid_t *pids=NULL;
+pid_t *threads=NULL;
-int server_num=0;
int CONFIG_POLLER_FORKS = POLLER_FORKS;
/* For trapper */
@@ -103,7 +104,6 @@ int CONFIG_LISTEN_PORT = 10051;
int CONFIG_TRAPPER_TIMEOUT = TRAPPER_TIMEOUT;
/**/
/*int CONFIG_NOTIMEWAIT =0;*/
-int CONFIG_TIMEOUT = POLLER_TIMEOUT;
int CONFIG_HOUSEKEEPING_FREQUENCY = 1;
int CONFIG_SENDER_FREQUENCY = 30;
int CONFIG_PINGER_FREQUENCY = 60;
@@ -113,9 +113,6 @@ int CONFIG_UNREACHABLE_PERIOD = 45;
int CONFIG_UNREACHABLE_DELAY = 15;
int CONFIG_UNAVAILABLE_DELAY = 60;
int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING;
-char *CONFIG_FILE = NULL;
-char *CONFIG_PID_FILE = NULL;
-char *CONFIG_LOG_FILE = NULL;
char *CONFIG_ALERT_SCRIPTS_PATH = NULL;
char *CONFIG_FPING_LOCATION = NULL;
char *CONFIG_DBHOST = NULL;
@@ -131,187 +128,6 @@ int CONFIG_REFRESH_UNSUPPORTED = 0;
/******************************************************************************
* *
- * Function: uninit *
- * *
- * Purpose: kill all child processes, if any, and exit *
- * *
- * Parameters: *
- * *
- * Return value: *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: *
- * *
- ******************************************************************************/
-void uninit(void)
-{
- int i;
-
- if(server_num == 0)
- {
- if(pids != NULL)
- {
- for(i=0;i<CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS-1;i++)
- {
- if(kill(pids[i],SIGTERM) !=0 )
- {
- zabbix_log( LOG_LEVEL_WARNING, "Cannot kill process. PID=[%d] [%s]", pids[i], strerror(errno));
- }
- else
- {
- zabbix_log( LOG_LEVEL_DEBUG, "%d. Killing PID=[%d]", i, pids[i]);
- }
- }
- }
-
- if(unlink(CONFIG_PID_FILE) != 0)
- {
- zabbix_log( LOG_LEVEL_DEBUG, "Cannot remove PID file [%s] [%s]",
- CONFIG_PID_FILE, strerror(errno));
- }
- zabbix_log( LOG_LEVEL_CRIT, "ZABBIX server is down.");
- }
- exit(FAIL);
-}
-
-/******************************************************************************
- * *
- * Function: signal_handler *
- * *
- * Purpose: handle signals *
- * *
- * Parameters: sig - signal id *
- * *
- * Return value: *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: *
- * *
- ******************************************************************************/
-void signal_handler( int sig )
-{
- if( SIGALRM == sig )
- {
- signal( SIGALRM, signal_handler );
-
- zabbix_log( LOG_LEVEL_DEBUG, "Timeout while executing operation." );
- }
- else if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig || SIGPIPE == sig )
- {
- zabbix_log( LOG_LEVEL_DEBUG, "Server [%d]. Got QUIT or INT or TERM or PIPE signal. Exiting...", server_num );
- uninit();
- }
- else if( (SIGCHLD == sig) && (server_num == 0) )
- {
- zabbix_log( LOG_LEVEL_CRIT, "One server process died. Shutting down...");
- uninit();
- }
-/* else if( SIGCHLD == sig )
- {
- zabbix_log( LOG_LEVEL_ERR, "One child died. Exiting ..." );
- uninit();
- exit( FAIL );
- }*/
- else if( SIGPIPE == sig)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Got SIGPIPE. Where it came from???");
- }
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "Got signal [%d]. Ignoring ...", sig);
- }
-}
-
-/******************************************************************************
- * *
- * Function: daemon-init *
- * *
- * Purpose: init process as daemon *
- * *
- * Parameters: *
- * *
- * Return value: *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: it doesn't allow running under 'root' *
- * *
- ******************************************************************************/
-void daemon_init(void)
-{
- int i;
- pid_t pid;
- struct passwd *pwd;
-
- /* running as root ?*/
- if((getuid()==0) || (getgid()==0))
- {
- pwd = getpwnam("zabbix");
- if ( pwd == NULL )
- {
- fprintf(stderr,"User zabbix does not exist.\n");
- fprintf(stderr, "Cannot run as root !\n");
- exit(FAIL);
- }
- if( (setgid(pwd->pw_gid) ==-1) || (setuid(pwd->pw_uid) == -1) )
- {
- fprintf(stderr,"Cannot setgid or setuid to zabbix [%s]", strerror(errno));
- exit(FAIL);
- }
-
-#ifdef HAVE_FUNCTION_SETEUID
- if( setegid(pwd->pw_gid) ==-1)
- {
- fprintf(stderr,"Cannot setegid to zabbix [%s]\n", strerror(errno));
- exit(FAIL);
- }
- if( seteuid(pwd->pw_uid) ==-1)
- {
- fprintf(stderr,"Cannot seteuid to zabbix [%s]\n", strerror(errno));
- exit(FAIL);
- }
-#endif
-/* fprintf(stderr,"UID [%d] GID [%d] EUID[%d] GUID[%d]\n", getuid(), getgid(), geteuid(), getegid());*/
-
- }
-
- if(CONFIG_LOG_FILE == NULL)
- {
- zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL);
- }
- else
- {
- zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE);
- }
-
- if( (pid = fork()) != 0 )
- {
- exit( 0 );
- }
- setsid();
-
- signal( SIGHUP, SIG_IGN );
-
- if( (pid = fork()) !=0 )
- {
- exit( 0 );
- }
-
- chdir("/");
-
-/* umask(022);*/
- umask(002);
-
- for(i=0;i<MAXFD;i++)
- {
- if(i != fileno(stderr)) close(i);
- }
-}
-
-/******************************************************************************
- * *
* Function: init_config *
* *
* Purpose: parse config file and update configuration parameters *
@@ -346,7 +162,7 @@ void init_config(void)
{"DisablePinger",&CONFIG_DISABLE_PINGER,0,TYPE_INT,PARM_OPT,0,1},
{"DisableHousekeeping",&CONFIG_DISABLE_HOUSEKEEPING,0,TYPE_INT,PARM_OPT,0,1},
{"DebugLevel",&CONFIG_LOG_LEVEL,0,TYPE_INT,PARM_OPT,0,4},
- {"PidFile",&CONFIG_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0},
+ {"PidFile",&APP_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0},
{"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0},
{"AlertScriptsPath",&CONFIG_ALERT_SCRIPTS_PATH,0,TYPE_STRING,PARM_OPT,0,0},
{"DBHost",&CONFIG_DBHOST,0,TYPE_STRING,PARM_OPT,0,0},
@@ -371,9 +187,9 @@ void init_config(void)
zabbix_log( LOG_LEVEL_CRIT, "DBName not in config file");
exit(1);
}
- if(CONFIG_PID_FILE == NULL)
+ if(APP_PID_FILE == NULL)
{
- CONFIG_PID_FILE=strdup("/tmp/zabbix_server.pid");
+ APP_PID_FILE=strdup("/tmp/zabbix_server.pid");
}
if(CONFIG_ALERT_SCRIPTS_PATH == NULL)
{
@@ -396,16 +212,16 @@ void trend(void)
int i,j;
- snprintf(sql,sizeof(sql)-1,"select itemid from items");
+ zbx_snprintf(sql,sizeof(sql),"select itemid from items");
result2 = DBselect(sql);
for(i=0;i<DBnum_rows(result2);i++)
{
- snprintf(sql,sizeof(sql)-1,"select clock-clock%%3600, count(*),min(value),avg(value),max(value) from history where itemid=%d group by 1",atoi(DBget_field(result2,i,0)));
+ zbx_snprintf(sql,sizeof(sql),"select clock-clock%%3600, count(*),min(value),avg(value),max(value) from history where itemid=%d group by 1",atoi(DBget_field(result2,i,0)));
result = DBselect(sql);
for(j=0;j<DBnum_rows(result);j++)
{
- snprintf(sql,sizeof(sql)-1,"insert into trends (itemid, clock, num, value_min, value_avg, value_max) values (%d,%d,%d,%f,%f,%f)",atoi(DBget_field(result2,i,0)), atoi(DBget_field(result,j,0)),atoi(DBget_field(result,j,1)),atof(DBget_field(result,j,2)),atof(DBget_field(result,j,3)),atof(DBget_field(result,j,4)));
+ zbx_snprintf(sql,sizeof(sql),"insert into trends (itemid, clock, num, value_min, value_avg, value_max) values (%d,%d,%d,%f,%f,%f)",atoi(DBget_field(result2,i,0)), atoi(DBget_field(result,j,0)),atoi(DBget_field(result,j,1)),atof(DBget_field(result,j,2)),atof(DBget_field(result,j,3)),atof(DBget_field(result,j,4)));
DBexecute(sql);
}
DBfree_result(result);
@@ -454,13 +270,13 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp)
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{
zabbix_log( LOG_LEVEL_CRIT, "Cannot bind to port %d. Another zabbix_server running? Shutting down...", port);
- uninit();
+ exit(FAIL);
}
if(listen(sockfd, LISTENQ) !=0 )
{
zabbix_log( LOG_LEVEL_CRIT, "listen() failed");
- uninit();
+ exit(FAIL);
}
*addrlenp = sizeof(serv_addr);
@@ -517,20 +333,10 @@ void test()
int main(int argc, char **argv)
{
int ch;
- int i;
- pid_t pid;
-
- struct sigaction phan;
-
- int listenfd;
- socklen_t addrlen;
-
- char host[128];
-
- char sql[MAX_STRING_LEN];
+
+#ifdef HAVE_ZZZ
DB_RESULT result;
DB_ROW row;
-#ifdef HAVE_ZZZ
const char ** v;
#endif
@@ -612,37 +418,38 @@ int main(int argc, char **argv)
return 0;
#endif
- daemon_init();
-
- phan.sa_handler = &signal_handler; /* set up sig handler using sigaction() */
- sigemptyset(&phan.sa_mask);
- phan.sa_flags = 0;
- sigaction(SIGINT, &phan, NULL);
- sigaction(SIGQUIT, &phan, NULL);
- sigaction(SIGTERM, &phan, NULL);
- sigaction(SIGPIPE, &phan, NULL);
-
-/* Moved to daemon_init() */
-/* if(CONFIG_LOG_FILE == NULL)
+ return daemon_start(CONFIG_ALLOW_ROOT_PERMISSION);
+}
+
+int MAIN_ZABBIX_ENTRY(void)
+{
+ DB_RESULT result;
+ DB_ROW row;
+
+ int i;
+ pid_t pid;
+
+ int listenfd;
+ socklen_t addrlen;
+
+ char host[128];
+
+ int server_num = 0;
+
+ if(CONFIG_LOG_FILE == NULL)
{
zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL);
}
else
{
zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE);
- }*/
-
- if( FAIL == create_pid_file(CONFIG_PID_FILE))
- {
- exit(FAIL);
}
zabbix_log( LOG_LEVEL_WARNING, "Starting zabbix_server. ZABBIX %s.", ZABBIX_VERSION);
DBconnect();
- snprintf(sql,sizeof(sql)-1,"select refresh_unsupported from config");
- result = DBselect(sql);
+ result = DBselect("select refresh_unsupported from config");
row = DBfetch(result);
if(row && DBis_null(row[0]) != SUCCEED)
@@ -663,18 +470,18 @@ int main(int argc, char **argv)
return 0;
#endif
DBclose();
- pids=calloc(CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS-1,sizeof(pid_t));
+ threads = calloc(CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS,sizeof(pid_t));
- for(i=1;i<CONFIG_POLLER_FORKS;i++)
+ for(i=1; i<CONFIG_POLLER_FORKS; i++)
{
if((pid = fork()) == 0)
{
- server_num=i;
- break;
+ server_num = i;
+ break;
}
else
{
- pids[i-1]=pid;
+ threads[i]=pid;
}
}
@@ -682,7 +489,7 @@ int main(int argc, char **argv)
if( server_num == 0)
{
- sigaction(SIGCHLD, &phan, NULL);
+
/* Run trapper processes then do housekeeping */
if(gethostname(host,127) != 0)
{
@@ -692,20 +499,22 @@ int main(int argc, char **argv)
listenfd = tcp_listen(host,CONFIG_LISTEN_PORT,&addrlen);
- for(i = CONFIG_POLLER_FORKS; i< CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS; i++)
+ for(i = CONFIG_POLLER_FORKS; i < CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS; i++)
{
- pids[i-1] = child_trapper_make(i, listenfd, addrlen);
+ threads[i] = child_trapper_make(i, listenfd, addrlen);
}
/* First instance of zabbix_server performs housekeeping procedures */
zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Housekeeper]",server_num);
- for(i=0;i<CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS-1;i++)
+ for(i=0; i < CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS; i++)
{
- zabbix_log( LOG_LEVEL_DEBUG, "%d. PID=[%d]", i, pids[i]);
+ zabbix_log( LOG_LEVEL_DEBUG, "%d. PID=[%d]", i, threads[i]);
}
zabbix_log( LOG_LEVEL_CRIT, "ZABBIX server is up.");
+ init_main_process();
+
main_housekeeper_loop();
}
else if(server_num == 1)
@@ -735,7 +544,7 @@ int main(int argc, char **argv)
zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:OFF]",server_num);
#endif
- main_poller_loop();
+ main_poller_loop(server_num);
}
else
{
@@ -746,8 +555,44 @@ int main(int argc, char **argv)
zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:OFF]",server_num);
#endif
- main_poller_loop();
+ main_poller_loop(server_num);
}
return SUCCEED;
}
+
+void zbx_on_exit()
+{
+ zabbix_log(LOG_LEVEL_DEBUG, "zbx_on_exit() called.");
+
+#if !defined(WIN32)
+
+ int i = 0;
+
+ if(threads != NULL)
+ {
+ for(i = 0; i < CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS; i++)
+ {
+ if(threads[i]) {
+ kill(threads[i],SIGTERM);
+ threads[i] = (ZBX_THREAD_HANDLE)NULL;
+ }
+ }
+ }
+
+#endif /* not WIN32 */
+
+#ifdef USE_PID_FILE
+
+ daemon_stop();
+
+#endif /* USE_PID_FILE */
+
+ zbx_sleep(2); /* wait for all threads closing */
+
+ zabbix_log(LOG_LEVEL_INFORMATION, "ZABBIX Server stopped");
+ zabbix_close_log();
+
+ exit(SUCCEED);
+}
+
diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c
index 5dcc27c2..648bd6eb 100644
--- a/src/zabbix_server/timer/timer.c
+++ b/src/zabbix_server/timer/timer.c
@@ -77,22 +77,20 @@ void main_timer_loop()
for(;;)
{
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("updating nodata() functions");
-#endif
+ zbx_setproctitle("updating nodata() functions");
DBconnect();
now=time(NULL);
/*
#ifdef HAVE_PGSQL
- snprintf(sql,sizeof(sql)-1,"select distinct f.itemid,f.functionid,f.parameter from functions f, items i,hosts h where h.hostid=i.hostid and h.status=%d and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter::text::integer<=%d and i.status=%d", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select distinct f.itemid,f.functionid,f.parameter from functions f, items i,hosts h where h.hostid=i.hostid and h.status=%d and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter::text::integer<=%d and i.status=%d", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE);
#else
- snprintf(sql,sizeof(sql)-1,"select distinct f.itemid,f.functionid,f.parameter,f.function from functions f, items i,hosts h where h.hostid=i.hostid and h.status=%d and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter<=%d and i.status=%d", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select distinct f.itemid,f.functionid,f.parameter,f.function from functions f, items i,hosts h where h.hostid=i.hostid and h.status=%d and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter<=%d and i.status=%d", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE);
#endif
*/
- snprintf(sql,sizeof(sql)-1,"select distinct %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now') and i.itemid=f.itemid", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE);
+ zbx_snprintf(sql,sizeof(sql),"select distinct %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now') and i.itemid=f.itemid", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE);
result = DBselect(sql);
@@ -101,7 +99,7 @@ void main_timer_loop()
DBget_item_from_db(&item,row);
/* Update triggers will update value for NODATA */
-/* snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='1' where itemid=%d and function='%s' and parameter='%s'" , itemid, function, parameter );
+/* zbx_snprintf(sql,sizeof(sql),"update functions set lastvalue='1' where itemid=%d and function='%s' and parameter='%s'" , itemid, function, parameter );
DBexecute(sql);*/
update_functions(&item);
@@ -111,9 +109,8 @@ void main_timer_loop()
DBfree_result(result);
DBclose();
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("sleeping for 30 sec");
-#endif
+ zbx_setproctitle("sleeping for 30 sec");
+
sleep(30);
}
}
diff --git a/src/zabbix_server/trapper/active.c b/src/zabbix_server/trapper/active.c
index 4930e5c6..31424422 100644
--- a/src/zabbix_server/trapper/active.c
+++ b/src/zabbix_server/trapper/active.c
@@ -69,12 +69,12 @@ int send_list_of_active_checks(int sockfd, char *host)
zabbix_log( LOG_LEVEL_DEBUG, "In send_list_of_active_checks()");
- snprintf(sql,sizeof(sql)-1,"select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s'", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host);
+ zbx_snprintf(sql,sizeof(sql),"select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s'", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host);
result = DBselect(sql);
while((row=DBfetch(result)))
{
- snprintf(s,sizeof(s)-1,"%s:%s:%s\n",row[0],row[1],row[2]);
+ zbx_snprintf(s,sizeof(s),"%s:%s:%s\n",row[0],row[1],row[2]);
zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s);
if( write(sockfd,s,strlen(s)) == -1 )
{
@@ -92,7 +92,7 @@ int send_list_of_active_checks(int sockfd, char *host)
}
DBfree_result(result);
- snprintf(s,sizeof(s)-1,"%s\n","ZBX_EOF");
+ zbx_snprintf(s,sizeof(s),"%s\n","ZBX_EOF");
zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s);
if( write(sockfd,s,strlen(s)) == -1 )
{
diff --git a/src/zabbix_server/trapper/autoregister.c b/src/zabbix_server/trapper/autoregister.c
index 2076ed8e..99f63203 100644
--- a/src/zabbix_server/trapper/autoregister.c
+++ b/src/zabbix_server/trapper/autoregister.c
@@ -57,7 +57,7 @@ int autoregister(char *server)
return FAIL;
}
- snprintf(sql,sizeof(sql)-1,"select id,pattern,hostid from autoreg order by priority");
+ zbx_snprintf(sql,sizeof(sql),"select id,pattern,hostid from autoreg order by priority");
result = DBselect(sql);
diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c
index 6fc3ce18..d0755c61 100644
--- a/src/zabbix_server/trapper/trapper.c
+++ b/src/zabbix_server/trapper/trapper.c
@@ -52,6 +52,8 @@
#include "autoregister.h"
#include "trapper.h"
+#include "daemon.h"
+
extern int send_list_of_active_checks(int sockfd, char *host);
int process_trap(int sockfd,char *s, int max_len)
@@ -143,11 +145,11 @@ int process_trap(int sockfd,char *s, int max_len)
ret=process_data(sockfd,server,key,value_string,lastlogsize,timestamp,source,severity);
if( SUCCEED == ret)
{
- snprintf(result,sizeof(result)-1,"OK\n");
+ zbx_snprintf(result,sizeof(result),"OK\n");
}
else
{
- snprintf(result,sizeof(result)-1,"NOT OK\n");
+ zbx_snprintf(result,sizeof(result),"NOT OK\n");
}
zabbix_log( LOG_LEVEL_DEBUG, "Sending back [%s]", result);
zabbix_log( LOG_LEVEL_DEBUG, "Length [%d]", strlen(result));
@@ -171,7 +173,7 @@ void process_trapper_child(int sockfd)
zabbix_log( LOG_LEVEL_DEBUG, "In process_trapper_child");
- phan.sa_handler = &signal_handler;
+ phan.sa_handler = &child_signal_handler;
sigemptyset(&phan.sa_mask);
phan.sa_flags = 0;
sigaction(SIGALRM, &phan, NULL);
@@ -234,15 +236,14 @@ void child_trapper_main(int i,int listenfd, int addrlen)
for(;;)
{
clilen = addrlen;
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("waiting for connection");
-#endif
+
+ zbx_setproctitle("waiting for connection");
+
zabbix_log( LOG_LEVEL_DEBUG, "Before accept()");
connfd=accept(listenfd,&cliaddr, &clilen);
zabbix_log( LOG_LEVEL_DEBUG, "After accept()");
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("processing data");
-#endif
+
+ zbx_setproctitle("processing data");
process_trapper_child(connfd);
@@ -259,10 +260,6 @@ pid_t child_trapper_make(int i,int listenfd, int addrlen)
{
return (pid);
}
- else
- {
- server_num=i;
- }
/* never returns */
child_trapper_main(i, listenfd, addrlen);
diff --git a/src/zabbix_server/zlog.c b/src/zabbix_server/zlog.c
index 5a9d36d4..3dffec26 100644
--- a/src/zabbix_server/zlog.c
+++ b/src/zabbix_server/zlog.c
@@ -63,7 +63,7 @@ void zabbix_syslog(const char *fmt, ...)
zabbix_log(LOG_LEVEL_DEBUG, "In zabbix_log()");
- snprintf(sql,sizeof(sql)-1,"select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d", ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR);
+ zbx_snprintf(sql,sizeof(sql),"select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d", ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR);
result = DBselect(sql);
while((row=DBfetch(result)))
diff --git a/src/zabbix_snmptrapper/zabbix_snmptrapper.c b/src/zabbix_snmptrapper/zabbix_snmptrapper.c
index 00dd3fcb..4388d546 100644
--- a/src/zabbix_snmptrapper/zabbix_snmptrapper.c
+++ b/src/zabbix_snmptrapper/zabbix_snmptrapper.c
@@ -171,7 +171,7 @@ int send_value(char *server,int port,char *shortname,char *value)
return FAIL;
}
- sprintf(tosend,"%s:%s\n",shortname,value);
+ zbx_snprintf(tosend, sizeof(tosend), "%s:%s\n",shortname,value);
if( sendto(s,tosend,strlen(tosend),0,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
{
@@ -272,7 +272,7 @@ int main(int argc, char **argv)
alarm(SNMPTRAPPER_TIMEOUT);
- sprintf(str,"%s(%s)", hostname, ip);
+ zbx_snprintf(str, sizeof(str), "%s(%s)", hostname, ip);
ret = send_value(CONFIG_SERVER, CONFIG_SERVER_PORT, argv[3],argv[4]);