From: Kern Sibbald Date: Sat, 6 Feb 2010 16:11:12 +0000 (+0100) Subject: Fix bug #1481 -- bat consumes all console file descriptors X-Git-Tag: Release-7.0.0~2273 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fdbb09dc32dc86f41e5caa46994eac05a19081ad;p=bacula%2Fbacula Fix bug #1481 -- bat consumes all console file descriptors --- diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 8c383c8cb0..16e17b0124 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -96,8 +96,9 @@ void Console::stopTimer() void Console::poll_messages() { int conn; - if (!availableDirComm(conn)) + if (!availableDirComm(conn)) { return; + } DirComm *dircomm = m_dircommHash.value(conn); if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus() && !mainWin->getWaitState()){ @@ -251,16 +252,18 @@ bool Console::sql_cmd(int &conn, QString &query, QStringList &results) bool Console::sql_cmd(QString &query, QStringList &results) { int conn; - if (!availableDirComm(conn)) + if (!availableDirComm(conn)) { return false; + } return sql_cmd(conn, query.toUtf8().data(), results, true); } bool Console::sql_cmd(const char *query, QStringList &results) { int conn; - if (!availableDirComm(conn)) + if (!availableDirComm(conn)) { return false; + } return sql_cmd(conn, query, results, true); } @@ -318,16 +321,18 @@ 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 (availableDirComm(conn)) { write_dir(conn, msg); + } return conn; } int Console::write_dir(const char *msg, bool dowait) { int conn; - if (availableDirComm(conn)) + if (availableDirComm(conn)) { write_dir(conn, msg, dowait); + } return conn; } @@ -669,8 +674,9 @@ QString Console::returnFromPrompt(int conn) int Console::notifyOff() { int conn = 0; - if (availableDirComm(conn)) + if (availableDirComm(conn)) { notify(conn, false); + } return conn; } @@ -814,19 +820,10 @@ bool Console::is_connected(int conn) */ bool Console::availableDirComm(int &conn) { - QHash::const_iterator iter = m_dircommHash.constBegin(); - while (iter != m_dircommHash.constEnd()) { - DirComm *dircomm = iter.value(); - if (dircomm->m_at_prompt && dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) { - conn = dircomm->m_conn; - return true; - } - ++iter; - } - if (newDirComm(conn)) + if (currentDirComm(conn)) { return true; - else - return false; + } + return newDirComm(conn); } @@ -835,13 +832,19 @@ bool Console::availableDirComm(int &conn) */ bool Console::currentDirComm(int &conn) { + int i = 1; QHash::const_iterator iter = m_dircommHash.constBegin(); while (iter != m_dircommHash.constEnd()) { DirComm *dircomm = iter.value(); - if (dircomm->m_at_prompt && !dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) { + if (dircomm->m_at_prompt && dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) { conn = dircomm->m_conn; return true; } + 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++; + } ++iter; } return false; @@ -852,18 +855,26 @@ bool Console::currentDirComm(int &conn) */ bool Console::newDirComm(int &conn) { - m_dircommCounter += 1; - conn = m_dircommCounter; - if (mainWin->m_connDebug) - Pmsg2(000, "DirComm %i About to Create and Connect %s\n", m_dircommCounter, m_dir->name()); + m_dircommCounter++; + if (mainWin->m_connDebug) { + Pmsg2(000, "newDirComm=%i to: %s\n", m_dircommCounter, m_dir->name()); + } DirComm *dircomm = new DirComm(this, m_dircommCounter); m_dircommHash.insert(m_dircommCounter, dircomm); bool success = dircomm->connect_dir(); if (mainWin->m_connDebug) { - if (success) - Pmsg2(000, "DirComm %i Connected %s\n", conn, m_dir->name()); - else - Pmsg2(000, "DirComm %i NOT Connected %s\n", conn, m_dir->name()); + if (success) { + Pmsg2(000, "newDirComm=%i Connected %s\n", m_dircommCounter, m_dir->name()); + } else { + Emsg2(M_ERROR, 0, "DirComm=%i. Unable to connect to %s\n", + m_dircommCounter, m_dir->name()); + } + } + if (!success) { + m_dircommHash.remove(m_dircommCounter); + delete dircomm; + m_dircommCounter--; } + conn = m_dircommCounter; return success; }