Skip to content

Commit

Permalink
properly redirect stdin, stdout, and stderr when daemonizing
Browse files Browse the repository at this point in the history
  • Loading branch information
thwarted committed Oct 12, 2009
1 parent af30178 commit 10764f3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nodebot
Expand Up @@ -184,6 +184,13 @@ def gen_nick():

def daemonize():
os.fork() and sys.exit(0)
os.close(0)
os.close(1)
os.close(2)
null = getattr(os, 'devnull', '/dev/null')
os.open(null, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
os.setsid()
os.fork() and sys.exit(0)
os.chdir('/')
Expand Down

0 comments on commit 10764f3

Please sign in to comment.