[Swan-commit] Changes to ref refs/heads/master

D. Hugh Redelmeier hugh at mimosa.com
Tue Mar 5 20:47:35 EET 2013


| From: Paul Wouters <paul at vault.libreswan.fi>

| New commits:
| commit eeaf4d5c2cbf8257cce3ed5715581ef8ce518c77
| Author: Paul Wouters <pwouters at redhat.com>
| Date:   Tue Mar 5 12:25:18 2013 -0500
| 
|     * libswan/pluto: don't use localtime/gmtime - not thread safe
|     
|     Instead use localtime_r/gmtime_r
|     
|     This resolves a crasher when many rekeys with XAUTH are happening,
|     and the do_authentication() call in the threads are logging a lot.

This change would make one of your changes more concise.

If you think that the use of function pointers is obscure, then you could 
use the slightly less concise form that is more like the original
	struct tm *tm = (utc)? gmtime_r(timep, &tm1) : localtime(timep, &tm1);

(The names tm and tm1 could be improved but it doesn't matter in
such short code.)

diff --git a/lib/libswan/lswtime.c b/lib/libswan/lswtime.c
index d7523a7..d3f29e9 100644
--- a/lib/libswan/lswtime.c
+++ b/lib/libswan/lswtime.c
@@ -64,13 +64,8 @@ timetoa(const time_t *timep, bool utc, char *b, size_t blen)
 	snprintf(b, blen, "--- -- --:--:--%s----", (utc)?" UTC ":" ");
     else
     {
-	struct tm tm1, *tm;
-	if (utc)
-	{
-	  tm = gmtime_r(timep, &tm1);
-	} else {
-	  tm = localtime_r(timep, &tm1);
-	}
+	struct tm tm1;
+	struct tm *tm = (utc? gmtime_r : localtime_r)(timep, &tm1);
 	
 	snprintf(b, blen, "%s %02d %02d:%02d:%02d%s%04d",
 	    months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,


More information about the Swan-commit mailing list