Skip to content

Commit 94b2659

Browse files
refactor: use /tmp instead of /opt/maxkb-app/sandbox/tmp if SANDBOX_TMP_DIR_ENABLED is enabled.
1 parent ca9fa9d commit 94b2659

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

apps/common/utils/tool_code.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ def __init__(self, sandbox=False):
3232
self.sandbox_so_path = f'{self.sandbox_path}/lib/sandbox.so'
3333
self.process_timeout_seconds = int(CONFIG.get("SANDBOX_PYTHON_PROCESS_TIMEOUT_SECONDS", '3600'))
3434
try:
35-
self._init_dir()
35+
self._init_sandbox_dir()
3636
except Exception as e:
3737
# 本机忽略异常,容器内不忽略
3838
maxkb_logger.error(f'Exception: {e}', exc_info=True)
3939
if self.sandbox:
4040
raise e
4141

42-
def _init_dir(self):
42+
def _init_sandbox_dir(self):
43+
if not self.sandbox:
44+
# 不是sandbox就不初始化目录
45+
return
4346
try:
4447
# 只初始化一次
4548
fd = os.open(os.path.join(PROJECT_DIR, 'tmp', 'tool_executor_init_dir.lock'),
@@ -49,17 +52,14 @@ def _init_dir(self):
4952
# 文件已存在 → 已初始化过
5053
return
5154
maxkb_logger.debug("init dir")
52-
if self.sandbox:
53-
try:
54-
os.system("chmod -R g-rwx /dev/shm /dev/mqueue")
55-
os.system("chmod o-rwx /run/postgresql")
56-
except Exception as e:
57-
maxkb_logger.warning(f'Exception: {e}', exc_info=True)
58-
pass
55+
try:
56+
os.system("chmod -R g-rwx /dev/shm /dev/mqueue")
57+
os.system("chmod o-rwx /run/postgresql")
58+
except Exception as e:
59+
maxkb_logger.warning(f'Exception: {e}', exc_info=True)
60+
pass
5961
if CONFIG.get("SANDBOX_TMP_DIR_ENABLED", '0') == "1":
60-
tmp_dir_path = os.path.join(self.sandbox_path, 'tmp')
61-
os.makedirs(tmp_dir_path, 0o700, exist_ok=True)
62-
os.system(f"chown -R {self.user}:root {tmp_dir_path}")
62+
os.system("chmod g+rwx /tmp")
6363
# 初始化sandbox配置文件
6464
sandbox_lib_path = os.path.dirname(self.sandbox_so_path)
6565
sandbox_conf_file_path = f'{sandbox_lib_path}/.sandbox.conf'

0 commit comments

Comments
 (0)