void Logger::terminate() { Info( "Terminating Logger" ); if ( mFileLevel > NOLOG ) closeFile(); if ( mSyslogLevel > NOLOG ) closeSyslog(); }
void Logger::terminate() { Debug(1, "Terminating Logger" ); if ( mFileLevel > NOLOG ) closeFile(); if ( mSyslogLevel > NOLOG ) closeSyslog(); if ( mDatabaseLevel > NOLOG ) closeDatabase(); }
Logger::~Logger() { closeLogFile(); closeSyslog(); for (size_t i = 0; i < m_levelCount; ++i) delete[] m_levelsMap[i].types; delete[] m_levelsMap; delete[] m_types; if (pthread_rwlock_destroy(&m_settingsLock)) fprintf(stderr, "pthread_rwlock_destroy failed\n"); }
Logger::Level Logger::syslogLevel( Logger::Level syslogLevel ) { if ( syslogLevel > NOOPT ) { syslogLevel = limit(syslogLevel); if ( mSyslogLevel != syslogLevel ) { if ( mSyslogLevel > NOLOG ) closeSyslog(); mSyslogLevel = syslogLevel; if ( mSyslogLevel > NOLOG ) openSyslog(); } } return( mSyslogLevel ); }
void Logger::LogToSyslog(const char *ident, bool teeLogToStderr) { LogAutoLock lock(&m_settingsLock, LogAutoLock::Write); int opt = LOG_NDELAY; if (teeLogToStderr) opt |= LOG_PERROR; closeLogFile(); closeSyslog(); openlog(ident, opt, LOG_DAEMON); m_useSyslog = true; m_ident = ident; }
/* * Main gateway logic */ int main(int argc, char **argv) { struct pollfd fds; struct group* devGrp; MyGateway *gw = NULL; int status = EXIT_SUCCESS; int ret, c; while ((c = getopt (argc, argv, "d")) != -1) { switch (c) { case 'd': daemonizeFlag = 1; break; } } openSyslog(); log(LOG_INFO,"Starting PiGatewaySerial...\n"); log(LOG_INFO,"Protocol version - %s\n", LIBRARY_VERSION); /* register the signal handler */ signal(SIGINT, handle_sigint); signal(SIGTERM, handle_sigint); signal(SIGUSR1, handle_sigusr1); /* create MySensors Gateway object */ #ifdef __PI_BPLUS gw = new MyGateway(RPI_BPLUS_GPIO_J8_22, RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ, 1); #else gw = new MyGateway(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ, 1); #endif if (gw == NULL) { log(LOG_ERR,"Could not create MyGateway! (%d) %s\n", errno, strerror(errno)); status = EXIT_FAILURE; goto cleanup; } /* create PTY - Pseudo TTY device */ ret = openpty(&pty_master, &pty_slave, NULL, NULL, NULL); if (ret != 0) { log(LOG_ERR,"Could not create a PTY! (%d) %s\n", errno, strerror(errno)); status = EXIT_FAILURE; goto cleanup; } errno = 0; devGrp = getgrnam(devGroupName); if(devGrp == NULL) { log(LOG_ERR,"getgrnam: %s failed. (%d) %s\n", devGroupName, errno, strerror(errno)); status = EXIT_FAILURE; goto cleanup; } ret = chown(ttyname(pty_slave),-1,devGrp->gr_gid); if (ret == -1) { log(LOG_ERR,"chown failed. (%d) %s\n", errno, strerror(errno)); status = EXIT_FAILURE; goto cleanup; } ret = chmod(ttyname(pty_slave),ttyPermissions); if (ret != 0) { log(LOG_ERR,"Could not change PTY permissions! (%d) %s\n", errno, strerror(errno)); status = EXIT_FAILURE; goto cleanup; } log(LOG_INFO,"Created PTY '%s'\n", ttyname(pty_slave)); /* create a symlink with predictable name to the PTY device */ unlink(serial_tty); // remove the symlink if it already exists ret = symlink(ttyname(pty_slave), serial_tty); if (ret != 0) { log(LOG_ERR,"Could not create a symlink '%s' to PTY! (%d) %s\n", serial_tty, errno, strerror(errno)); status = EXIT_FAILURE; goto cleanup; } log(LOG_INFO,"Gateway tty: %s\n", serial_tty); close(pty_slave); configure_master_fd(pty_master); fds.events = POLLRDNORM; fds.fd = pty_master; if (daemonizeFlag) daemonize(); /* we are ready, initialize the Gateway */ gw->begin(RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, &write_msg_to_pty); /* Do the work until interrupted */ while(running) { /* process radio msgs */ gw->processRadioMessage(); /* process serial port msgs */ ret = poll(&fds, 1, 500); if (ret == -1) { log(LOG_ERR,"poll() error (%d) %s\n", errno, strerror(errno)); sleep(10); } else if (ret == 0) { /* timeout */ continue; } else { if (fds.revents & POLLRDNORM) { char buff[256]; ssize_t size; fds.revents = 0; size = read(pty_master, buff, sizeof(buff)); if (size < 0) { log(LOG_ERR,"read error (%d) %s\n", errno, strerror(errno)); continue; } buff[size] = '\0'; gw->parseAndSend(buff); } else { sleep(60); } } } cleanup: log(LOG_INFO,"Exiting...\n"); if (gw) delete(gw); (void) unlink(serial_tty); closeSyslog(); return status; }