Skip to content

Commit

Permalink
Restoring terminal settings after daemonizing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Furter committed Feb 5, 2021
1 parent 12024b9 commit 047da26
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/arch/unix/ArchDaemonUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "arch/unix/XArchUnix.h"
#include "base/Log.h"
#include "barrier/App.h"

#include <unistd.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/base/EventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/base/IEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/lib/base/NonBlockingStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/lib/base/NonBlockingStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class NonBlockingStream
~NonBlockingStream();

bool try_read_char(char &ch) const;
void restoreTerminal(void) const;

private:
int _fd;
Expand Down
1 change: 1 addition & 0 deletions src/test/mock/barrier/MockEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};

0 comments on commit 047da26

Please sign in to comment.