daemon option -l --logfile added; ebusd strings replaced with ebus-daemon
This commit is contained in:
+33
-19
@@ -49,48 +49,60 @@ CYCData* cycdata;
|
|||||||
void define_args()
|
void define_args()
|
||||||
{
|
{
|
||||||
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
||||||
"\tebus device address (FF)",
|
"\tebus device address (default: FF)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_device", Appl::Param("/dev/ttyUSB0"), "d", "device",
|
A.addItem("p_device", Appl::Param("/dev/ttyUSB0"), "d", "device",
|
||||||
"\tebus device (serial or network) (/dev/ttyUSB0)",
|
"\tebus device (serial or network) (default: /dev/ttyUSB0)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_nodevicecheck", Appl::Param(false), "n", "nodevicecheck",
|
A.addItem("p_nodevicecheck", Appl::Param(false), "n", "nodevicecheck",
|
||||||
"disable valid ebus device test\n", Appl::type_bool, Appl::opt_none);
|
"disable valid ebus device test\n",
|
||||||
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_ebusconfdir", Appl::Param("contrib/csv/vaillant"), "e", "ebusconfdir",
|
A.addItem("p_ebusconfdir", Appl::Param("contrib/csv/vaillant"), "e", "ebusconfdir",
|
||||||
"directory for ebus configuration (contrib/csv/vaillant)\n",
|
"directory for ebus configuration (default: contrib/csv/vaillant)\n",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_foreground", Appl::Param(false), "f", "foreground",
|
A.addItem("p_foreground", Appl::Param(false), "f", "foreground",
|
||||||
"run in foreground\n", Appl::type_bool, Appl::opt_none);
|
"run in foreground\n",
|
||||||
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
||||||
"\tlisten port (8888)", Appl::type_int, Appl::opt_mandatory);
|
"\tlisten port (default: 8888)",
|
||||||
|
Appl::type_int, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_localhost", Appl::Param(false), "", "localhost",
|
A.addItem("p_localhost", Appl::Param(false), "", "localhost",
|
||||||
"listen localhost only\n", Appl::type_bool, Appl::opt_none);
|
"listen localhost only\n",
|
||||||
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
|
A.addItem("p_logfile", Appl::Param("/var/log/ebus-daemon.log"), "l", "logfile",
|
||||||
|
"\tlog file name (default: /var/log/ebus-daemon.log)",
|
||||||
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_area", Appl::Param(all), "", "logarea",
|
A.addItem("p_area", Appl::Param(all), "", "logarea",
|
||||||
"\tlogging area (bas=1, net=2, bus=4, cyc=8, all=15)",
|
"\tlogging area (bas=1, net=2, bus=4, cyc=8, default: all=15)",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_int, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_level", Appl::Param(trace), "", "loglevel",
|
A.addItem("p_level", Appl::Param(trace), "", "loglevel",
|
||||||
"\tlogging level (error=1, event=2, trace=3, debug=4)\n",
|
"\tlogging level (error=1, event=2, default: trace=3, debug=4)\n",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_int, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_dump", Appl::Param(false), "D", "dump",
|
A.addItem("p_dump", Appl::Param(false), "D", "dump",
|
||||||
"\tenable dump", Appl::type_bool, Appl::opt_none);
|
"\tenable dump",
|
||||||
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_dumpfile", Appl::Param("/tmp/dump_ebus.bin"), "", "dumpfile",
|
A.addItem("p_dumpfile", Appl::Param("/tmp/ebus_dump.bin"), "", "dumpfile",
|
||||||
"\tdump file name (/tmp/dump_ebusd.bin)", Appl::type_string, Appl::opt_mandatory);
|
"\tdump file name (default: /tmp/ebus_dump.bin)",
|
||||||
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_dumpsize", Appl::Param(100), "", "dumpsize",
|
A.addItem("p_dumpsize", Appl::Param(100), "", "dumpsize",
|
||||||
"\tmax size for dump file in kB (100)\n", Appl::type_long, Appl::opt_mandatory);
|
"\tmax size for dump file in kB (default: 100)\n",
|
||||||
|
Appl::type_long, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_help", Appl::Param(false), "h", "help",
|
A.addItem("p_help", Appl::Param(false), "h", "help",
|
||||||
"\tprint this message", Appl::type_bool, Appl::opt_none);
|
"\tprint this message",
|
||||||
|
Appl::type_bool, Appl::opt_none);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
@@ -126,7 +138,7 @@ void shutdown()
|
|||||||
D.stop();
|
D.stop();
|
||||||
|
|
||||||
// stop Logger
|
// stop Logger
|
||||||
L.log(bas, event, "ebusd stopped");
|
L.log(bas, event, "ebus-daemon stopped");
|
||||||
L.stop();
|
L.stop();
|
||||||
L.join();
|
L.join();
|
||||||
|
|
||||||
@@ -173,11 +185,13 @@ int main(int argc, char* argv[])
|
|||||||
// make me Daemon
|
// make me Daemon
|
||||||
if (A.getParam<bool>("p_foreground") == true) {
|
if (A.getParam<bool>("p_foreground") == true) {
|
||||||
L += new LogConsole(A.getParam<int>("p_area"),
|
L += new LogConsole(A.getParam<int>("p_area"),
|
||||||
static_cast<const Level>(A.getParam<int>("p_level")), "logConsole");
|
static_cast<const Level>(A.getParam<int>("p_level")),
|
||||||
|
"logConsole");
|
||||||
} else {
|
} else {
|
||||||
D.run("/var/run/ebusd.pid");
|
D.run("/var/run/ebus-daemon.pid");
|
||||||
L += new LogFile(A.getParam<int>("p_area"),
|
L += new LogFile(A.getParam<int>("p_area"),
|
||||||
static_cast<const Level>(A.getParam<int>("p_level")), "logFile", "/var/log/ebusd.log");
|
static_cast<const Level>(A.getParam<int>("p_level")),
|
||||||
|
"logFile", A.getParam<const char*>("p_logfile"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// trap Signals that we expect to receive
|
// trap Signals that we expect to receive
|
||||||
@@ -187,7 +201,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// start Logger
|
// start Logger
|
||||||
L.start("logInstance");
|
L.start("logInstance");
|
||||||
L.log(bas, event, "ebusd started");
|
L.log(bas, event, "ebus-daemon started");
|
||||||
|
|
||||||
// print Daemon status
|
// print Daemon status
|
||||||
if (D.status() == true)
|
if (D.status() == true)
|
||||||
|
|||||||
+7
-8
@@ -33,18 +33,20 @@ Appl& A = Appl::Instance();
|
|||||||
void define_args()
|
void define_args()
|
||||||
{
|
{
|
||||||
A.addItem("p_device", Appl::Param("/dev/ttyUSB60"), "d", "device",
|
A.addItem("p_device", Appl::Param("/dev/ttyUSB60"), "d", "device",
|
||||||
"dummy serial device (/dev/ttyUSB60)\n\t\t(socat -d -d pty,raw,echo=0 pty,raw,echo=0)",
|
"dummy serial device (default: /dev/ttyUSB60)\n\t\t(socat -d -d pty,raw,echo=0 pty,raw,echo=0)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_file", Appl::Param("test/scan_ebusd.bin"), "f", "file",
|
A.addItem("p_file", Appl::Param("test/ebus_dump.bin"), "f", "file",
|
||||||
"dump file with raw data (test/scan_ebusd.bin)",
|
"dump file with raw data (default: test/ebus_dump.bin)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_time", Appl::Param(10000), "t", "time",
|
A.addItem("p_time", Appl::Param(10000), "t", "time",
|
||||||
"wait time [ms] (10000)", Appl::type_long, Appl::opt_mandatory);
|
"wait time [ms] (default: 10000)",
|
||||||
|
Appl::type_long, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_help", Appl::Param(false), "h", "help",
|
A.addItem("p_help", Appl::Param(false), "h", "help",
|
||||||
"print this message", Appl::type_bool, Appl::opt_none);
|
"print this message",
|
||||||
|
Appl::type_bool, Appl::opt_none);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
@@ -64,7 +66,6 @@ int main(int argc, char* argv[])
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string dev(A.getParam<const char*>("p_device"));
|
std::string dev(A.getParam<const char*>("p_device"));
|
||||||
Port port(dev, true);
|
Port port(dev, true);
|
||||||
|
|
||||||
@@ -72,7 +73,6 @@ int main(int argc, char* argv[])
|
|||||||
if(port.isOpen() == true)
|
if(port.isOpen() == true)
|
||||||
std::cout << "openPort successful." << std::endl;
|
std::cout << "openPort successful." << std::endl;
|
||||||
|
|
||||||
|
|
||||||
std::fstream file(A.getParam<const char*>("p_file"), std::ios::in | std::ios::binary);
|
std::fstream file(A.getParam<const char*>("p_file"), std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
if(file.is_open() == true) {
|
if(file.is_open() == true) {
|
||||||
@@ -89,7 +89,6 @@ int main(int argc, char* argv[])
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
port.close();
|
port.close();
|
||||||
if(port.isOpen() == false)
|
if(port.isOpen() == false)
|
||||||
std::cout << "closePort successful." << std::endl;
|
std::cout << "closePort successful." << std::endl;
|
||||||
|
|||||||
+3
-3
@@ -44,7 +44,7 @@ void Daemon::run(const char* file)
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
std::cerr << "ebusd fork() failed." << std::endl;
|
std::cerr << "daemon fork() failed." << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +62,14 @@ void Daemon::run(const char* file)
|
|||||||
// Create a new SID for the child process and
|
// Create a new SID for the child process and
|
||||||
// detach the process from the parent (normally a shell)
|
// detach the process from the parent (normally a shell)
|
||||||
if (setsid() < 0) {
|
if (setsid() < 0) {
|
||||||
std::cerr << "ebusd setsid() failed." << std::endl;
|
std::cerr << "daemon setsid() failed." << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the current working directory. This prevents the current
|
// Change the current working directory. This prevents the current
|
||||||
// directory from being locked; hence not being able to remove it.
|
// directory from being locked; hence not being able to remove it.
|
||||||
if (chdir("/tmp") < 0) { //DAEMON_WORKDIR
|
if (chdir("/tmp") < 0) { //DAEMON_WORKDIR
|
||||||
std::cerr << "ebusd chdir() failed." << std::endl;
|
std::cerr << "daemon chdir() failed." << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user