Mercurial > dropbear
annotate test/parent_dropbear_map.py @ 1938:77bc00dcc19f default tip main master
Bump version to 2022.82
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 01 Apr 2022 14:43:27 +0800 |
parents | 1c9215154d4a |
children |
rev | line source |
---|---|
1861 | 1 #!/usr/bin/env python3 |
2 | |
3 import os | |
4 import sys | |
5 import time | |
6 import psutil | |
7 | |
8 from pathlib import Path | |
9 | |
10 | |
11 want_name = "dropbear" | |
1874
1c9215154d4a
Handle /proc/.../maps being reordered
Matt Johnston <matt@ucc.asn.au>
parents:
1861
diff
changeset
|
12 # Walks up the parent process tree, prints a r-xp line of /proc/pid/maps when |
1861 | 13 # it finds the wanted name |
14 | |
15 def main(): | |
16 | |
17 try: | |
18 for p in psutil.Process().parents(): | |
19 print(p.pid, file=sys.stderr) | |
20 print(p.name(), file=sys.stderr) | |
21 print(p.cmdline(), file=sys.stderr) | |
22 | |
23 if want_name in p.name(): | |
24 with (Path('/proc') / str(p.pid) / "maps").open() as f: | |
1874
1c9215154d4a
Handle /proc/.../maps being reordered
Matt Johnston <matt@ucc.asn.au>
parents:
1861
diff
changeset
|
25 for i, l in enumerate(f, 1): |
1c9215154d4a
Handle /proc/.../maps being reordered
Matt Johnston <matt@ucc.asn.au>
parents:
1861
diff
changeset
|
26 if ' r-xp ' in l: |
1c9215154d4a
Handle /proc/.../maps being reordered
Matt Johnston <matt@ucc.asn.au>
parents:
1861
diff
changeset
|
27 print(l.rstrip()) |
1c9215154d4a
Handle /proc/.../maps being reordered
Matt Johnston <matt@ucc.asn.au>
parents:
1861
diff
changeset
|
28 break |
1861 | 29 return |
30 | |
31 raise RuntimeError(f"Couldn't find parent {want_name} process") | |
32 except Exception as e: | |
33 print(psutil.Process().parents()) | |
34 for p in psutil.Process().parents(): | |
35 print(p.name()) | |
36 print(e) | |
37 # time.sleep(100) | |
38 raise | |
39 | |
40 if __name__ == "__main__": | |
41 main() |