Linux + iPhone Continuity / iMessage / SMS
Cleanup
sfreeman42205721b651654
diff --git a/src/core/src/net.cpp b/src/core/src/net.cppindex 9e9addc..530ee46 100644--- a/src/core/src/net.cpp+++ b/src/core/src/net.cpp@@ -1338,11 +1338,16 @@ namespace tether {reason += ebuf;}ERR_clear_error();- if (reason.empty())- reason = (err == SSL_ERROR_ZERO_RETURN || (err == SSL_ERROR_SYSCALL && ret == 0))- ? "peer closed connection during handshake"- : (err == SSL_ERROR_SYSCALL ? std::string("syscall error: ") + std::strerror(errno)- : "ssl error " + std::to_string(err));+ if (reason.empty()) {+ if (err == SSL_ERROR_ZERO_RETURN || (err == SSL_ERROR_SYSCALL && ret == 0)) {+ reason = "peer closed connection during handshake";+ } else if (err == SSL_ERROR_SYSCALL) {+ reason = (errno != 0) ? std::string("syscall error: ") + std::strerror(errno)+ : "ssl syscall failed";+ } else {+ reason = "ssl error " + std::to_string(err);+ }+ }debug::log(ERR,"TcpServer: TLS handshake failed for {} (fd: {}): {}",client_info_[client_fd].address,diff --git a/test/test_net.cpp b/test/test_net.cppindex cf27313..3e5c007 100644--- a/test/test_net.cpp+++ b/test/test_net.cpp@@ -6,6 +6,7 @@#include <tether/net.hpp>#include <arpa/inet.h>+#include <cerrno>#include <chrono>#include <csignal>#include <cstdlib>@@ -21,6 +22,10 @@namespace {+ std::string unique_test_dir(const std::string& prefix) {+ return (std::filesystem::temp_directory_path() / (prefix + "_" + std::to_string(getpid()))).string();+ }+// Helper RAII class to ensure proper cleanupclass CleanupGuard {public:@@ -41,10 +46,20 @@ namespace {public:ProcessGuard(pid_t pid) : pid_(pid) {}~ProcessGuard() {- if (pid_ > 0) {+ if (pid_ <= 0)+ return;++ int status = 0;+ const pid_t waited = waitpid(pid_, &status, WNOHANG);+ if (waited == pid_) {+ pid_ = -1;+ return;+ }+ if (waited == 0) {kill(pid_, SIGKILL);- waitpid(pid_, nullptr, 0);+ waitpid(pid_, &status, 0);}+ pid_ = -1;}private:@@ -56,7 +71,7 @@ namespace {// pair dialog) inherits it and keeps the lock alive after the daemon is gone,// which permanently blocks restarts with "tetherd is already running".TEST(SingleInstanceLockTest, ExecedHelpersDoNotKeepTheLockAliveAfterTheDaemonExits) {- const std::string runtime_dir = "/tmp/tether_lock_test";+ const std::string runtime_dir = unique_test_dir("tether_lock_test");CleanupGuard cleanup_guard(runtime_dir);std::filesystem::remove_all(runtime_dir);std::filesystem::create_directories(runtime_dir);@@ -152,7 +167,7 @@ namespace {};TEST(TcpServerTest, ReportsWhyATlsHandshakeFailed) {- const std::string home = "/tmp/tether_net_test";+ const std::string home = unique_test_dir("tether_net_test");CleanupGuard cleanup_guard(home);std::filesystem::remove_all(home);std::filesystem::create_directories(home);