Restoring terminal settings after daemonizing.

Signed-off-by: Dom Rodriguez <shymega@shymega.org.uk>
This commit is contained in:
Martin Furter 2021-02-05 18:16:22 +05:30 committed by Dom Rodriguez
parent 4ed0141389
commit 020ae96bf3
No known key found for this signature in database
GPG Key ID: 72DCF1231E54BD43
6 changed files with 17 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include "arch/unix/XArchUnix.h" #include "arch/unix/XArchUnix.h"
#include "base/Log.h" #include "base/Log.h"
#include "barrier/App.h"
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
@ -86,6 +87,8 @@ ArchDaemonUnix::daemonize(const char* name, DaemonFunc func)
break; break;
default: default:
// first restore terminal settings
App::instance().getEvents()->restoreTerminal();
// parent exits // parent exits
exit(0); exit(0);
} }

View File

@ -63,6 +63,7 @@ public:
virtual Event::Type getRegisteredType(const std::string& name) const; virtual Event::Type getRegisteredType(const std::string& name) const;
void* getSystemTarget(); void* getSystemTarget();
virtual void waitForReady() const; virtual void waitForReady() const;
virtual void restoreTerminal() const { m_parentStream.restoreTerminal(); }
private: private:
UInt32 saveEvent(const Event& event); UInt32 saveEvent(const Event& event);

View File

@ -184,6 +184,11 @@ public:
be added. be added.
*/ */
virtual void waitForReady() const = 0; virtual void waitForReady() const = 0;
//! Restore the terminal settings
/*!
Called to restore the terminal settings after daemonizing.
*/
virtual void restoreTerminal() const = 0;
//@} //@}
//! @name accessors //! @name accessors

View File

@ -57,4 +57,10 @@ bool NonBlockingStream::try_read_char(char &ch) const
return false; return false;
} }
void NonBlockingStream::restoreTerminal() const
{
tcsetattr(_fd, TCSANOW, _p_ta_previous);
fcntl(_fd, F_SETFL, _cntl_previous);
}
#endif // !defined(_WIN32) #endif // !defined(_WIN32)

View File

@ -39,6 +39,7 @@ public:
~NonBlockingStream(); ~NonBlockingStream();
bool try_read_char(char &ch) const; bool try_read_char(char &ch) const;
void restoreTerminal(void) const;
private: private:
int _fd; int _fd;

View File

@ -64,4 +64,5 @@ public:
MOCK_METHOD0(forClipboard, ClipboardEvents&()); MOCK_METHOD0(forClipboard, ClipboardEvents&());
MOCK_METHOD0(forFile, FileEvents&()); MOCK_METHOD0(forFile, FileEvents&());
MOCK_CONST_METHOD0(waitForReady, void()); MOCK_CONST_METHOD0(waitForReady, void());
MOCK_CONST_METHOD0(restoreTerminal, void());
}; };