void BoardInit( void ) { uint8_t i; /* Setup SysTick Timer for 1 us interrupts ( not too often to save power ) */ if( SysTick_Config( SystemCoreClock / 1000 ) ) { /* Capture error */ while (1); } // Initialize unused GPIO to optimize power consumption InitUnusedGPIO( ); // Initialize Selector SelectorInit( ); // Initialize SPI SpiInit( ); // Initialize LED for( i = 0; i < LED_NB; i++ ) { LedInit( ( tLed )i ); } LedOn( LED1 ); LedOn( LED2 ); LedOn( LED3 ); LongDelay( 1 ); LedOff( LED1 ); LedOff( LED2 ); LedOff( LED3 ); }
int main(int argc, char** argv) { const unsigned short PORT = 8888; Selector selector; #if defined(HAVE_POSIX) Listener unixListener; #endif Listener inetListener; char sockfileBuf[MAX_PATH_SIZE]; #if defined(ENABLE_PIDFILE) int pidfile; char pidfileBuf[MAX_PATH_SIZE]; #endif /* defined(ENABLE_PIDFILE) */ arg0 = argv[0]; ErrSetArg0(arg0); /* Set the default options */ memset(&g_options, 0, sizeof(Options)); g_options.sockfile = MakePath(ID_SOCKFILE, sockfileBuf); g_options.port = PORT; /* Set the default options */ #if defined(ENABLE_ROLES) /* Load roles.conf */ { char buf[MAX_PATH_SIZE]; char err[128]; if (RolesLoad(MakePath(ID_ROLES_CONF, buf), err, sizeof(err)) != 0) Err("%s", err); } #endif /* defined(ENABLE_ROLES) */ /* Set the default options */ /* Process the configuration file before the command-line options */ _GetConfFileOptions(); /* Get command line options */ _GetOptions(&g_options, &argc, argv); /* Dump the paths? */ if (g_options.paths) { DumpPaths(); exit(0); } /* Dump the roles */ if (g_options.roles) { RoleDump(); exit(0); } #if defined(ENABLE_PAM_AUTH) /* Check that the PAM plugin is installed */ if (access("/etc/pam.d/phit", R_OK) != 0) { fprintf(stderr, "%s: /etc/pam.d/phit not found\n\n", arg0); exit(1); } #endif /* Stop the server? */ if (g_options.stop) { #if defined(ENABLE_PIDFILE) _StopServer(); #else Err("use kill (-s option is diabled)"); #endif /* defined(ENABLE_PIDFILE) */ } /* Check arguments */ if (argc != 1) { fprintf(stderr, "Use -h for help\n"); exit(1); } #if defined(ENABLE_PIDFILE) /* Bail out if server is already running */ if (PIDFileIsRunning() == 0) { Err("already running: %s", MakePath(ID_PIDFILE, pidfileBuf)); } #endif /* defined(ENABLE_PIDFILE) */ /* Load the plugins file */ { char error[128]; if (PluginLoad(error, PHIT_ARRAY_SIZE(error)) != 0) Err("%s", error); } /* Initialize the selector */ SelectorInit(&selector); /* Handle SIGTERM */ signal(SIGTERM, _HandleSIGTERM); /* Ignore SIGPIPE */ #if defined(HAVE_POSIX) signal(SIGPIPE, SIG_IGN); #endif /* Initialize the sockets layer */ { int r = SockStart(); (void)r; DEBUG_ASSERT(r == 0); } #if defined(HAVE_POSIX) /* Create listener for Unix-domain sockets */ if (ListenerInit(&unixListener, &selector, g_options.sockfile, 0) != 0) { char buf[MAX_PATH_SIZE]; Err("listen failed (uds): %s", MakePath(ID_SOCKFILE, buf)); } #endif /* defined(HAVE_POSIX) */ /* Create listener for internet sockets */ if (ListenerInit(&inetListener, &selector, NULL, g_options.port) != 0) { Err("listen failed (inet): port %u", g_options.port); } /* Daemonize */ #if defined(HAVE_POSIX) if (!g_options.nodaemonize) ProcessDaemonize(); #endif #if defined(ENABLE_PIDFILE) /* Create PID file (after daemonize) */ if ((pidfile = PIDFileCreate()) == -1) { Err("failed to create %s", MakePath(ID_PIDFILE, pidfileBuf)); } #endif /* defined(ENABLE_PIDFILE) */ /* Run the selector */ while (!_terminated) { SelectorRun(&selector, 1, 0); } /* Unload the plugins */ PluginUnload(); /* Close and delete the PID file */ #if defined(ENABLE_PIDFILE) { close(pidfile); if (PIDFileDelete() != 0) { Err("delete failed: %s\n", MakePath(ID_PIDFILE, pidfileBuf)); } } #endif /* defined(ENABLE_PIDFILE) */ /* Release the selector (and any surviving handlers) */ SelectorDestroy(&selector); /* Remove the socket file */ #if defined(ENABLE_EXEC_PROVIDERS) unlink(MakePath(ID_SOCKFILE, sockfileBuf)); #endif /* Shutdown the sockets layer */ SockStop(); LOGI(("Terminated")); /* Call all cleanup handlers */ Cleanup(); #if defined(ENABLE_ALLOCATOR) /* Print allocation statistics */ AllocPrintStatsAssert(); #endif #if defined(ENABLE_SOCKTRACE) printf("Bytes sent: %llu\n", SockGetBytesSent()); printf("Bytes recv: %llu\n", SockGetBytesRecv()); #endif /* ENABLE_SOCKTRACE */ return 0; }