From: Kern Sibbald Date: Mon, 8 Feb 2010 16:42:05 +0000 (+0100) Subject: Fix bat bug that consumes connections + add braces on ifs + rename subroutines X-Git-Tag: Release-5.2.1~1796 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3301239c4d5f3e6b871d6f90d3d9dbcdebcb44b8;p=bacula%2Fbacula Fix bat bug that consumes connections + add braces on ifs + rename subroutines --- diff --git a/bacula/src/qt-console/bcomm/dircomm.cpp b/bacula/src/qt-console/bcomm/dircomm.cpp index 52ca833c6b..2f49c0c557 100644 --- a/bacula/src/qt-console/bcomm/dircomm.cpp +++ b/bacula/src/qt-console/bcomm/dircomm.cpp @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2009 Free Software Foundation Europe e.V. + Copyright (C) 2007-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -26,9 +26,7 @@ Switzerland, email:ftf@fsfeurope.org. */ /* - * Version $Id$ - * - * Console Class + * DirComm, Director communications,class * * Kern Sibbald, January MMVII * @@ -90,11 +88,15 @@ bool DirComm::connect_dir() mainWin->set_status( tr("Already connected.")); m_console->display_textf(_("Already connected\"%s\".\n"), m_console->m_dir->name()); - if (mainWin->m_connDebug) + if (mainWin->m_connDebug) { Pmsg2(000, "DirComm %i BAILING already connected %s\n", m_conn, m_console->m_dir->name()); + } goto bail_out; } + if (mainWin->m_connDebug) { + Pmsg2(000, "DirComm %i connecting %s\n", m_conn, m_console->m_dir->name()); + } memset(jcr, 0, sizeof(JCR)); mainWin->set_statusf(_("Connecting to Director %s:%d"), m_console->m_dir->address, m_console->m_dir->DIRport); @@ -213,13 +215,15 @@ bool DirComm::connect_dir() mainWin->set_status(_("Connected")); - if (mainWin->m_connDebug) + if (mainWin->m_connDebug) { Pmsg2(000, "Returning TRUE from DirComm->connect_dir : %i %s\n", m_conn, m_console->m_dir->name()); + } return true; bail_out: - if (mainWin->m_connDebug) + if (mainWin->m_connDebug) { Pmsg2(000, "Returning FALSE from DirComm->connect_dir : %i %s\n", m_conn, m_console->m_dir->name()); + } delete jcr; return false; } @@ -363,7 +367,6 @@ int DirComm::read() } continue; case BNET_START_SELECT: - notify(false); if (mainWin->m_commDebug) Pmsg1(000, "conn %i START SELECT\n", m_conn); m_in_select = true; new selectDialog(m_console, m_conn); @@ -458,10 +461,7 @@ bool DirComm::notify(bool enable) prev_enabled = m_notifier->isEnabled(); m_notifier->setEnabled(enable); if (mainWin->m_connDebug) { - if (prev_enabled && !enable) - Pmsg2(000, "m_notifier Disabling notifier: %i %s\n", m_conn, m_console->m_dir->name()); - else if (!prev_enabled && enable) - Pmsg2(000, "m_notifier Enabling notifier: %i %s\n", m_conn, m_console->m_dir->name()); + Pmsg3(000, "conn=%i 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()); diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 16e17b0124..e75910b083 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -96,11 +96,16 @@ void Console::stopTimer() void Console::poll_messages() { int conn; - if (!availableDirComm(conn)) { - return; + + /* + * Note if we call getDirComm here, we continuously consume + * file descriptors. + */ + if (!findDirComm(conn)) { /* find a free DirComm */ + return; /* try later */ } - DirComm *dircomm = m_dircommHash.value(conn); + DirComm *dircomm = m_dircommHash.value(conn); if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus() && !mainWin->getWaitState()){ messagesPending(true); dircomm->write(".messages"); @@ -125,8 +130,9 @@ void Console::connect_dir() m_textEdit = textEdit; /* our console screen */ if (dircomm->connect_dir()) { - if (mainWin->m_connDebug) + if (mainWin->m_connDebug) { Pmsg1(000, "DirComm 0 Seems to have Connected %s\n", m_dir->name()); + } beginNewCommand(0); } mainWin->set_status(_("Connected")); @@ -141,9 +147,14 @@ void Console::connect_dir() void Console::populateLists(bool /*forcenew*/) { int conn; - if (!availableDirComm(conn) && !newDirComm(conn)) { - Emsg1(M_ABORT, 0, "Failed to connect to %s for populateLists.\n", m_dir->name()); - return; + if (!getDirComm(conn)) { + if (mainWin->m_connDebug) { + Pmsg0(000, "call newDirComm\n"); + } + if (!newDirComm(conn)) { + Emsg1(M_ABORT, 0, "Failed to connect to %s for populateLists.\n", m_dir->name()); + return; + } } populateLists(conn); } @@ -204,7 +215,7 @@ bool Console::dir_cmd(QString &cmd, QStringList &results) bool Console::dir_cmd(const char *cmd, QStringList &results) { int conn; - if (availableDirComm(conn)) { + if (getDirComm(conn)) { dir_cmd(conn, cmd, results); return true; } else { @@ -252,7 +263,7 @@ bool Console::sql_cmd(int &conn, QString &query, QStringList &results) bool Console::sql_cmd(QString &query, QStringList &results) { int conn; - if (!availableDirComm(conn)) { + if (!getDirComm(conn)) { return false; } return sql_cmd(conn, query.toUtf8().data(), results, true); @@ -261,7 +272,7 @@ bool Console::sql_cmd(QString &query, QStringList &results) bool Console::sql_cmd(const char *query, QStringList &results) { int conn; - if (!availableDirComm(conn)) { + if (!getDirComm(conn)) { return false; } return sql_cmd(conn, query, results, true); @@ -321,7 +332,7 @@ bool Console::sql_cmd(int &conn, const char *query, QStringList &results, bool d int Console::write_dir(const char *msg) { int conn; - if (availableDirComm(conn)) { + if (getDirComm(conn)) { write_dir(conn, msg); } return conn; @@ -330,7 +341,7 @@ int Console::write_dir(const char *msg) int Console::write_dir(const char *msg, bool dowait) { int conn; - if (availableDirComm(conn)) { + if (getDirComm(conn)) { write_dir(conn, msg, dowait); } return conn; @@ -639,7 +650,9 @@ void Console::discardToPrompt(int conn) } } } - if (mainWin->m_commDebug) Pmsg2(000, "endDiscardToPrompt=%d %s\n", stat, m_dir->name()); + if (mainWin->m_commDebug) { + Pmsg2(000, "endDiscardToPrompt conn=%i %s\n", conn, m_dir->name()); + } } QString Console::returnFromPrompt(int conn) @@ -670,11 +683,11 @@ QString Console::returnFromPrompt(int conn) * m_console->notifiy(false); */ -/* dual purpose function to turn notify off and return an available connection */ +/* dual purpose function to turn notify off and return a connection */ int Console::notifyOff() { int conn = 0; - if (availableDirComm(conn)) { + if (getDirComm(conn)) { notify(conn, false); } return conn; @@ -816,21 +829,32 @@ bool Console::is_connected(int conn) } /* - * Need an available connection. Check existing connections or create one + * Need a connection. Check existing connections or create one */ -bool Console::availableDirComm(int &conn) +bool Console::getDirComm(int &conn) { - if (currentDirComm(conn)) { + if (findDirComm(conn)) { return true; } + if (mainWin->m_connDebug) { + Pmsg0(000, "call newDirComm\n"); + } return newDirComm(conn); } /* - * Need current connection. + * Try to find a free (unused but established) connection + * KES: Note, I think there is a problem here because for + * some reason, the notifier is often turned off on file + * descriptors that seem to me to be available. That means + * that we do not use a free descriptor and thus we will create + * a new connection that is maybe not necessary. Someone needs + * to look into whether or not notify() is correctly turned on + * when we are back at the command prompt and idle. + * */ -bool Console::currentDirComm(int &conn) +bool Console::findDirComm(int &conn) { int i = 1; QHash::const_iterator iter = m_dircommHash.constBegin(); diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 3d4676b1db..7835818483 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -80,8 +80,8 @@ public: int notifyOff(); // enables/disables socket notification - returns the previous state bool notify(int conn, bool enable); // enables/disables socket notification - returns the previous state bool is_notify_enabled(int conn) const; - bool availableDirComm(int &conn); - bool currentDirComm(int &conn); + bool getDirComm(int &conn); + bool findDirComm(int &conn); void displayToPrompt(int conn); QString returnFromPrompt(int conn); diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 61ce6b44db..e72cd7562a 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -599,7 +599,7 @@ void MainWin::input_line() QString cmdStr = lineEdit->text(); /* Get the text */ lineEdit->clear(); /* clear the lineEdit box */ if (m_currentConsole->is_connected()) { - if (m_currentConsole->currentDirComm(conn)) { + if (m_currentConsole->findDirComm(conn)) { m_currentConsole->consoleCommand(cmdStr, conn); } else { /* Use consoleCommand to allow typing anything */ diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index 4932189814..de0f2d3926 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -272,7 +272,7 @@ void Pages::consoleCommand(QString &command, bool setCurrent) { int conn; bool donotify = false; - if (m_console->availableDirComm(conn)) { + if (m_console->getDirComm(conn)) { if (m_console->is_notify_enabled(conn)) { donotify = true; m_console->notify(conn, false); diff --git a/bacula/src/qt-console/select/select.cpp b/bacula/src/qt-console/select/select.cpp index 35fe1fe660..c1c9c561ac 100644 --- a/bacula/src/qt-console/select/select.cpp +++ b/bacula/src/qt-console/select/select.cpp @@ -49,6 +49,7 @@ selectDialog::selectDialog(Console *console, int conn) int row = 0; m_console = console; + m_console->notify(m_conn, false); setupUi(this); connect(listBox, SIGNAL(currentRowChanged(int)), this, SLOT(index_change(int))); setAttribute(Qt::WA_DeleteOnClose);