aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ex-meta1.texi10
-rw-r--r--modules/mysql/mysql.c37
-rw-r--r--modules/postgres/postgres.c32
3 files changed, 32 insertions, 47 deletions
diff --git a/doc/ex-meta1.texi b/doc/ex-meta1.texi
index d74b49c..a62b4be 100644
--- a/doc/ex-meta1.texi
+++ b/doc/ex-meta1.texi
@@ -18,9 +18,8 @@ initialization in @file{smapd.conf} looks like:
@example
-module mysql mysql open config-group=smap
+module mysql mysql config-group=smap
@end example
-The @samp{open} parameter instructs the module to open the requested
-databases. The @samp{config-group} parameter refers to a group
-name in the default @file{/etc/my.cnf} file that contains information
-about the @acronym{MySQL} database and credentials for accessing it.
+The @samp{config-group} parameter refers to a group name in the
+default @file{/etc/my.cnf} file that contains information about the
+@acronym{MySQL} database and credentials for accessing it.
The following is a sample snippet from @file{/etc/my.cnf}:
@@ -63,3 +62,2 @@ The smap database is defined as follows:
database userdb mysql \
- defaultdb
query="SELECT user FROM userdb WHERE user='$key'"
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
@@ -33,5 +33,4 @@
-#define MDB_INIT 0x01
-#define MDB_OPEN 0x02
-#define MDB_DEFDB 0x04
+#define MDB_OPEN 0x01
+#define MDB_DEFDB 0x02
@@ -92,8 +91,2 @@ opendb(struct mod_mysql_db *db)
- if (!(db->flags & MDB_INIT)) {
- smap_error("%s: module settings do not include opendb flag",
- db->name);
- return 1;
- }
-
if (!mysql_init(&db->mysql)) {
@@ -158,2 +151,17 @@ 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)
@@ -161,3 +169,2 @@ mod_init(int argc, char **argv)
int rc;
- int opendb = 0;
@@ -165,4 +172,2 @@ mod_init(int argc, char **argv)
struct smap_option init_option[] = {
- { SMAP_OPTSTR(open), smap_opt_bool,
- &opendb },
{ SMAP_OPTSTR(config-file), smap_opt_string,
@@ -199,4 +204,3 @@ mod_init(int argc, char **argv)
return rc;
- if (opendb)
- def_db.flags = MDB_INIT;
+ def_db.flags = 0;
return 0;
@@ -264,3 +268,3 @@ mod_init_db(const char *dbid, int argc, char **argv)
- db->flags = MDB_INIT | flags;
+ db->flags = flags;
db->name = dbid;
@@ -280,2 +284,5 @@ mod_init_db(const char *dbid, int argc, char **argv)
+ if (!dbdeclared(db))
+ db->flags |= MDB_DEFDB;
+
return (smap_database_t) db;
diff --git a/modules/postgres/postgres.c b/modules/postgres/postgres.c
index 3e696ca..1218564 100644
--- a/modules/postgres/postgres.c
+++ b/modules/postgres/postgres.c
@@ -34,5 +34,4 @@
-#define MDB_INIT 0x01
-#define MDB_OPEN 0x02
-#define MDB_DEFDB 0x04
+#define MDB_OPEN 0x01
+#define MDB_DEFDB 0x02
@@ -85,8 +84,2 @@ opendb(struct modpg_db *db)
- if (!(db->flags & MDB_INIT)) {
- smap_error("%s: module settings do not include opendb flag",
- db->name);
- return 1;
- }
-
db->pgconn = PQconnectdb(db->conninfo);
@@ -204,3 +197,2 @@ modpg_init(int argc, char **argv)
int rc;
- int opendb = 0;
@@ -208,4 +200,2 @@ modpg_init(int argc, char **argv)
struct smap_option init_option[] = {
- { SMAP_OPTSTR(open), smap_opt_bool,
- &opendb },
{ SMAP_OPTSTR(query), smap_opt_string,
@@ -229,9 +219,3 @@ modpg_init(int argc, char **argv)
}
- }
- if (opendb) {
- if (!def_db.conninfo) {
- smap_error("no connection info given");
- return 1;
- }
- def_db.flags = MDB_INIT;
+ def_db.flags = 0;
def_db.name = "postgres";
@@ -253,4 +237,2 @@ modpg_init_db(const char *dbid, int argc, char **argv)
struct smap_option init_option[] = {
- { SMAP_OPTSTR(defaultdb), smap_opt_bitmask,
- &flags, { MDB_DEFDB } },
{ SMAP_OPTSTR(query), smap_opt_string,
@@ -281,8 +263,6 @@ modpg_init_db(const char *dbid, int argc, char **argv)
}
- } else if (!(flags & MDB_DEFDB)) {
- smap_error("%s: no connection info given", dbid);
- return NULL;
- }
+ } else
+ flags |= MDB_DEFDB;
- db->flags = MDB_INIT | flags;
+ db->flags = flags;
db->name = dbid;

Return to:

Send suggestions and report system problems to the System administrator.