William Lallemand | 7755f9f | 2018-09-11 16:51:30 +0200 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | """ |
| 3 | Python wrapper example to test socketpair protocol |
| 4 | ./test-socketpair.py test.cfg |
| 5 | |
| 6 | use sockpair@${FD1} and sockpair@${FD2} in your configuration file |
| 7 | |
| 8 | """ |
| 9 | |
| 10 | import socket, os, sys |
| 11 | |
| 12 | s = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM) |
| 13 | os.set_inheritable(s[0].fileno(), 1) |
| 14 | os.set_inheritable(s[1].fileno(), 1) |
| 15 | |
| 16 | FD1 = s[0].fileno() |
| 17 | FD2 = s[1].fileno() |
| 18 | |
| 19 | print("FD1={} FD2={}".format(FD1, FD2)) |
| 20 | |
| 21 | os.environ["FD1"] = str(FD1) |
| 22 | os.environ["FD2"] = str(FD2) |
| 23 | |
| 24 | cmd = ["./haproxy", |
| 25 | "-f", |
| 26 | "{}".format(sys.argv[1]) |
| 27 | ] |
| 28 | os.execve(cmd[0], cmd, os.environ) |