From 9f3ce9a105ab5f8a397d305bc488d8825f1380bd Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 18 Jun 2012 23:36:18 +0200 Subject: [PATCH] Fix bat from eating all Dir connections -- fixes bug #1872 --- bacula/src/qt-console/bcomm/dircomm.cpp | 15 +++++---- bacula/src/qt-console/bcomm/dircomm.h | 1 + bacula/src/qt-console/console/console.cpp | 37 +++++++++++++++-------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/bacula/src/qt-console/bcomm/dircomm.cpp b/bacula/src/qt-console/bcomm/dircomm.cpp index a74f579dbc..94ddd6d105 100644 --- a/bacula/src/qt-console/bcomm/dircomm.cpp +++ b/bacula/src/qt-console/bcomm/dircomm.cpp @@ -51,6 +51,7 @@ DirComm::DirComm(Console *parent, int conn): m_notifier(NULL), m_api_set(false m_conn = conn; m_in_command = 0; m_in_select = false; + m_notify = false; } DirComm::~DirComm() @@ -65,6 +66,7 @@ void DirComm::terminate() m_notifier->setEnabled(false); delete m_notifier; m_notifier = NULL; + m_notify = false; } if (mainWin->m_connDebug) Pmsg2(000, "DirComm %i terminating connections %s\n", m_conn, m_console->m_dir->name()); @@ -211,6 +213,7 @@ bool DirComm::connect_dir() m_notifier = new QSocketNotifier(m_sock->m_fd, QSocketNotifier::Read, 0); QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(notify_read_dir(int))); m_notifier->setEnabled(true); + m_notify = true; write(".api 1"); m_api_set = true; @@ -454,6 +457,7 @@ int DirComm::read() m_notifier->setEnabled(false); delete m_notifier; m_notifier = NULL; + m_notify = false; } mainWin->set_status(_("Director disconnected.")); stat = BNET_HARDEOF; @@ -489,7 +493,7 @@ void DirComm::notify_read_dir(int /* fd */) * * When we are in a bat dialog, we want to control *all* output * from the Directory, so we set notify to off. - * m_console->notifiy(false); + * m_console->notify(false); */ bool DirComm::notify(bool enable) { @@ -498,10 +502,9 @@ bool DirComm::notify(bool enable) mainWin->m_notify = enable; if (m_notifier) { prev_enabled = m_notifier->isEnabled(); - if (prev_enabled != enable) { - m_notifier->setEnabled(enable); - } - if (mainWin->m_connDebug) Pmsg3(000, "conn=%i notify=%d prev=%d\n", m_conn, enable, prev_enabled); + m_notifier->setEnabled(enable); + m_notify = enable; + if (mainWin->m_connDebug) Pmsg3(000, "conn=%i set_notify=%d prev=%d\n", m_conn, enable, prev_enabled); } else if (mainWin->m_connDebug) { Pmsg2(000, "m_notifier does not exist: %i %s\n", m_conn, m_console->m_dir->name()); } @@ -510,7 +513,7 @@ bool DirComm::notify(bool enable) bool DirComm::is_notify_enabled() const { - return mainWin->m_notify; + return m_notify; } /* diff --git a/bacula/src/qt-console/bcomm/dircomm.h b/bacula/src/qt-console/bcomm/dircomm.h index 31a5c82fd7..b0989140f0 100644 --- a/bacula/src/qt-console/bcomm/dircomm.h +++ b/bacula/src/qt-console/bcomm/dircomm.h @@ -79,6 +79,7 @@ private: bool m_at_prompt; bool m_at_main_prompt; bool m_sent_blank; + bool m_notify; int m_in_command; QSocketNotifier *m_notifier; bool m_api_set; diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index d980fcf6ec..65656a88ec 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -159,6 +159,7 @@ void Console::populateLists(bool /*forcenew*/) } } populateLists(conn); + notify(conn, true); } void Console::populateLists(int conn) @@ -237,13 +238,15 @@ bool Console::dir_cmd(int conn, const char *cmd, QStringList &results) mainWin->waitEnter(); DirComm *dircomm = m_dircommHash.value(conn); int stat; - bool prev_notify = mainWin->m_notify; + bool prev_notify = is_notify_enabled(conn); if (mainWin->m_connDebug) { QString dbgmsg = QString("dir_cmd conn %1 %2 %3\n").arg(conn).arg(m_dir->name()).arg(cmd); Pmsg1(000, "%s", dbgmsg.toUtf8().data()); } - notify(conn, false); + if (prev_notify) { + notify(conn, false); + } dircomm->write(cmd); while ((stat = dircomm->read()) > 0 && dircomm->is_in_command()) { if (mainWin->m_displayAll) display_text(dircomm->msg()); @@ -294,7 +297,7 @@ bool Console::sql_cmd(int &conn, const char *query, QStringList &results, bool d DirComm *dircomm = m_dircommHash.value(conn); int stat; POOL_MEM cmd(PM_MESSAGE); - bool prev_notify = mainWin->m_notify; + bool prev_notify = is_notify_enabled(conn); if (!is_connectedGui()) { return false; @@ -332,6 +335,9 @@ bool Console::sql_cmd(int &conn, const char *query, QStringList &results, bool d } discardToPrompt(conn); mainWin->waitExit(); + if (donotify && prev_notify) { + dircomm->notify(true); + } return !mainWin->isClosing(); /* return false if closing */ } @@ -393,12 +399,13 @@ void Console::write_dir(int conn, const char *msg, bool dowait) bool Console::get_job_defaults(struct job_defaults &job_defs) { int conn; + getDirComm(conn); return get_job_defaults(conn, job_defs, true); } bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs) { - return get_job_defaults(conn, job_defs, false); + return get_job_defaults(conn, job_defs, true); } /* @@ -410,14 +417,14 @@ bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs, bool do QString scmd; int stat; char *def; - bool prev_notify = mainWin->m_notify; + bool prev_notify = is_notify_enabled(conn); bool rtn = false; + DirComm *dircomm = m_dircommHash.value(conn); if (donotify) { - conn = notifyOff(); + dircomm->notify(false); } beginNewCommand(conn); - DirComm *dircomm = m_dircommHash.value(conn); bool prevWaitState = mainWin->getWaitState(); if (!prevWaitState) mainWin->waitEnter(); @@ -714,14 +721,22 @@ int Console::notifyOff() bool Console::notify(int conn, bool enable) { DirComm *dircomm = m_dircommHash.value(conn); - return dircomm->notify(enable); + if (dircomm) { + return dircomm->notify(enable); + } else { + return false; + } } /* knowing a connection, return notify state */ bool Console::is_notify_enabled(int conn) const { DirComm *dircomm = m_dircommHash.value(conn); - return dircomm->is_notify_enabled(); + if (dircomm) { + return dircomm->is_notify_enabled(); + } else { + return false; + } } void Console::setDirectorTreeItem(QTreeWidgetItem *item) @@ -871,7 +886,6 @@ bool Console::getDirComm(int &conn) */ bool Console::findDirComm(int &conn) { - int i = 1; QHash::const_iterator iter = m_dircommHash.constBegin(); while (iter != m_dircommHash.constEnd()) { DirComm *dircomm = iter.value(); @@ -881,8 +895,7 @@ bool Console::findDirComm(int &conn) } if (mainWin->m_connDebug) { Pmsg4(000, "currentDirComm=%d at_prompt=%d at_main=%d && notify=%d\n", - i, dircomm->m_at_prompt, dircomm->m_at_main_prompt, dircomm->is_notify_enabled()); - i++; + dircomm->m_conn, dircomm->m_at_prompt, dircomm->m_at_main_prompt, dircomm->is_notify_enabled()); } ++iter; } -- 2.39.5