Refactored main functionality to allow easier adoption into other
projects.
This commit is contained in:
@@ -30,8 +30,7 @@ void signalCallback(int signum);
|
|||||||
|
|
||||||
volatile bool contProc = true;
|
volatile bool contProc = true;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
bool initialiseLights(const string& prog) {
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
disableACTTrigger(true);
|
disableACTTrigger(true);
|
||||||
@@ -42,15 +41,18 @@ int main(int argc, char **argv)
|
|||||||
cerr << e.what() << endl;
|
cerr << e.what() << endl;
|
||||||
|
|
||||||
if (getuid() != 0)
|
if (getuid() != 0)
|
||||||
cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl;
|
cerr << "Try running as root, using \'sudo " << prog << "\'" << endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int handleTransactions(const string& prog, const string& privKeyDir)
|
||||||
|
{
|
||||||
signal(SIGINT, signalCallback);
|
signal(SIGINT, signalCallback);
|
||||||
|
|
||||||
string privKeyDir = (argc == 2 ? argv[1] : STORAGE_PREFIX);
|
|
||||||
|
|
||||||
Storage::init(privKeyDir);
|
Storage::init(privKeyDir);
|
||||||
|
|
||||||
Controller ch{ 0xF1D00000 };
|
Controller ch{ 0xF1D00000 };
|
||||||
|
|
||||||
while (contProc)
|
while (contProc)
|
||||||
@@ -64,7 +66,8 @@ int main(int argc, char **argv)
|
|||||||
cerr << e.what() << endl;
|
cerr << e.what() << endl;
|
||||||
|
|
||||||
if (getuid() != 0)
|
if (getuid() != 0)
|
||||||
cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl;
|
cerr << "Try running as root, using \'sudo " << prog << "\'" << endl;
|
||||||
|
|
||||||
raise(SIGINT);
|
raise(SIGINT);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Storage::save();
|
Storage::save();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deinitialiseLights(const string& prog) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
disableACTTrigger(false);
|
disableACTTrigger(false);
|
||||||
@@ -81,9 +87,14 @@ int main(int argc, char **argv)
|
|||||||
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 " << prog << "\'" << endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void signalCallback([[maybe_unused]] int signum)
|
void signalCallback([[maybe_unused]] int signum)
|
||||||
|
|||||||
25
U2FDevice.hpp
Normal file
25
U2FDevice.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
U2FDevice - A program to allow Raspberry Pi Zeros to act as U2F tokens
|
||||||
|
Copyright (C) 2019 Michael Kuc
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
bool initialiseLights(const std::string& prog);
|
||||||
|
bool deinitialiseLights(const std::string& prog);
|
||||||
|
int handleTransactions(const std::string& prog, const std::string& privKeyDir);
|
||||||
|
|
||||||
Reference in New Issue
Block a user