Changeset ee6b30f for functions.c


Ignore:
Timestamp:
Oct 8, 2017, 6:02:19 PM (7 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master
Children:
4fd3c04
Parents:
09530e6
git-author:
Anders Kaseorg <andersk@mit.edu> (10/07/17 03:25:44)
git-committer:
Anders Kaseorg <andersk@mit.edu> (10/08/17 18:02:19)
Message:
Avoid thread-unsafe functions ctime, localtime, strtok

BarnOwl seems to be growing threads at an alarming rate, so let’s be
sure these don’t turn into race conditions.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rb61ad80 ree6b30f  
    12261226  FILE *file;
    12271227  time_t now;
     1228  struct tm tm;
    12281229  va_list ap;
    12291230
     
    12371238  now = time(NULL);
    12381239
    1239   tmpbuff = owl_util_format_time(localtime(&now));
     1240  tmpbuff = owl_util_format_time(localtime_r(&now, &tm));
    12401241  fprintf(file, "[%d -  %s - %lds]: ",
    12411242          (int) getpid(), tmpbuff, now - owl_global_get_starttime(&g));
     
    17751776  char buff[MAXPATHLEN+1];
    17761777  time_t start;
     1778  struct tm tm;
    17771779  int up, days, hours, minutes;
    17781780  owl_fmtext fm;
     
    18001802  owl_fmtext_append_normal(&fm, "\n");
    18011803
    1802   tmpbuff = owl_util_format_time(localtime(&start));
     1804  tmpbuff = owl_util_format_time(localtime_r(&start, &tm));
    18031805  owl_fmtext_appendf_normal(&fm, "  Startup Time: %s\n", tmpbuff);
    18041806  g_free(tmpbuff);
     
    34243426  char *date;
    34253427  time_t now;
     3428  struct tm tm;
    34263429  char *buff;
    34273430
    34283431  now = time(NULL);
    3429   date = owl_util_format_time(localtime(&now));
     3432  date = owl_util_format_time(localtime_r(&now, &tm));
    34303433
    34313434  buff = g_strdup_printf("%s %s", date, string);
Note: See TracChangeset for help on using the changeset viewer.