Skip to content

Commit

Permalink
Prevent tunneling setup errors from causing terminal issues after exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Gauci committed Sep 1, 2017
1 parent 70c81fb commit 1a25db7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/UnixSocketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ void UnixSocketHandler::createServerSockets(int port) {
cerr << "Error binding " << p->ai_family << "/" << p->ai_socktype << "/"
<< p->ai_protocol << ": " << errno << " " << strerror(errno)
<< flush;
exit(1);
stringstream oss;
oss << "Error binding port " << port
<< ": " << errno << " " << strerror(errno);
string s = oss.str();
throw std::runtime_error(s.c_str());
// close(sockfd);
// continue;
}
Expand Down
44 changes: 25 additions & 19 deletions terminal/TerminalClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ int main(int argc, char** argv) {
globalClient = createClient();
shared_ptr<UnixSocketHandler> socketHandler =
static_pointer_cast<UnixSocketHandler>(globalClient->getSocketHandler());
winsize win;
ioctl(1, TIOCGWINSZ, &win);

termios terminal_local;
tcgetattr(0, &terminal_local);
memcpy(&terminal_backup, &terminal_local, sizeof(struct termios));
cfmakeraw(&terminal_local);
tcsetattr(0, TCSANOW, &terminal_local);

// Whether the TE should keep running.
bool run = true;
Expand All @@ -168,20 +160,34 @@ int main(int argc, char** argv) {
}

PortForwardClientRouter portForwardRouter;
if (FLAGS_portforward.length()) {
auto j = split(FLAGS_portforward, ',');
for (auto& pair : j) {
vector<string> sourceDestination = split(pair, ':');
// TODO: Handle bad input
int sourcePort = stoi(sourceDestination[0]);
int destinationPort = stoi(sourceDestination[1]);

portForwardRouter.addListener(
shared_ptr<PortForwardClientListener>(new PortForwardClientListener(
socketHandler, sourcePort, destinationPort)));
try {
if (FLAGS_portforward.length()) {
auto j = split(FLAGS_portforward, ',');
for (auto& pair : j) {
vector<string> sourceDestination = split(pair, ':');
// TODO: Handle bad input
int sourcePort = stoi(sourceDestination[0]);
int destinationPort = stoi(sourceDestination[1]);

portForwardRouter.addListener(
shared_ptr<PortForwardClientListener>(new PortForwardClientListener(
socketHandler, sourcePort, destinationPort)));
}
}
} catch (const std::runtime_error& ex) {
cout << "Error establishing port forward: " << ex.what() << endl;
exit(1);
}

winsize win;
ioctl(1, TIOCGWINSZ, &win);

termios terminal_local;
tcgetattr(0, &terminal_local);
memcpy(&terminal_backup, &terminal_local, sizeof(struct termios));
cfmakeraw(&terminal_local);
tcsetattr(0, TCSANOW, &terminal_local);

while (run && !globalClient->isShuttingDown()) {
// Data structures needed for select() and
// non-blocking I/O.
Expand Down

0 comments on commit 1a25db7

Please sign in to comment.