From 95ebe009a3c22037a5ff01444ca2dd661356306a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 4 Nov 2009 17:16:55 +0100 Subject: [PATCH] More db + sd error handling cleanup --- bacula/src/cats/dbi.c | 7 +++---- bacula/src/cats/postgresql.c | 7 +++---- bacula/src/cats/sql.c | 15 +++++++-------- bacula/src/cats/sql_create.c | 9 ++++++--- bacula/src/stored/dircmd.c | 5 +++-- bacula/src/stored/fd_cmds.c | 6 ++++-- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index 7cbfc1868f..7a039ba255 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -278,10 +278,9 @@ db_open_database(JCR *jcr, B_DB *mdb) } if ( dbstat != 0 ) { - Mmsg3(&mdb->errmsg, _("Unable to connect to DBI interface.\n" - "Type=%s Database=%s User=%s\n" - "It is probably not running or your password is incorrect.\n"), - mdb->db_driver, mdb->db_name, mdb->db_user); + Mmsg3(&mdb->errmsg, _("Unable to connect to DBI interface. Type=%s Database=%s User=%s\n" + "Possible causes: SQL server not running; password incorrect; max_connections exceeded.\n"), + mdb->db_driver, mdb->db_name, mdb->db_user); V(mutex); return 0; } diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 969232734b..08f5846f95 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -228,10 +228,9 @@ db_open_database(JCR *jcr, B_DB *mdb) mdb->db_password==NULL?"(NULL)":mdb->db_password); if (PQstatus(mdb->db) != CONNECTION_OK) { - Mmsg2(&mdb->errmsg, _("Unable to connect to PostgreSQL server.\n" - "Database=%s User=%s\n" - "It is probably not running or your password is incorrect.\n"), - mdb->db_name, mdb->db_user); + Mmsg2(&mdb->errmsg, _("Unable to connect to PostgreSQL server. Database=%s User=%s\n" + "Possible causes: SQL server not running; password incorrect; max_connections exceeded.\n"), + mdb->db_name, mdb->db_user); V(mutex); return 0; } diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 5872fa3087..72ab05b512 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -740,10 +740,10 @@ vertical_list: */ bool db_open_batch_connexion(JCR *jcr, B_DB *mdb) { - int multi_db=false; - #ifdef HAVE_BATCH_FILE_INSERT - multi_db=true; /* we force a new connexion only if batch insert is enabled */ + const int multi_db = true; /* we force a new connection only if batch insert is enabled */ +#else + const int multi_db = false; #endif if (!jcr->db_batch) { @@ -756,16 +756,15 @@ bool db_open_batch_connexion(JCR *jcr, B_DB *mdb) mdb->db_socket, multi_db /* multi_db = true when using batch mode */); if (!jcr->db_batch) { - Jmsg0(jcr, M_FATAL, 0, "Could not init batch connexion"); + Mmsg0(&mdb->errmsg, _("Could not init database batch connection")); + Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } if (!db_open_database(jcr, jcr->db_batch)) { - POOLMEM *errmsg = get_pool_memory(PM_MESSAGE); - Mmsg2(&errmsg, _("Could not open database \"%s\": ERR=%s\n"), + Mmsg2(&mdb->errmsg, _("Could not open database \"%s\": ERR=%s\n"), jcr->db_batch->db_name, db_strerror(jcr->db_batch)); - Jmsg1(jcr, M_FATAL, 0, "%s", errmsg); - free_pool_memory(errmsg); + Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count, diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index c51261a0ac..7dc11fb462 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -909,6 +909,10 @@ bool db_write_batch_file_records(JCR *jcr) * is a single FileName record and a single Path record, no matter * how many times it occurs. This is this subroutine, we separate * the file and the path and fill temporary tables with this three records. + * + * Note: all routines that call this expect to be able to call + * db_strerror(mdb) to get the error message, so the error message + * MUST be edited into mdb->errmsg before returning an error status. */ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) { @@ -917,14 +921,13 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) /* Open the dedicated connexion */ if (!jcr->batch_started) { - if (!db_open_batch_connexion(jcr, mdb)) { - return false; + return false; /* error already printed */ } if (!sql_batch_start(jcr, jcr->db_batch)) { Mmsg1(&mdb->errmsg, "Can't start batch mode: ERR=%s", db_strerror(jcr->db_batch)); - Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg); + Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } jcr->batch_started = true; diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index c658f5d36d..8ce44e5beb 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -119,7 +119,7 @@ static struct s_cmds cmds[] = { {"status", status_cmd, 1}, {".status", qstatus_cmd, 1}, {"unmount", unmount_cmd, 0}, - {"action_on_purge", action_on_purge_cmd, 0}, + {"action_on_purge", action_on_purge_cmd, 0}, {"use storage=", use_cmd, 0}, {"run", run_cmd, 0}, // {"query", query_cmd, 0}, @@ -327,7 +327,8 @@ static bool cancel_cmd(JCR *cjcr) Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId); pthread_cond_broadcast(&wait_device_release); } - Jmsg(jcr, M_INFO, 0, _("Job %s marked to be canceled.\n"), jcr->Job); + Jmsg(jcr, M_INFO, 0, _("JobId=%d Job=\"%s\" marked to be canceled.\n"), + (int)jcr->JobId, jcr->Job); dir->fsend(_("3000 Job %s marked to be canceled.\n"), jcr->Job); free_jcr(jcr); } diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index f096e5f4a8..992d705e4d 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -176,8 +176,10 @@ void do_fd_commands(JCR *jcr) } } if (!found) { /* command not found */ - Jmsg1(jcr, M_FATAL, 0, _("FD command not found: %s\n"), fd->msg); - Dmsg1(110, "msg); + if (!job_canceled(jcr)) { + Jmsg1(jcr, M_FATAL, 0, _("FD command not found: %s\n"), fd->msg); + Dmsg1(110, "msg); + } fd->fsend(ferrmsg); break; } -- 2.39.5