annotate test/parent_dropbear_map.py @ 1889:fc4c9ef61856

Split CPPFLAGS and CFLAGS more carefully This has no change to the build, but makes it easier to try other build tools that only want CPPFLAGS
author Matt Johnston <matt@ucc.asn.au>
date Tue, 22 Mar 2022 16:17:05 +0800
parents 1c9215154d4a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1861
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #!/usr/bin/env python3
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 import os
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 import sys
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 import time
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 import psutil
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 from pathlib import Path
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
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
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 # it finds the wanted name
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 def main():
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 try:
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 for p in psutil.Process().parents():
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 print(p.pid, file=sys.stderr)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 print(p.name(), file=sys.stderr)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 print(p.cmdline(), file=sys.stderr)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 if want_name in p.name():
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
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
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 return
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 raise RuntimeError(f"Couldn't find parent {want_name} process")
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 except Exception as e:
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 print(psutil.Process().parents())
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 for p in psutil.Process().parents():
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 print(p.name())
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 print(e)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 # time.sleep(100)
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 raise
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 if __name__ == "__main__":
2b3a8026a6ce Add re-exec for server
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 main()