26 #include <sys/ioctl.h> 
   28 #include <sys/select.h> 
   31 #include <sys/types.h> 
   42 #include <sys/epoll.h> 
   51 static int g_nodaemon;
 
   55 #define dbg(fmt, ...) if (g_debug > 1) { \ 
   56         fprintf(stderr, "nmlogd: " fmt, ##__VA_ARGS__); \ 
   59 #define err(fmt, ...) if (g_debug) { \ 
   60         fprintf(stderr, "nmlogd: " fmt, ##__VA_ARGS__); \ 
   67                 "nmlogd - The EasyNMC logging daemon\n" 
   68                 "(c) 2014 RC Module | Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>\n" 
   69                 "This is free software; see the source for copying conditions.  There is NO\n" 
   70                 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" 
   72                 "Usage: %s [options]   - operate on core 0 (default)\n" 
   73                 "Valid options are: \n" 
   74                 "  --help             - Show this help\n" 
   75                 "  --syslog[=facility]- Log to syslog facility (default - neuromatrix)\n" 
   76                 "  --file=/tmp/log    - Log to a file.  " 
   77                 "  --nodaemon         - Do not daemonize and log to stdout\n" 
   78                 "  --core=n           - Log on core n. Can be specified multiple times.\n" 
   79                 "  --pidfile          - Write a pid file\n"  
   80                 "  --log-interrupts   - Log incoming interrupts\n" 
   81                 "Debugging options: \n" 
   82                 "  --debug            - Print lots of debugging info (nmctl)\n" 
   83                 "  --debug-lib        - Print lots of debugging info (libeasynmc)\n" 
   88 static struct option long_options[] =
 
   91         {
"help",             no_argument,         0, 
'h' },
 
   94         {
"prefix",           required_argument,        0,        
'P' },
 
   95         {
"core",             required_argument,        0,        
'c' },
 
   96         {
"syslog",           optional_argument,        &g_mode,  
's' },
 
   97         {
"file",             required_argument,        0,        
'f' },
 
   98         {
"pid",              required_argument,        0,        
'p' },
 
   99         {
"nodaemon",         no_argument,              &g_nodaemon,   1 },
 
  103         {
"debug",            no_argument,        &
g_debug,            2 },
 
  104         {
"dump-ldr-regs",    optional_argument,   0,                
'D' },
 
  129                 asprintf(&prefix, 
"core%d: ", numcore);
 
  138         struct epoll_event evt;
 
  140         evt.events   = EPOLLIN | EPOLLHUP;
 
  141         int ret = epoll_ctl(efd, EPOLL_CTL_ADD, c->
h->
iofd, &evt);
 
  144         int flags = fcntl(c->
h->
iofd, F_GETFL, 0);
 
  145         fcntl(c->
h->
iofd, F_SETFL, flags | O_NONBLOCK);
 
  147         setvbuf(c->
rfd, NULL, _IOLBF, 2048);
 
  166 int main(
int argc, 
char* argv[]) 
 
  169                 usage(argv[0]), exit(1);
 
  174         int efd = epoll_create(argc);
 
  176         int numaddedcores = 0;
 
  183                 int option_index = 0;
 
  184                 c = getopt_long (argc, argv, 
"P:c:s:f:p:Dh",
 
  185                                  long_options, &option_index);
 
  194                         if (strcmp(optarg, 
"all") == 0)
 
  197                                 numcore = atoi(optarg);
 
  201                                 err(
"Failed to add core %d to logger\n", numcore);
 
  216         dbg(
"added %d core(s) to the logger\n", numaddedcores);
 
  224                 struct epoll_event evt;
 
  225                 num = epoll_wait(efd, &evt, 1, -1);
 
  227                         perror(
"epoll_wait");
 
  241                 if (evt.events & EPOLLIN) {
 
  243                         fprintf(
"gets %x %s\n",ret, tmp);
 
  247                 if (evt.events & EPOLLHUP) {
 
  248                         do_log(c, 
"NOTICE: Application stopped!");