Improved error handling.

This commit is contained in:
2018-08-12 10:12:42 +00:00
parent c53386c4f4
commit a51b8955e2
3 changed files with 31 additions and 8 deletions

View File

@@ -12,10 +12,15 @@ Controller::Controller(const uint32_t startChannel)
void Controller::handleTransaction() void Controller::handleTransaction()
{ {
if (channels.size() != 0 && chrono::duration_cast<chrono::seconds>(chrono::system_clock::now() - lastMessage) < 5s) try
toggleACTLED(); {
else if (channels.size() != 0 && chrono::duration_cast<chrono::seconds>(chrono::system_clock::now() - lastMessage) < 5s)
enableACTLED(false); toggleACTLED();
else
enableACTLED(false);
}
catch (runtime_error)
{}
auto msg = U2FMessage::readNonBlock(); auto msg = U2FMessage::readNonBlock();

View File

@@ -13,6 +13,9 @@ OBJECTS := $(MODULES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
U2FDevice: $(OBJECTS) libuECC.o libcppb64.o U2FDevice: $(OBJECTS) libuECC.o libcppb64.o
g++ $(LDFLAGS) -o $@ $^ g++ $(LDFLAGS) -o $@ $^
install: U2FDevice
install -m775 -t /usr/bin U2FDevice
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
@@ -22,7 +25,7 @@ clean:
rm $(OBJ_DIR)/* rm $(OBJ_DIR)/*
rm U2FDevice rm U2FDevice
.PHONY: libuECC.o libcppb64.so clean .PHONY: libuECC.o libcppb64.so clean install
libuECC.o: libuECC.o:
$(MAKE) -C micro-ecc $(MAKE) -C micro-ecc
cp micro-ecc/libuECC.o libuECC.o cp micro-ecc/libuECC.o libuECC.o

View File

@@ -11,7 +11,7 @@ void signalCallback(int signum);
volatile bool contProc = true; volatile bool contProc = true;
int main() int main(int argc, char **argv)
{ {
try try
{ {
@@ -21,6 +21,9 @@ int main()
catch (runtime_error &e) catch (runtime_error &e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
if (getuid() != 0)
cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl;
} }
signal(SIGINT, signalCallback); signal(SIGINT, signalCallback);
@@ -30,7 +33,19 @@ int main()
while (contProc) while (contProc)
{ {
ch.handleTransaction(); try
{
ch.handleTransaction();
}
catch (const runtime_error &e)
{
cerr << e.what() << endl;
if (getuid() != 0)
cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl;
raise(SIGINT);
return EXIT_FAILURE;
}
usleep(10000); usleep(10000);
} }
@@ -52,5 +67,5 @@ int main()
void signalCallback([[maybe_unused]] int signum) void signalCallback([[maybe_unused]] int signum)
{ {
contProc = false; contProc = false;
clog << "\nCaught SIGINT signal" << endl; clog << "\nClosing" << endl;
} }