Skip to content

Commit

Permalink
Allow stopping (via kill -STOP) and "fg" to resume session
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Nov 4, 2012
1 parent 07b2942 commit 28ed30c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/frontend/stmclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@

#include "networktransport.cc"

void STMClient::resume( void )
{
/* Restore termios state */
if ( tcsetattr( STDIN_FILENO, TCSANOW, &raw_termios ) < 0 ) {
perror( "tcsetattr" );
exit( 1 );
}

/* Put terminal in application-cursor-key mode */
swrite( STDOUT_FILENO, Terminal::Emulator::open().c_str() );

/* Flag that outer terminal state is unknown */
repaint_requested = true;
}

void STMClient::init( void )
{
if ( !is_utf8_locale() ) {
Expand Down Expand Up @@ -146,7 +161,6 @@ void STMClient::main_init( void )
sel.add_signal( SIGINT );
sel.add_signal( SIGHUP );
sel.add_signal( SIGPIPE );
sel.add_signal( SIGTSTP );
sel.add_signal( SIGCONT );

/* get initial window size */
Expand Down Expand Up @@ -376,12 +390,14 @@ void STMClient::main( void )
if ( !process_resize() ) { return; }
}

if ( sel.signal( SIGCONT ) ) {
resume();
}

if ( sel.signal( SIGTERM )
|| sel.signal( SIGINT )
|| sel.signal( SIGHUP )
|| sel.signal( SIGPIPE )
|| sel.signal( SIGTSTP )
|| sel.signal( SIGCONT ) ) {
|| sel.signal( SIGPIPE ) ) {
/* shutdown signal */
if ( !network->has_remote_addr() ) {
break;
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/stmclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class STMClient {
return network && ( network->get_remote_state_num() == 0 );
}

void resume( void ); /* restore state after SIGCONT */

public:
STMClient( const char *s_ip, int s_port, const char *s_key, const char *predict_mode )
: ip( s_ip ), port( s_port ), key( s_key ),
Expand Down

0 comments on commit 28ed30c

Please sign in to comment.