diff --git a/src/lib/arch/unix/ArchDaemonUnix.cpp b/src/lib/arch/unix/ArchDaemonUnix.cpp index f1ac1d5421e..90f2fa1ff65 100644 --- a/src/lib/arch/unix/ArchDaemonUnix.cpp +++ b/src/lib/arch/unix/ArchDaemonUnix.cpp @@ -20,6 +20,7 @@ #include "arch/unix/XArchUnix.h" #include "base/Log.h" +#include "barrier/App.h" #include #include @@ -86,6 +87,8 @@ ArchDaemonUnix::daemonize(const char* name, DaemonFunc func) break; default: + // first restore terminal settings + App::instance().getEvents()->restoreTerminal(); // parent exits exit(0); } diff --git a/src/lib/base/EventQueue.h b/src/lib/base/EventQueue.h index 55b6fce0e7f..be2342d7289 100644 --- a/src/lib/base/EventQueue.h +++ b/src/lib/base/EventQueue.h @@ -63,6 +63,7 @@ class EventQueue : public IEventQueue { virtual Event::Type getRegisteredType(const std::string& name) const; void* getSystemTarget(); virtual void waitForReady() const; + virtual void restoreTerminal() const { m_parentStream.restoreTerminal(); } private: UInt32 saveEvent(const Event& event); diff --git a/src/lib/base/IEventQueue.h b/src/lib/base/IEventQueue.h index 833081cd91b..e0eb2d52f7c 100644 --- a/src/lib/base/IEventQueue.h +++ b/src/lib/base/IEventQueue.h @@ -184,6 +184,11 @@ class IEventQueue : public IInterface { be added. */ virtual void waitForReady() const = 0; + //! Restore the terminal settings + /*! + Called to restore the terminal settings after daemonizing. + */ + virtual void restoreTerminal() const = 0; //@} //! @name accessors diff --git a/src/lib/base/NonBlockingStream.cpp b/src/lib/base/NonBlockingStream.cpp index d44add15751..b16c0cb4559 100644 --- a/src/lib/base/NonBlockingStream.cpp +++ b/src/lib/base/NonBlockingStream.cpp @@ -57,4 +57,10 @@ bool NonBlockingStream::try_read_char(char &ch) const return false; } +void NonBlockingStream::restoreTerminal() const +{ + tcsetattr(_fd, TCSANOW, _p_ta_previous); + fcntl(_fd, F_SETFL, _cntl_previous); +} + #endif // !defined(_WIN32) diff --git a/src/lib/base/NonBlockingStream.h b/src/lib/base/NonBlockingStream.h index 4c27762af5b..bf830e53d82 100644 --- a/src/lib/base/NonBlockingStream.h +++ b/src/lib/base/NonBlockingStream.h @@ -39,6 +39,7 @@ class NonBlockingStream ~NonBlockingStream(); bool try_read_char(char &ch) const; + void restoreTerminal(void) const; private: int _fd; diff --git a/src/test/mock/barrier/MockEventQueue.h b/src/test/mock/barrier/MockEventQueue.h index 76175bbf397..99d2500923a 100644 --- a/src/test/mock/barrier/MockEventQueue.h +++ b/src/test/mock/barrier/MockEventQueue.h @@ -64,4 +64,5 @@ class MockEventQueue : public IEventQueue MOCK_METHOD0(forClipboard, ClipboardEvents&()); MOCK_METHOD0(forFile, FileEvents&()); MOCK_CONST_METHOD0(waitForReady, void()); + MOCK_CONST_METHOD0(restoreTerminal, void()); };