aboutsummaryrefslogtreecommitdiff
path: root/modules/mysql/mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mysql/mysql.c')
-rw-r--r--modules/mysql/mysql.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/modules/mysql/mysql.c b/modules/mysql/mysql.c
index 3d24542..315dd8b 100644
--- a/modules/mysql/mysql.c
+++ b/modules/mysql/mysql.c
@@ -31,9 +31,8 @@
#include <smap/stream.h>
#include <smap/wordsplit.h>
-#define MDB_INIT 0x01
-#define MDB_OPEN 0x02
-#define MDB_DEFDB 0x04
+#define MDB_OPEN 0x01
+#define MDB_DEFDB 0x02
struct mod_mysql_db {
int flags;
@@ -90,12 +89,6 @@ opendb(struct mod_mysql_db *db)
return 0;
}
- if (!(db->flags & MDB_INIT)) {
- smap_error("%s: module settings do not include opendb flag",
- db->name);
- return 1;
- }
-
if (!mysql_init(&db->mysql)) {
smap_error("%s: not enough memory", db->name);
return 1;
@@ -156,15 +149,27 @@ freedb(struct mod_mysql_db *db)
}
static int
+dbdeclared(struct mod_mysql_db *db)
+{
+ return db->config_file ||
+ db->config_group ||
+ db->ssl_ca ||
+ db->host ||
+ db->user ||
+ db->password ||
+ db->database ||
+ db->port ||
+ db->socket;
+}
+
+
+static int
mod_init(int argc, char **argv)
{
int rc;
- int opendb = 0;
dbgid = smap_debug_alloc("mysql");
struct smap_option init_option[] = {
- { SMAP_OPTSTR(open), smap_opt_bool,
- &opendb },
{ SMAP_OPTSTR(config-file), smap_opt_string,
&def_db.config_file },
{ SMAP_OPTSTR(config-group), smap_opt_string,
@@ -197,8 +202,7 @@ mod_init(int argc, char **argv)
rc = smap_parseopt(init_option, argc, argv, 0, NULL);
if (rc)
return rc;
- if (opendb)
- def_db.flags = MDB_INIT;
+ def_db.flags = 0;
return 0;
}
@@ -262,7 +266,7 @@ mod_init_db(const char *dbid, int argc, char **argv)
return NULL;
}
- db->flags = MDB_INIT | flags;
+ db->flags = flags;
db->name = dbid;
db->config_file = config_file;
db->config_group = config_group;
@@ -278,6 +282,9 @@ mod_init_db(const char *dbid, int argc, char **argv)
db->negative_reply = negative_reply;
db->onerror_reply = onerror_reply;
+ if (!dbdeclared(db))
+ db->flags |= MDB_DEFDB;
+
return (smap_database_t) db;
}

Return to:

Send suggestions and report system problems to the System administrator.