summaryrefslogtreecommitdiffstats
path: root/gl/error.c
diff options
context:
space:
mode:
authorTon Voon <ton.voon@opsera.com>2010-06-17 09:16:43 (GMT)
committertonvoon <ton.voon@opsera.com>2010-06-23 13:30:34 (GMT)
commit18f6835edaf7d640a2c9e476cb1babdbdadbfd9b (patch)
treeae11f40e48dc34658445c99012726f32bfb45c56 /gl/error.c
parentf61412478ceb7c821793c8356b936f64066508bf (diff)
downloadmonitoring-plugins-18f6835edaf7d640a2c9e476cb1babdbdadbfd9b.tar.gz
Added state retention APIs. Implemented for check_snmp with --rate option.
See http://nagiosplugin.org/c-api-private for more details on the API. Also updated check_snmp -l option to change the perfdata label.
Diffstat (limited to 'gl/error.c')
-rw-r--r--gl/error.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/gl/error.c b/gl/error.c
index c79e8d4..ed9dba0 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -88,6 +88,15 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
88# include <fcntl.h> 88# include <fcntl.h>
89# include <unistd.h> 89# include <unistd.h>
90 90
91# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
92/* Get declarations of the Win32 API functions. */
93# define WIN32_LEAN_AND_MEAN
94# include <windows.h>
95# endif
96
97/* The gnulib override of fcntl is not needed in this file. */
98# undef fcntl
99
91# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P 100# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
92# ifndef HAVE_DECL_STRERROR_R 101# ifndef HAVE_DECL_STRERROR_R
93"this configure-time declaration test was not run" 102"this configure-time declaration test was not run"
@@ -104,10 +113,29 @@ extern char *program_name;
104# endif /* HAVE_STRERROR_R || defined strerror_r */ 113# endif /* HAVE_STRERROR_R || defined strerror_r */
105#endif /* not _LIBC */ 114#endif /* not _LIBC */
106 115
116#if !_LIBC
117/* Return non-zero if FD is open. */
118static inline int
119is_open (int fd)
120{
121# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
122 /* On Win32: The initial state of unassigned standard file descriptors is
123 that they are open but point to an INVALID_HANDLE_VALUE. There is no
124 fcntl, and the gnulib replacement fcntl does not support F_GETFL. */
125 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
126# else
127# ifndef F_GETFL
128# error Please port fcntl to your platform
129# endif
130 return 0 <= fcntl (fd, F_GETFL);
131# endif
132}
133#endif
134
107static inline void 135static inline void
108flush_stdout (void) 136flush_stdout (void)
109{ 137{
110#if !_LIBC && defined F_GETFL 138#if !_LIBC
111 int stdout_fd; 139 int stdout_fd;
112 140
113# if GNULIB_FREOPEN_SAFER 141# if GNULIB_FREOPEN_SAFER
@@ -124,7 +152,7 @@ flush_stdout (void)
124 /* POSIX states that fflush (stdout) after fclose is unspecified; it 152 /* POSIX states that fflush (stdout) after fclose is unspecified; it
125 is safe in glibc, but not on all other platforms. fflush (NULL) 153 is safe in glibc, but not on all other platforms. fflush (NULL)
126 is always defined, but too draconian. */ 154 is always defined, but too draconian. */
127 if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL)) 155 if (0 <= stdout_fd && is_open (stdout_fd))
128#endif 156#endif
129 fflush (stdout); 157 fflush (stdout);
130} 158}