summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-11-10 13:38:54 +0100
committerDavid Sommerseth <davids@redhat.com>2009-11-10 13:38:54 +0100
commit20f464f64d02def70d3333e8130b38c3cda393a8 (patch)
treef30e84edb7aab8a6e6ae758d05b80974cca03b8b /server
parent5f32bf6011ee2687003c8876278c3ffff22760b9 (diff)
downloadrteval-20f464f64d02def70d3333e8130b38c3cda393a8.tar.gz
rteval-20f464f64d02def70d3333e8130b38c3cda393a8.tar.xz
rteval-20f464f64d02def70d3333e8130b38c3cda393a8.zip
Simplified the API to parse_report() and check_filesize()
Passing threadData_t * directly, instead of several individual parameters deriving from a threadData_t pointer.
Diffstat (limited to 'server')
-rw-r--r--server/parser/parsethread.c76
1 files changed, 35 insertions, 41 deletions
diff --git a/server/parser/parsethread.c b/server/parser/parsethread.c
index 3b24ef5..ff80073 100644
--- a/server/parser/parsethread.c
+++ b/server/parser/parsethread.c
@@ -138,13 +138,12 @@ static char *get_destination_path(LogContext *log, const char *destdir,
/**
* Checks if the file size of the given file is below the given max size value.
*
- * @param log Log context
- * @param fname Filename to the file to check
- * @param maxsize Maximum allowed file size
+ * @param thrdata Pointer to a threadData_t structure with log context and max_report_size setting
+ * @param fname Filename of the file to check
*
* @return Returns 1 if file is within the limit, otherwise 0. On errors -1 is returned.
*/
-inline int check_filesize(LogContext *log, const char *fname, unsigned int maxsize) {
+inline int check_filesize(threadData_t *thrdata, const char *fname) {
struct stat info;
if( !fname ) {
@@ -153,12 +152,12 @@ inline int check_filesize(LogContext *log, const char *fname, unsigned int maxsi
errno = 0;
if( (stat(fname, &info) < 0) ) {
- writelog(log, LOG_ERR, "Failed to check report file '%s': %s",
+ writelog(thrdata->dbc->log, LOG_ERR, "Failed to check report file '%s': %s",
fname, strerror(errno));
return -1;
}
- return (info.st_size <= maxsize);
+ return (info.st_size <= thrdata->max_report_size);
}
@@ -166,13 +165,8 @@ inline int check_filesize(LogContext *log, const char *fname, unsigned int maxsi
* The core parse function. Parses an XML file and stores it in the database according to
* the xmlparser.xsl template.
*
- * @param dbc Database connection
- * @param max_fsize Maximum "allowed" file size for reports to be parsed
- * @param xslt Pointer to a parsed XSLT Stylesheet (xmlparser.xsl)
- * @param mtx_sysreg Mutex locking to avoid simultaneous registration of systems, as they cannot
- * be in an SQL transaction (due to SHA1 sysid must be registered and visible ASAP)
- * @param destdir Destination directory for the report file, when moved from the queue.
- * @param job Pointer to a parseJob_t structure containing the job information
+ * @param thrdata Pointer to a threadData_t structure with database connection, log context, settings, etc
+ * @param job Pointer to a parseJob_t structure containing the job information
*
* @return Return values:
* @code
@@ -187,8 +181,7 @@ inline int check_filesize(LogContext *log, const char *fname, unsigned int maxsi
* STAT_REPMOVE : Failed to move the report file
* @endcode
*/
-inline int parse_report(dbconn *dbc, unsigned int max_fsize, xsltStylesheet *xslt,
- pthread_mutex_t *mtx_sysreg, const char *destdir, parseJob_t *job)
+inline int parse_report(threadData_t *thrdata, parseJob_t *job)
{
int syskey = -1, rterid = -1;
int rc = -1;
@@ -196,90 +189,92 @@ inline int parse_report(dbconn *dbc, unsigned int max_fsize, xsltStylesheet *xsl
char *destfname;
// Check file size - and reject too big files
- if( check_filesize(dbc->log, job->filename, max_fsize) == 0 ) {
- writelog(dbc->log, LOG_ERR, "Report file '%s' is too big, rejected", job->filename);
+ if( check_filesize(thrdata, job->filename) == 0 ) {
+ writelog(thrdata->dbc->log, LOG_ERR,
+ "Report file '%s' is too big, rejected", job->filename);
return STAT_FTOOBIG;
}
repxml = xmlParseFile(job->filename);
if( !repxml ) {
- writelog(dbc->log, LOG_ERR,
+ writelog(thrdata->dbc->log, LOG_ERR,
"Could not parse XML file: %s", job->filename);
return STAT_XMLFAIL;
}
- pthread_mutex_lock(mtx_sysreg);
- syskey = db_register_system(dbc, xslt, repxml);
+ pthread_mutex_lock(thrdata->mtx_sysreg);
+ syskey = db_register_system(thrdata->dbc, thrdata->xslt, repxml);
if( syskey < 0 ) {
- writelog(dbc->log, LOG_ERR,
+ writelog(thrdata->dbc->log, LOG_ERR,
"Failed to register system (XML file: %s)", job->filename);
rc = STAT_SYSREG;
goto exit;
}
- rterid = db_get_new_rterid(dbc);
+ rterid = db_get_new_rterid(thrdata->dbc);
if( rterid < 0 ) {
- writelog(dbc->log, LOG_ERR,
+ writelog(thrdata->dbc->log, LOG_ERR,
"Failed to register rteval run (XML file: %s)", job->filename);
rc = STAT_RTERIDREG;
goto exit;
}
- pthread_mutex_unlock(mtx_sysreg);
+ pthread_mutex_unlock(thrdata->mtx_sysreg);
- if( db_begin(dbc) < 1 ) {
+ if( db_begin(thrdata->dbc) < 1 ) {
rc = STAT_GENDB;
goto exit;
}
// Create a new filename of where to save the report
- destfname = get_destination_path(dbc->log, destdir, job, rterid);
+ destfname = get_destination_path(thrdata->dbc->log, thrdata->destdir, job, rterid);
if( !destfname ) {
- writelog(dbc->log, LOG_ERR,
+ writelog(thrdata->dbc->log, LOG_ERR,
"Failed to generate local report filename for (%i) %s",
job->submid, job->filename);
- db_rollback(dbc);
+ db_rollback(thrdata->dbc);
rc = STAT_UNKNFAIL;
goto exit;
}
- if( db_register_rtevalrun(dbc, xslt, repxml, job->submid, syskey, rterid, destfname) < 0 ) {
- writelog(dbc->log, LOG_ERR,
+ if( db_register_rtevalrun(thrdata->dbc, thrdata->xslt, repxml, job->submid,
+ syskey, rterid, destfname) < 0 ) {
+ writelog(thrdata->dbc->log, LOG_ERR,
"Failed to register rteval run (XML file: %s)",
job->filename);
- db_rollback(dbc);
+ db_rollback(thrdata->dbc);
rc = STAT_RTEVRUNS;
goto exit;
}
- if( db_register_cyclictest(dbc, xslt, repxml, rterid) != 1 ) {
- writelog(dbc->log, LOG_ERR,
+ if( db_register_cyclictest(thrdata->dbc, thrdata->xslt, repxml, rterid) != 1 ) {
+ writelog(thrdata->dbc->log, LOG_ERR,
"Failed to register cyclictest data (XML file: %s)",
job->filename);
- db_rollback(dbc);
+ db_rollback(thrdata->dbc);
rc = STAT_CYCLIC;
goto exit;
}
// When all database registrations are done, move the file to it's right place
- if( make_report_dir(dbc->log, destfname) < 1 ) { // Make sure report directory exists
- db_rollback(dbc);
+ if( make_report_dir(thrdata->dbc->log, destfname) < 1 ) { // Make sure report directory exists
+ db_rollback(thrdata->dbc);
rc = STAT_REPMOVE;
goto exit;
}
if( rename(job->filename, destfname) < 0 ) { // Move the file
- writelog(dbc->log, LOG_ERR,
+ writelog(thrdata->dbc->log, LOG_ERR,
"Failed to move report file from %s to %s (%s)",
job->filename, destfname, strerror(errno));
- db_rollback(dbc);
+ db_rollback(thrdata->dbc);
rc = STAT_REPMOVE;
goto exit;
}
free_nullsafe(destfname);
rc = STAT_SUCCESS;
- db_commit(dbc);
+ db_commit(thrdata->dbc);
exit:
xmlFreeDoc(repxml);
@@ -353,8 +348,7 @@ void *parsethread(void *thrargs) {
// Mark the job as "in progress", if successful update, continue parsing it
if( db_update_submissionqueue(args->dbc, jobinfo.submid, STAT_INPROG) ) {
- res = parse_report(args->dbc, args->max_report_size, args->xslt,
- args->mtx_sysreg, args->destdir, &jobinfo);
+ res = parse_report(args, &jobinfo);
// Set the status for the submission
db_update_submissionqueue(args->dbc, jobinfo.submid, res);
} else {