Skip to content

Commit

Permalink
Fixing incompatible for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Wh1isper committed Nov 29, 2023
1 parent 1d0df22 commit ec249b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions duetector/injectors/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import glob
import itertools
import os
import signal
from datetime import datetime, timedelta
from pathlib import Path
Expand Down Expand Up @@ -42,12 +43,14 @@ def from_pid(cls, pid: int, proc_root: str | Path = "/proc") -> "ProcInfo":
proc_dir = (proc_root / str(pid)).resolve()

try:
cwd = (proc_dir / "cwd").readlink().as_posix()
exe = (proc_dir / "exe").readlink().as_posix()
root = (proc_dir / "root").readlink().as_posix()
# Path.readlink is new in Python 3.9
# Use os.readlink for Python 3.8
cwd = os.readlink(proc_dir / "cwd")
exe = os.readlink(proc_dir / "exe")
root = os.readlink(proc_dir / "root")

cgroup = (proc_dir / "cgroup").read_text().strip().split("\n")
ns = {p.name: p.readlink().as_posix() for p in (proc_dir / "ns").glob("*")}
ns = {p.name: os.readlink(p) for p in (proc_dir / "ns").glob("*")}

except PermissionError as e:
logger.warning(f"{e}, check if you are running as root.")
Expand Down

0 comments on commit ec249b7

Please sign in to comment.