Mercurial > dropbear
annotate test/parent_dropbear_map.py @ 1923:ffa0f666fde2
Expand home path for MOTD file
Patch modified by Matt Johnston
Signed-off-by: Begley Brothers Inc <[email protected]>
author | Begley Brothers Inc <begleybrothers@gmail.com> |
---|---|
date | Thu, 09 Jul 2020 22:06:26 +1000 |
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() |