[or-cvs] Fix an evil bug: when we failed to write to our log, fputs()

Roger Dingledine arma at seul.org
Tue Sep 28 21:14:42 UTC 2004


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

Modified Files:
	main.c test.c 
Log Message:
Fix an evil bug: when we failed to write to our log, fputs()
gave us a sigpipe, and we logged that we were ignoring it,
causing us to fail to log that, and delete the log entry. Then
when the signal handler exited, we proceeded to delete the log
entry that had already been deleted.

Now we make sure to only log inside our signal handler if we'll
be exit()ing right after.


Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.327
retrieving revision 1.328
diff -u -d -r1.327 -r1.328
--- main.c	23 Sep 2004 04:32:43 -0000	1.327
+++ main.c	28 Sep 2004 21:14:40 -0000	1.328
@@ -49,6 +49,7 @@
 static int please_dumpstats=0; /**< Whether we should dump stats during the loop. */
 static int please_reset=0; /**< Whether we just got a sighup. */
 static int please_reap_children=0; /**< Whether we should waitpid for exited children. */
+static int please_sigpipe=0; /**< Whether we've caught a sigpipe lately. */
 static int please_shutdown=0; /**< Whether we should shut down Tor. */
 #endif /* signal stuff */
 
@@ -833,6 +834,10 @@
       }
       please_shutdown = 0;
     }
+    if(please_sigpipe) {
+      log(LOG_NOTICE,"Caught sigpipe. Ignoring.");
+      please_sigpipe = 0;
+    }
     if(please_dumpstats) {
       /* prefer to log it at INFO, but make sure we always see it */
       dumpstats(get_min_log_level()>LOG_INFO ? get_min_log_level() : LOG_INFO);
@@ -898,7 +903,9 @@
       please_shutdown = 1;
       break;
     case SIGPIPE:
-      log(LOG_NOTICE,"Caught sigpipe. Ignoring.");
+      /* don't log here, since it's possible you got the sigpipe because
+       * your log failed! */
+      please_sigpipe = 1;
       break;
     case SIGHUP:
       please_reset = 1;
@@ -911,6 +918,8 @@
       break;
     default:
       log(LOG_WARN,"Caught signal %d that we can't handle??", the_signal);
+      tor_cleanup();
+      exit(1);
   }
 #endif /* signal stuff */
 }

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- test.c	27 Sep 2004 06:00:43 -0000	1.115
+++ test.c	28 Sep 2004 21:14:40 -0000	1.116
@@ -1024,7 +1024,6 @@
   test_eq(0, is_obsolete_version("0.0.5.1-cvs", "0.0.5"));
 
   test_eq(0, tor_version_as_new_as("Tor 0.0.5", "0.0.9pre1-cvs"));
-  test_eq(0, tor_version_as_new_as("Tor 0.0.5", "0.0.9pre1-cvs"));
   test_eq(1, tor_version_as_new_as(
           "Tor 0.0.8 on Darwin 64-121-192-100.c3-0.sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh", "0.0.8rc2"));
   test_eq(0, tor_version_as_new_as(



More information about the tor-commits mailing list