Commit 256b08d7 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Fixed bugs from branch nmxptool_1_2_4_beta8_fixing_MTSAFE2


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1284 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent aef3f0e8
......@@ -11,7 +11,7 @@ m4_define([major_version], [1])
m4_define([minor_version], [2])
m4_define([micro_version], [4])
# Comment build_version for stable release
m4_define([build_version], [beta8])
m4_define([build_version], [beta9])
m4_ifdef([build_version], [
m4_define([version],
......@@ -119,6 +119,8 @@ AM_CONDITIONAL(ENABLE_DLL_PTHREAD, test x$DLL_PTHREAD != x)
AC_ARG_VAR(DIR_PTHREAD, [Directory containing PThread DDL library])
AC_ARG_VAR(DLL_PTHREAD, [Name of PThread DLL library - i.e. pthreadVC2.dll])
CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS"
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/stat.h sys/time.h unistd.h pthread.h])
......@@ -257,7 +259,7 @@ AC_STRUCT_TM
# AC_CHECK_SIZEOF([long int])
# Checks for library functions.
AC_FUNC_MALLOC
# AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRERROR_R
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.h,v 1.34 2009-08-17 08:47:13 mtheo Exp $
* $Id: nmxp_base.h,v 1.35 2009-08-31 12:16:41 mtheo Exp $
*
*/
......@@ -78,7 +78,7 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec);
/*! \brief Wrapper to strerror, strerror_r or WSAGetLastErrorMessage
*
* \return String message of errno_value. It is static, not need to be freed.
* \return String message of errno_value. It is not static, need to be freed.
*
*/
char *nmxp_strerror(int errno_value);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_chan.h,v 1.25 2009-03-10 16:36:25 mtheo Exp $
* $Id: nmxp_chan.h,v 1.26 2009-08-31 12:16:41 mtheo Exp $
*
*/
......@@ -179,6 +179,8 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList);
*
* \return Name of channel with key. NULL on error.
*
* \warning Returned value will need to be freed!
*
*/
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.c,v 1.94 2009-08-17 08:57:10 mtheo Exp $
* $Id: nmxp.c,v 1.95 2009-08-31 12:16:41 mtheo Exp $
*
*/
......@@ -46,39 +46,41 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
int recv_errno;
NMXP_MSG_SERVER type;
char buffer[NMXP_MAX_LENGTH_DATA_BUFFER];
char buffer[NMXP_MAX_LENGTH_DATA_BUFFER]={0};
int32_t length;
*pchannelList = NULL;
ret = nmxp_receiveMessage(isock, &type, buffer, &length, 0, &recv_errno, NMXP_MAX_LENGTH_DATA_BUFFER);
if(type != NMXP_MSG_CHANNELLIST) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Type %d is not NMXP_MSG_CHANNELLIST!\n", type);
} else {
(*pchannelList) = (NMXP_CHAN_LIST *) NMXP_MEM_MALLOC(length);
if( (*pchannelList) != NULL) {
memmove((*pchannelList), buffer, length);
(*pchannelList)->number = ntohl((*pchannelList)->number);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "number of channels %d\n", (*pchannelList)->number);
/* TODO check*/
for(i=0; i < (*pchannelList)->number; i++) {
(*pchannelList)->channel[i].key = ntohl((*pchannelList)->channel[i].key);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "%12d %s\n",
(*pchannelList)->channel[i].key,
NMXP_LOG_STR((*pchannelList)->channel[i].name));
}
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "nmxp_receiveChannelList() Error allocating pchannelList!\n");
ret = NMXP_SOCKET_ERROR;
}
/*TODO controllare ret*/
if (ret == NMXP_SOCKET_OK) {
if(type != NMXP_MSG_CHANNELLIST) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Type %d is not NMXP_MSG_CHANNELLIST!\n", type);
} else {
(*pchannelList) = (NMXP_CHAN_LIST *) NMXP_MEM_MALLOC(length);
if( (*pchannelList) != NULL) {
memmove((*pchannelList), buffer, length);
(*pchannelList)->number = ntohl((*pchannelList)->number);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "number of channels %d\n", (*pchannelList)->number);
/* TODO check*/
for(i=0; i < (*pchannelList)->number; i++) {
(*pchannelList)->channel[i].key = ntohl((*pchannelList)->channel[i].key);
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CHANNEL, "%12d %s\n",
(*pchannelList)->channel[i].key,
NMXP_LOG_STR((*pchannelList)->channel[i].name));
}
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "nmxp_receiveChannelList() Error allocating pchannelList!\n");
ret = NMXP_SOCKET_ERROR;
}
}
}
return ret;
......@@ -136,6 +138,7 @@ int nmxp_sendAddTimeSeriesChannel_raw(int isock, NMXP_CHAN_LIST_NET *channelList
int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, int32_t shortTermCompletion, int32_t out_format, NMXP_BUFFER_FLAG buffer_flag, int n_channel, int n_usec, int flag_restart) {
static int i = 0;
static int first_time = 1;
/*TODO avoid static Stefano*/
static struct timeval last_tp_now;
char s_channels[MAX_LEN_S_CHANNELS];
......@@ -221,7 +224,7 @@ int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, in
NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code, int timeoutsec, int *recv_errno ) {
NMXP_MSG_SERVER type;
char buffer[NMXP_MAX_LENGTH_DATA_BUFFER];
char buffer[NMXP_MAX_LENGTH_DATA_BUFFER]={0};
int32_t length;
NMXP_DATA_PROCESS *pd = NULL;
......@@ -744,6 +747,8 @@ void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_t
raw_stream_buffer->max_pdlist_items = max_tolerable_latency * 4;
raw_stream_buffer->timeoutrecv = timeoutrecv;
raw_stream_buffer->n_pdlist = 0;
raw_stream_buffer->pdlist=NULL;
raw_stream_buffer->pdlist = (NMXP_DATA_PROCESS **) NMXP_MEM_MALLOC(raw_stream_buffer->max_pdlist_items * sizeof(NMXP_DATA_PROCESS *));
for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
raw_stream_buffer->pdlist[j] = NULL;
......@@ -797,6 +802,10 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
/* Allocate memory for pd and copy a_pd */
pd = (NMXP_DATA_PROCESS *) NMXP_MEM_MALLOC(sizeof(NMXP_DATA_PROCESS));
if (pd == NULL) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_RAWSTREAM,"nmxp_raw_stream_manage(): Error allocating memory\n");
exit(-1);
}
memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS));
if(a_pd->nSamp * sizeof(int) > 0) {
pd->pDataPtr = (int *) NMXP_MEM_MALLOC(a_pd->nSamp * sizeof(int));
......@@ -889,7 +898,8 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
}
} else {
if(pd) {
p->pdlist[p->n_pdlist++] = pd;
p->pdlist[p->n_pdlist] = pd;
p->n_pdlist++;
}
}
......@@ -1021,10 +1031,12 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
if(p->pdlist[k]) {
NMXP_MEM_FREE(p->pdlist[k]);
p->pdlist[k] = NULL;
/*nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_RAWSTREAM, "Freeing p->pdlist[%d]\n", k);*/
}
}
if(k + j < p->n_pdlist) {
p->pdlist[k] = p->pdlist[k+j];
p->pdlist[k+j]=NULL;
} else {
p->pdlist[k] = NULL;
}
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.c,v 1.80 2009-08-17 08:47:13 mtheo Exp $
* $Id: nmxp_base.c,v 1.81 2009-08-31 12:16:41 mtheo Exp $
*
*/
......@@ -41,6 +41,7 @@
int nmxp_openSocket(char *hostname, int portNum, int (*func_cond)(void))
{
/*TODO stefano avoid static*/
static int sleepTime = 1;
int isock = -1;
struct hostent *hostinfo = NULL;
......@@ -227,19 +228,19 @@ int nmxp_setsockopt_RCVTIMEO(int isock, int timeoutsec) {
#define MAXLEN_RECV_ERRNO_STR 200
char *nmxp_strerror(int errno_value) {
static char ret_recv_errno_str[MAXLEN_RECV_ERRNO_STR];
char * ret_recv_errno_str;
#ifdef HAVE_WINDOWS_H
char *recv_errno_str;
#else
#ifdef HAVE_STRERROR_R
char recv_errno_str[MAXLEN_RECV_ERRNO_STR];
char recv_errno_str[MAXLEN_RECV_ERRNO_STR]="";
#else
char *recv_errno_str;
char *recv_errno_str=NULL;
#endif
#endif
ret_recv_errno_str= (char *) NMXP_MEM_MALLOC (MAXLEN_RECV_ERRNO_STR * sizeof(char));
ret_recv_errno_str[0] = 0;
#ifdef HAVE_WINDOWS_H
......@@ -319,7 +320,7 @@ int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *rec
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "nmxp_recv_ctrl(): %s (errno=%d recvCount=%d length=%d cc=%d)\n",
NMXP_LOG_STR(recv_errno_str), *recv_errno, recvCount, length, cc);
}
NMXP_MEM_FREE(recv_errno_str);
/* TO IMPROVE
* Fixed bug receiving zero byte from recv() 'TCP FIN or EOF received'
* */
......@@ -356,14 +357,14 @@ int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, int32_t length)
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *length, int timeoutsec, int *recv_errno )
{
int ret ;
NMXP_MESSAGE_HEADER msg;
NMXP_MESSAGE_HEADER msg={0};
ret = nmxp_recv_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER), timeoutsec, recv_errno);
*type = 0;
*length = 0;
if(ret == NMXP_SOCKET_OK) {
if((ret == NMXP_SOCKET_OK) && (msg.type != 0)) {
msg.signature = ntohl(msg.signature);
msg.type = ntohl(msg.type);
msg.length = ntohl(msg.length);
......@@ -464,25 +465,26 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da
int32_t *pDataPtr = NULL;
int swap = 0;
int idx;
static int32_t outdata[MAX_OUTDATA];
int32_t *outdata = NULL;
char station_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char *nmxp_channel_name = NULL;
static NMXP_DATA_PROCESS pd;
NMXP_DATA_PROCESS *pd = NULL;
/* copy the header contents into local fields and swap */
memcpy(&netInt, &buffer_data[0], 4);
pKey = ntohl(netInt);
if ( pKey != netInt ) { swap = 1; }
nmxp_data_init(&pd);
nmxp_data_init(pd);
outdata = (int32_t *) NMXP_MEM_MALLOC(MAX_OUTDATA*sizeof(int32_t));
nmxp_channel_name = nmxp_chan_lookupName(pKey, channelList);
if(nmxp_channel_name) {
if(nmxp_channel_name != NULL) {
memcpy(&pTime, &buffer_data[4], 8);
if ( swap ) { nmxp_data_swap_8b(&pTime); }
......@@ -506,36 +508,40 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not in STA.CHAN format: %s\n",
NMXP_LOG_STR(nmxp_channel_name));
}
pd.key = pKey;
pd->key = pKey;
if(network_code[0] != 0) {
strncpy(pd.network, network_code, NMXP_DATA_NETWORK_LENGTH);
strncpy(pd->network, network_code, NMXP_DATA_NETWORK_LENGTH);
} else {
strncpy(pd.network, network_code_default, NMXP_DATA_NETWORK_LENGTH);
strncpy(pd->network, network_code_default, NMXP_DATA_NETWORK_LENGTH);
}
if(station_code[0] != 0) {
strncpy(pd.station, station_code, NMXP_DATA_STATION_LENGTH);
strncpy(pd->station, station_code, NMXP_DATA_STATION_LENGTH);
}
if(channel_code[0] != 0) {
strncpy(pd.channel, channel_code, NMXP_DATA_CHANNEL_LENGTH);
strncpy(pd->channel, channel_code, NMXP_DATA_CHANNEL_LENGTH);
}
pd.packet_type = NMXP_MSG_DECOMPRESSED;
pd.x0 = -1;
pd.xn = -1;
pd.x0n_significant = 0;
pd->packet_type = NMXP_MSG_DECOMPRESSED;
pd->x0 = -1;
pd->xn = -1;
pd->x0n_significant = 0;
pd->time = pTime;
pd->nSamp = pNSamp;
pd->pDataPtr = pDataPtr;
pd->sampRate = pSampRate;
/* TODO*/
/* pd.oldest_seq_no = ;*/
/* pd.seq_no = ;*/
pd.time = pTime;
pd.nSamp = pNSamp;
pd.pDataPtr = pDataPtr;
pd.sampRate = pSampRate;
NMXP_MEM_FREE(nmxp_channel_name);
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not found for key %d\n", pKey);
}
return &pd;
return pd;
}
......@@ -551,7 +557,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
static NMXP_DATA_PROCESS pd;
NMXP_DATA_PROCESS *pd = NULL;
int32_t nmx_rate_code_to_sample_rate[32] = {
0,1,2,5,10,20,40,50,
......@@ -572,7 +580,8 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
int32_t comp_bytecount;
unsigned char *indata;
static int32_t outdata[MAX_OUTDATA];
int32_t * outdata = NULL;
int32_t nout, i, k;
int32_t prev_xn;
const uint32_t high_scale = 4096 * 2048;
......@@ -580,6 +589,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
char *nmxp_channel_name = NULL;
pd= (NMXP_DATA_PROCESS *) NMXP_MEM_MALLOC(sizeof(NMXP_DATA_PROCESS));
memset(pd,0,sizeof(NMXP_DATA_PROCESS));
/* TOREMOVE int my_order = get_my_wordorder();*/
int my_host_is_bigendian = nmxp_data_bigendianhost();
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN, "my_host_is_bigendian %d\n", my_host_is_bigendian);
......@@ -645,8 +657,8 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
pSampRate = this_sample_rate;
nmxp_data_init(&pd);
nmxp_data_init(pd);
outdata = (int32_t *) NMXP_MEM_MALLOC(MAX_OUTDATA*sizeof(int32_t));
nmxp_channel_name = nmxp_chan_lookupName(pKey, channelList);
if(nmxp_channel_name) {
......@@ -693,37 +705,38 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_PACKETMAN, "Unpacked %d samples.\n", nout);
pDataPtr = outdata;
pNSamp = nout;
pd.key = pKey;
pd->key = pKey;
if(network_code[0] != 0) {
strncpy(pd.network, network_code, NMXP_DATA_NETWORK_LENGTH);
strncpy(pd->network, network_code, NMXP_DATA_NETWORK_LENGTH);
} else {
strncpy(pd.network, network_code_default, NMXP_DATA_NETWORK_LENGTH);
strncpy(pd->network, network_code_default, NMXP_DATA_NETWORK_LENGTH);
}
if(station_code[0] != 0) {
strncpy(pd.station, station_code, NMXP_DATA_STATION_LENGTH);
strncpy(pd->station, station_code, NMXP_DATA_STATION_LENGTH);
}
if(channel_code[0] != 0) {
strncpy(pd.channel, channel_code, NMXP_DATA_CHANNEL_LENGTH);
strncpy(pd->channel, channel_code, NMXP_DATA_CHANNEL_LENGTH);
}
pd.packet_type = nmx_ptype;
pd.x0 = nmx_x0;
pd.xn = pDataPtr[nout];
pd.x0n_significant = 1;
pd.oldest_seq_no = nmx_oldest_sequence_number;
pd.seq_no = nmx_seqno;
pd.time = pTime;
pd.nSamp = pNSamp;
pd.pDataPtr = pDataPtr;
pd.sampRate = pSampRate;
pd->packet_type = nmx_ptype;
pd->x0 = nmx_x0;
pd->xn = pDataPtr[nout];
pd->x0n_significant = 1;
pd->oldest_seq_no = nmx_oldest_sequence_number;
pd->seq_no = nmx_seqno;
pd->time = pTime;
pd->nSamp = pNSamp;
pd->pDataPtr = pDataPtr;
pd->sampRate = pSampRate;
NMXP_MEM_FREE(nmxp_channel_name);
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_PACKETMAN, "Channel name not found for key %d\n", pKey);
}
return &pd;
return pd;
}
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_chan.c,v 1.44 2009-03-10 16:57:07 mtheo Exp $
* $Id: nmxp_chan.c,v 1.45 2009-08-31 12:16:41 mtheo Exp $
*
*/
......@@ -231,7 +231,7 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList)
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList)
{
int i_chan = 0;
static char ret[NMXP_CHAN_MAX_SIZE_NAME];
char *ret = (char *) NMXP_MEM_MALLOC(NMXP_CHAN_MAX_SIZE_NAME);
ret[0] = 0;
......@@ -243,6 +243,7 @@ char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList)
}
if(ret[0] == 0) {
NMXP_MEM_FREE(ret);
return NULL;
} else {
return ret;
......@@ -338,6 +339,8 @@ NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE
i_chan_duplicated, channelList->channel[i_chan_duplicated].key);
}
NMXP_MEM_FREE(nmxp_channel_name);
nmxp_channel_name = NULL;
}
}
}
......
......@@ -2,16 +2,14 @@
*
* \brief Computing a 32 bit CRC.
*
* $Id: nmxp_crc32.c,v 1.6 2008-02-24 15:10:52 mtheo Exp $
* $Id: nmxp_crc32.c,v 1.7 2009-08-31 12:16:41 mtheo Exp $
*
*
*/
#include "nmxp_crc32.h"
static uint32_t crc32_tab[256];
void crc32_init_table () {
void crc32_init_table (uint32_t crc32_tab[256]) {
unsigned int i, j;
uint32_t h = 1;
crc32_tab[0] = 0;
......@@ -27,8 +25,9 @@ void crc32_init_table () {
uint32_t crc32(uint32_t crc32val, const char *s, uint32_t len)
{
uint32_t i;
uint32_t crc32_tab[256];
crc32_init_table();
crc32_init_table(crc32_tab);
crc32val ^= 0xffffffff;
for (i = 0; i < len; i ++) {
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_data.c,v 1.69 2009-08-17 08:19:46 mtheo Exp $
* $Id: nmxp_data.c,v 1.70 2009-08-31 12:16:41 mtheo Exp $
*
*/
......@@ -41,31 +41,29 @@ UTC, call mktime() and restore the value of TZ. Something like
time_t my_timegm (struct tm *tm) {
time_t ret;
/*TODO stefano avoid static*/
static char first_time = 1;
char *tz;
#ifndef HAVE_SETENV
#ifndef HAVE_UNDERSCORE_TIMEZONE
#warning Computation of packet latencies could be wrong if local time is not equal to UTC.
static int first_time = 1;
if(first_time) {
first_time = 0;
nmxp_log(NMXP_LOG_WARN, NMXP_LOG_D_ANY, "Computation of packet latencies could be wrong if local time is not equal to UTC.\n");
}
#endif
#else
char *tz;
tz = getenv("TZ");
setenv("TZ", "", 1);
tzset();
#endif
ret = mktime(tm);
#ifdef HAVE_SETENV
if (tz)
if(first_time) {
first_time = 0;
tz = getenv("TZ");
setenv("TZ", tz, 1);
else
unsetenv("TZ");
tzset();
tzset();
}
#endif
#ifdef HAVE_UNDERSCORE_TIMEZONE
......@@ -173,25 +171,26 @@ int nmxp_data_unpack_bundle (int32_t *outdata, unsigned char *indata, int32_t *p
int nmxp_data_to_str(char *out_str, double time_d) {
time_t time_t_start_time;
struct tm *tm_start_time;
struct tm tm_start_time;
if(time_d > 0.0) {
time_t_start_time = (time_t) time_d;
} else {
time_t_start_time = 0;
}
tm_start_time = gmtime(&time_t_start_time);
gmtime_r(&time_t_start_time, &tm_start_time);
snprintf(out_str, NMXP_DATA_MAX_SIZE_DATE, "%04d.%03d,%02d:%02d:%02d.%04d",
tm_start_time->tm_year + 1900,
tm_start_time.tm_year + 1900,
/*
tm_start_time->tm_mon + 1,
tm_start_time->tm_mday,
tm_start_time.tm_mon + 1,
tm_start_time.tm_mday,
*/
tm_start_time->tm_yday + 1,
tm_start_time->tm_hour,
tm_start_time->tm_min,
tm_start_time->tm_sec,
tm_start_time.tm_yday + 1,
tm_start_time.tm_hour,
tm_start_time.tm_min,
tm_start_time.tm_sec,
(time_t_start_time == 0)? 0 : (int) ( ((time_d - (double) time_t_start_time)) * 10000.0 )
);
......@@ -200,31 +199,31 @@ int nmxp_data_to_str(char *out_str, double time_d) {
int nmxp_data_year_from_epoch(double time_d) {
time_t time_t_start_time;
struct tm *tm_start_time;
struct tm tm_start_time;
if(time_d > 0.0) {
time_t_start_time = (time_t) time_d;
} else {
time_t_start_time = 0;
}
tm_start_time = gmtime(&time_t_start_time);
return tm_start_time->tm_year + 1900;
/*Use reentrant to be trhead safe*/
gmtime_r(&time_t_start_time,&tm_start_time);
return tm_start_time.tm_year + 1900;
}
int nmxp_data_yday_from_epoch(double time_d) {
time_t time_t_start_time;
struct tm *tm_start_time;
struct tm tm_start_time;
if(time_d > 0.0) {
time_t_start_time = (time_t) time_d;
} else {
time_t_start_time = 0;
}
tm_start_time = gmtime(&time_t_start_time);
return tm_start_time->tm_yday + 1;
}
/*Use reentrant to be trhead safe*/
gmtime_r(&time_t_start_time,&tm_start_time);
return tm_start_time.tm_yday + 1;
}
int nmxp_data_trim(NMXP_DATA_PROCESS *pd, double trim_start_time, double trim_end_time, unsigned char exclude_bitmap) {
......@@ -325,14 +324,7 @@ int nmxp_data_trim(NMXP_DATA_PROCESS *pd, double trim_start_time, double trim_en
time_t nmxp_data_gmtime_now() {
time_t time_now;
struct tm *tm_now;
NMXP_TM_T tmt_now;
time(&time_now);
tm_now = gmtime(&time_now);
memcpy(&(tmt_now.t), tm_now, sizeof(struct tm));
tmt_now.d = 0;
time_now = nmxp_data_tm_to_time(&tmt_now);
return time_now;
}
......@@ -434,7 +426,7 @@ int nmxp_data_parse_date(const char *pstr_date, NMXP_TM_T *ret_tmt) {
int flag_finished = 0;
time_t time_now;
struct tm *tm_now;
struct tm tm_now;
int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m, d, day_sum, jday;
......@@ -460,19 +452,19 @@ int nmxp_data_parse_date(const char *pstr_date, NMXP_TM_T *ret_tmt) {
/* initialize ret_tmt */
time(&time_now);
tm_now = gmtime(&time_now);
gmtime_r(&time_now,&tm_now);
ret_tmt->t.tm_sec = 0 ;
ret_tmt->t.tm_min = 0;
ret_tmt->t.tm_hour = 0;
ret_tmt->t.tm_mday = tm_now->tm_mday;
ret_tmt->t.tm_mon = tm_now->tm_mon;
ret_tmt->t.tm_year = tm_now->tm_year;
ret_tmt->t.tm_wday = tm_now->tm_wday;
ret_tmt->t.tm_yday = tm_now->tm_yday;
ret_tmt->t.tm_isdst = tm_now->tm_isdst;
ret_tmt->t.tm_mday = tm_now.tm_mday;
ret_tmt->t.tm_mon = tm_now.tm_mon;
ret_tmt->t.tm_year = tm_now.tm_year;
ret_tmt->t.tm_wday = tm_now.tm_wday;
ret_tmt->t.tm_yday = tm_now.tm_yday;
ret_tmt->t.tm_isdst = tm_now.tm_isdst;
#ifdef HAVE_STRUCT_TM_TM_GMTOFF
ret_tmt->t.tm_gmtoff = tm_now->tm_gmtoff;
ret_tmt->t.tm_gmtoff = tm_now.tm_gmtoff;
#endif
ret_tmt->d = 0;
......
......@@ -7,12 +7,11 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_log.c,v 1.22 2009-03-10 16:56:40 mtheo Exp $
* $Id: nmxp_log.c,v 1.23 2009-08-31 12:16:41 mtheo Exp $
*
*/
#include "nmxp_log.h"