AutoYADM commit: 2025-06-09 19:11:37
This commit is contained in:
parent
f25709871c
commit
d0893f3708
1 changed files with 27 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# pyright: strict, reportUnusedCallResult=false
|
||||
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
|
@ -64,6 +66,27 @@ def gen_kakoune_output(inp: str, outp: str) -> str:
|
|||
return f"declare_option -hidden str diagpipe_in {inp}\ndeclare_option -hidden str diagpipe_out {outp}"
|
||||
|
||||
|
||||
def daemonize():
|
||||
# exit parent
|
||||
if os.fork() > 0:
|
||||
sys.exit(0)
|
||||
# new session
|
||||
os.setsid()
|
||||
if os.fork() > 0:
|
||||
# exit first child
|
||||
sys.exit(0)
|
||||
_ = sys.stdin.close()
|
||||
_ = sys.stdout.flush()
|
||||
_ = sys.stderr.flush()
|
||||
|
||||
# redirect IO to /dev/null
|
||||
with open("/dev/null", "rb", 0) as dn:
|
||||
os.dup2(dn.fileno(), sys.stdin.fileno())
|
||||
with open("/dev/null", "ab", 0) as dn:
|
||||
os.dup2(dn.fileno(), sys.stdout.fileno())
|
||||
os.dup2(dn.fileno(), sys.stderr.fileno())
|
||||
|
||||
|
||||
def main():
|
||||
# create unique directory and names
|
||||
fifo_dir = tempfile.mkdtemp(prefix="diagpipe-")
|
||||
|
@ -76,8 +99,10 @@ def main():
|
|||
|
||||
_ = atexit.register(lambda: cleanup(in_path, out_path, fifo_dir))
|
||||
|
||||
print(in_path, flush=True)
|
||||
print(out_path, flush=True)
|
||||
output = gen_kakoune_output(in_path, out_path)
|
||||
print(output)
|
||||
sys.stdout.flush()
|
||||
daemonize()
|
||||
|
||||
with open(in_path, "r") as infile, open(out_path, "w") as outfile:
|
||||
diagnostics = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue