[Nagios-checkins] SF.net SVN: nagios:[2078] nagioscore/trunk

ageric at users.sourceforge.net ageric at users.sourceforge.net
Mon Aug 20 16:25:36 UTC 2012


Revision: 2078
          http://nagios.svn.sourceforge.net/nagios/?rev=2078&view=rev
Author:   ageric
Date:     2012-08-20 16:25:36 +0000 (Mon, 20 Aug 2012)
Log Message:
-----------
Add lib/lnag-utils.h

Since libnagios can't use anything from core nagios although the
other way around works fine, we're forced to move everything we
want to have in the library to somewhere where we can use it. The
things we want to move includes a few macros that are generally
useful, so we introduce the "lnag-utils.h" header file, which can
keep track of declarations for small inline functions, various
micro-helpers and the above-mentioned useful macros for us, while
updating everything else to be able to make use of it.

This means the CGI's can now use header-files from libnagios exactly
like the core daemon can, which paves the way for linking the cgi's
against libnagios too.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/cgi/Makefile.in
    nagioscore/trunk/include/broker.h
    nagioscore/trunk/include/cgiauth.h
    nagioscore/trunk/include/cgiutils.h
    nagioscore/trunk/include/comments.h
    nagioscore/trunk/include/common.h
    nagioscore/trunk/include/downtime.h
    nagioscore/trunk/include/getcgi.h
    nagioscore/trunk/include/logging.h
    nagioscore/trunk/include/macros.h
    nagioscore/trunk/include/nagios.h
    nagioscore/trunk/include/nebcallbacks.h
    nagioscore/trunk/include/nebmods.h
    nagioscore/trunk/include/nebmodules.h
    nagioscore/trunk/include/nebstructs.h
    nagioscore/trunk/include/netutils.h
    nagioscore/trunk/include/objects.h
    nagioscore/trunk/include/perfdata.h
    nagioscore/trunk/include/shared.h
    nagioscore/trunk/include/skiplist.h
    nagioscore/trunk/include/sretention.h
    nagioscore/trunk/include/statusdata.h
    nagioscore/trunk/lib/libnagios.h

Added Paths:
-----------
    nagioscore/trunk/lib/lnag-utils.h

Removed Paths:
-------------
    nagioscore/trunk/include/compat.h

Modified: nagioscore/trunk/cgi/Makefile.in
===================================================================
--- nagioscore/trunk/cgi/Makefile.in	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/cgi/Makefile.in	2012-08-20 16:25:36 UTC (rev 2078)
@@ -25,7 +25,7 @@
 
 CP=@CP@
 CC=@CC@
-CFLAGS=-Wall @CFLAGS@ @DEFS@ -DNSCGI
+CFLAGS=-Wall -I.. @CFLAGS@ @DEFS@ -DNSCGI
 
 # Compiler flags for optimization (overrides default)
 #CFLAGS=-O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -DHAVE_CONFIG_H -DNSCGI

Modified: nagioscore/trunk/include/broker.h
===================================================================
--- nagioscore/trunk/include/broker.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/broker.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -177,7 +177,6 @@
 /****** EVENT BROKER FUNCTIONS *************/
 
 #ifdef USE_EVENT_BROKER
-#include "compat.h"
 NAGIOS_BEGIN_DECL
 
 struct timeval get_broker_timestamp(struct timeval *);

Modified: nagioscore/trunk/include/cgiauth.h
===================================================================
--- nagioscore/trunk/include/cgiauth.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/cgiauth.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -22,7 +22,6 @@
 
 #ifndef _AUTH_H
 #define _AUTH_H
-#include "compat.h"
 #include "common.h"
 #include "objects.h"
 

Modified: nagioscore/trunk/include/cgiutils.h
===================================================================
--- nagioscore/trunk/include/cgiutils.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/cgiutils.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -20,7 +20,7 @@
 
 #ifndef _CGIUTILS_H
 #define _CGIUTILS_H
-#include "compat.h"
+#include "lib/libnagios.h"
 #include "logging.h"
 #include "objects.h"
 #include "cgiauth.h"

Modified: nagioscore/trunk/include/comments.h
===================================================================
--- nagioscore/trunk/include/comments.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/comments.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,6 @@
 
 #ifndef _COMMENTS_H
 #define _COMMENTS_H
-#include "compat.h"
 #include "common.h"
 #include "objects.h"
 

Modified: nagioscore/trunk/include/common.h
===================================================================
--- nagioscore/trunk/include/common.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/common.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -27,10 +27,7 @@
 /* Experimental performance tweaks - use with caution */
 #undef USE_MEMORY_PERFORMANCE_TWEAKS
 
-/* my_free has been freed from bondage as a function */
-#define my_free(ptr) do { if(ptr) { free(ptr); ptr = NULL; } } while(0)
 
-
 /****************** SERVICE STATES ********************/
 #define STATE_OK			0
 #define STATE_WARNING			1

Deleted: nagioscore/trunk/include/compat.h
===================================================================
--- nagioscore/trunk/include/compat.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/compat.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -1,19 +0,0 @@
-/* compatibility macros, primarily to keep indentation programs
- * from going bananas when indenting everything below
- #ifdef __cplusplus
- 'extern "C" {'
- #endif
- * as if it was a real block, which is just godsdamn annoying.
- */
-#ifndef _COMPAT_H
-#define _COMPAT_H
-
-#ifdef __cplusplus
-# define NAGIOS_BEGIN_DECL extern "C" {
-# define NAGIOS_END_DECL }
-#else
-# define NAGIOS_BEGIN_DECL /* nothing */
-# define NAGIOS_END_DECL /* more of nothing */
-#endif
-
-#endif /* _COMPAT_H */

Modified: nagioscore/trunk/include/downtime.h
===================================================================
--- nagioscore/trunk/include/downtime.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/downtime.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -24,7 +24,6 @@
 #ifndef _DOWNTIME_H
 #define _DOWNTIME_H
 
-#include "compat.h"
 #include "common.h"
 #include "objects.h"
 #ifdef NSCORE

Modified: nagioscore/trunk/include/getcgi.h
===================================================================
--- nagioscore/trunk/include/getcgi.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/getcgi.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -5,7 +5,7 @@
  *
  *****************************************************/
 
-#include "compat.h"
+#include "lib/lnag-utils.h"
 NAGIOS_BEGIN_DECL
 
 char **getcgivars(void);

Modified: nagioscore/trunk/include/logging.h
===================================================================
--- nagioscore/trunk/include/logging.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/logging.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -1,7 +1,6 @@
 #ifndef INCLUDE_logging_h__
 #define INCLUDE_logging_h__
 
-#include "compat.h"
 #include "objects.h"
 
 /******************* LOGGING TYPES ********************/

Modified: nagioscore/trunk/include/macros.h
===================================================================
--- nagioscore/trunk/include/macros.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/macros.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -22,7 +22,6 @@
 #ifndef _MACROS_H
 #define _MACROS_H
 
-#include "compat.h"
 #include "common.h"
 #include "objects.h"
 

Modified: nagioscore/trunk/include/nagios.h
===================================================================
--- nagioscore/trunk/include/nagios.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/nagios.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -27,13 +27,11 @@
 # define NSCORE
 #endif
 
-#include "compat.h"
-#include "logging.h"
 #include "common.h"
+#include "logging.h"
 #include "locations.h"
 #include "objects.h"
 #include "macros.h"
-#include "lib/libnagios.h"
 
 	/************* MISC LENGTH/SIZE DEFINITIONS ***********/
 

Modified: nagioscore/trunk/include/nebcallbacks.h
===================================================================
--- nagioscore/trunk/include/nebcallbacks.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/nebcallbacks.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,6 @@
 #ifndef _NEBCALLBACKS_H
 #define _NEBCALLBACKS_H
 
-#include "compat.h"
 #include "nebmodules.h"
 
 

Modified: nagioscore/trunk/include/nebmods.h
===================================================================
--- nagioscore/trunk/include/nebmods.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/nebmods.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,6 @@
 #ifndef _NEBMODS_H
 #define _NEBMODS_H
 
-#include "compat.h"
 #include "nebcallbacks.h"
 #include "nebmodules.h"
 

Modified: nagioscore/trunk/include/nebmodules.h
===================================================================
--- nagioscore/trunk/include/nebmodules.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/nebmodules.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,7 @@
 #ifndef _NEBMODULES_H
 #define _NEBMODULES_H
 
-#include "compat.h"
+#include "common.h"
 NAGIOS_BEGIN_DECL
 
 	/***** MODULE VERSION INFORMATION *****/

Modified: nagioscore/trunk/include/nebstructs.h
===================================================================
--- nagioscore/trunk/include/nebstructs.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/nebstructs.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,7 @@
 #ifndef _NEBSTRUCTS_H
 #define _NEBSTRUCTS_H
 
-#include "compat.h"
+#include "common.h"
 #include "objects.h"
 #include "nagios.h"
 

Modified: nagioscore/trunk/include/netutils.h
===================================================================
--- nagioscore/trunk/include/netutils.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/netutils.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -1,6 +1,6 @@
 #ifndef _NETUTILS_H
 #define _NETUTILS_H
-#include "compat.h"
+#include "common.h"
 NAGIOS_BEGIN_DECL
 int my_tcp_connect(char *host_name, int port, int *sd, int timeout);
 int my_sendall(int s, char *buf, int *len, int timeout);

Modified: nagioscore/trunk/include/objects.h
===================================================================
--- nagioscore/trunk/include/objects.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/objects.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -24,7 +24,6 @@
 #ifndef _OBJECTS_H
 #define _OBJECTS_H
 
-#include "compat.h"
 #include "common.h"
 
 NAGIOS_BEGIN_DECL

Modified: nagioscore/trunk/include/perfdata.h
===================================================================
--- nagioscore/trunk/include/perfdata.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/perfdata.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,7 @@
 #ifndef _PERFDATA_H
 #define _PERFDATA_H
 
-#include "compat.h"
+#include "common.h"
 #include "objects.h"
 
 NAGIOS_BEGIN_DECL

Modified: nagioscore/trunk/include/shared.h
===================================================================
--- nagioscore/trunk/include/shared.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/shared.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -2,7 +2,7 @@
 #define INCLUDE__shared_h__
 
 #include <time.h>
-#include "compat.h"
+#include "lib/libnagios.h"
 
 NAGIOS_BEGIN_DECL
 
@@ -33,9 +33,6 @@
 	unsigned int servicegroups;
 	};
 
-/* only usable on compile-time initialized arrays, for obvious reasons */
-#define ARRAY_SIZE(ary) (sizeof(ary) / sizeof(ary[0]))
-
 extern char *my_strtok(char *buffer, char *tokens);
 extern char *my_strsep(char **stringp, const char *delim);
 extern mmapfile *mmap_fopen(char *filename);

Modified: nagioscore/trunk/include/skiplist.h
===================================================================
--- nagioscore/trunk/include/skiplist.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/skiplist.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -21,7 +21,7 @@
 
 #ifndef _SKIPLIST_H
 #define _SKIPLIST_H
-#include "compat.h"
+#include "common.h"
 
 #define SKIPLIST_OK              0
 #define SKIPLIST_ERROR_ARGS      1

Modified: nagioscore/trunk/include/sretention.h
===================================================================
--- nagioscore/trunk/include/sretention.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/sretention.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -20,7 +20,7 @@
  *
  *****************************************************************************/
 
-#include "compat.h"
+#include "common.h"
 NAGIOS_BEGIN_DECL
 
 int initialize_retention_data(char *);

Modified: nagioscore/trunk/include/statusdata.h
===================================================================
--- nagioscore/trunk/include/statusdata.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/include/statusdata.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -23,7 +23,7 @@
 #ifndef _STATUSDATA_H
 #define _STATUSDATA_H
 
-#include "compat.h"
+#include "common.h"
 
 #ifdef NSCORE
 #include "objects.h"

Modified: nagioscore/trunk/lib/libnagios.h
===================================================================
--- nagioscore/trunk/lib/libnagios.h	2012-08-20 16:24:38 UTC (rev 2077)
+++ nagioscore/trunk/lib/libnagios.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -6,6 +6,7 @@
 
 #ifndef LIB_libnagios_h__
 #define LIB_libnagios_h__
+#include "lnag-utils.h"
 #include "pqueue.h"
 #include "squeue.h"
 #include "kvvec.h"

Added: nagioscore/trunk/lib/lnag-utils.h
===================================================================
--- nagioscore/trunk/lib/lnag-utils.h	                        (rev 0)
+++ nagioscore/trunk/lib/lnag-utils.h	2012-08-20 16:25:36 UTC (rev 2078)
@@ -0,0 +1,75 @@
+#ifndef LIBNAGIOS_lnag_utils_h__
+#define LIBNAGIOS_lnag_utils_h__
+
+#ifdef __cplusplus
+# define NAGIOS_BEGIN_DECL extern "C" {
+# define NAGIOS_END_DECL }
+#else
+# define NAGIOS_BEGIN_DECL /* nothing */
+# define NAGIOS_END_DECL /* more of nothing */
+#endif
+
+/**
+ * @file lnag-utils.h
+ * @brief libnagios helper functions that lack a "real" home.
+ *
+ * @{
+ */
+
+/** Useful macro to safely avoid double-free memory corruption */
+#define my_free(ptr) do { if(ptr) { free(ptr); ptr = NULL; } } while(0)
+
+#ifndef ARRAY_SIZE
+/** Useful for iterating over all elements in a static array */
+# define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#endif
+#ifndef veclen
+/** useful for iterating over all elements in a static array */
+# define veclen ARRAY_SIZE
+#endif
+
+NAGIOS_BEGIN_DECL
+
+/**
+ * Check if a number is a power of 2
+ * @param x The number to check
+ * @return 1 if the number is a power of 2, 0 if it's not
+ */
+static inline int lnag_ispof2(unsigned int x)
+{
+	return !(x & (x - 1));
+}
+
+#ifdef __GNUC__
+# define lnag_clz(x) __builtin_clz(x)
+#else
+/**
+ * Count leading zeroes
+ * @param x The unsigned integer to check
+ * @return Number of leading zero bits
+ */
+static inline int lnag_clz(unsigned int x)
+{
+	for (i = 0; i < sizeof(x) * 8; i++) {
+		if (x >> (i * sizeof(x) * 8) == 1)
+			return i;
+	}
+}
+#endif
+
+/**
+ * Round up to a power of 2
+ * Yes, this is the most cryptic function name in all of Nagios, but I
+ * like it, so shush.
+ * @param r The number to round up
+ * @return r, rounded up to the nearest power of 2.
+ */
+static inline unsigned int rup2pof2(unsigned int r)
+{
+	return lnag_ispof2(r) ? r : 1 << ((sizeof(r) * 8) - (lnag_clz(r)));
+}
+
+NAGIOS_END_DECL
+
+/** @} */
+#endif /* NAGIOSINCLUDE_pp_utils_h__ */

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list