]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Isolate warn_about_resource_exhaution()
authorqontinuum <qontinuum@monaco.mc>
Tue, 29 Nov 2022 20:34:06 +0000 (21:34 +0100)
committerqontinuum <qontinuum@monaco.mc>
Sun, 11 Dec 2022 09:14:18 +0000 (10:14 +0100)
src/core/mainloop/connection.c

index b0b297ac57b6905439bd6520763e207d9c0d6d91..7de53e818ff1f8dfe820579bd9b9bb3760278fb4 100644 (file)
@@ -1256,6 +1256,23 @@ create_unix_sockaddr(const char *listenaddress, char **readable_address,
 }
 #endif /* defined(HAVE_SYS_UN_H) || defined(RUNNING_DOXYGEN) */
 
+/* Log a rate-limited warning about resource exhaustion */
+static void
+warn_about_resource_exhaution(void)
+{
+#define WARN_TOO_MANY_CONNS_INTERVAL (6*60*60)
+  static ratelim_t last_warned = RATELIM_INIT(WARN_TOO_MANY_CONNS_INTERVAL);
+  char *m;
+  if ((m = rate_limit_log(&last_warned, approx_time()))) {
+    int n_conns = get_n_open_sockets();
+    log_warn(LD_NET,"Failing because we have %d connections already. Please "
+             "read doc/TUNING for guidance.%s", n_conns, m);
+    tor_free(m);
+    control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d",
+                                 n_conns);
+  }
+}
+
 /**
  * A socket failed from resource exhaustion.
  *
@@ -1284,17 +1301,7 @@ socket_failed_from_resource_exhaustion(void)
     rep_hist_note_overload(OVERLOAD_FD_EXHAUSTED);
   }
 
-#define WARN_TOO_MANY_CONNS_INTERVAL (6*60*60)
-  static ratelim_t last_warned = RATELIM_INIT(WARN_TOO_MANY_CONNS_INTERVAL);
-  char *m;
-  if ((m = rate_limit_log(&last_warned, approx_time()))) {
-    int n_conns = get_n_open_sockets();
-    log_warn(LD_NET,"Failing because we have %d connections already. Please "
-             "read doc/TUNING for guidance.%s", n_conns, m);
-    tor_free(m);
-    control_event_general_status(LOG_WARN, "TOO_MANY_CONNECTIONS CURRENT=%d",
-                                 n_conns);
-  }
+  warn_about_resource_exhaution();
 }
 
 #ifdef HAVE_SYS_UN_H