diff --git a/include/smax-postgres.h b/include/smax-postgres.h index 746b489..0d93806 100644 --- a/include/smax-postgres.h +++ b/include/smax-postgres.h @@ -101,14 +101,14 @@ #define SMAXPQ_VERSION_STRING str_2(SMAXPQ_MAJOR_VERSION) "." str_2(SMAXPQ_MINOR_VERSION) \ "." str_2(SMAXPQ_PATCHLEVEL) SMAXPQ_RELEASE_STRING -extern boolean debug; ///< whether to show debug messages +extern XBoolean debug; ///< whether to show debug messages /** * A set of properties that determine how an SMA-X variable is logged into the PostgreSQL DB. */ typedef struct { - boolean force; ///< Whether the variable should be logged no matter what other settings. - boolean exclude; ///< Whether to exclude this variable from logging + XBoolean force; ///< Whether the variable should be logged no matter what other settings. + XBoolean exclude; ///< Whether to exclude this variable from logging int sampling; ///< sampling step for array data (sampling every n values only) } logger_properties; @@ -150,8 +150,8 @@ int setSQLUserName(const char *name); const char *getSQLAuth(); int setSQLAuth(const char *passwd); -boolean isUseHyperTables(); -void setUseHyperTables(boolean value); +XBoolean isUseHyperTables(); +void setUseHyperTables(XBoolean value); int getUpdateInterval(); int getSnapshotInterval(); diff --git a/src/logger-config.c b/src/logger-config.c index 50cdf90..0a20193 100644 --- a/src/logger-config.c +++ b/src/logger-config.c @@ -48,7 +48,7 @@ static char *sqlServer; static char *dbName; static char *dbUser; static char *dbAuth; -static boolean use_hyper_tables = FALSE; +static XBoolean use_hyper_tables = FALSE; static int update_interval = MINUTE; ///< (s) The rate of fast updates for changing variables (min. 1m). static int snapshot_interval = MINUTE; ///< (s) The rate of snapshotting all variables (min. 1m). @@ -426,7 +426,7 @@ logger_properties *getLogProperties(const char *id) { * @param updateTime (s) UNIX timestamp when the variable was last updated in the SMA-X database. * @return TRUE (1) if the variable should be logged into the SQL database, or else FALSE (0) */ -boolean isLogging(const char *id, double updateTime) { +XBoolean isLogging(const char *id, double updateTime) { const logger_properties *p; const time_t now = time(NULL); @@ -614,7 +614,7 @@ int setSQLAuth(const char *passwd) { * * @sa setUseHyperTables() */ -boolean isUseHyperTables() { +XBoolean isUseHyperTables() { return use_hyper_tables; } @@ -626,7 +626,7 @@ boolean isUseHyperTables() { * * @sa isUseHyperTables() */ -void setUseHyperTables(boolean value) { +void setUseHyperTables(XBoolean value) { use_hyper_tables = (value != 0); } diff --git a/src/postgres-backend.c b/src/postgres-backend.c index 0695886..7e77824 100644 --- a/src/postgres-backend.c +++ b/src/postgres-backend.c @@ -71,7 +71,7 @@ typedef struct { int cols; ///< Number of array elements (columns) char sqlType[SQL_TYPE_LEN]; ///< The SQL storage type - boolean hasMeta; ///< (boolean) if we have metadata available + XBoolean hasMeta; ///< (boolean) if we have metadata available int metaVersion; ///< metadata serial number int sampling; ///< the current sampling interval for array data int ndim; ///< array dimensions (may be 0 for scalars) @@ -620,7 +620,7 @@ static size_t appendValue(const void *data, XType type, char *dst, size_t len) { switch (type) { - case X_BOOLEAN: return pos + x_snprintf(dst, len - pos, "%s",*(boolean *) data ? "true" : "false"); + case X_BOOLEAN: return pos + x_snprintf(dst, len - pos, "%s",*(XBoolean *) data ? "true" : "false"); case X_BYTE: return pos + x_snprintf(dst, len - pos, "%hhd", *(char *) data); @@ -1010,6 +1010,7 @@ static int sqlCreateMetaTable(int id) { static int sqlAddMeta(const Variable *u, TableDescriptor *t) { const XField *f = &u->field; size_t l = 0; + struct tm tm = {}; int step, ndim; if(!u || !t) { @@ -1028,7 +1029,8 @@ static int sqlAddMeta(const Variable *u, TableDescriptor *t) { ensureCommandCapacity(200 + META_SHAPE_LEN + META_UNIT_LEN); l += x_snprintf(&cmd[l], cmdSize - l, "INSERT INTO " META_NAME_PATTERN " VALUES(DEFAULT" SQL_SEP, t->index); - l += strftime(&cmd[l], cmdSize - l, SQL_DATE_FORMAT, gmtime(&u->updateTime)); + gmtime_r(&u->updateTime, &tm); + l += strftime(&cmd[l], cmdSize - l, SQL_DATE_FORMAT, &tm); l += x_snprintf(&cmd[l], cmdSize - l, SQL_SEP "%d", step); l += x_snprintf(&cmd[l], cmdSize - l, SQL_SEP "%d", ndim); @@ -1108,7 +1110,7 @@ static int sqlGetLastMeta(TableDescriptor *t) { } -static boolean isMetaUpdate(const Variable *u, const TableDescriptor *t) { +static XBoolean isMetaUpdate(const Variable *u, const TableDescriptor *t) { const XField *f = &u->field; int i; int ndim = f->ndim; @@ -1460,6 +1462,7 @@ static int sqlAddValues(const Variable *u) { TableDescriptor *t; int len; size_t pos = 0; + struct tm tm = {}; char sqlType[SQL_TYPE_LEN]; if(!u) { @@ -1511,9 +1514,11 @@ static int sqlAddValues(const Variable *u) { ensureCommandCapacity(200 + SQL_TABLE_NAME_LEN + getSampleCount(u) * len); + gmtime_r(&u->grabTime, &tm); + /* Now insert the data */ pos += x_snprintf(&cmd[pos], cmdSize - pos, "INSERT INTO " TABLE_NAME_PATTERN " VALUES(", t->index); - pos += strftime(&cmd[pos], cmdSize - pos, SQL_DATE_FORMAT, gmtime(&u->grabTime)); + pos += strftime(&cmd[pos], cmdSize - pos, SQL_DATE_FORMAT, &tm); pos += x_snprintf(&cmd[pos], cmdSize - pos, SQL_SEP "'%d'", (int) (u->grabTime - u->updateTime)); pos += appendValues(u, &cmd[pos], cmdSize - pos); @@ -1544,7 +1549,7 @@ static int sqlAddValues(const Variable *u) { } -static boolean sqlDeleteVar(const char *id) { +static XBoolean sqlDeleteVar(const char *id) { int tid, n = 0; if(!id) return FALSE; diff --git a/src/smax-collector.c b/src/smax-collector.c index 6c9e735..b8120c1 100644 --- a/src/smax-collector.c +++ b/src/smax-collector.c @@ -71,7 +71,7 @@ static void *GrabberThread(void *arg); * @return X_SUCCESS (0) if successful or else an error code (<0). */ int initCollector() { - static boolean warned; + static XBoolean warned; int i, status; @@ -185,12 +185,12 @@ static void DestroyEntries(RedisEntry *entries, int n) { * @return TRUE (1) if successfully queued a DB update for the variable, or else FALSE (0; errno may be * set to indicate the type of error -- if any). */ -static boolean SubmitUpdate(Update *u) { +static XBoolean SubmitUpdate(Update *u) { const XMeta *m; const logger_properties *p; Variable *v; XField *f; - boolean force = FALSE; + XBoolean force = FALSE; if(!u || !u->var) { errno = EINVAL; @@ -546,7 +546,7 @@ static double GetServerTime() { * perform an incremental update of the variable that have changed since last time. * @return X_SUCCESS (0) or else an error code (<0) */ -static int Grab(VarGroup *group, const time_t grabTime, boolean isSnapshot) { +static int Grab(VarGroup *group, const time_t grabTime, XBoolean isSnapshot) { double t = GetServerTime(); int status; @@ -594,7 +594,7 @@ static void *GrabberThread(void *arg) { for(;;) { time_t target = SleepToRound(getUpdateInterval()); - boolean isSnapshot = FALSE; + XBoolean isSnapshot = FALSE; int i; if(getSnapshotInterval() > 0) isSnapshot = (target % getSnapshotInterval() < getUpdateInterval()); diff --git a/src/smax-postgres.c b/src/smax-postgres.c index 7913c1a..567c2c9 100644 --- a/src/smax-postgres.c +++ b/src/smax-postgres.c @@ -22,7 +22,7 @@ #include "smax-postgres.h" -boolean debug = FALSE; +XBoolean debug = FALSE; static void *CleanupThread(void *arg) { @@ -66,7 +66,7 @@ int main(int argc, const char *argv[]) { char *configFile = SMAXPQ_DEFAULT_CONFIG; char *owner = "postgres"; char *ownerPasswd = NULL; - boolean bootstrap = FALSE, version = FALSE; + XBoolean bootstrap = FALSE, version = FALSE; int c; const struct poptOption options[] = {