Compare commits

..

3 Commits

Author SHA1 Message Date
remittor
b0fc623183 luci: Fix func execAndRead 2026-01-31 23:09:12 +03:00
remittor
1f784b5773 executor: Fix error "XHR request timed out" 2026-01-31 21:27:45 +03:00
remittor
d85c80504f makefile: use UPX for packing nfqws2 2026-01-31 20:57:34 +03:00
3 changed files with 62 additions and 15 deletions

View File

@@ -809,11 +809,23 @@ return baseclass.extend({
{
ticks += 1;
try {
if (retCode < 0) {
let rc = await fs.exec('/bin/cat', [ rcFile ], null);
if (rc.code != 0) {
fixLogEnd();
resolve(callback.call(ctx, 542, 'ERROR: cannot read file "' + rcFile + '"'));
return;
}
if (rc.stdout) {
retCode = parseInt(rc.stdout.trim(), 10);
}
}
let res = await fs.exec('/bin/cat', [ logFile ], null);
if (res.code != 0) {
if (ticks > 1) {
console.log('ERROR: execAndRead: '+JSON.stringify(opt_list));
resolve(callback.call(ctx, 541, 'ERROR: Failed on read process log: code = ' + res.code));
fixLogEnd();
resolve(callback.call(ctx, 546, 'ERROR: Failed on read process log: code = ' + res.code));
return;
}
setTimeout(epoll, 500);
@@ -831,17 +843,6 @@ return baseclass.extend({
appendLog(log, '');
lastLen = res.stdout.length;
}
if (retCode < 0) {
let rc = await fs.exec('/bin/cat', [ rcFile ], null);
if (rc.code != 0) {
fixLogEnd();
resolve(callback.call(ctx, 545, 'ERROR: cannot read file "' + rcFile + '"'));
return;
}
if (rc.stdout) {
retCode = parseInt(rc.stdout.trim(), 10);
}
}
if (retCode >= 0) {
fixLogEnd();
if (retCode == 0 && res.stdout) {

View File

@@ -53,6 +53,19 @@ else
LUA_LIBRARY:=-L$(STAGING_DIR)/usr/lib -llua$(LUA_VER)
endif
UPX_VER:=5.1.0
UPX_URL:=https://github.com/upx/upx/releases/download/v$(UPX_VER)
UPX_URL_FILE:=upx-$(UPX_VER)-amd64_linux.tar.xz
UPX_TAR:=$(PKG_NAME)-$(UPX_URL_FILE)
UPX_DIR:=$(PKG_BUILD_DIR)/upx
UPX_BIN:=$(UPX_DIR)/upx
ifneq ($(filter mips64,$(ARCH)),)
USE_UPX := 0
else
USE_UPX := 1
endif
#TAR_OPTIONS:=--strip-components 1 $(TAR_OPTIONS)
#TAR_CMD=$(HOST_TAR) -C $(1) $(TAR_OPTIONS)
@@ -80,6 +93,14 @@ endef
$(eval $(call Download,$(PKG_NAME)-luajit))
endif
define Download/$(PKG_NAME)-upx
FILE:=$(UPX_TAR)
URL:=$(UPX_URL)
URL_FILE:=$(UPX_URL_FILE)
HASH:=skip
endef
$(eval $(call Download,$(PKG_NAME)-upx))
define Build/Prepare
$(Build/Prepare/Default)
rm -f $(PKG_BUILD_DIR)/$(MAKE_PATH)/nfqws2
@@ -97,6 +118,9 @@ define Build/Prepare
tar -xzf "$(DL_DIR)/$(LUAJIT_TGZ)" --strip-components=1 -C "$(LUASRC_DIR)" ; \
rm -rf $(LUAOUT_DIR) ; \
fi
rm -rf $(UPX_DIR)
mkdir -p $(UPX_DIR)
tar -xf "$(DL_DIR)/$(UPX_TAR)" --strip-components=1 -C "$(UPX_DIR)"
endef
#define Build/Configure
@@ -135,6 +159,16 @@ define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR)/$(MAKE_PATH) $(TARGET_CONFIGURE_OPTS) LUA_JIT=$(LUA_JIT) LUA_CFLAGS="$(LUA_INCLUDE)" LUA_LIB="$(LUA_LIBRARY)"
$(MAKE) -C $(PKG_BUILD_DIR)/ip2net $(TARGET_CONFIGURE_OPTS)
$(MAKE) -C $(PKG_BUILD_DIR)/mdig $(TARGET_CONFIGURE_OPTS)
ifeq ($(USE_UPX),1)
@if [ -x "$(UPX_BIN)" ]; then \
echo "Packing nfqws2 with UPX"; \
$(UPX_BIN) --best --lzma $(PKG_BUILD_DIR)/$(MAKE_PATH)/nfqws2; \
else \
echo "WARNING: UPX not found, skipping packing"; \
fi
else
@echo "Skipping UPX for $(ARCH)"
endif
endef
ZAPRET_DIR := /opt/zapret2

View File

@@ -1,12 +1,18 @@
#!/bin/sh
# Copyright (c) 2024 remittor
PID_FILE=/tmp/zapret-script-exec.pid
[ -f $PID_FILE ] && exit 70
if [ -f $PID_FILE ]; then
echo "ERROR: file $PID_FILE already exists!" | awk 'NR==1'
exit 70
fi
LOG_FILE=$1
RC_FILE=$1.rc
SH_FILE=$2
shift 2
[ ! -f $SH_FILE ] && exit 71
if [ ! -f $SH_FILE ]; then
echo "ERROR: script $SH_FILE not found!" | awk 'NR==1'
exit 71
fi
: > $LOG_FILE
: > $RC_FILE
start-stop-daemon -S -b -p $PID_FILE -x /bin/sh -- -c '
@@ -16,7 +22,13 @@ start-stop-daemon -S -b -p $PID_FILE -x /bin/sh -- -c '
shift 3
sh $SH_FILE "$@" > $LOG_FILE 2>&1
RET_CODE=$?
sleep 1
wc -l $LOG_FILE >/dev/null
echo $RET_CODE > $RC_FILE
' sh $LOG_FILE $RC_FILE $SH_FILE "$@"
RET_CODE=$?
if [ $RET_CODE != 0 ]; then
echo "ERROR: script $SH_FILE not executed! ret_code = $RET_CODE" | awk 'NR==1'
exit $RET_CODE
fi
echo "Script $SH_FILE running..." | awk 'NR==1'
exit 0