fix
This commit is contained in:
Binary file not shown.
@@ -183,7 +183,6 @@ class OccupationResolver:
|
|||||||
if main_mount_point and main_mount_point != 'N/A' and main_mount_point != '[SWAP]':
|
if main_mount_point and main_mount_point != 'N/A' and main_mount_point != '[SWAP]':
|
||||||
logger.debug(f"设备 {device_path} 的主挂载点是 {main_mount_point}。")
|
logger.debug(f"设备 {device_path} 的主挂载点是 {main_mount_point}。")
|
||||||
|
|
||||||
# 尝试卸载嵌套挂载,并循环几次,因为某些挂载可能需要多次尝试
|
|
||||||
max_unmount_attempts = 3
|
max_unmount_attempts = 3
|
||||||
for attempt in range(max_unmount_attempts):
|
for attempt in range(max_unmount_attempts):
|
||||||
logger.info(f"尝试卸载嵌套挂载点 (第 {attempt + 1} 次尝试)。")
|
logger.info(f"尝试卸载嵌套挂载点 (第 {attempt + 1} 次尝试)。")
|
||||||
@@ -203,7 +202,6 @@ class OccupationResolver:
|
|||||||
return True # 主挂载点已卸载,设备应该已空闲
|
return True # 主挂载点已卸载,设备应该已空闲
|
||||||
|
|
||||||
# 3. 检查设备本身或其(可能已不存在的)主挂载点是否仍被占用 (fuser)
|
# 3. 检查设备本身或其(可能已不存在的)主挂载点是否仍被占用 (fuser)
|
||||||
# 即使主挂载点已卸载,也可能存在进程直接占用设备文件的情况,或者之前卸载失败。
|
|
||||||
fuser_targets = [device_path]
|
fuser_targets = [device_path]
|
||||||
if main_mount_point and main_mount_point != 'N/A' and main_mount_point != '[SWAP]' and main_mount_point not in fuser_targets:
|
if main_mount_point and main_mount_point != 'N/A' and main_mount_point != '[SWAP]' and main_mount_point not in fuser_targets:
|
||||||
fuser_targets.append(main_mount_point)
|
fuser_targets.append(main_mount_point)
|
||||||
@@ -227,14 +225,26 @@ class OccupationResolver:
|
|||||||
if success_fuser and stdout_fuser:
|
if success_fuser and stdout_fuser:
|
||||||
logger.debug(f"fuser -vm {target} 输出:\n{stdout_fuser}")
|
logger.debug(f"fuser -vm {target} 输出:\n{stdout_fuser}")
|
||||||
for line in stdout_fuser.splitlines():
|
for line in stdout_fuser.splitlines():
|
||||||
occupation_info_lines.append(line.strip())
|
line = line.strip() # 清除行首尾空白
|
||||||
|
if not line: # 跳过空行
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 收集所有非空行用于最终显示
|
||||||
|
occupation_info_lines.append(line)
|
||||||
|
|
||||||
|
# 检查是否包含 "kernel" 关键字
|
||||||
if "kernel" in line:
|
if "kernel" in line:
|
||||||
kernel_mounts_found = True
|
kernel_mounts_found = True
|
||||||
|
|
||||||
match = re.match(r'^\S+:\s+\S+\s+(?P<id>\d+)\s+.*', line)
|
# 尝试从详细格式的行中提取 PID (例如: /dev/sda2: root 42032 .rce. gpg-agent)
|
||||||
if match:
|
match_verbose = re.match(r'^\S+:\s+\S+\s+(?P<id>\d+)\s+.*', line)
|
||||||
pids_to_kill.add(match.group('id'))
|
if match_verbose:
|
||||||
|
pids_to_kill.add(match_verbose.group('id'))
|
||||||
|
else:
|
||||||
|
# 如果不是详细格式,检查是否是纯数字 PID (例如: 42032)
|
||||||
|
# 这种情况下,fuser -vm 可能只输出了 PID
|
||||||
|
if line.isdigit():
|
||||||
|
pids_to_kill.add(line)
|
||||||
|
|
||||||
pids_to_kill_list = list(pids_to_kill)
|
pids_to_kill_list = list(pids_to_kill)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user