Skip to content

Commit

Permalink
catalog: Fix argument mixup.
Browse files Browse the repository at this point in the history
Seems the last fix to the catalog functions was not fully right as we
didn't fix all functions to have the same argument order which leads to
the wrong value being passed on to some functions. This patch fixes that
as from now on need_private is the last argument for each function and
from now on the number of default arguments for db_init_database() is
just like the pooling functions only the need_private flag. We thank
Coverity for finding this nasty bug.
  • Loading branch information
Marco van Wieringen committed May 20, 2016
1 parent bcdd2b1 commit f0da0e8
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/cats/bdb_dbi.h
Expand Up @@ -44,9 +44,9 @@ class B_DB_DBI: public B_DB_PRIV {
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal);
bool exit_on_fatal,
bool need_private);
~B_DB_DBI();

/* low level operations */
Expand Down
4 changes: 2 additions & 2 deletions src/cats/bdb_ingres.h
Expand Up @@ -40,9 +40,9 @@ class B_DB_INGRES: public B_DB_PRIV {
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal);
bool exit_on_fatal,
bool need_private);
~B_DB_INGRES();

/* low level operations */
Expand Down
4 changes: 2 additions & 2 deletions src/cats/bdb_mysql.h
Expand Up @@ -45,9 +45,9 @@ class B_DB_MYSQL: public B_DB_PRIV {
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal);
bool exit_on_fatal,
bool need_private);
~B_DB_MYSQL();

/* low level operations */
Expand Down
4 changes: 2 additions & 2 deletions src/cats/bdb_postgresql.h
Expand Up @@ -38,9 +38,9 @@ class B_DB_POSTGRESQL: public B_DB_PRIV {
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal);
bool exit_on_fatal,
bool need_private);
~B_DB_POSTGRESQL();

/* low level operations */
Expand Down
4 changes: 2 additions & 2 deletions src/cats/bdb_sqlite.h
Expand Up @@ -40,9 +40,9 @@ class B_DB_SQLITE: public B_DB_PRIV {
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal);
bool exit_on_fatal,
bool need_private);
~B_DB_SQLITE();

/* Used internaly by sqlite.c to access fields in db_sql_query() */
Expand Down
16 changes: 8 additions & 8 deletions src/cats/cats_backends.c
Expand Up @@ -90,9 +90,9 @@ B_DB *db_init_database(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
struct stat st;
char *backend_dir;
Expand Down Expand Up @@ -144,9 +144,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
}
}
}
Expand Down Expand Up @@ -245,9 +245,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
} else {
Jmsg(jcr, M_ABORT, 0, _("Unable to load any shared library for libbareoscats-%s%s\n"),
backend_interface_mapping->interface_name, DYN_LIB_EXTENSION);
Expand Down Expand Up @@ -291,9 +291,9 @@ B_DB *db_init_database(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
Jmsg(jcr, M_FATAL, 0, _("Please replace this dummy libbareoscats library with a proper one.\n"));
Dmsg0(0, _("Please replace this dummy libbareoscats library with a proper one.\n"));
Expand Down
4 changes: 2 additions & 2 deletions src/cats/cats_backends.h
Expand Up @@ -39,9 +39,9 @@ typedef B_DB *(*t_backend_instantiate)(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal);
bool exit_on_fatal,
bool need_private);

typedef void (*t_flush_backend)(void);
}
Expand Down
11 changes: 6 additions & 5 deletions src/cats/dbi.c
Expand Up @@ -1465,9 +1465,9 @@ extern "C" B_DB CATS_IMP_EXP *backend_instantiate(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#else
B_DB *db_init_database(JCR *jcr,
const char *db_driver,
Expand All @@ -1481,7 +1481,8 @@ B_DB *db_init_database(JCR *jcr,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#endif
{
B_DB_DBI *mdb = NULL;
Expand Down Expand Up @@ -1528,9 +1529,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal));
exit_on_fatal,
need_private));

bail_out:
V(mutex);
Expand Down
16 changes: 8 additions & 8 deletions src/cats/ingres.c
Expand Up @@ -140,9 +140,9 @@ B_DB_INGRES::B_DB_INGRES(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
B_DB_INGRES *mdb;
int next_session_id = 0;
Expand Down Expand Up @@ -1014,9 +1014,9 @@ extern "C" B_DB CATS_IMP_EXP *backend_instantiate(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#else
B_DB *db_init_database(JCR *jcr,
const char *db_driver,
Expand All @@ -1028,9 +1028,9 @@ B_DB *db_init_database(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#endif
{
B_DB_INGRES *mdb = NULL;
Expand Down Expand Up @@ -1070,9 +1070,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal));
exit_on_fatal,
need_private));

bail_out:
V(mutex);
Expand Down
16 changes: 8 additions & 8 deletions src/cats/mysql.c
Expand Up @@ -64,9 +64,9 @@ B_DB_MYSQL::B_DB_MYSQL(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
/*
* Initialize the parent class members.
Expand Down Expand Up @@ -805,9 +805,9 @@ extern "C" B_DB CATS_IMP_EXP *backend_instantiate(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#else
B_DB *db_init_database(JCR *jcr,
const char *db_driver,
Expand All @@ -819,9 +819,9 @@ B_DB *db_init_database(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#endif
{
B_DB_MYSQL *mdb = NULL;
Expand Down Expand Up @@ -859,9 +859,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal));
exit_on_fatal,
need_private));

bail_out:
V(mutex);
Expand Down
16 changes: 8 additions & 8 deletions src/cats/postgresql.c
Expand Up @@ -65,9 +65,9 @@ B_DB_POSTGRESQL::B_DB_POSTGRESQL(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
/*
* Initialize the parent class members.
Expand Down Expand Up @@ -1183,9 +1183,9 @@ extern "C" B_DB CATS_IMP_EXP *backend_instantiate(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#else
B_DB *db_init_database(JCR *jcr,
const char *db_driver,
Expand All @@ -1197,9 +1197,9 @@ B_DB *db_init_database(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#endif
{
B_DB_POSTGRESQL *mdb = NULL;
Expand Down Expand Up @@ -1237,9 +1237,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal));
exit_on_fatal,
need_private));

bail_out:
V(mutex);
Expand Down
10 changes: 5 additions & 5 deletions src/cats/sql_glue.h
Expand Up @@ -34,11 +34,11 @@ B_DB *db_init_database(JCR *jcr,
const char *db_address,
int db_port,
const char *db_socket,
bool mult_db_connections = false,
bool disable_batch_insert = false,
bool is_private = false,
bool try_reconnect = false,
bool exit_on_fatal = false);
bool mult_db_connections,
bool disable_batch_insert,
bool try_reconnect,
bool exit_on_fatal,
bool need_private = false);

/*
* Glue functions from sql_glue.c
Expand Down
16 changes: 8 additions & 8 deletions src/cats/sqlite.c
Expand Up @@ -71,9 +71,9 @@ B_DB_SQLITE::B_DB_SQLITE(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
/*
* Initialize the parent class members.
Expand Down Expand Up @@ -667,9 +667,9 @@ extern "C" B_DB CATS_IMP_EXP *backend_instantiate(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#else
B_DB *db_init_database(JCR *jcr,
const char *db_driver,
Expand All @@ -681,9 +681,9 @@ B_DB *db_init_database(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
#endif
{
B_DB *mdb = NULL;
Expand Down Expand Up @@ -717,9 +717,9 @@ B_DB *db_init_database(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal));
exit_on_fatal,
need_private));

bail_out:
V(mutex);
Expand Down
6 changes: 5 additions & 1 deletion src/dird/dbcheck.c
Expand Up @@ -314,7 +314,11 @@ int main (int argc, char *argv[])
password,
dbhost,
dbport,
NULL);
NULL,
false,
false,
false,
false);
if (!db_open_database(NULL, db)) {
Emsg1(M_FATAL, 0, "%s", db_strerror(db));
return 1;
Expand Down
14 changes: 13 additions & 1 deletion src/stored/bscan.c
Expand Up @@ -326,7 +326,19 @@ int main (int argc, char *argv[])
db_set_backend_dirs(backend_directories);
#endif

if ((db = db_init_database(NULL, db_driver, db_name, db_user, db_password, db_host, db_port, NULL)) == NULL) {
db = db_init_database(NULL,
db_driver,
db_name,
db_user,
db_password,
db_host,
db_port,
NULL,
false,
false,
false,
false);
if (db == NULL) {
Emsg0(M_ERROR_TERM, 0, _("Could not init Bareos database\n"));
}
if (!db_open_database(NULL, db)) {
Expand Down

0 comments on commit f0da0e8

Please sign in to comment.