RPi: Log refactor

This commit is contained in:
Marcelo Aquino
2016-10-18 16:55:47 -02:00
parent 75aad5de35
commit 2be804a1ef
13 changed files with 196 additions and 80 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ void hwInit()
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
#ifdef MY_LINUX_SERIAL_GROUPNAME
if (!MY_SERIALDEVICE.setGroupPerm(MY_LINUX_SERIAL_GROUPNAME)) {
mys_log(LOG_ERR, "Unable to change permission for serial port device.\n");
logError("Unable to change permission for serial port device.\n");
exit(1);
}
#endif
@@ -125,7 +125,7 @@ void hwDebugPrint(const char *fmt, ...)
va_list args;
va_start(args, fmt);
mys_log_v(LOG_DEBUG, fmt, args);
vlogDebug(fmt, args);
va_end(args);
}
#endif
+3 -3
View File
@@ -29,7 +29,7 @@ static SoftEeprom eeprom = SoftEeprom(MY_LINUX_CONFIG_FILE, 1024); // ATMega328
void hwInit()
{
if (!bcm2835_init()) {
mys_log(LOG_ERR, "Failed to initialized bcm2835.\n");
logError("Failed to initialized bcm2835.\n");
exit(1);
}
@@ -37,7 +37,7 @@ void hwInit()
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
#ifdef MY_LINUX_SERIAL_GROUPNAME
if (!MY_SERIALDEVICE.setGroupPerm(MY_LINUX_SERIAL_GROUPNAME)) {
mys_log(LOG_ERR, "Unable to change permission for serial port device.\n");
logError("Unable to change permission for serial port device.\n");
exit(1);
}
#endif
@@ -130,7 +130,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
va_list args;
va_start(args, fmt);
mys_log_v(LOG_DEBUG, fmt, args);
vlogDebug(fmt, args);
va_end(args);
}
#endif
+14 -11
View File
@@ -32,9 +32,9 @@
void handle_sigint(int sig)
{
if (sig == SIGINT) {
mys_log(LOG_NOTICE, "Received SIGINT\n\n");
logNotice("Received SIGINT\n\n");
} else if (sig == SIGTERM) {
mys_log(LOG_NOTICE, "Received SIGTERM\n\n");
logNotice("Received SIGTERM\n\n");
} else {
return;
}
@@ -47,6 +47,8 @@ void handle_sigint(int sig)
MY_SERIALDEVICE.end();
#endif
closelog();
exit(0);
}
@@ -57,7 +59,7 @@ static int daemonize(void)
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
mys_log(LOG_ERR, "fork: %s\n", strerror(errno));
logError("fork: %s\n", strerror(errno));
return -1;
}
/* If we got a good PID, then we can exit the parent process. */
@@ -73,25 +75,25 @@ static int daemonize(void)
/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
mys_log(LOG_ERR, "setsid: %s\n", strerror(errno));
logError("setsid: %s\n", strerror(errno));
return -1;
}
/* Change the current working directory. This prevents the current
directory from being locked; hence not being able to remove it. */
if ((chdir("/")) < 0) {
mys_log(LOG_ERR, "chdir(\"/\"): %s\n", strerror(errno));
logError("chdir(\"/\"): %s\n", strerror(errno));
return -1;
}
if (freopen( "/dev/null", "r", stdin) == NULL) {
mys_log(LOG_ERR, "freopen: %s\n", strerror(errno));
logError("freopen: %s\n", strerror(errno));
}
if (freopen( "/dev/null", "r", stdout) == NULL) {
mys_log(LOG_ERR, "freopen: %s\n", strerror(errno));
logError("freopen: %s\n", strerror(errno));
}
if (freopen( "/dev/null", "r", stderr) == NULL) {
mys_log(LOG_ERR, "freopen: %s\n", strerror(errno));
logError("freopen: %s\n", strerror(errno));
}
return 0;
@@ -137,9 +139,10 @@ int main(int argc, char *argv[])
log_opts |= LOG_PERROR;
}
if (!debug) {
// Ignore debug type messages
setlogmask(LOG_UPTO (LOG_INFO));
}
openlog(NULL, log_opts, LOG_USER);
logOpen(log_opts, LOG_USER);
if (!foreground && !debug) {
if (daemonize() != 0) {
@@ -147,8 +150,8 @@ int main(int argc, char *argv[])
}
}
mys_log(LOG_INFO, "Starting gateway...\n");
mys_log(LOG_INFO, "Protocol version - %s\n", MYSENSORS_LIBRARY_VERSION);
logInfo("Starting gateway...\n");
logInfo("Protocol version - %s\n", MYSENSORS_LIBRARY_VERSION);
_begin(); // Startup MySensors library