]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoa-server: Externalise debug functions
authorThierry FOURNIER <thierry.fournier@ozon.io>
Sun, 25 Feb 2018 09:54:56 +0000 (10:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 May 2019 15:43:47 +0000 (17:43 +0200)
Make external LOG and DEBUG function. Other process can use this ones
and later these functions will be replaced by another log system

contrib/spoa_server/spoa.c
contrib/spoa_server/spoa.h

index 52d1c914db35d9839fb3e1e107b8a90934d8f959..94be6c05502e07bc5b551a1c5c8c02ca17a9bfea 100644 (file)
 
 #define SLEN(str) (sizeof(str)-1)
 
-#define LOG(fmt, args...)                                           \
-       do {                                                        \
-               struct timeval now;                                 \
-               int wid = *((int*)pthread_getspecific(worker_id));  \
-                                                                   \
-               gettimeofday(&now, NULL);                           \
-               fprintf(stderr, "%ld.%06ld [%02d] " fmt "\n",       \
-                       now.tv_sec, now.tv_usec, wid, ##args);      \
-       } while (0)
-
-#define DEBUG(x...)                             \
-       do {                                    \
-               if (debug)                      \
-                       LOG(x);                 \
-       } while (0)
-
 /* Frame Types sent by HAProxy and by agents */
 enum spoe_frame_type {
        /* Frames sent by HAProxy */
@@ -110,8 +94,8 @@ static const char *spoe_frm_err_reasons[SPOE_FRM_ERRS] = {
        [SPOE_FRM_ERR_UNKNOWN]        = "an unknown error occurred",
 };
 
-static bool debug = false;
-static pthread_key_t worker_id;
+bool debug = false;
+pthread_key_t worker_id;
 
 static void
 check_ipv4_reputation(struct worker *w, struct in_addr *ipv4)
index 81f5816c2e87cd6363a0f5f8fea6945d1f91a0c0..92c24ac55b205b588c02c8d6c309229eaa295de4 100644 (file)
 #ifndef __SPOA_H__
 #define __SPOA_H__
 
+#include <pthread.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <netinet/in.h>
+#include <sys/time.h>
 
 #define MAX_FRAME_SIZE    16384
 #define SPOP_VERSION      "1.0"
@@ -78,4 +80,23 @@ struct spoe_data {
        union spoe_value    u;     /* spoe data value */
 };
 
+extern bool debug;
+extern pthread_key_t worker_id;
+
+#define LOG(fmt, args...) \
+       do { \
+               struct timeval now; \
+               int wid = *((int*)pthread_getspecific(worker_id)); \
+               \
+               gettimeofday(&now, NULL); \
+               fprintf(stderr, "%ld.%06ld [%02d] " fmt "\n", \
+                       now.tv_sec, now.tv_usec, wid, ##args); \
+       } while (0)
+
+#define DEBUG(x...) \
+       do { \
+               if (debug) \
+                       LOG(x); \
+       } while (0)
+
 #endif /* __SPOA_H__ */