summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpaulo <paul@bayleaf.org.uk>2010-02-05 12:05:47 +0000
committerpaulo <paul@bayleaf.org.uk>2010-02-05 12:05:47 +0000
commit9cf5d831389086c2060a2bfbe3f9ac79f488623f (patch)
tree81d3484cefac2dc9060c013cd5955f5647d39613
parentc751ea18005633ceac54cf7415147e04adb19cb5 (diff)
downloadquagga-9cf5d831389086c2060a2bfbe3f9ac79f488623f.tar.bz2
quagga-9cf5d831389086c2060a2bfbe3f9ac79f488623f.tar.xz
Relace localtime with localtime_r to be thread safe.
-rw-r--r--bgpd/bgp_dump.c14
-rw-r--r--lib/keychain.c6
-rw-r--r--lib/log.c6
3 files changed, 13 insertions, 13 deletions
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index 0a18ae29..b44b57ce 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -96,21 +96,21 @@ bgp_dump_open_file (struct bgp_dump *bgp_dump)
{
int ret;
time_t clock;
- struct tm *tm;
+ struct tm tm;
char fullpath[MAXPATHLEN];
char realpath[MAXPATHLEN];
mode_t oldumask;
time (&clock);
- tm = localtime (&clock);
+ localtime_r(&clock, &tm);
if (bgp_dump->filename[0] != DIRECTORY_SEP)
{
sprintf (fullpath, "%s/%s", vty_get_cwd (), bgp_dump->filename);
- ret = strftime (realpath, MAXPATHLEN, fullpath, tm);
+ ret = strftime (realpath, MAXPATHLEN, fullpath, &tm);
}
else
- ret = strftime (realpath, MAXPATHLEN, bgp_dump->filename, tm);
+ ret = strftime (realpath, MAXPATHLEN, bgp_dump->filename, &tm);
if (ret == 0)
{
@@ -141,7 +141,7 @@ bgp_dump_interval_add (struct bgp_dump *bgp_dump, int interval)
{
int secs_into_day;
time_t t;
- struct tm *tm;
+ struct tm tm;
if (interval > 0)
{
@@ -152,8 +152,8 @@ bgp_dump_interval_add (struct bgp_dump *bgp_dump, int interval)
* intervals, dump every interval seconds starting from midnight
*/
(void) time(&t);
- tm = localtime(&t);
- secs_into_day = tm->tm_sec + 60*tm->tm_min + 60*60*tm->tm_hour;
+ localtime_r(&t, &tm);
+ secs_into_day = tm.tm_sec + 60*tm.tm_min + 60*60*tm.tm_hour;
interval = interval - secs_into_day % interval; /* always > 0 */
}
bgp_dump->t_interval = thread_add_timer (master, bgp_dump_interval_func,
diff --git a/lib/keychain.c b/lib/keychain.c
index 6719cebf..41c463f9 100644
--- a/lib/keychain.c
+++ b/lib/keychain.c
@@ -865,12 +865,12 @@ static struct cmd_node keychain_key_node =
static int
keychain_strftime (char *buf, int bufsiz, time_t *time)
{
- struct tm *tm;
+ struct tm tm;
size_t len;
- tm = localtime (time);
+ localtime_r(time, &tm);
- len = strftime (buf, bufsiz, "%T %b %d %Y", tm);
+ len = strftime (buf, bufsiz, "%T %b %d %Y", &tm);
return len;
}
diff --git a/lib/log.c b/lib/log.c
index 12b76c14..2d636599 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -117,11 +117,11 @@ uquagga_timestamp(int timestamp_precision, char *buf, size_t buflen)
/* first, we update the cache if the time has changed */
if (cache.last != clock.tv_sec)
{
- struct tm *tm;
+ struct tm tm;
cache.last = clock.tv_sec;
- tm = localtime(&cache.last);
+ localtime_r(&cache.last, &tm);
cache.len = strftime(cache.buf, sizeof(cache.buf),
- "%Y/%m/%d %H:%M:%S", tm);
+ "%Y/%m/%d %H:%M:%S", &tm);
}
/* note: it's not worth caching the subsecond part, because
chances are that back-to-back calls are not sufficiently close together