-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,692 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Mac", | ||
"includePath": [ | ||
"${workspaceFolder}", | ||
"${workspaceFolder}/build", | ||
"${workspaceFolder}/src", | ||
"${workspaceFolder}/terminal", | ||
"${workspaceFolder}/htm", | ||
"/Library/Developer/CommandLineTools/usr/include/c++/v1", | ||
"/usr/local/include", | ||
"/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include", | ||
"/Library/Developer/CommandLineTools/usr/include", | ||
"/usr/include" | ||
], | ||
"defines": [], | ||
"intelliSenseMode": "clang-x64", | ||
"browse": { | ||
"path": [ | ||
"${workspaceFolder}", | ||
"/Library/Developer/CommandLineTools/usr/include/c++/v1", | ||
"/usr/local/include", | ||
"/Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include", | ||
"/Library/Developer/CommandLineTools/usr/include", | ||
"/usr/include" | ||
], | ||
"limitSymbolsToIncludedHeaders": true, | ||
"databaseFilename": "" | ||
}, | ||
"macFrameworkPath": [ | ||
"/System/Library/Frameworks", | ||
"/Library/Frameworks" | ||
], | ||
"compilerPath": "/usr/bin/clang", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17" | ||
}, | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"/usr/include", | ||
"/usr/local/include", | ||
"${workspaceFolder}", | ||
"${workspaceFolder}/build", | ||
"${workspaceFolder}/src", | ||
"${workspaceFolder}/terminal", | ||
"${workspaceFolder}/htm" | ||
], | ||
"defines": [], | ||
"intelliSenseMode": "clang-x64", | ||
"browse": { | ||
"path": [ | ||
"/usr/include", | ||
"/usr/local/include", | ||
"${workspaceFolder}" | ||
], | ||
"limitSymbolsToIncludedHeaders": true, | ||
"databaseFilename": "" | ||
} | ||
}, | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", | ||
"${workspaceFolder}", | ||
"${workspaceFolder}/build", | ||
"${workspaceFolder}/src", | ||
"${workspaceFolder}/terminal", | ||
"${workspaceFolder}/htm" | ||
], | ||
"defines": [ | ||
"_DEBUG", | ||
"UNICODE", | ||
"_UNICODE" | ||
], | ||
"intelliSenseMode": "msvc-x64", | ||
"browse": { | ||
"path": [ | ||
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", | ||
"${workspaceFolder}" | ||
], | ||
"limitSymbolsToIncludedHeaders": true, | ||
"databaseFilename": "" | ||
} | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"files.associations": { | ||
"sstream": "cpp", | ||
"strstream": "cpp", | ||
"fstream": "cpp", | ||
"locale": "cpp", | ||
"*.ipp": "cpp", | ||
"__locale": "cpp", | ||
"__string": "cpp", | ||
"string": "cpp", | ||
"string_view": "cpp", | ||
"*.tcc": "cpp", | ||
"__bit_reference": "cpp", | ||
"algorithm": "cpp", | ||
"bitset": "cpp", | ||
"chrono": "cpp", | ||
"hash_map": "cpp", | ||
"hash_set": "cpp", | ||
"map": "cpp", | ||
"set": "cpp", | ||
"unordered_map": "cpp", | ||
"unordered_set": "cpp", | ||
"stdexcept": "cpp", | ||
"memory": "cpp", | ||
"utility": "cpp", | ||
"__hash_table": "cpp", | ||
"__split_buffer": "cpp", | ||
"__tree": "cpp", | ||
"array": "cpp", | ||
"deque": "cpp", | ||
"forward_list": "cpp", | ||
"initializer_list": "cpp", | ||
"iterator": "cpp", | ||
"list": "cpp", | ||
"valarray": "cpp", | ||
"vector": "cpp", | ||
"slist": "cpp", | ||
"iosfwd": "cpp", | ||
"__config": "cpp", | ||
"__nullptr": "cpp", | ||
"cstddef": "cpp", | ||
"exception": "cpp", | ||
"new": "cpp", | ||
"type_traits": "cpp", | ||
"typeinfo": "cpp", | ||
"cctype": "cpp", | ||
"cstdlib": "cpp", | ||
"random": "cpp" | ||
}, | ||
"C_Cpp.clang_format_style": "Google" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "HtmClient.hpp" | ||
|
||
#include "HTM.pb.h" | ||
|
||
#include "HtmServer.hpp" | ||
#include "IpcPairClient.hpp" | ||
#include "LogHandler.hpp" | ||
#include "MultiplexerState.hpp" | ||
#include "RawSocketUtils.hpp" | ||
|
||
namespace et { | ||
HtmClient::HtmClient() : IpcPairClient(HtmServer::getPipeName()) {} | ||
|
||
void HtmClient::run() { | ||
const int BUF_SIZE = 1024; | ||
char buf[BUF_SIZE]; | ||
while (true) { | ||
// Data structures needed for select() and | ||
// non-blocking I/O. | ||
fd_set rfd; | ||
timeval tv; | ||
|
||
FD_ZERO(&rfd); | ||
FD_SET(endpointFd, &rfd); | ||
FD_SET(STDIN_FILENO, &rfd); | ||
tv.tv_sec = 0; | ||
tv.tv_usec = 10000; | ||
select(max(STDIN_FILENO, endpointFd) + 1, &rfd, NULL, NULL, &tv); | ||
|
||
if (FD_ISSET(STDIN_FILENO, &rfd)) { | ||
VLOG(1) << "READING FROM STDIN"; | ||
int rc = ::read(STDIN_FILENO, buf, BUF_SIZE); | ||
if (rc < 0) { | ||
throw std::runtime_error("Cannot read from raw socket"); | ||
} | ||
if (rc == 0) { | ||
throw std::runtime_error("stdin has closed abruptly."); | ||
} | ||
RawSocketUtils::writeAll(endpointFd, buf, rc); | ||
} | ||
|
||
if (FD_ISSET(endpointFd, &rfd)) { | ||
VLOG(1) << "READING FROM ENDPOINT"; | ||
int rc = ::read(endpointFd, buf, BUF_SIZE); | ||
if (rc < 0) { | ||
throw std::runtime_error("Cannot read from raw socket"); | ||
} | ||
if (rc == 0) { | ||
throw std::runtime_error("htmd has closed abruptly."); | ||
} | ||
RawSocketUtils::writeAll(STDOUT_FILENO, buf, rc); | ||
} | ||
} | ||
} | ||
} // namespace et |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef __HTM_CLIENT_H__ | ||
#define __HTM_CLIENT_H__ | ||
|
||
#include "Headers.hpp" | ||
|
||
#include "IpcPairClient.hpp" | ||
|
||
namespace et { | ||
class HtmClient : public IpcPairClient { | ||
public: | ||
HtmClient(); | ||
void run(); | ||
}; | ||
} // namespace et | ||
|
||
#endif // __HTM_CLIENT_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "HTM.pb.h" | ||
|
||
#include "DaemonCreator.hpp" | ||
#include "HtmClient.hpp" | ||
#include "HtmServer.hpp" | ||
#include "IpcPairClient.hpp" | ||
#include "LogHandler.hpp" | ||
#include "MultiplexerState.hpp" | ||
#include "RawSocketUtils.hpp" | ||
|
||
DEFINE_bool(x, false, "flag to kill all old sessions belonging to the user"); | ||
|
||
int main(int argc, char** argv) { | ||
// Version string need to be set before GFLAGS parse arguments | ||
SetVersionString(string(ET_VERSION)); | ||
GOOGLE_PROTOBUF_VERIFY_VERSION; | ||
srand(1); | ||
|
||
setvbuf(stdin, NULL, _IONBF, 0); // turn off buffering | ||
setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering | ||
|
||
// Turn on raw terminal mode | ||
termios terminal_backup; | ||
termios terminal_local; | ||
tcgetattr(0, &terminal_local); | ||
memcpy(&terminal_backup, &terminal_local, sizeof(struct termios)); | ||
cfmakeraw(&terminal_local); | ||
tcsetattr(0, TCSANOW, &terminal_local); | ||
|
||
// Setup easylogging configurations | ||
el::Configurations defaultConf = | ||
et::LogHandler::SetupLogHandler(&argc, &argv); | ||
defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false"); | ||
el::Loggers::setVerboseLevel(3); | ||
// default max log file size is 20MB for etserver | ||
string maxlogsize = "20971520"; | ||
et::LogHandler::SetupLogFile(&defaultConf, "/tmp/htm.log", maxlogsize); | ||
|
||
// Reconfigure default logger to apply settings above | ||
el::Loggers::reconfigureLogger("default", defaultConf); | ||
|
||
uid_t myuid = getuid(); | ||
if (FLAGS_x) { | ||
LOG(INFO) << "Killing previous htmd"; | ||
// Kill previous htm daemon | ||
string command = | ||
string("pkill -x -U ") + to_string(myuid) + string(" htmd"); | ||
system(command.c_str()); | ||
} | ||
|
||
// Check if daemon exists | ||
string command = string("pgrep -x -U ") + to_string(myuid) + string(" htmd"); | ||
string pgrepOutput = SystemToStr(command.c_str()); | ||
|
||
if (pgrepOutput.length() == 0) { | ||
// Fork to create the daemon | ||
int result = et::DaemonCreator::create(); | ||
if (result == et::DaemonCreator::CHILD) { | ||
// This means we are the daemon | ||
exit(system("htmd")); | ||
} | ||
} | ||
|
||
// This means we are the client to the daemon | ||
usleep(10 * 1000); // Sleep for 10ms to let the daemon come alive | ||
et::HtmClient htmClient; | ||
htmClient.run(); | ||
|
||
tcsetattr(0, TCSANOW, &terminal_backup); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.