]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
nginx: add support for unix domain sockets
authorBas Stottelaar <basstottelaar@gmail.com>
Wed, 16 Jun 2021 21:49:38 +0000 (23:49 +0200)
committerBas Stottelaar <basstottelaar@gmail.com>
Wed, 16 Jun 2021 22:53:53 +0000 (00:53 +0200)
Support for UNIX domain socket was introduced in NGINX version 0.8.21
[1]. One can use this to create option to have the stub_status plugin
reachable via a socket-only server.

[1] http://nginx.org/en/docs/http/ngx_http_core_module.html#listen

configure.ac
src/nginx.c

index bcfb8cf572209be24302172a1eaaed6af13477a6..ae2fb08c734075b9ba7c2e55e9e2c2e4382f68dd 100644 (file)
@@ -2322,6 +2322,12 @@ if test "x$with_libcurl" = "xyes"; then
       [have_curlopt_timeout="no"],
       [[#include <curl/curl.h>]]
     )
+
+    AC_CHECK_DECL(CURLOPT_UNIX_SOCKET_PATH,
+      [have_curlopt_unix_socket_path="yes"],
+      [have_curlopt_unix_socket_path="no"],
+      [[#include <curl/curl.h>]]
+    )
   fi
 fi
 
@@ -2373,6 +2379,12 @@ if test "x$with_libcurl" = "xyes"; then
       [Define if libcurl supports CURLOPT_TIMEOUT_MS option.]
     )
   fi
+
+  if test "x$have_curlopt_unix_socket_path" = "xyes"; then
+    AC_DEFINE([HAVE_CURLOPT_UNIX_SOCKET_PATH], [1],
+      [Define if libcurl supports CURLOPT_UNIX_SOCKET_PATH option.]
+    )
+  fi
 fi
 
 AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS)
index 0da66ce2e94525902008090a31d3d148fb18a51a..08293a506ac7542aab1ad66819640195d3380b3e 100644 (file)
@@ -40,6 +40,7 @@ static char *verify_peer;
 static char *verify_host;
 static char *cacert;
 static char *timeout;
+static char *sock;
 
 static CURL *curl;
 
@@ -47,8 +48,9 @@ static char nginx_buffer[16384];
 static size_t nginx_buffer_len;
 static char nginx_curl_error[CURL_ERROR_SIZE];
 
-static const char *config_keys[] = {
-    "URL", "User", "Password", "VerifyPeer", "VerifyHost", "CACert", "Timeout"};
+static const char *config_keys[] = {"URL",        "User",       "Password",
+                                    "VerifyPeer", "VerifyHost", "CACert",
+                                    "Timeout",    "Socket"};
 static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
 
 static size_t nginx_curl_callback(void *buf, size_t size, size_t nmemb,
@@ -98,6 +100,8 @@ static int config(const char *key, const char *value) {
     return config_set(&cacert, value);
   else if (strcasecmp(key, "timeout") == 0)
     return config_set(&timeout, value);
+  else if (strcasecmp(key, "socket") == 0)
+    return config_set(&sock, value);
   else
     return -1;
 } /* int config */
@@ -161,6 +165,12 @@ static int init(void) {
   }
 #endif
 
+#ifdef HAVE_CURLOPT_UNIX_SOCKET_PATH
+  if (sock != NULL) {
+    curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, sock);
+  }
+#endif
+
   return 0;
 } /* void init */