diff --git a/src/mysql.c b/src/mysql.c
index 444acaa26aef33ed1d858e78564f52adec599f05..57ad23978de761297e235d3d87c28824a16b5b13 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
#include "plugin.h"
#include "configfile.h"
-#ifdef HAVE_MYSQL_MYSQL_H
+#ifdef HAVE_MYSQL_H
+#include <mysql.h>
+#elif defined(HAVE_MYSQL_MYSQL_H)
#include <mysql/mysql.h>
#endif
"User",
"Password",
"Database",
+ "Port",
+ "Socket",
NULL
};
-static int config_keys_num = 4;
+static int config_keys_num = 6;
static char *host = "localhost";
static char *user;
static char *pass;
static char *db = NULL;
+static char *socket = NULL;
+static int port = 0;
static MYSQL *getconnection (void)
{
return (NULL);
}
- if (mysql_real_connect (con, host, user, pass, db, 0, NULL, 0) == NULL)
+ if (mysql_real_connect (con, host, user, pass, db, port, socket, 0) == NULL)
{
ERROR ("mysql_real_connect failed: %s", mysql_error (con));
state = 0;
return ((pass = strdup (value)) == NULL ? 1 : 0);
else if (strcasecmp (key, "database") == 0)
return ((db = strdup (value)) == NULL ? 1 : 0);
+ else if (strcasecmp (key, "socket") == 0)
+ return ((socket = strdup (value)) == NULL ? 1 : 0);
+ else if (strcasecmp (key, "port") == 0)
+ {
+ char *endptr = NULL;
+ int temp;
+
+ errno = 0;
+ temp = strtol (value, &endptr, 0);
+ if ((errno != 0) || (value == endptr))
+ {
+ ERROR ("mysql plugin: Invalid \"Port\" argument: %s",
+ value);
+ port = 0;
+ return (1);
+ }
+ else if ((temp < 0) || (temp >= 65535))
+ {
+ ERROR ("mysql plugin: Port number out of range: %i",
+ temp);
+ port = 0;
+ return (1);
+ }
+
+ port = temp;
+ return (0);
+ }
else
return (-1);
-}
+} /* int config */
static void counter_submit (const char *type, const char *type_instance,
counter_t value)
vl.values = values;
vl.values_len = 1;
vl.time = time (NULL);
- strcpy (vl.host, hostname_g);
- strcpy (vl.plugin, "mysql");
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
sstrncpy (vl.type, type, sizeof (vl.type));
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
vl.values = values;
vl.values_len = 5;
vl.time = time (NULL);
- strcpy (vl.host, hostname_g);
- strcpy (vl.plugin, "mysql");
- strcpy (vl.type, "mysql_qcache");
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+ sstrncpy (vl.type, "mysql_qcache", sizeof (vl.type));
plugin_dispatch_values (&vl);
} /* void qcache_submit */
vl.values = values;
vl.values_len = 4;
vl.time = time (NULL);
- strcpy (vl.host, hostname_g);
- strcpy (vl.plugin, "mysql");
- strcpy (vl.type, "mysql_threads");
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+ sstrncpy (vl.type, "mysql_threads", sizeof (vl.type));
plugin_dispatch_values (&vl);
} /* void threads_submit */
vl.values = values;
vl.values_len = 2;
vl.time = time (NULL);
- strcpy (vl.host, hostname_g);
- strcpy (vl.plugin, "mysql");
- strcpy (vl.type, "mysql_octets");
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+ sstrncpy (vl.type, "mysql_octets", sizeof (vl.type));
plugin_dispatch_values (&vl);
} /* void traffic_submit */