Skip to content

Commit 491c39f

Browse files
refactor: change dir permissions.
1 parent a9b6f2b commit 491c39f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

apps/common/utils/tool_code.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
class ToolExecutor:
21-
_dir_initialized = False
2221

2322
def __init__(self, sandbox=False):
2423
self.sandbox = sandbox
@@ -33,9 +32,15 @@ def __init__(self, sandbox=False):
3332
self._init_dir()
3433

3534
def _init_dir(self):
36-
if ToolExecutor._dir_initialized:
35+
try:
3736
# 只初始化一次
37+
fd = os.open(os.path.join(PROJECT_DIR, 'tmp', 'tool_executor_init_dir.lock'),
38+
os.O_CREAT | os.O_EXCL | os.O_WRONLY)
39+
os.close(fd)
40+
except FileExistsError:
41+
# 文件已存在 → 已执行过
3842
return
43+
maxkb_logger.debug("init dir")
3944
if self.sandbox:
4045
os.chmod("/dev/shm", 0o707)
4146
os.chmod("/dev/mqueue", 0o707)
@@ -61,7 +66,6 @@ def _init_dir(self):
6166
except Exception as e:
6267
maxkb_logger.error(f'Failed to init SANDBOX_BANNED_HOSTS due to exception: {e}', exc_info=True)
6368
pass
64-
ToolExecutor._dir_initialized = True
6569

6670
def exec_code(self, code_str, keywords):
6771
self.validate_banned_keywords(code_str)

installer/start-maxkb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ if [ ! -d /opt/maxkb/local ]; then
1010
fi
1111
mkdir -p /opt/maxkb/python-packages
1212

13-
rm -f /opt/maxkb-app/tmp/*.pid
13+
rm -f /opt/maxkb-app/tmp/*
1414
python /opt/maxkb-app/main.py start

0 commit comments

Comments
 (0)