aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-03-17 02:41:36 +0000
committerNick Mathewson <nickm@torproject.org>2003-03-17 02:41:36 +0000
commit743e61e8c6aee0a70eb3015e1665a9dcd32a04ac (patch)
tree913934363aa0244697a9535f1f206e1dc46b4b92 /src/or
parent5dc443a8c55688637e71f984c76b45ba1515fb71 (diff)
downloadtor-743e61e8c6aee0a70eb3015e1665a9dcd32a04ac.tar
tor-743e61e8c6aee0a70eb3015e1665a9dcd32a04ac.tar.gz
Add daemon logic
svn:r185
Diffstat (limited to 'src/or')
-rw-r--r--src/or/main.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/or/main.c b/src/or/main.c
index fe2de2ebc..fc310424f 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -607,6 +607,24 @@ void dump_directory_to_string(char *s, int maxlen) {
}
+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;
@@ -615,6 +633,9 @@ int main(int argc, char *argv[]) {
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) {
log(LOG_ERR,"main(): We're running without a dns handler. Bad news.");