[or-cvs] Add daemon logic
Nick Mathewson
nickm at seul.org
Mon Mar 17 02:41:39 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv2453/src/or
Modified Files:
main.c
Log Message:
Add daemon logic
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- main.c 11 Mar 2003 21:38:38 -0000 1.43
+++ main.c 17 Mar 2003 02:41:36 -0000 1.44
@@ -607,6 +607,24 @@
}
+void daemonize() {
+ /* Fork; parent exits. */
+ if (fork())
+ exit(0);
+
+ /* Create new session; make sure we never get a terminal */
+ setsid();
+ if (fork())
+ exit(0);
+
+ chdir("/");
+ umask(000);
+
+ fclose(stdin);
+ fclose(stdout);
+ fclose(stderr);
+}
+
int main(int argc, char *argv[]) {
int retval = 0;
@@ -614,6 +632,9 @@
exit(1);
log(options.loglevel,NULL); /* assign logging severity level from options */
global_role = options.Role; /* assign global_role from options. FIXME: remove from global namespace later. */
+
+ if (options.Daemon)
+ daemonize();
if(options.Role & ROLE_OR_LISTEN) { /* only spawn dns handlers if we're a router */
if(dns_master_start() < 0) {
More information about the tor-commits
mailing list