new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_dbd / dbd.c
old mode 100755 (executable)
new mode 100644 (file)
index dff139c..3cf3b7a
@@ -1,6 +1,3 @@
-/* @(#) $Id: ./src/os_dbd/dbd.c, 2011/09/08 dcid Exp $
- */
-
 /* Copyright (C) 2009 Trend Micro Inc.
  * All rights reserved.
  *
@@ -8,82 +5,60 @@
  * and/or modify it under the terms of the GNU General Public
  * License (version 2) as published by the FSF - Free Software
  * Foundation.
- *
- * License details at the LICENSE file included with OSSEC or
- * online at: http://www.ossec.net/en/licensing.html
  */
 
-
-#ifndef DBD
-   #define DBD
-#endif
-
-#ifndef ARGV0
-   #define ARGV0 "ossec-dbd"
-#endif
-
 #include "shared.h"
 #include "dbd.h"
 
+#ifndef ARGV0
+#define ARGV0 "ossec-dbd"
+#endif
 
 
-/* OS_DBD: Monitor the alerts and insert them into the database.
- * Only return in case of error.
+/* Monitor the alerts and insert them into the database
+ * Only returns in case of error
  */
 void OS_DBD(DBConfig *db_config)
 {
     time_t tm;
     struct tm *p;
-
     file_queue *fileq;
     alert_data *al_data;
 
-
-    /* Getting currently time before starting */
+    /* Get current time before starting */
     tm = time(NULL);
-    p = localtime(&tm);        
+    p = localtime(&tm);
 
-
-    /* Initating file queue - to read the alerts */
+    /* Initialize file queue to read the alerts */
     os_calloc(1, sizeof(file_queue), fileq);
     Init_FileQueue(fileq, p, 0);
 
-
-    /* Creating location hash */
+    /* Create location hash */
     db_config->location_hash = OSHash_Create();
-    if(!db_config->location_hash)
-    {
-        ErrorExit(MEM_ERROR, ARGV0);
+    if (!db_config->location_hash) {
+        ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));
     }
 
-
-    /* Getting maximum ID */
+    /* Get maximum ID */
     db_config->alert_id = OS_SelectMaxID(db_config);
     db_config->alert_id++;
 
-
-    /* Infinite loop reading the alerts and inserting them. */
-    while(1)
-    {
+    /* Infinite loop reading the alerts and inserting them */
+    while (1) {
         tm = time(NULL);
         p = localtime(&tm);
 
-
         /* Get message if available (timeout of 5 seconds) */
         al_data = Read_FileMon(fileq, p, 5);
-        if(!al_data)
-        {
+        if (!al_data) {
             continue;
         }
 
-
-        /* Inserting into the db */
+        /* Insert into the db */
         OS_Alert_InsertDB(al_data, db_config);
 
-
-        /* Clearing the memory */
+        /* Clear the memory */
         FreeAlertData(al_data);
     }
 }
 
-/* EOF */