Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring terminal settings after daemonizing. #1055

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
};