bind plugin: Fix building with --enable-standards.
[collectd.git] / src / oracle.c
index b008e5c..7a8ccc6 100644 (file)
@@ -295,7 +295,7 @@ static int o_config (oconfig_item_t *ci) /* {{{ */
     oconfig_item_t *child = ci->children + i;
     if (strcasecmp ("Query", child->key) == 0)
       udb_query_create (&queries, &queries_num, child,
-          /* callback = */ NULL);
+          /* callback = */ NULL, /* legacy mode = */ 0);
     else if (strcasecmp ("Database", child->key) == 0)
       o_config_add_database (child);
     else
@@ -497,7 +497,7 @@ static int o_read_database_query (o_database_t *db, /* {{{ */
   for (i = 0; i < column_num; i++) /* {{{ */
   {
     char *column_name;
-    size_t column_name_length;
+    ub4 column_name_length;
     OCIParam *oci_param;
 
     oci_param = NULL;
@@ -533,8 +533,8 @@ static int o_read_database_query (o_database_t *db, /* {{{ */
     column_names[i][column_name_length] = 0;
 
     DEBUG ("oracle plugin: o_read_database_query: column_names[%zu] = %s; "
-        "column_name_length = %zu;",
-        i, column_names[i], column_name_length);
+        "column_name_length = %"PRIu32";",
+        i, column_names[i], (uint32_t) column_name_length);
 
     status = OCIDefineByPos (oci_statement,
         &oci_defines[i], oci_error, (ub4) (i + 1),
@@ -598,6 +598,47 @@ static int o_read_database (o_database_t *db) /* {{{ */
   size_t i;
   int status;
 
+  if (db->oci_service_context != NULL)
+  {
+    OCIServer *server_handle;
+    ub4 connection_status;
+
+    server_handle = NULL;
+    status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX, 
+        (void *) &server_handle, /* size pointer = */ NULL,
+        OCI_ATTR_SERVER, oci_error);
+    if (status != OCI_SUCCESS)
+    {
+      o_report_error ("o_read_database", "OCIAttrGet", oci_error);
+      return (-1);
+    }
+
+    if (server_handle == NULL)
+    {
+      connection_status = OCI_SERVER_NOT_CONNECTED;
+    }
+    else /* if (server_handle != NULL) */
+    {
+      connection_status = 0;
+      status = OCIAttrGet ((void *) server_handle, OCI_HTYPE_SERVER,
+          (void *) &connection_status, /* size pointer = */ NULL,
+          OCI_ATTR_SERVER_STATUS, oci_error);
+      if (status != OCI_SUCCESS)
+      {
+        o_report_error ("o_read_database", "OCIAttrGet", oci_error);
+        return (-1);
+      }
+    }
+
+    if (connection_status != OCI_SERVER_NORMAL)
+    {
+      INFO ("oracle plugin: Connection to %s lost. Trying to reconnect.",
+          db->name);
+      OCIHandleFree (db->oci_service_context, OCI_HTYPE_SVCCTX);
+      db->oci_service_context = NULL;
+    }
+  } /* if (db->oci_service_context != NULL) */
+
   if (db->oci_service_context == NULL)
   {
     status = OCILogon (oci_env, oci_error,