[or-cvs] add in basic support for pidfiles

Roger Dingledine arma at seul.org
Wed Oct 8 08:54:54 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	config.c main.c or.h 
Log Message:
add in basic support for pidfiles
(patch courtesy aaron turner)


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- config.c	8 Oct 2003 04:10:54 -0000	1.55
+++ config.c	8 Oct 2003 08:54:52 -0000	1.56
@@ -153,6 +153,7 @@
     config_compare(list, "LogLevel",       CONFIG_TYPE_STRING, &options->LogLevel) ||
     config_compare(list, "DataDirectory",  CONFIG_TYPE_STRING, &options->DataDirectory) ||
     config_compare(list, "RouterFile",     CONFIG_TYPE_STRING, &options->RouterFile) ||
+    config_compare(list, "PidFile",        CONFIG_TYPE_STRING, &options->PidFile) ||
     config_compare(list, "Nickname",       CONFIG_TYPE_STRING, &options->Nickname) ||
     config_compare(list, "Address",        CONFIG_TYPE_STRING, &options->Address) ||
     config_compare(list, "ExitPolicy",     CONFIG_TYPE_STRING, &options->ExitPolicy) ||
@@ -201,6 +202,7 @@
   options->LogLevel = "info";
   options->ExitPolicy = "reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*";
   options->loglevel = LOG_DEBUG;
+  options->PidFile = "tor.pid";
   options->DataDirectory = NULL;
   options->CoinWeight = 0.1;
   options->MaxConn = 900;

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- main.c	8 Oct 2003 02:04:07 -0000	1.127
+++ main.c	8 Oct 2003 08:54:52 -0000	1.128
@@ -637,6 +637,9 @@
     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 @@
 #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)) {
@@ -733,6 +748,9 @@
   log_set_severity(options.loglevel);     /* assign logging severity level from options */
   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();

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -d -r1.161 -r1.162
--- or.h	8 Oct 2003 04:10:59 -0000	1.161
+++ or.h	8 Oct 2003 08:54:52 -0000	1.162
@@ -421,6 +421,7 @@
    char *RouterFile;
    char *Nickname;
    char *Address;
+   char *PidFile;
    char *ExitPolicy;
    double CoinWeight;
    int Daemon;



More information about the tor-commits mailing list