[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ulogd
Subject:    [ulogd] [PATCH] MYSQL plugin socket option
From:       Emrys Ingersoll <eingerso () eecs ! berkeley ! edu>
Date:       2005-04-18 18:20:47
Message-ID: 20050418182047.GF20207 () eecs ! berkeley ! edu
[Download RAW message or body]

Here's a patch to enable the use of sockets with the MYSQL plugin
for ulogd.

I've created it to use -p0, I didn't know if there was any standard in
place for ulogd patches, would you prefer -p1?

Signed-off-by: Emrys Ingersoll <eingerso@eecs.berkeley.edu>

--- mysql/ulogd_MYSQL.c.orig	2005-03-09 14:19:06.835434000 -0800
+++ mysql/ulogd_MYSQL.c	2005-04-18 10:53:44.388560000 -0700
@@ -31,6 +31,10 @@
  *
  * 09 Feb 2005, Sven Schuster <schuster.sven@gmx.de>:
  * 	Added the "port" parameter to specify ports different from 3306
+ *
+ * 18 Apr 2005, Emrys Ingersoll <eingerso@eecs.berkeley.edu>:
+ * 	Added the "socket" parameter to allow non-tcp connections to
+ * 	a mysql server running on the local machine
  */
 
 #include <stdlib.h>
@@ -106,6 +110,18 @@ static config_entry_t port_ce = {
 	.next = &table_ce,
 	.key = "port",
 	.type = CONFIG_TYPE_INT,
+	.options = CONFIG_OPT_NONE,
+	.hit = 0,
+	.u.value = 3306
+};
+
+static config_entry_t socket_ce = {
+	.next = &port_ce,
+	.key = "socket",
+	.type = CONFIG_TYPE_STRING,
+	.options = CONFIG_OPT_NONE,
+	.hit = 0,
+	.u.string = "/tmp/mysql.sock"
 };
 
 /* our main output function, called by ulogd */
@@ -328,14 +344,14 @@ static int mysql_get_columns(const char 
 }
 
 /* make connection and select database */
-static int mysql_open_db(char *server, int port, char *user, char *pass, 
-			 char *db)
+static int mysql_open_db(char *server, char *user, char *pass, 
+			 char *db, int port, char *sock) 
 {
 	dbh = mysql_init(NULL);
 	if (!dbh)
 		return 1;
 
-	if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0))
+	if (!mysql_real_connect(dbh, server, user, pass, db, port, sock, 0))
 		return 1;
 
 	return 0;
@@ -344,10 +360,12 @@ static int mysql_open_db(char *server, i
 static int _mysql_init(void)
 {
 	/* have the opts parsed */
-	config_parse_file("MYSQL", &port_ce);
+	config_parse_file("MYSQL", &socket_ce);
+
+	if (mysql_open_db(host_ce.u.string, user_ce.u.string,
+			  pass_ce.u.string, db_ce.u.string,
+			  port_ce.u.value, socket_ce.u.string)) {
 
-	if (mysql_open_db(host_ce.u.string, port_ce.u.value, user_ce.u.string, 
-			   pass_ce.u.string, db_ce.u.string)) {
 		ulogd_log(ULOGD_ERROR, "can't establish database connection\n");
 		return -1;
 	}

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic