• Avery Pennarun's avatar
    Rearrange daemonization/syslog stuff and make it more resilient. · 8a5ae1a4
    Avery Pennarun authored
    Rename --background to -D/--daemon, to match other programs (like smbd).
    
    You can now have --syslog even without --daemon.
    
    Avoid using atexit(); try/finally is better.
    
    Don't just close stderr; we'll end up eating error output from ssh!
    Instead, redirect stderr to a 'logger' subprocess that will send to syslog.
    
    Delay redirecting stderr until after we know we're daemonizing, so handy
    error messages can go to stderr instead of syslog.
    
    Make pidfile stuff more resilient: support already-existing files, files
    with strict permissions, outdated files containing an already-dead pid.  Add
    a --pidfile option to let you specify the pidfile path.
    
    chdir("/") while daemonizing, so that the filesystem containing $PWD can
    later be unmounted without killing the daemon.
    
    fw.done() can't wait on the firewall subprocess on exit when daemonized; we
    no longer are the parent of that process.
    8a5ae1a4
helpers.py 652 Bytes