# HG changeset patch # User Matt Johnston # Date 1340717814 -28800 # Node ID 7dec59b7eeef2ed9d4b279c553ffb2a14066bc4a # Parent aaa94f90eaa158f76dac014bfc575d30b30a36e3 cheap_daemon() diff -r aaa94f90eaa1 -r 7dec59b7eeef server/ts.py --- a/server/ts.py Tue Jun 26 21:21:51 2012 +0800 +++ b/server/ts.py Tue Jun 26 21:36:54 2012 +0800 @@ -172,6 +172,9 @@ def main(): next_wake_time = 0 + if '--daemon' in sys.argv: + utils.cheap_daemon() + while True: sock = None try: diff -r aaa94f90eaa1 -r 7dec59b7eeef server/utils.py --- a/server/utils.py Tue Jun 26 21:21:51 2012 +0800 +++ b/server/utils.py Tue Jun 26 21:36:54 2012 +0800 @@ -97,3 +97,24 @@ uc += 1 i += 1 return crc + +def cheap_daemon(): + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print>>sys.stderr, "Bad fork()" + sys.exit(1) + + os.setsid() + + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print>>sys.stderr, "Bad fork()" + sys.exit(1) + +