bug 102 patch

remotes/origin/master-1.0.x
Gurvinder Singh 16 years ago committed by Victor Julien
parent 4fd4c1331e
commit 4879045c6f

@ -116,6 +116,11 @@ int AlertUnifiedAlertWriteFileHeader(LogFileCtx *file_ctx) {
if (file_ctx->flags & LOGFILE_HEADER_WRITTEN)
return 0;
if (file_ctx->fp == NULL) {
SCLogError(SC_ERR_FOPEN, "file pointer is NULL");
return -1;
}
/** write the fileheader to the file so the reader can recognize it */
AlertUnifiedAlertFileHeader hdr;
hdr.magic = ALERTUNIFIEDALERT_ALERTMAGIC;
@ -383,7 +388,7 @@ int AlertUnifiedAlertOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
if (file_ctx->fp == NULL) {
SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename,
strerror(errno));
ret = -1;
return TM_ECODE_FAILED;
}
file_ctx->flags = 0;

@ -138,7 +138,8 @@ int AlertUnifiedLogWriteFileHeader(LogFileCtx *file_ctx) {
ret = fwrite(&hdr, sizeof(hdr), 1, file_ctx->fp);
if (ret != 1) {
printf("Error: fwrite failed: ret = %" PRId32 ", %s\n", ret, strerror(errno));
SCLogError(SC_ERR_FWRITE, "fwrite failed: ret = %" PRId32 ", %s", ret,
strerror(errno));
return -1;
}
@ -236,7 +237,7 @@ TmEcode AlertUnifiedLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
ret = fwrite(buf, buflen, 1, aun->file_ctx->fp);
if (ret != 1) {
printf("Error: fwrite failed: %s\n", strerror(errno));
SCLogError(SC_ERR_FWRITE, "fwrite failed: %s", strerror(errno));
aun->file_ctx->alerts += i;
SCMutexUnlock(&aun->file_ctx->fp_mutex);
return TM_ECODE_FAILED;
@ -262,13 +263,19 @@ TmEcode AlertUnifiedLogThreadInit(ThreadVars *t, void *initdata, void **data)
memset(aun, 0, sizeof(AlertUnifiedLogThread));
if (initdata == NULL) {
SCLogDebug("Error getting context for UnifiedLog. \"initdata\" argument NULL");
SCLogDebug("Error getting context for UnifiedLog. \"initdata\" argument NULL");
SCFree(aun);
return TM_ECODE_FAILED;
}
/** Use the Ouptut Context (file pointer and mutex) */
aun->file_ctx = ((OutputCtx *)initdata)->data;
if (aun->file_ctx->fp == NULL) {
SCLogError (SC_ERR_OPENING_FILE, "Target file has not been opened, check"
" the write permission");
return TM_ECODE_FAILED;
}
*data = (void *)aun;
return TM_ECODE_OK;
}
@ -307,7 +314,7 @@ OutputCtx *AlertUnifiedLogInitCtx(ConfNode *conf)
LogFileCtx* file_ctx=LogFileNewCtx();
if (file_ctx == NULL) {
printf("AlertUnifiedLogInitCtx: Couldn't create new file_ctx\n");
SCLogError(SC_ERR_MEM_ALLOC, "Couldn't create new file_ctx");
return NULL;
}
@ -403,7 +410,7 @@ int AlertUnifiedLogOpenFileCtx(LogFileCtx *file_ctx, const char *prefix)
if (file_ctx->fp == NULL) {
SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", filename,
strerror(errno));
ret = -1;
return TM_ECODE_FAILED;
}
/** Write Unified header */

@ -50,7 +50,7 @@ LogFileCtx *LogFileNewCtx()
if(lf_ctx == NULL)
{
printf("LogFileCtxNew: Couldn't SCMalloc \n");
SCLogError(SC_ERR_MEM_ALLOC, "Couldn't SCMalloc");
return NULL;
}
memset(lf_ctx, 0, sizeof(LogFileCtx));

@ -128,6 +128,8 @@ const char * SCErrorToString(SCError err)
CASE_CODE (SC_ERR_INVALID_YAML_CONF_ENTRY);
CASE_CODE (SC_ERR_TMQ_ALREADY_REGISTERED);
CASE_CODE (SC_ERR_CONFLICTING_RULE_KEYWORDS);
CASE_CODE (SC_ERR_INITIALIZATION);
CASE_CODE (SC_ERR_UNIFIED_LOG_FILE_HEADER);
default:
return "UNKNOWN_ERROR";
}

@ -145,6 +145,10 @@ typedef enum {
SC_ERR_INVALID_YAML_CONF_ENTRY,
SC_ERR_TMQ_ALREADY_REGISTERED,
SC_ERR_CONFLICTING_RULE_KEYWORDS,
SC_ERR_UNIFIED_LOG_FILE_HEADER, /**< Error to indicate the unified file
header writing function has been
failed */
} SCError;
const char *SCErrorToString(SCError);

Loading…
Cancel
Save