penguin/tinyproxy

An L4 proxy designed to act as a tiny transparent shim

commit 3501c2577d131dc2fb8a606648b9ee419aa1118d

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-05-30T13:57:58Z
subjectAdding freebsd target
commit 3501c2577d131dc2fb8a606648b9ee419aa1118d
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-05-30T13:57:58Z

    Adding freebsd target
---
 .github/workflows/cmake-multi-platform.yml | 40 ++++++++++++++++++++++++++++--
 mk/common.mk                               | 16 ++++++++++--
 src/worker.c                               | 18 +++++++++++---
 3 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml
index 16d02f8..b966f8f 100644
--- a/.github/workflows/cmake-multi-platform.yml
+++ b/.github/workflows/cmake-multi-platform.yml
@@ -45,7 +45,7 @@ jobs:
 
           mkdir -p dist/debug dist/prod
 
-          make clean all STATIC=1 CFLAGS="-Og -g3 -Wall -Wextra -Wpedantic"
+          make clean all STATIC=1 EXTRA_CFLAGS="-Og -g3 -Wpedantic"
           cp bin/tinyproxy dist/debug/tinyproxy
 
           make clean all STATIC=1
@@ -138,6 +138,42 @@ jobs:
       - *package_unix
       - *upload_unix
 
+  freebsd-amd64:
+    name: FreeBSD amd64
+    runs-on: ubuntu-latest
+
+    steps:
+      - *checkout
+
+      - name: Build and test on FreeBSD
+        uses: vmactions/freebsd-vm@v1
+        with:
+          release: "14.2"
+          usesh: true
+          prepare: |
+            pkg install -y gmake pkgconf libevent python3 haproxy
+          run: |
+            set -eu
+
+            gmake clean all EXTRA_CFLAGS="-Og -g3 -Wpedantic"
+            gmake test
+
+            gmake clean all
+
+            mkdir -p dist/tinyproxy
+            cp bin/tinyproxy dist/tinyproxy/
+            cp -r examples dist/tinyproxy/
+
+            tar -C dist -czf tinyproxy-freebsd-amd64.tar.gz tinyproxy
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v4
+        with:
+          name: tinyproxy-freebsd-amd64
+          path: tinyproxy-freebsd-amd64.tar.gz
+          if-no-files-found: error
+          retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
+
   macos:
     name: macOS build
     runs-on: macos-15
@@ -156,7 +192,7 @@ jobs:
 
           mkdir -p dist/debug dist/prod
 
-          make clean all STATIC=0 CFLAGS="-Og -g3 -Wall -Wextra -Wpedantic" LDFLAGS=""
+          make clean all STATIC=0 EXTRA_CFLAGS="-Og -g3 -Wpedantic"
           cp bin/tinyproxy dist/debug/tinyproxy
 
           make clean all STATIC=0
diff --git a/mk/common.mk b/mk/common.mk
index c499d5b..effef9b 100644
--- a/mk/common.mk
+++ b/mk/common.mk
@@ -19,7 +19,11 @@ EXEEXT := .exe
 WINDOWS_LDLIBS += -lws2_32
 endif
 
-CFLAGS ?= -O2 -DNDEBUG -Wall -Wextra -ffunction-sections -fdata-sections
+BASE_CFLAGS ?= -O2 -DNDEBUG -Wall -Wextra -ffunction-sections -fdata-sections
+
+CFLAGS += $(BASE_CFLAGS)
+CFLAGS += $(EXTRA_CFLAGS)
+
 CPPFLAGS += -I$(SRC_DIR)
 
 UNAME_S := $(shell uname)
@@ -34,9 +38,17 @@ else ifeq ($(OS),Windows_NT)
 STATIC ?= 0
 LDFLAGS += -Wl,--gc-sections
 TEST_FLAGS := CONCURRENCY=100 TOTAL=100 FD_LIMIT=512
+else ifeq ($(UNAME_S),FreeBSD)
+STATIC ?= 0
+CFLAGS += -pthread
+CPPFLAGS += -I/usr/local/include
+LDFLAGS += -pthread
+LDFLAGS += -L/usr/local/lib
+LDFLAGS += -Wl,--gc-sections
+TEST_FLAGS :=
 else
 STATIC ?= 1
-CFLAGS  += -pthread
+CFLAGS += -pthread
 LDFLAGS += -Wl,--gc-sections
 TEST_FLAGS :=
 endif
diff --git a/src/worker.c b/src/worker.c
index 0c3dcf0..ebb1142 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -16,17 +16,27 @@ static int notify_worker(struct worker *w)
 	char byte = 1;
 	int rc;
 
-	(void)w;
-
 #ifdef _WIN32
 	rc = send(w->notify_send_fd, &byte, 1, 0);
 	if (rc == SOCKET_ERROR) {
-		return WSAGetLastError();
+		int err = WSAGetLastError();
+
+		if (err == WSAEWOULDBLOCK) {
+			return 0; /* already has pending wakeup */
+		}
+
+		return err;
 	}
 #else
 	rc = (int)send(w->notify_send_fd, &byte, 1, 0);
 	if (rc < 0) {
-		return errno;
+		int err = errno;
+
+		if (err == EAGAIN || err == EWOULDBLOCK) {
+			return 0; /* already has pending wakeup */
+		}
+
+		return err;
 	}
 #endif