Skip to content

Commit 047da26

Browse files
committed
Restoring terminal settings after daemonizing.
1 parent 12024b9 commit 047da26

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

src/lib/arch/unix/ArchDaemonUnix.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "arch/unix/XArchUnix.h"
2222
#include "base/Log.h"
23+
#include "barrier/App.h"
2324

2425
#include <unistd.h>
2526
#include <sys/types.h>
@@ -86,6 +87,8 @@ ArchDaemonUnix::daemonize(const char* name, DaemonFunc func)
8687
break;
8788

8889
default:
90+
// first restore terminal settings
91+
App::instance().getEvents()->restoreTerminal();
8992
// parent exits
9093
exit(0);
9194
}

src/lib/base/EventQueue.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class EventQueue : public IEventQueue {
6363
virtual Event::Type getRegisteredType(const std::string& name) const;
6464
void* getSystemTarget();
6565
virtual void waitForReady() const;
66+
virtual void restoreTerminal() const { m_parentStream.restoreTerminal(); }
6667

6768
private:
6869
UInt32 saveEvent(const Event& event);

src/lib/base/IEventQueue.h

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ class IEventQueue : public IInterface {
184184
be added.
185185
*/
186186
virtual void waitForReady() const = 0;
187+
//! Restore the terminal settings
188+
/*!
189+
Called to restore the terminal settings after daemonizing.
190+
*/
191+
virtual void restoreTerminal() const = 0;
187192

188193
//@}
189194
//! @name accessors

src/lib/base/NonBlockingStream.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@ bool NonBlockingStream::try_read_char(char &ch) const
5757
return false;
5858
}
5959

60+
void NonBlockingStream::restoreTerminal() const
61+
{
62+
tcsetattr(_fd, TCSANOW, _p_ta_previous);
63+
fcntl(_fd, F_SETFL, _cntl_previous);
64+
}
65+
6066
#endif // !defined(_WIN32)

src/lib/base/NonBlockingStream.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class NonBlockingStream
3939
~NonBlockingStream();
4040

4141
bool try_read_char(char &ch) const;
42+
void restoreTerminal(void) const;
4243

4344
private:
4445
int _fd;

src/test/mock/barrier/MockEventQueue.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ class MockEventQueue : public IEventQueue
6464
MOCK_METHOD0(forClipboard, ClipboardEvents&());
6565
MOCK_METHOD0(forFile, FileEvents&());
6666
MOCK_CONST_METHOD0(waitForReady, void());
67+
MOCK_CONST_METHOD0(restoreTerminal, void());
6768
};

0 commit comments

Comments
 (0)