]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix: Crash on SIGSEGV if at least one worker thread cannot be launched
authorWaldemar Zimpel <w.zimpel@dev.utilizer.de>
Thu, 27 Mar 2025 22:15:05 +0000 (23:15 +0100)
committerWaldemar Zimpel <w.zimpel@dev.utilizer.de>
Thu, 27 Mar 2025 22:15:05 +0000 (23:15 +0100)
Perform a clean shutdown in case worker threads cannot be lauched.

src/app/main/main.c
src/core/mainloop/cpuworker.c
src/core/mainloop/cpuworker.h

index 6d05bd1f5e2489473e19f793ee964e9aeef82949..0bb87eb08d5d1936cb251f0d78ab76b7c6af861f 100644 (file)
@@ -1244,7 +1244,8 @@ run_tor_main_loop(void)
 
   /* launch cpuworkers. Need to do this *after* we've read the onion key. */
   /* launch them always for all tors, now that clients can solve onion PoWs. */
-  cpuworker_init();
+  if (cpuworker_init() == -1)
+    return -1;
 
   consdiffmgr_enable_background_compression();
 
index b12879a17866b4a3072aaa4a0e0337bfc022283f..602ebda22821f658ff1624af9e9626635ecf27f7 100644 (file)
@@ -113,10 +113,8 @@ cpuworker_consensus_has_changed(const networkstatus_t *ns)
   set_max_pending_tasks(ns);
 }
 
-/** Initialize the cpuworker subsystem. It is OK to call this more than once
- * during Tor's lifetime.
- */
-void
+/** Initialize the cpuworker subsystem. */
+int
 cpuworker_init(void)
 {
   /*
@@ -132,11 +130,18 @@ cpuworker_init(void)
                               worker_state_free_void,
                               NULL);
 
+  if (!threadpool) {
+    log_err(LD_GENERAL, "Can't create worker thread pool");
+    return -1;
+  }
+
   int r = threadpool_register_reply_event(threadpool, NULL);
 
   tor_assert(r == 0);
 
   set_max_pending_tasks(NULL);
+
+  return 0;
 }
 
 /** Free all resources allocated by cpuworker. */
index 7f00f363fe5c29881078b23bc318f1637db1f345..f976a4b3790c40ff45c7ed7ea3dbf2c239a205c4 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef TOR_CPUWORKER_H
 #define TOR_CPUWORKER_H
 
-void cpuworker_init(void);
+int cpuworker_init(void);
 void cpuworker_free_all(void);
 void cpuworkers_rotate_keyinfo(void);