summaryrefslogtreecommitdiff
path: root/script/moveto3.py
blob: fba5ddd86262669e0f3c908c6e7d09fae644a89f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
import argparse
import os
import sys


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("-a", default="qmail-authuser", dest="pam")
    ap.add_argument("fd", type=int)
    ap.add_argument("prog")
    ap.add_argument("args", nargs='*')

    vals = ap.parse_args()

    if vals.fd < 3:
        raise ValueError(f"fd({fd}) must be 3 or greater")

    if vals.fd != 3:
        os.dup2(vals.fd, 3)
        os.close(vals.fd)

    os.execvp(vals.pam, [vals.pam, vals.prog] + vals.args)

    raise ValueError("should not be reachable")


if __name__ == '__main__':
    main()