Switch to thread safe versions of localtime and asctime

This commit is contained in:
Mark Riddoch
2014-12-03 09:53:17 +00:00
parent 1e5bc37780
commit fdb9c5e6dc
3 changed files with 29 additions and 12 deletions

View File

@ -344,8 +344,10 @@ SERVER_PARAM *param;
} }
} }
if (server->node_ts > 0) { if (server->node_ts > 0) {
struct tm result;
char buf[40];
dcb_printf(dcb, "\tLast Repl Heartbeat:\t%s", dcb_printf(dcb, "\tLast Repl Heartbeat:\t%s",
asctime(localtime(&server->node_ts))); asctime_r(localtime_r((time_t *)(&server->node_ts), &result), buf));
} }
if ((param = server->parameters) != NULL) if ((param = server->parameters) != NULL)
{ {

View File

@ -810,12 +810,15 @@ void
printService(SERVICE *service) printService(SERVICE *service)
{ {
SERVER *ptr = service->databases; SERVER *ptr = service->databases;
struct tm result;
char time_buf[30];
int i; int i;
printf("Service %p\n", service); printf("Service %p\n", service);
printf("\tService: %s\n", service->name); printf("\tService: %s\n", service->name);
printf("\tRouter: %s (%p)\n", service->routerModule, service->router); printf("\tRouter: %s (%p)\n", service->routerModule, service->router);
printf("\tStarted: %s", asctime(localtime(&service->stats.started))); printf("\tStarted: %s",
asctime_r(localtime_r(&service->stats.started, &result), time_buf));
printf("\tBackend databases\n"); printf("\tBackend databases\n");
while (ptr) while (ptr)
{ {
@ -888,6 +891,8 @@ SERVICE *ptr;
void dprintService(DCB *dcb, SERVICE *service) void dprintService(DCB *dcb, SERVICE *service)
{ {
SERVER *server = service->databases; SERVER *server = service->databases;
struct tm result;
char timebuf[30];
int i; int i;
dcb_printf(dcb, "Service %p\n", service); dcb_printf(dcb, "Service %p\n", service);
@ -898,7 +903,7 @@ int i;
if (service->router) if (service->router)
service->router->diagnostics(service->router_instance, dcb); service->router->diagnostics(service->router_instance, dcb);
dcb_printf(dcb, "\tStarted: %s", dcb_printf(dcb, "\tStarted: %s",
asctime(localtime(&service->stats.started))); asctime_r(localtime_r(&service->stats.started, &result), timebuf));
dcb_printf(dcb, "\tRoot user access: %s\n", dcb_printf(dcb, "\tRoot user access: %s\n",
service->enable_root ? "Enabled" : "Disabled"); service->enable_root ? "Enabled" : "Disabled");
if (service->n_filters) if (service->n_filters)

View File

@ -465,11 +465,15 @@ int rval = 0;
void void
printSession(SESSION *session) printSession(SESSION *session)
{ {
struct tm result;
char timebuf[40];
printf("Session %p\n", session); printf("Session %p\n", session);
printf("\tState: %s\n", session_state(session->state)); printf("\tState: %s\n", session_state(session->state));
printf("\tService: %s (%p)\n", session->service->name, session->service); printf("\tService: %s (%p)\n", session->service->name, session->service);
printf("\tClient DCB: %p\n", session->client); printf("\tClient DCB: %p\n", session->client);
printf("\tConnected: %s", asctime(localtime(&session->stats.connect))); printf("\tConnected: %s",
asctime_r(localtime_r(&session->stats.connect, &result), timebuf));
} }
/** /**
@ -566,6 +570,8 @@ int norouter = 0;
void void
dprintAllSessions(DCB *dcb) dprintAllSessions(DCB *dcb)
{ {
struct tm result;
char timebuf[40];
SESSION *ptr; SESSION *ptr;
spinlock_acquire(&session_spin); spinlock_acquire(&session_spin);
@ -578,7 +584,8 @@ SESSION *ptr;
dcb_printf(dcb, "\tClient DCB: %p\n", ptr->client); dcb_printf(dcb, "\tClient DCB: %p\n", ptr->client);
if (ptr->client && ptr->client->remote) if (ptr->client && ptr->client->remote)
dcb_printf(dcb, "\tClient Address: %s\n", ptr->client->remote); dcb_printf(dcb, "\tClient Address: %s\n", ptr->client->remote);
dcb_printf(dcb, "\tConnected: %s", asctime(localtime(&ptr->stats.connect))); dcb_printf(dcb, "\tConnected: %s",
asctime_r(localtime_r(&ptr->stats.connect, &result), timebuf));
ptr = ptr->next; ptr = ptr->next;
} }
spinlock_release(&session_spin); spinlock_release(&session_spin);
@ -596,6 +603,8 @@ SESSION *ptr;
void void
dprintSession(DCB *dcb, SESSION *ptr) dprintSession(DCB *dcb, SESSION *ptr)
{ {
struct tm result;
char buf[30];
int i; int i;
dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr); dcb_printf(dcb, "Session %d (%p)\n",ptr->ses_id, ptr);
@ -604,7 +613,8 @@ int i;
dcb_printf(dcb, "\tClient DCB: %p\n", ptr->client); dcb_printf(dcb, "\tClient DCB: %p\n", ptr->client);
if (ptr->client && ptr->client->remote) if (ptr->client && ptr->client->remote)
dcb_printf(dcb, "\tClient Address: %s\n", ptr->client->remote); dcb_printf(dcb, "\tClient Address: %s\n", ptr->client->remote);
dcb_printf(dcb, "\tConnected: %s", asctime(localtime(&ptr->stats.connect))); dcb_printf(dcb, "\tConnected: %s",
asctime_r(localtime_r(&ptr->stats.connect, &result), buf));
if (ptr->n_filters) if (ptr->n_filters)
{ {
for (i = 0; i < ptr->n_filters; i++) for (i = 0; i < ptr->n_filters; i++)