/* Forward referenced subroutines */
void terminate_dird(int sig);
static bool check_resources();
-static void dir_sql_query(JCR *jcr, const char *cmd);
static void cleanup_old_files();
/* Exported subroutines */
#define CONFIG_FILE "bacula-dir.conf" /* default configuration file */
+/*
+ * This allows the message handler to operate on the database
+ * by using a pointer to this function. The pointer is
+ * needed because the other daemons do not have access
+ * to the database. If the pointer is
+ * not defined (other daemons), then writing the database
+ * is disabled.
+ */
+static bool dir_sql_query(JCR *jcr, const char *cmd)
+{
+ if (!jcr || !jcr->db || !jcr->db->is_connected()) {
+ return false;
+ }
+
+ return db_sql_query(jcr->db, cmd);
+}
+
+static bool dir_sql_escape(JCR *jcr, B_DB *mdb, char *snew, char *old, int len)
+{
+ if (!jcr || !jcr->db || !jcr->db->is_connected()) {
+ return false;
+ }
+
+ db_escape_string(jcr, mdb, snew, old, len);
+ return true;
+}
static void usage()
{
/* Plug database interface for library routines */
p_sql_query = (sql_query_func)dir_sql_query;
- p_sql_escape = (sql_escape_func)db_escape_string;
+ p_sql_escape = (sql_escape_func)dir_sql_escape;
FDConnectTimeout = (int)director->FDConnectTimeout;
SDConnectTimeout = (int)director->SDConnectTimeout;
return 0;
}
-/*
- * This allows the message handler to operate on the database
- * by using a pointer to this function. The pointer is
- * needed because the other daemons do not have access
- * to the database. If the pointer is
- * not defined (other daemons), then writing the database
- * is disabled.
- */
-static void dir_sql_query(JCR *jcr, const char *cmd)
-{
- if (!jcr || !jcr->db) {
- return;
- }
- db_sql_query(jcr->db, cmd, NULL, NULL);
-}
-
/* Cleanup and then exit */
void terminate_dird(int sig)
{
switch (d->dest_code) {
case MD_CATALOG:
char ed1[50];
- if (!jcr || !jcr->db || !jcr->db->is_connected()) {
+ if (!jcr || !jcr->db) {
break;
}
if (p_sql_query && p_sql_escape) {
int len = strlen(msg) + 1;
esc_msg = check_pool_memory_size(esc_msg, len * 2 + 1);
- p_sql_escape(jcr, jcr->db, esc_msg, msg, len);
-
- bstrutime(dt, sizeof(dt), mtime);
- Mmsg(cmd, "INSERT INTO Log (JobId, Time, LogText) VALUES (%s,'%s','%s')",
- edit_int64(jcr->JobId, ed1), dt, esc_msg);
- p_sql_query(jcr, cmd);
+ if (p_sql_escape(jcr, jcr->db, esc_msg, msg, len)) {
+ bstrutime(dt, sizeof(dt), mtime);
+ Mmsg(cmd, "INSERT INTO Log (JobId, Time, LogText) VALUES (%s,'%s','%s')",
+ edit_int64(jcr->JobId, ed1), dt, esc_msg);
+ if (!p_sql_query(jcr, cmd)) {
+ delivery_error(_("Msg delivery error: Unable to store data in database.\n"));
+ }
+ } else {
+ delivery_error(_("Msg delivery error: Unable to store data in database.\n"));
+ }
free_pool_memory(cmd);
free_pool_memory(esc_msg);
const char *get_basename(const char *pathname);
class B_DB;
-typedef void (*sql_query_func)(JCR *jcr, const char *cmd);
-typedef void (*sql_escape_func)(JCR *jcr, B_DB* db, char *snew, char *old, int len);
+typedef bool (*sql_query_func)(JCR *jcr, const char *cmd);
+typedef bool (*sql_escape_func)(JCR *jcr, B_DB *db, char *snew, char *old, int len);
extern DLL_IMP_EXP sql_query_func p_sql_query;
extern DLL_IMP_EXP sql_escape_func p_sql_escape;