diff options
author | David Sommerseth <davids@redhat.com> | 2009-10-22 13:21:37 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-10-22 13:21:37 +0200 |
commit | 5cbe607d2078b83d9491ab4b8d3b6209d73b292c (patch) | |
tree | 7ff6750fb3cff2485ec75d38942a9d806a020b5c | |
parent | 51243cbc51fd027978a7747fdb2bbca561ed74c9 (diff) | |
download | rteval-5cbe607d2078b83d9491ab4b8d3b6209d73b292c.tar.gz rteval-5cbe607d2078b83d9491ab4b8d3b6209d73b292c.tar.xz rteval-5cbe607d2078b83d9491ab4b8d3b6209d73b292c.zip |
Improved overall logging information
-rw-r--r-- | server/parser/configparser.c | 5 | ||||
-rw-r--r-- | server/parser/eurephia_nullsafe.c | 3 | ||||
-rw-r--r-- | server/parser/eurephia_values.c | 2 | ||||
-rw-r--r-- | server/parser/eurephia_xml.c | 4 | ||||
-rw-r--r-- | server/parser/log.c | 27 | ||||
-rw-r--r-- | server/parser/parsethread.c | 34 | ||||
-rw-r--r-- | server/parser/pgsql.c | 128 | ||||
-rw-r--r-- | server/parser/pgsql.h | 3 | ||||
-rw-r--r-- | server/parser/rteval_parserd.c | 65 | ||||
-rw-r--r-- | server/parser/xmlparser.c | 24 |
10 files changed, 173 insertions, 122 deletions
diff --git a/server/parser/configparser.c b/server/parser/configparser.c index dc01984..88c7ae3 100644 --- a/server/parser/configparser.c +++ b/server/parser/configparser.c @@ -139,12 +139,12 @@ eurephiaVALUES *read_config(LogContext *log, const char *cfgname, const char *se struct stat fi; if( stat(cfgname, &fi) == -1 ) { - writelog(log, LOG_EMERG, "Could not open the config file: %s\n", cfgname); + writelog(log, LOG_EMERG, "Could not open the config file: %s", cfgname); return NULL; } if( (fp = fopen(cfgname, "r")) == NULL ) { - writelog(log, LOG_EMERG, "Could not open the config file: %s\n", cfgname); + writelog(log, LOG_EMERG, "Could not open the config file: %s", cfgname); return NULL; } @@ -153,6 +153,7 @@ eurephiaVALUES *read_config(LogContext *log, const char *cfgname, const char *se sprintf(sectmatch, "[%s]", section); cfg = default_cfg_values(log); + writelog(log, LOG_DEBUG, "Reading config file: %s", cfgname); while( fgets(buf, fi.st_size, fp) != NULL ) { if( strncmp(buf, "[", 1) == 0 ) { sectfound = (!sectfound && (strncmp(buf, sectmatch, strlen(sectmatch)) == 0)); diff --git a/server/parser/eurephia_nullsafe.c b/server/parser/eurephia_nullsafe.c index 24ded87..363bc4f 100644 --- a/server/parser/eurephia_nullsafe.c +++ b/server/parser/eurephia_nullsafe.c @@ -59,8 +59,7 @@ __malloc__ void *malloc_nullsafe(LogContext *log, size_t sz) { buf = calloc(1, sz); /* Using calloc, also gives a zero'd memory region */ if( !buf ) { - writelog(log, LOG_EMERG, "** FATAL ERROR ** " - "Could not allocate memory region for %ld bytes\n", sz); + writelog(log, LOG_EMERG, "Could not allocate memory region for %ld bytes", sz); exit(9); } return buf; diff --git a/server/parser/eurephia_values.c b/server/parser/eurephia_values.c index 66375b2..55c8d53 100644 --- a/server/parser/eurephia_values.c +++ b/server/parser/eurephia_values.c @@ -178,7 +178,7 @@ void eAdd_value(eurephiaVALUES *vls, const char *key, const char *val) // Allocate buffer and save values ptr = eCreate_value_space(vls->log, vls->evid); if( ptr == NULL ) { - writelog(vls->log, LOG_EMERG, "**ERROR** Failed to add value to the value chain\n"); + writelog(vls->log, LOG_EMERG, "Failed to add value to the value chain"); exit(9); } ptr->key = strdup_nullsafe(key); diff --git a/server/parser/eurephia_xml.c b/server/parser/eurephia_xml.c index bda8f33..b54d904 100644 --- a/server/parser/eurephia_xml.c +++ b/server/parser/eurephia_xml.c @@ -137,7 +137,7 @@ char *xmlNodeToString(LogContext *log, xmlNode *node) { char *ret = NULL; if( node == NULL ) { - writelog(log, LOG_ALERT, "** ERROR ** Input data is NULL\n"); + writelog(log, LOG_ALERT, "xmlNodeToString: Input data is NULL"); return NULL; } @@ -148,7 +148,7 @@ char *xmlNodeToString(LogContext *log, xmlNode *node) { assert( serctx != NULL ); if( xmlSaveTree(serctx, node) < 0 ) { - writelog(log, LOG_ALERT, "** ERROR ** Failed to serialise xmlNode\n"); + writelog(log, LOG_ALERT, "xmlNodeToString: Failed to serialise xmlNode"); return NULL; } xmlSaveClose(serctx); diff --git a/server/parser/log.c b/server/parser/log.c index 992f408..f8fe905 100644 --- a/server/parser/log.c +++ b/server/parser/log.c @@ -134,7 +134,34 @@ void writelog(LogContext *lctx, unsigned int loglvl, const char *fmt, ... ) { case ltCONSOLE: case ltFILE: pthread_mutex_lock(lctx->mtx_log); + switch( loglvl ) { + case LOG_EMERG: + fprintf(lctx->logfp, "** EMERG ERROR ** "); + break; + case LOG_ALERT: + fprintf(lctx->logfp, "** ALERT ERROR ** "); + break; + case LOG_CRIT: + fprintf(lctx->logfp, "** CRITICAL ERROR ** "); + break; + case LOG_ERR: + fprintf(lctx->logfp, "** ERROR ** "); + break; + case LOG_WARNING: + fprintf(lctx->logfp, "*WARNING* "); + break; + case LOG_NOTICE: + fprintf(lctx->logfp, "[NOTICE] "); + break; + case LOG_INFO: + fprintf(lctx->logfp, "[INFO] "); + break; + case LOG_DEBUG: + fprintf(lctx->logfp, "[DEBUG] "); + break; + } vfprintf(lctx->logfp, fmt, ap); + fprintf(lctx->logfp, "\n"); pthread_mutex_unlock(lctx->mtx_log); break; } diff --git a/server/parser/parsethread.c b/server/parser/parsethread.c index 02d20aa..2f841a2 100644 --- a/server/parser/parsethread.c +++ b/server/parser/parsethread.c @@ -80,16 +80,16 @@ static int make_report_dir(LogContext *log, const char *fname) { if( mkdir(chkdir, 0755) < 0 ) { // If creating dir failed, report error writelog(log, LOG_ALERT, - "** ERROR ** Could not create directory: %s\n" - "** ERROR ** %s\n", chkdir, strerror(errno)); + "Could not create directory: %s (%s)", + chkdir, strerror(errno)); ret = -1; goto exit; } break; default: // If other failure, report that and exit writelog(log, LOG_ALERT, - "** ERROR ** Could not access directory: %s\n" - "** ERROR ** %s\n", chkdir, strerror(errno)); + "Could not access directory: %s (%s)", + chkdir, strerror(errno)); ret = -1; goto exit; } @@ -167,7 +167,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ repxml = xmlParseFile(job->filename); if( !repxml ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Could not parse XML file: %s\n", job->filename); + "Could not parse XML file: %s", job->filename); return STAT_XMLFAIL; } @@ -175,7 +175,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ syskey = db_register_system(dbc, xslt, repxml); if( syskey < 0 ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Failed to register system (XML file: %s)\n", job->filename); + "Failed to register system (XML file: %s)", job->filename); rc = STAT_SYSREG; goto exit; @@ -183,8 +183,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ rterid = db_get_new_rterid(dbc); if( rterid < 0 ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Failed to register rteval run (XML file: %s)\n", - job->filename); + "Failed to register rteval run (XML file: %s)", job->filename); rc = STAT_RTERIDREG; goto exit; } @@ -199,7 +198,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ destfname = get_destination_path(dbc->log, destdir, job, rterid); if( !destfname ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Failed to generate local report filename for (%i) %s\n", + "Failed to generate local report filename for (%i) %s", job->submid, job->filename); db_rollback(dbc); rc = STAT_UNKNFAIL; @@ -208,7 +207,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ if( db_register_rtevalrun(dbc, xslt, repxml, job->submid, syskey, rterid, destfname) < 0 ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Failed to register rteval run (XML file: %s)\n", + "Failed to register rteval run (XML file: %s)", job->filename); db_rollback(dbc); rc = STAT_RTEVRUNS; @@ -217,7 +216,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ if( db_register_cyclictest(dbc, xslt, repxml, rterid) != 1 ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Failed to register cyclictest data (XML file: %s)\n", + "Failed to register cyclictest data (XML file: %s)", job->filename); db_rollback(dbc); rc = STAT_CYCLIC; @@ -233,8 +232,7 @@ inline int parse_report(dbconn *dbc, xsltStylesheet *xslt, pthread_mutex_t *mtx_ if( rename(job->filename, destfname) < 0 ) { // Move the file writelog(dbc->log, LOG_ERR, - "** ERROR ** Failed to move report file from %s to %s\n" - "** ERROR ** %s\n", + "Failed to move report file from %s to %s (%s)", job->filename, destfname, strerror(errno)); db_rollback(dbc); rc = STAT_REPMOVE; @@ -264,7 +262,7 @@ void *parsethread(void *thrargs) { threadData_t *args = (threadData_t *) thrargs; parseJob_t jobinfo; - writelog(args->dbc->log, LOG_DEBUG, "** Starting thread %i\n", args->id); + writelog(args->dbc->log, LOG_DEBUG, "[Thread %i] Starting", args->id); while( !*(args->shutdown) ) { int len = 0; unsigned int prio = 0; @@ -275,7 +273,7 @@ void *parsethread(void *thrargs) { len = mq_receive(args->msgq, (char *)&jobinfo, sizeof(parseJob_t), &prio); if( (len < 0) && errno != EAGAIN ) { writelog(args->dbc->log, LOG_CRIT, - "** ERROR ** Could not receive the message from queue: %s\n", + "Could not receive the message from queue: %s", strerror(errno)); pthread_exit((void *) 1); } @@ -285,7 +283,7 @@ void *parsethread(void *thrargs) { int res = 0; writelog(args->dbc->log, LOG_DEBUG, - "** Thread %i: Job recieved, submid: %i\n", + "** Thread %i: Job recieved, submid: %i", args->id, jobinfo.submid); // Mark the job as "in progress", if successful update, continue parsing it @@ -296,7 +294,7 @@ void *parsethread(void *thrargs) { db_update_submissionqueue(args->dbc, jobinfo.submid, res); } else { writelog(args->dbc->log, LOG_CRIT, - "** ERROR ** Failed to mark submid %i as STAT_INPROG\n", + "Failed to mark submid %i as STAT_INPROG", jobinfo.submid); } } else { @@ -304,6 +302,6 @@ void *parsethread(void *thrargs) { sleep(5); } } - writelog(args->dbc->log, LOG_DEBUG, "** Thread %i shut down\n", args->id); + writelog(args->dbc->log, LOG_DEBUG, "[Thread %i] Shut down", args->id); pthread_exit((void *) 0); } diff --git a/server/parser/pgsql.c b/server/parser/pgsql.c index fbf6052..7c244e6 100644 --- a/server/parser/pgsql.c +++ b/server/parser/pgsql.c @@ -51,12 +51,17 @@ * * @return Returns a database connection context */ -dbconn *db_connect(eurephiaVALUES *cfg, LogContext *log) { +dbconn *db_connect(eurephiaVALUES *cfg, unsigned int id, LogContext *log) { dbconn *ret = NULL; ret = (dbconn *) malloc_nullsafe(log, sizeof(dbconn)+2); + ret->id = id; ret->log = log; + writelog(log, LOG_DEBUG, "[Connection %i] Connecting to database: server=%s:%s, " + "database=%s, user=%s", ret->id, + eGet_value(cfg, "db_server"), eGet_value(cfg, "db_port"), + eGet_value(cfg, "database"), eGet_value(cfg, "db_username")); ret->db = PQsetdbLogin(eGet_value(cfg, "db_server"), eGet_value(cfg, "db_port"), NULL, /* pgopt */ @@ -67,14 +72,14 @@ dbconn *db_connect(eurephiaVALUES *cfg, LogContext *log) { if( !ret->db ) { writelog(log, LOG_EMERG, - "** ERROR ** Could not connect to the database (unknown reason)\n"); + "[Connection %i] Could not connect to the database (unknown reason)", ret->id); free_nullsafe(ret); return NULL; } if( PQstatus(ret->db) != CONNECTION_OK ) { - writelog(log, LOG_EMERG, "** ERROR ** Failed to connect to the database\n%s\n", - PQerrorMessage(ret->db)); + writelog(log, LOG_EMERG, "[Connection %i] Failed to connect to the database: %s", + ret->id, PQerrorMessage(ret->db)); free_nullsafe(ret); return NULL; } @@ -89,8 +94,10 @@ dbconn *db_connect(eurephiaVALUES *cfg, LogContext *log) { */ void db_disconnect(dbconn *dbc) { if( dbc && dbc->db ) { + writelog(dbc->log, LOG_DEBUG, "[Connection %i] Disconnecting from database", dbc->id); PQfinish(dbc->db); dbc->db = NULL; + dbc->log = NULL; } } @@ -167,14 +174,14 @@ eurephiaVALUES *pgsql_INSERT(dbconn *dbc, xmlDoc *sqldoc) { root_n = xmlDocGetRootElement(sqldoc); if( !root_n || (xmlStrcmp(root_n->name, (xmlChar *) "sqldata") != 0) ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Input XML document is not a valid sqldata document\n"); + "[Connection %i] Input XML document is not a valid sqldata document", dbc->id); return NULL; } table = xmlGetAttrValue(root_n->properties, "table"); if( !table ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Input XML document is missing table reference\n"); + "[Connection %i] Input XML document is missing table reference", dbc->id); return NULL; } @@ -184,7 +191,8 @@ eurephiaVALUES *pgsql_INSERT(dbconn *dbc, xmlDoc *sqldoc) { recs_n = xmlFindNode(root_n, "records"); if( !fields_n || !recs_n ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Input XML document is missing either <fields/> or <records/>\n"); + "[Connection %i] Input XML document is missing either <fields/> or <records/>", + dbc->id); return NULL; } @@ -248,11 +256,14 @@ eurephiaVALUES *pgsql_INSERT(dbconn *dbc, xmlDoc *sqldoc) { } // Create a prepared SQL query +#ifdef DEBUG_SQL + writelog(dbc->log, LOG_DEBUG, "[Connection %i] Preparing SQL statement: %s", dbc->id, sql); +#endif dbres = PQprepare(dbc->db, "", sql, fieldcnt, NULL); if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { writelog(dbc->log, LOG_ALERT, - "** ERROR ** Failed to prepare SQL query\n%s\n", - PQresultErrorMessage(dbres)); + "[Connection %i] Failed to prepare SQL query: %s", + dbc->id, PQresultErrorMessage(dbres)); PQclear(dbres); goto exit; } @@ -293,8 +304,8 @@ eurephiaVALUES *pgsql_INSERT(dbconn *dbc, xmlDoc *sqldoc) { dbres = PQexecPrepared(dbc->db, "", fieldcnt, (const char * const *)value_ar, NULL, NULL, 0); if( PQresultStatus(dbres) != (key ? PGRES_TUPLES_OK : PGRES_COMMAND_OK) ) { - writelog(dbc->log, LOG_ALERT, "** ERROR ** Failed to do SQL INSERT query\n%s\n", - PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_ALERT, "[Connection %i] Failed to do SQL INSERT query: %s", + dbc->id, PQresultErrorMessage(dbres)); PQclear(dbres); eFree_values(res); res = NULL; @@ -346,8 +357,8 @@ int db_begin(dbconn *dbc) { dbres = PQexec(dbc->db, "BEGIN"); if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { writelog(dbc->log, LOG_ALERT, - "** ERROR ** Failed to do prepare a transaction (BEGIN)\n%s\n", - PQresultErrorMessage(dbres)); + "[Connection %i] Failed to do prepare a transaction (BEGIN): %s", + dbc->id, PQresultErrorMessage(dbres)); PQclear(dbres); return -1; } @@ -369,8 +380,8 @@ int db_commit(dbconn *dbc) { dbres = PQexec(dbc->db, "COMMIT"); if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { writelog(dbc->log, LOG_ALERT, - "** ERROR ** Failed to do commit a database transaction (COMMIT)\n%s\n", - PQresultErrorMessage(dbres)); + "[Connection %i] Failed to do commit a database transaction (COMMIT): %s", + dbc->id, PQresultErrorMessage(dbres)); PQclear(dbres); return -1; } @@ -392,8 +403,8 @@ int db_rollback(dbconn *dbc) { dbres = PQexec(dbc->db, "ROLLBACK"); if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { writelog(dbc->log, LOG_CRIT, - "** ERROR ** Failed to do abort/rollback a transaction (ROLLBACK)\n%s\n", - PQresultErrorMessage(dbres)); + "[Connection %i] Failed to do abort/rollback a transaction (ROLLBACK): %s", + dbc->id, PQresultErrorMessage(dbres)); PQclear(dbres); return -1; } @@ -422,11 +433,11 @@ int db_wait_notification(dbconn *dbc, const int *shutdown, const char *listenfor assert( sql != NULL ); // Initiate listening - sprintf(sql, "LISTEN %s\n", listenfor); + sprintf(sql, "LISTEN %s", listenfor); dbres = PQexec(dbc->db, sql); if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { - writelog(dbc->log, LOG_ALERT, - "** ERROR ** SQL %s\n", PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_ALERT, "[Connection %i] SQL %s", + dbc->id, PQresultErrorMessage(dbres)); free_nullsafe(sql); PQclear(dbres); return -1; @@ -450,8 +461,8 @@ int db_wait_notification(dbconn *dbc, const int *shutdown, const char *listenfor // report errors if we're not shutting down, or else exit normally with // successful waiting. if( *shutdown == 0 ) { - writelog(dbc->log, LOG_CRIT, - "** ERROR ** select() failed: %s\n", strerror(errno)); + writelog(dbc->log, LOG_CRIT, "[Connection %i] select() failed: %s", + dbc->id, strerror(errno)); ret = -1; } else { ret = 1; @@ -464,8 +475,8 @@ int db_wait_notification(dbconn *dbc, const int *shutdown, const char *listenfor while ((notify = PQnotifies(dbc->db)) != NULL) { // If a notification was received, inform and exit with success. writelog(dbc->log, LOG_DEBUG, - "** INFO ** Received notfication from pid %d\n", - notify->be_pid); + "[Connection %i] Received notfication from pid %d", + dbc->id, notify->be_pid); PQfreemem(notify); ret = 1; break; @@ -473,10 +484,11 @@ int db_wait_notification(dbconn *dbc, const int *shutdown, const char *listenfor } // Stop listening when we exit - sprintf(sql, "UNLISTEN %s\n", listenfor); + sprintf(sql, "UNLISTEN %s", listenfor); dbres = PQexec(dbc->db, sql); if( PQresultStatus(dbres) != PGRES_COMMAND_OK ) { - writelog(dbc->log, LOG_ALERT, "** ERROR ** SQL %s\n", PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_ALERT, "[Connection %i] SQL %s", + dbc->id, PQresultErrorMessage(dbres)); free_nullsafe(sql); ret = -1; } @@ -518,8 +530,8 @@ parseJob_t *db_get_submissionqueue_job(dbconn *dbc, pthread_mutex_t *mtx) { if( PQresultStatus(res) != PGRES_TUPLES_OK ) { pthread_mutex_unlock(mtx); writelog(dbc->log, LOG_ALERT, - "** ERROR ** Failed to query submission queue (SELECT)\n%s\n", - PQresultErrorMessage(res)); + "[Connection %i] Failed to query submission queue (SELECT): %s", + dbc->id, PQresultErrorMessage(res)); PQclear(res); free_nullsafe(job); return NULL; @@ -534,8 +546,8 @@ parseJob_t *db_get_submissionqueue_job(dbconn *dbc, pthread_mutex_t *mtx) { // Update the submission queue status if( db_update_submissionqueue(dbc, job->submid, STAT_ASSIGNED) < 1 ) { pthread_mutex_unlock(mtx); - writelog(dbc->log, LOG_ALERT, - "** ERROR ** Failed to update submission queue statis to STAT_ASSIGNED\n"); + writelog(dbc->log, LOG_ALERT, "[Connection %i] Failed to update " + "submission queue statis to STAT_ASSIGNED", dbc->id); free_nullsafe(job); return NULL; } @@ -592,21 +604,21 @@ int db_update_submissionqueue(dbconn *dbc, unsigned int submid, int status) { default: case STAT_NEW: writelog(dbc->log, LOG_ERR, - "** ERROR ** Invalid status (%i) attempted to set on submid %i\n", - status, submid); + "[Connection %i] Invalid status (%i) attempted to set on submid %i", + dbc->id, status, submid); return 0; } res = PQexec(dbc->db, sql); if( !res ) { writelog(dbc->log, LOG_ALERT, - "** ERROR ** Unkown error when updating submid %i to status %i\n", - submid, status); + "[Connection %i] Unkown error when updating submid %i to status %i", + dbc->id, submid, status); return -1; } else if( PQresultStatus(res) != PGRES_COMMAND_OK ) { writelog(dbc->log, LOG_ALERT, - "** ERROR ** Failed to UPDATE submissionqueue (submid: %i, status: %i)\n%s\n", - submid, status, PQresultErrorMessage(res)); + "[Connection %i] Failed to UPDATE submissionqueue (submid: %i, status: %i): %s", + dbc->id, submid, status, PQresultErrorMessage(res)); PQclear(res); return -1; } @@ -641,14 +653,14 @@ int db_register_system(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml) { prms.table = "systems"; sysinfo_d = parseToSQLdata(dbc->log, xslt, summaryxml, &prms); if( !sysinfo_d ) { - writelog(dbc->log, LOG_ERR, "** ERROR ** Could not parse the input XML data\n"); + writelog(dbc->log, LOG_ERR, "[Connection %i] Could not parse the input XML data", dbc->id); syskey= -1; goto exit; } sysid = sqldataGetValue(dbc->log, sysinfo_d, "sysid", 0); if( !sysid ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Could not retrieve the sysid field from the input XML\n"); + "[Connection %i] Could not retrieve the sysid field from the input XML", dbc->id); syskey= -1; goto exit; } @@ -658,9 +670,10 @@ int db_register_system(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml) { free_nullsafe(sysid); dbres = PQexec(dbc->db, sqlq); if( PQresultStatus(dbres) != PGRES_TUPLES_OK ) { - writelog(dbc->log, LOG_ALERT, - "** ERROR ** SQL query failed: %s\n** ERROR ** %s\n", - sqlq, PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_ALERT, "[Connection %i] SQL %s", + dbc->id, PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_DEBUG, "[Connection %i] Failing SQL query: %s", + dbc->id, sqlq); PQclear(dbres); syskey= -1; goto exit; @@ -675,7 +688,8 @@ int db_register_system(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml) { goto exit; } if( (eCount(dbdata) != 1) || !dbdata->val ) { // Only one record should be registered - writelog(dbc->log, LOG_ALERT, "** ERROR ** Failed to register the system\n"); + writelog(dbc->log, LOG_ALERT, + "[Connection %i] Failed to register the system", dbc->id); eFree_values(dbdata); syskey= -1; goto exit; @@ -708,9 +722,10 @@ int db_register_system(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml) { hostname, ipaddr); dbres = PQexec(dbc->db, sqlq); if( PQresultStatus(dbres) != PGRES_TUPLES_OK ) { - writelog(dbc->log, LOG_ALERT, - "** ERROR ** SQL query failed: %s\n** ERROR ** %s\n", - sqlq, PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_ALERT, "[Connection %i] SQL %s", + dbc->id, PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_DEBUG, "[Connection %i] Failing SQL query: %s", + dbc->id, sqlq); PQclear(dbres); syskey= -1; goto exit; @@ -724,8 +739,8 @@ int db_register_system(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml) { PQclear(dbres); } else { // Critical -- system IDs should not be registered more than once - writelog(dbc->log, LOG_CRIT, - "** CRITICAL ERROR ** Multiple systems registered (%s)", sqlq); + writelog(dbc->log, LOG_CRIT, "[Connection %i] Multiple systems registered (%s)", + dbc->id, sqlq); syskey= -1; } @@ -762,10 +777,11 @@ int db_get_new_rterid(dbconn *dbc) { if( rterid < 1 ) { writelog(dbc->log, LOG_CRIT, - "** ERROR ** Failed to retrieve a new rterid value\n"); + "[Connection %i] Failed to retrieve a new rterid value", dbc->id); } if( rterid < 0 ) { - writelog(dbc->log, LOG_ALERT, "SQL %s\n", PQresultErrorMessage(dbres)); + writelog(dbc->log, LOG_ALERT, "[Connection %i] SQL %s", + dbc->id, PQresultErrorMessage(dbres)); } PQclear(dbres); return rterid; @@ -802,7 +818,8 @@ int db_register_rtevalrun(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml, prms.report_filename = report_fname; rtevalrun_d = parseToSQLdata(dbc->log, xslt, summaryxml, &prms); if( !rtevalrun_d ) { - writelog(dbc->log, LOG_ERR, "** ERROR ** Could not parse the input XML data\n"); + writelog(dbc->log, LOG_ERR, + "[Connection %i] Could not parse the input XML data", dbc->id); ret = -1; goto exit; } @@ -815,7 +832,8 @@ int db_register_rtevalrun(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml, } if( eCount(dbdata) != 1 ) { - writelog(dbc->log, LOG_ALERT, "** ERROR ** Failed to register the rteval run\n"); + writelog(dbc->log, LOG_ALERT, + "[Connection %i] Failed to register the rteval run", dbc->id); ret = -1; eFree_values(dbdata); goto exit; @@ -829,7 +847,8 @@ int db_register_rtevalrun(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml, rtevalrundets_d = parseToSQLdata(dbc->log, xslt, summaryxml, &prms); if( !rtevalrundets_d ) { writelog(dbc->log, LOG_ERR, - "** ERROR ** Could not parse the input XML data (rtevalruns_details)\n"); + "[Connection %i] Could not parse the input XML data (rtevalruns_details)", + dbc->id); ret = -1; goto exit; } @@ -843,7 +862,8 @@ int db_register_rtevalrun(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml, // Check that only one record was inserted if( eCount(dbdata) != 1 ) { - writelog(dbc->log, LOG_ALERT, "** ERROR ** Failed to register the rteval run details\n"); + writelog(dbc->log, LOG_ALERT, + "[Connection %i] Failed to register the rteval run details", dbc->id); ret = -1; } eFree_values(dbdata); @@ -908,7 +928,7 @@ int db_register_cyclictest(dbconn *dbc, xsltStylesheet *xslt, xmlDoc *summaryxml // Report error if not enough cyclictest data is registered. if( cyclicdata > 1 ) { writelog(dbc->log, LOG_ALERT, - "** ERROR ** No cyclictest raw data or histogram data registered\n"); + "[Connection %i] No cyclictest raw data or histogram data registered", dbc->id); result = -1; } else { result = 1; diff --git a/server/parser/pgsql.h b/server/parser/pgsql.h index d0b35d3..efae34b 100644 --- a/server/parser/pgsql.h +++ b/server/parser/pgsql.h @@ -36,12 +36,13 @@ * A unified database abstraction layer, providing log support */ typedef struct { + unsigned int id; /**< Unique connection ID, used for debugging */ LogContext *log; /**< Initialised log context */ PGconn *db; /**< Database connection handler */ } dbconn; /* Generic database function */ -dbconn *db_connect(eurephiaVALUES *cfg, LogContext *log); +dbconn *db_connect(eurephiaVALUES *cfg, unsigned int id, LogContext *log); void db_disconnect(dbconn *dbc); int db_begin(dbconn *dbc); int db_commit(dbconn *dbc); diff --git a/server/parser/rteval_parserd.c b/server/parser/rteval_parserd.c index 737fd82..144cc71 100644 --- a/server/parser/rteval_parserd.c +++ b/server/parser/rteval_parserd.c @@ -54,9 +54,9 @@ static LogContext *logctx = NULL; /**< Initialsed log context, to be used b void sigcatch(int sig) { if( shutdown == 0 ) { shutdown = 1; - writelog(logctx, LOG_INFO, "** SIGNAL ** Starting shutting down\n"); + writelog(logctx, LOG_INFO, "[SIGNAL] Starting shutting down"); } else { - writelog(logctx, LOG_INFO, "** SIGNAL ** Shutdown in progress ... please be patient ...\n"); + writelog(logctx, LOG_INFO, "[SIGNAL] Shutdown in progress ... please be patient ..."); } // re-enable signals, to avoid brute force exits. @@ -79,26 +79,26 @@ unsigned int get_mqueue_msg_max(LogContext *log) { fp = fopen("/proc/sys/fs/mqueue/msg_max", "r"); if( !fp ) { - writelog(log, LOG_NOTICE, - "** ERROR ** Could not open /proc/sys/fs/mqueue/msg_max, defaulting to %i\n", + writelog(log, LOG_WARNING, + "Could not open /proc/sys/fs/mqueue/msg_max, defaulting to %i", msg_max); - writelog(log, LOG_DEBUG, "** ERROR ** %s\n", strerror(errno)); + writelog(log, LOG_INFO, "%s", strerror(errno)); return msg_max; } memset(&buf, 0, 130); if( fread(&buf, 1, 128, fp) < 1 ) { - writelog(log, LOG_NOTICE, - "** ERROR ** Could not read /proc/sys/fs/mqueue/msg_max, defaulting to %i\n", + writelog(log, LOG_WARNING, + "Could not read /proc/sys/fs/mqueue/msg_max, defaulting to %i", msg_max); - writelog(log, LOG_DEBUG, "** ERROR ** %s\n", strerror(errno)); + writelog(log, LOG_INFO, "%s", strerror(errno)); } else { msg_max = atoi_nullsafe(buf); if( msg_max < 1 ) { msg_max = DEFAULT_MSG_MAX; - writelog(log, LOG_NOTICE, - "** ERROR ** Failed to parse /proc/sys/fs/mqueue/msg_max," - "defaulting to %i\n", msg_max); + writelog(log, LOG_WARNING, + "Failed to parse /proc/sys/fs/mqueue/msg_max," + "defaulting to %i", msg_max); } } fclose(fp); @@ -125,7 +125,7 @@ int process_submission_queue(dbconn *dbc, mqd_t msgq) { job = db_get_submissionqueue_job(dbc, &mtx_submq); if( !job ) { writelog(dbc->log, LOG_EMERG, - "** ERROR ** Failed to get submission queue job - shutting down\n"); + "Failed to get submission queue job - shutting down"); shutdown = 1; rc = 1; goto exit; @@ -134,7 +134,7 @@ int process_submission_queue(dbconn *dbc, mqd_t msgq) { free_nullsafe(job); if( db_wait_notification(dbc, &shutdown, "rteval_submq") < 1 ) { writelog(dbc->log, LOG_EMERG, - "** ERROR ** Failed to wait for DB notification - shutting down\n"); + "Failed to wait for DB notification - shutting down"); shutdown = 1; rc = 1; goto exit; @@ -143,7 +143,7 @@ int process_submission_queue(dbconn *dbc, mqd_t msgq) { } // Send the job to the queue - writelog(dbc->log, LOG_NOTICE, "** New job: submid %i, %s\n", job->submid, job->filename); + writelog(dbc->log, LOG_INFO, "** New job: submid %i, %s", job->submid, job->filename); do { int res; @@ -151,15 +151,15 @@ int process_submission_queue(dbconn *dbc, mqd_t msgq) { res = mq_send(msgq, (char *) job, sizeof(parseJob_t), 1); if( (res < 0) && (errno != EAGAIN) ) { writelog(dbc->log, LOG_EMERG, - "** ERROR ** Could not send parse job to the queue " - "- shutting down\n"); + "Could not send parse job to the queue " + "- shutting down"); shutdown = 1; rc = 2; goto exit; } else if( errno == EAGAIN ) { writelog(dbc->log, LOG_WARNING, - "** WARNING ** Message queue filled up. " - "Will not add new messages to queue for the next 60 seconds\n"); + "Message queue filled up. " + "Will not add new messages to queue for the next 60 seconds"); sleep(60); } } while( (errno == EAGAIN) ); @@ -208,14 +208,16 @@ int main(int argc, char **argv) { // Parse XSLT template snprintf(xsltfile, 512, "%s/%s", eGet_value(config, "xsltpath"), XMLPARSER_XSL); + writelog(logctx, LOG_DEBUG, "Parsing XSLT file: %s", xsltfile); xslt = xsltParseStylesheetFile((xmlChar *) xsltfile); if( !xslt ) { - writelog(logctx, LOG_EMERG, "** ERROR ** Could not parse XSLT template: %s\n", xsltfile); + writelog(logctx, LOG_EMERG, "Could not parse XSLT template: %s", xsltfile); rc = 2; goto exit; } // Open a POSIX MQ + writelog(logctx, LOG_DEBUG, "Preparing POSIX MQ queue: /rteval_parsequeue"); memset(&msgq, 0, sizeof(mqd_t)); msgq_attr.mq_maxmsg = get_mqueue_msg_max(logctx); msgq_attr.mq_msgsize = sizeof(parseJob_t); @@ -223,13 +225,13 @@ int main(int argc, char **argv) { msgq = mq_open("/rteval_parsequeue", O_RDWR | O_CREAT | O_NONBLOCK, 0600, &msgq_attr); if( msgq < 0 ) { writelog(logctx, LOG_EMERG, - "** ERROR ** Could not open message queue: %s\n", strerror(errno)); + "Could not open message queue: %s", strerror(errno)); rc = 2; goto exit; } // Get a database connection for the main thread - dbc = db_connect(config, logctx); + dbc = db_connect(config, max_threads, logctx); if( !dbc ) { rc = 2; goto exit; @@ -242,21 +244,22 @@ int main(int argc, char **argv) { assert( (threads != NULL) && (thread_attrs != NULL) && (thrdata != NULL) ); reportdir = eGet_value(config, "reportdir"); + writelog(logctx, LOG_INFO, "Starting %i worker threads", max_threads); for( i = 0; i < max_threads; i++ ) { // Prepare thread specific data thrdata[i] = malloc_nullsafe(logctx, sizeof(threadData_t)); if( !thrdata[i] ) { writelog(logctx, LOG_EMERG, - "** ERROR ** Could not allocate memory for thread data\n"); + "Could not allocate memory for thread data"); rc = 2; goto exit; } // Get a database connection for the thread - thrdata[i]->dbc = db_connect(config, logctx); + thrdata[i]->dbc = db_connect(config, i, logctx); if( !thrdata[i]->dbc ) { writelog(logctx, LOG_EMERG, - "** ERROR ** Could not connect to the database for thread %i\n", i); + "Could not connect to the database for thread %i", i); rc = 2; shutdown = 1; goto exit; @@ -272,7 +275,7 @@ int main(int argc, char **argv) { thread_attrs[i] = malloc_nullsafe(logctx, sizeof(pthread_attr_t)); if( !thread_attrs[i] ) { writelog(logctx, LOG_EMERG, - "** ERROR ** Could not allocate memory for thread attributes\n"); + "Could not allocate memory for thread attributes"); rc = 2; goto exit; } @@ -282,7 +285,7 @@ int main(int argc, char **argv) { threads[i] = malloc_nullsafe(logctx, sizeof(pthread_t)); if( !threads[i] ) { writelog(logctx, LOG_EMERG, - "** ERROR ** Could not allocate memory for pthread_t\n"); + "Could not allocate memory for pthread_t"); rc = 2; goto exit; } @@ -309,9 +312,9 @@ int main(int argc, char **argv) { // checks the submission queue and puts unprocessed records on the POSIX MQ // to be parsed by one of the threads // - writelog(logctx, LOG_DEBUG, "** Starting submission queue checker\n"); + writelog(logctx, LOG_DEBUG, "Starting submission queue checker"); rc = process_submission_queue(dbc, msgq); - writelog(logctx, LOG_DEBUG, "** Submission queue checker shut down\n"); + writelog(logctx, LOG_DEBUG, "Submission queue checker shut down"); exit: // Clean up all threads @@ -323,7 +326,7 @@ int main(int argc, char **argv) { if( (j_rc = pthread_join(*threads[i], &thread_rc)) != 0 ) { writelog(logctx, LOG_CRIT, - "** ERROR ** Failed to join thread %i: %s\n", + "Failed to join thread %i: %s", i, strerror(j_rc)); } pthread_attr_destroy(thread_attrs[i]); @@ -344,12 +347,12 @@ int main(int argc, char **argv) { // Close message queue errno = 0; if( mq_close(msgq) < 0 ) { - writelog(logctx, LOG_CRIT, "** ERROR ** Failed to close message queue: %s\n", + writelog(logctx, LOG_CRIT, "Failed to close message queue: %s", strerror(errno)); } errno = 0; if( mq_unlink("/rteval_parsequeue") < 0 ) { - writelog(logctx, LOG_ALERT, "** ERROR ** Failed to remove the message queue: %s\n", + writelog(logctx, LOG_ALERT, "Failed to remove the message queue: %s", strerror(errno)); } diff --git a/server/parser/xmlparser.c b/server/parser/xmlparser.c index 66504ca..d561904 100644 --- a/server/parser/xmlparser.c +++ b/server/parser/xmlparser.c @@ -100,7 +100,7 @@ xmlDoc *parseToSQLdata(LogContext *log, xsltStylesheet *xslt, xmlDoc *indata_d, idx_syskey = 0, idx_rterid = 0, idx_repfname = 0; if( params->table == NULL ) { - writelog(log, LOG_ERR, "Table is not defined\n"); + writelog(log, LOG_ERR, "Table is not defined"); return NULL; } @@ -137,7 +137,7 @@ xmlDoc *parseToSQLdata(LogContext *log, xsltStylesheet *xslt, xmlDoc *indata_d, // Apply the XSLT template to the input XML data result_d = xsltApplyStylesheet(xslt, indata_d, (const char **)xsltparams); if( result_d == NULL ) { - writelog(log, LOG_CRIT, "Failed applying XSLT template to input XML\n"); + writelog(log, LOG_CRIT, "Failed applying XSLT template to input XML"); } // Free memory we allocated via encapsString()/encapsInt() @@ -253,14 +253,14 @@ int sqldataGetFid(LogContext *log, xmlNode *sql_n, const char *fname) { if( !sql_n || (xmlStrcmp(sql_n->name, (xmlChar *) "sqldata") != 0) ) { writelog(log, LOG_ERR, - "** ERROR ** Input XML document is not a valid sqldata document\n"); + "sqldataGetFid: Input XML document is not a valid sqldata document"); return -2; } f_n = xmlFindNode(sql_n, "fields"); if( !f_n || !f_n->children ) { writelog(log, LOG_ERR, - "** ERROR ** Input XML document does not contain a fields section\n"); + "sqldataGetFid: Input XML document does not contain a fields section"); return -2; } @@ -275,7 +275,8 @@ int sqldataGetFid(LogContext *log, xmlNode *sql_n, const char *fname) { char *fid = xmlGetAttrValue(f_n->properties, "fid"); if( !fid ) { writelog(log, LOG_ERR, - "** ERROR ** Field node is missing 'fid' attribute\n"); + "sqldataGetFid: Field node is missing 'fid' attribute (field: %s)", + fname); return -2; } return atoi_nullsafe(fid); @@ -301,13 +302,14 @@ char *sqldataGetValue(LogContext *log, xmlDoc *sqld, const char *fname, int reci int fid = -3, rc = 0; if( recid < 0 ) { - writelog(log, LOG_ERR, "** ERROR ** sqldataGetValue() :: Invalid recid\n"); + writelog(log, LOG_ERR, "sqldataGetValue: Invalid recid"); return NULL; } r_n = xmlDocGetRootElement(sqld); if( !r_n || (xmlStrcmp(r_n->name, (xmlChar *) "sqldata") != 0) ) { - writelog(log, LOG_ERR, "** ERROR ** Input XML document is not a valid sqldata document\n"); + writelog(log, LOG_ERR, + "sqldataGetValue: Input XML document is not a valid sqldata document"); return NULL; } @@ -319,7 +321,7 @@ char *sqldataGetValue(LogContext *log, xmlDoc *sqld, const char *fname, int reci r_n = xmlFindNode(r_n, "records"); if( !r_n || !r_n->children ) { writelog(log, LOG_ERR, - "** ERROR ** Input XML document does not contain a records section\n"); + "sqldataGetValue: Input XML document does not contain a records section"); return NULL; } @@ -379,7 +381,7 @@ xmlDoc *sqldataGetHostInfo(LogContext *log, xsltStylesheet *xslt, xmlDoc *summar hostinfo_d = parseToSQLdata(log, xslt, summaryxml, &prms); if( !hostinfo_d ) { writelog(log, LOG_ERR, - "** ERROR ** Could not parse input XML data (hostinfo)\n"); + "sqldatGetHostInfo: Could not parse input XML data"); xmlFreeDoc(hostinfo_d); goto exit; } @@ -388,7 +390,7 @@ xmlDoc *sqldataGetHostInfo(LogContext *log, xsltStylesheet *xslt, xmlDoc *summar *hostname = sqldataGetValue(log, hostinfo_d, "hostname", 0); if( !hostname ) { writelog(log, LOG_ERR, - "** ERROR ** Could not retrieve the hostname field from the input XML\n"); + "sqldatGetHostInfo: Could not retrieve the hostname field from the input XML"); xmlFreeDoc(hostinfo_d); goto exit; } @@ -397,7 +399,7 @@ xmlDoc *sqldataGetHostInfo(LogContext *log, xsltStylesheet *xslt, xmlDoc *summar *ipaddr = sqldataGetValue(log, hostinfo_d, "ipaddr", 0); if( !ipaddr ) { writelog(log, LOG_ERR, - "** ERROR ** Could not retrieve the IP address field from the input XML\n"); + "sqldatGetHostInfo: Could not retrieve the IP address field from the input XML"); free_nullsafe(hostname); xmlFreeDoc(hostinfo_d); goto exit; |