@@ -200,6 +200,7 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx)
200200 int err = 1 ;
201201 DIR * d ;
202202 struct dirent * ent ;
203+ struct tm result ;
203204
204205 d = opendir ("/proc" );
205206 if (d == NULL )
@@ -299,11 +300,11 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx)
299300
300301 // Calculate the start time
301302 s_time = time (NULL );
302- now = localtime (& s_time );
303+ now = localtime_r (& s_time , & result );
303304 tyear = now -> tm_year ;
304305 tday = now -> tm_yday ;
305306 s_time = boot + (start / ticks );
306- proc = localtime (& s_time );
307+ proc = localtime_r (& s_time , & result );
307308
308309 // Select format based on how long we've been running
309310 //
@@ -439,13 +440,13 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx)
439440
440441 // Get the start time
441442 s_time = time (NULL );
442- now = localtime (& s_time );
443+ now = localtime_r (& s_time , & result );
443444 tyear = now -> tm_year ;
444445 tday = now -> tm_yday ;
445446
446447 // Get current time
447448 s_time = psinfo -> pr_start .tv_sec ;
448- proc = localtime (& s_time );
449+ proc = localtime_r (& s_time , & result );
449450
450451 // Select format based on how long we've been running
451452 //
@@ -595,7 +596,8 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx)
595596 fmt = "%H:%M:%S" ;
596597 }
597598
598- struct tm * loc_time = localtime (& start_time );
599+ struct tm result ;
600+ struct tm * loc_time = localtime_r (& start_time , & result );
599601 strftime (start_buf , sizeof (start_buf ), fmt , loc_time );
600602
601603 switch (proc -> ki_tdev ) {
@@ -604,7 +606,7 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx)
604606 break ;
605607 default :
606608 snprintf (tty_buf , sizeof (tty_buf ), "%ld" , proc -> ki_tdev );
607- r .tty = tty_buf ;
609+ r .tty = tty_buf ;
608610 break ;
609611 }
610612
0 commit comments