diff options
author | Roger Dingledine <arma@torproject.org> | 2003-10-08 08:54:52 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-10-08 08:54:52 +0000 |
commit | 746d64e63121600fe694f11c15bd9dc0e3e52c85 (patch) | |
tree | 55378a31365ecec97ea60ea40d6cf4f22f94cacc /src/or/main.c | |
parent | 8b80362c76861b046105189a6d2613821b690906 (diff) | |
download | tor-746d64e63121600fe694f11c15bd9dc0e3e52c85.tar tor-746d64e63121600fe694f11c15bd9dc0e3e52c85.tar.gz |
add in basic support for pidfiles
(patch courtesy aaron turner)
svn:r565
Diffstat (limited to 'src/or/main.c')
-rw-r--r-- | src/or/main.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/or/main.c b/src/or/main.c index efcae90be..83a979e0c 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -637,6 +637,9 @@ static void catch(int the_signal) { case SIGTERM: case SIGINT: log(LOG_ERR,"Catching signal %d, exiting cleanly.", the_signal); + /* we don't care if there was an error when we unlink, + nothing we could do about it anyways */ + unlink(options.PidFile); exit(0); case SIGHUP: please_reset = 1; @@ -724,6 +727,18 @@ void daemonize(void) { #endif } +void write_pidfile(char *filename) { + FILE *pidfile; + + if ((pidfile = fopen(filename, "w")) == NULL) { + log_fn(LOG_WARNING, "unable to open %s for writing: %s", filename, + strerror(errno)); + } else { + fprintf(pidfile, "%d", getpid()); + fclose(pidfile); + } +} + int tor_main(int argc, char *argv[]) { if(getconfig(argc,argv,&options)) { @@ -734,6 +749,9 @@ int tor_main(int argc, char *argv[]) { global_read_bucket = options.TotalBandwidth; /* start it at 1 second of traffic */ stats_prev_global_read_bucket = global_read_bucket; + /* write our pid to the pid file */ + write_pidfile(options.PidFile); + if(options.Daemon) daemonize(); |