Andrew St. Jean Oct. 19, 2002 http://www.arda.homeunix.net/store/tofmipd-daemon.patch This patch adds the -D switch to tmda-ofmipd. This switch forces tmda-ofmipd to run as a background process. If you use the -D switch, you should not use an '&' to terminate the command that starts tmda-ofmipd. To apply this patch, copy tofmipd-daemon.patch into the directory where tmda-ofmipd resides and issue this command: patch -b --verbose < ./tofmipd-daemon.patch This patch has been successfully applied to versions 0.62 and 0.63 of TMDA. If you find that this patch works with other versions, please let me know. --- ../tmda-0.62/bin/tmda-ofmipd Sun Sep 1 21:23:53 2002 +++ ./tmda-ofmipd Sat Oct 19 14:47:59 2002 @@ -42,6 +42,10 @@ --debug Turn on debugging prints. + -D + --daemon + Run tmda-ofmipd as a background process. + -u --username The username that this program should run under. The default @@ -120,6 +124,7 @@ program = sys.argv[0] configdir = None authprog = None +daemon = 0 remoteauth = { 'proto': None, 'host': 'localhost', 'port': None, @@ -176,7 +181,7 @@ try: opts, args = getopt.getopt(sys.argv[1:], - 'p:u:R:A:a:c:C:dVh', ['proxyport=', + 'p:u:R:A:a:c:C:dDVh', ['proxyport=', 'username=', 'authfile=', 'remoteauth=', @@ -184,6 +189,7 @@ 'configdir=', 'connections=', 'debug', + 'daemon', 'version', 'help']) except getopt.error, msg: @@ -200,6 +206,8 @@ sys.exit() elif opt in ('-d', '--debug'): DEBUGSTREAM = sys.stderr + elif opt in ('-D', '--daemon'): + daemon = 1 elif opt in ('-p', '--proxyport'): proxyport = arg elif opt in ('-u', '--username'): @@ -974,4 +982,28 @@ # This is the end my friend. if __name__ == '__main__': + if daemon: + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError: + value = sys.exc_info()[1] + print 'Failed to daemonize process: %s' % value + sys.exit(1) + + os.chdir('/') + os.setsid() + os.umask(0) + + try: + pid = os.fork() + if pid > 0: + print pid + sys.exit(0) + except OSError: + value = sys.exc_info()[1] + print 'Failed to daemonize process: %s' % value + sys.exit(1) + main()