fix(core): nfqws segfault, trap cleanup, strategy name extraction

- install_nfqws.sh: strip LTO and --gc-sections flags from Makefile before
  build to prevent segfault on some systems; verify binary runs before install
- lib/functions.sh: check_nfqws() now also tests --help to catch segfaulting
  or missing-dependency binaries
- run_strategy.sh: replace broken single-quoted trap string with proper
  cleanup_tmp function so temp file is actually removed
- service.sh: extract strategy name by stripping general_ prefix from
  wrapper filename so ExecStart points to correct config

Fixes: nfqws segfault on build, service start failure, temp file leak.
This commit is contained in:
OpenCode Agent
2026-05-10 19:48:30 +04:00
parent 62ec6c5749
commit efdb5902a6
4 changed files with 31 additions and 2 deletions

View File

@@ -101,6 +101,8 @@ fi
cd "$BUILD_DIR/zapret"
echo "[*] Building nfqws..."
# Fix: disable LTO and aggressive section-gc that can cause segfaults on some systems
sed -i 's/-flto=auto//g; s/-Wl,--gc-sections//g; s/-ffunction-sections//g; s/-fdata-sections//g' nfq/Makefile 2>/dev/null || true
if ! make -C nfq; then
echo "[!] Build failed!"
exit 1
@@ -111,6 +113,21 @@ if [ ! -f "$BUILD_DIR/zapret/nfq/nfqws" ]; then
exit 1
fi
# Verify the binary actually runs (catch segfaults early)
if ! "$BUILD_DIR/zapret/nfq/nfqws" --help >/dev/null 2>&1; then
echo "[!] nfqws segfaults with current flags. Rebuilding without strip..."
sed -i 's/-s //g; s/ -s//g' nfq/Makefile 2>/dev/null || true
make -C nfq clean && make -C nfq
if [ ! -f "$BUILD_DIR/zapret/nfq/nfqws" ]; then
echo "[!] nfqws binary not found after rebuild"
exit 1
fi
if ! "$BUILD_DIR/zapret/nfq/nfqws" --help >/dev/null 2>&1; then
echo "[!] nfqws still segfaults. Aborting."
exit 1
fi
fi
mkdir -p "$BIN_DIR"
cp "$BUILD_DIR/zapret/nfq/nfqws" "$BIN_DIR/"
chmod +x "$BIN_DIR/nfqws"

View File

@@ -122,6 +122,16 @@ check_nfqws() {
echo ""
return 1
fi
# Verify the binary actually runs (catches segfaults/missing deps)
if ! "$BIN_DIR/nfqws" --help >/dev/null 2>&1; then
echo ""
print_red "ERROR: nfqws binary exists but does not run (segfault? missing deps?)"
echo ""
echo "Try rebuilding:"
echo " ./install_nfqws.sh"
echo ""
return 1
fi
return 0
}

View File

@@ -80,7 +80,8 @@ parse_conf_args() {
# Build args in main shell using temp file
cd "$SCRIPT_DIR"
TMP_ARGS="$(mktemp /tmp/zapret_args.XXXXXX)"
trap "rm -f '\$TMP_ARGS'" EXIT
cleanup_tmp() { rm -f "$TMP_ARGS" 2>/dev/null || true; }
trap cleanup_tmp EXIT
parse_conf_args "$CONF_FILE" > "$TMP_ARGS"

View File

@@ -149,7 +149,8 @@ service_install() {
fi
local strategy_name
strategy_name=$(basename "$selected" .sh)
strategy_name=$(basename "$selected" .sh | sed 's/^general_//')
[[ -z "$strategy_name" ]] && strategy_name="general"
echo ""
echo "[*] Installing strategy: $strategy_name"