daemon option -l --logfile added; ebusd strings replaced with ebus-daemon
This commit is contained in:
+43
-29
@@ -49,48 +49,60 @@ CYCData* cycdata;
|
||||
void define_args()
|
||||
{
|
||||
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
||||
"\tebus device address (FF)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
"\tebus device address (default: FF)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_device", Appl::Param("/dev/ttyUSB0"), "d", "device",
|
||||
"\tebus device (serial or network) (/dev/ttyUSB0)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
"\tebus device (serial or network) (default: /dev/ttyUSB0)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
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",
|
||||
"directory for ebus configuration (contrib/csv/vaillant)\n",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
"directory for ebus configuration (default: contrib/csv/vaillant)\n",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
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",
|
||||
"\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",
|
||||
"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",
|
||||
"\tlogging area (bas=1, net=2, bus=4, cyc=8, all=15)",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
"\tlogging area (bas=1, net=2, bus=4, cyc=8, default: all=15)",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_level", Appl::Param(trace), "", "loglevel",
|
||||
"\tlogging level (error=1, event=2, trace=3, debug=4)\n",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
"\tlogging level (error=1, event=2, default: trace=3, debug=4)\n",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
|
||||
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",
|
||||
"\tdump file name (/tmp/dump_ebusd.bin)", Appl::type_string, Appl::opt_mandatory);
|
||||
A.addItem("p_dumpfile", Appl::Param("/tmp/ebus_dump.bin"), "", "dumpfile",
|
||||
"\tdump file name (default: /tmp/ebus_dump.bin)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
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",
|
||||
"\tprint this message", Appl::type_bool, Appl::opt_none);
|
||||
"\tprint this message",
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
@@ -111,7 +123,7 @@ void shutdown()
|
||||
ebusloop->join();
|
||||
delete ebusloop;
|
||||
}
|
||||
|
||||
|
||||
// free Commands DB
|
||||
if (commands != NULL)
|
||||
delete commands;
|
||||
@@ -126,7 +138,7 @@ void shutdown()
|
||||
D.stop();
|
||||
|
||||
// stop Logger
|
||||
L.log(bas, event, "ebusd stopped");
|
||||
L.log(bas, event, "ebus-daemon stopped");
|
||||
L.stop();
|
||||
L.join();
|
||||
|
||||
@@ -163,21 +175,23 @@ int main(int argc, char* argv[])
|
||||
A.printArgs();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
// print Help
|
||||
if (A.getParam<bool>("p_help") == true) {
|
||||
A.printArgs();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
// make me Daemon
|
||||
if (A.getParam<bool>("p_foreground") == true) {
|
||||
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 {
|
||||
D.run("/var/run/ebusd.pid");
|
||||
D.run("/var/run/ebus-daemon.pid");
|
||||
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
|
||||
@@ -187,7 +201,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// start Logger
|
||||
L.start("logInstance");
|
||||
L.log(bas, event, "ebusd started");
|
||||
L.log(bas, event, "ebus-daemon started");
|
||||
|
||||
// print Daemon status
|
||||
if (D.status() == true)
|
||||
|
||||
+13
-14
@@ -33,18 +33,20 @@ Appl& A = Appl::Instance();
|
||||
void define_args()
|
||||
{
|
||||
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)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
"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);
|
||||
|
||||
A.addItem("p_file", Appl::Param("test/scan_ebusd.bin"), "f", "file",
|
||||
"dump file with raw data (test/scan_ebusd.bin)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
A.addItem("p_file", Appl::Param("test/ebus_dump.bin"), "f", "file",
|
||||
"dump file with raw data (default: test/ebus_dump.bin)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
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",
|
||||
"print this message", Appl::type_bool, Appl::opt_none);
|
||||
"print this message",
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
@@ -57,14 +59,13 @@ int main(int argc, char* argv[])
|
||||
A.printArgs();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
// print Help
|
||||
if (A.getParam<bool>("p_help") == true) {
|
||||
A.printArgs();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
std::string dev(A.getParam<const char*>("p_device"));
|
||||
Port port(dev, true);
|
||||
|
||||
@@ -72,11 +73,10 @@ int main(int argc, char* argv[])
|
||||
if(port.isOpen() == true)
|
||||
std::cout << "openPort successful." << std::endl;
|
||||
|
||||
|
||||
std::fstream file(A.getParam<const char*>("p_file"), std::ios::in | std::ios::binary);
|
||||
|
||||
if(file.is_open() == true) {
|
||||
|
||||
|
||||
while (file.eof() == false) {
|
||||
unsigned char byte = file.get();
|
||||
std::cout << std::hex << std::setw(2) << std::setfill('0')
|
||||
@@ -85,15 +85,14 @@ int main(int argc, char* argv[])
|
||||
port.send(&byte, 1);
|
||||
usleep(A.getParam<long>("p_time"));
|
||||
}
|
||||
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
port.close();
|
||||
if(port.isOpen() == false)
|
||||
std::cout << "closePort successful." << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -37,14 +37,14 @@ void Daemon::run(const char* file)
|
||||
m_status = false;
|
||||
m_pidfile = file;
|
||||
m_pidfd = 0;
|
||||
|
||||
|
||||
pid_t pid;
|
||||
|
||||
// fork off the parent process
|
||||
pid = fork();
|
||||
|
||||
|
||||
if (pid < 0) {
|
||||
std::cerr << "ebusd fork() failed." << std::endl;
|
||||
std::cerr << "daemon fork() failed." << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ void Daemon::run(const char* file)
|
||||
// Create a new SID for the child process and
|
||||
// detach the process from the parent (normally a shell)
|
||||
if (setsid() < 0) {
|
||||
std::cerr << "ebusd setsid() failed." << std::endl;
|
||||
std::cerr << "daemon setsid() failed." << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Change the current working directory. This prevents the current
|
||||
// directory from being locked; hence not being able to remove it.
|
||||
if (chdir("/tmp") < 0) { //DAEMON_WORKDIR
|
||||
std::cerr << "ebusd chdir() failed." << std::endl;
|
||||
std::cerr << "daemon chdir() failed." << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user