From 491c39f4d0964c0cf4dfa076de259f50a02fa307 Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Fri, 21 Nov 2025 12:23:36 +0800 Subject: [PATCH] refactor: change dir permissions. --- apps/common/utils/tool_code.py | 10 +++++++--- installer/start-maxkb.sh | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/common/utils/tool_code.py b/apps/common/utils/tool_code.py index 7519b80f0..fed7ef3e9 100644 --- a/apps/common/utils/tool_code.py +++ b/apps/common/utils/tool_code.py @@ -18,7 +18,6 @@ python_directory = sys.executable class ToolExecutor: - _dir_initialized = False def __init__(self, sandbox=False): self.sandbox = sandbox @@ -33,9 +32,15 @@ class ToolExecutor: self._init_dir() def _init_dir(self): - if ToolExecutor._dir_initialized: + try: # 只初始化一次 + fd = os.open(os.path.join(PROJECT_DIR, 'tmp', 'tool_executor_init_dir.lock'), + os.O_CREAT | os.O_EXCL | os.O_WRONLY) + os.close(fd) + except FileExistsError: + # 文件已存在 → 已执行过 return + maxkb_logger.debug("init dir") if self.sandbox: os.chmod("/dev/shm", 0o707) os.chmod("/dev/mqueue", 0o707) @@ -61,7 +66,6 @@ class ToolExecutor: except Exception as e: maxkb_logger.error(f'Failed to init SANDBOX_BANNED_HOSTS due to exception: {e}', exc_info=True) pass - ToolExecutor._dir_initialized = True def exec_code(self, code_str, keywords): self.validate_banned_keywords(code_str) diff --git a/installer/start-maxkb.sh b/installer/start-maxkb.sh index 5ffd5ca1e..73fc757e7 100644 --- a/installer/start-maxkb.sh +++ b/installer/start-maxkb.sh @@ -10,5 +10,5 @@ if [ ! -d /opt/maxkb/local ]; then fi mkdir -p /opt/maxkb/python-packages -rm -f /opt/maxkb-app/tmp/*.pid +rm -f /opt/maxkb-app/tmp/* python /opt/maxkb-app/main.py start \ No newline at end of file