Diff for /embedtools/src/pceng.c between versions 1.1.2.2 and 1.1.2.3

version 1.1.2.2, 2011/07/22 13:35:06 version 1.1.2.3, 2011/07/22 14:20:24
Line 47  SUCH DAMAGE. Line 47  SUCH DAMAGE.
 #include "pceng.h"  #include "pceng.h"
   
   
int Verbose;int Verbose, Kill;
 extern char compiled[], compiledby[], compilehost[];  extern char compiled[], compiledby[], compilehost[];
 sl_config cfg;  sl_config cfg;
   char szConf[MAXPATHLEN] = DEFAULT_PCENG_CFG;
   
   
 static void  static void
Line 65  Usage() Line 66  Usage()
                 "\n", compiled, compiledby, compilehost);                  "\n", compiled, compiledby, compilehost);
 }  }
   
   static void
   sigHand(int sig)
   {
           int stat;
   
           switch (sig) {
                   case SIGHUP:
                           UnloadConfig(&cfg);
                           if (LoadConfig(szConf, &cfg)) {
                                   syslog(LOG_ERR, "Error:: #%d - %s", cfg_GetErrno(), cfg_GetError());
                                   raise(SIGTERM);
                           }
                           VERB(1) syslog(LOG_WARNING, "Reload config %s", szConf);
                           break;
                   case SIGTERM:
                           VERB(1) syslog(LOG_WARNING, "Kill process ...");
                           Kill++;
                           break;
                   case SIGCHLD:
                           while (waitpid(-1, &stat, WNOHANG) > 0);
           }
   }
   
   
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
        char ch, szConf[MAXPATHLEN] = DEFAULT_PCENG_CFG;        char ch;
        int mode = 0;        int io, mode = 0;
         struct sigaction sact;
   
         while ((ch = getopt(argc, argv, "vhbc:")) != -1)          while ((ch = getopt(argc, argv, "vhbc:")) != -1)
                 switch (ch) {                  switch (ch) {
Line 91  main(int argc, char **argv) Line 116  main(int argc, char **argv)
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
           openlog("pceng", LOG_CONS | LOG_PID, LOG_DAEMON);
   
         if (LoadConfig(szConf, &cfg)) {          if (LoadConfig(szConf, &cfg)) {
                 printf("Error:: #%d - %s\n", cfg_GetErrno(), cfg_GetError());                  printf("Error:: #%d - %s\n", cfg_GetErrno(), cfg_GetError());
                 return 1;                  return 1;
         }          }
   
           sact.sa_handler = sigHand;
           sigemptyset(&sact.sa_mask);
           sigaction(SIGHUP, &sact, NULL);
           sigaction(SIGTERM, &sact, NULL);
           sigaction(SIGCHLD, &sact, NULL);
   
           io = open(_PATH_DEVIO, O_RDWR);
           if (io == -1) {
                   printf("Error:: in open dev %s #%d - %s\n", _PATH_DEVIO, errno, strerror(errno));
                   goto end;
           }
   
           if (!mode)
                   switch (fork()) {
                           case -1:
                                   printf("Error:: #%d - %s\n", errno, strerror(errno));
                                   goto end;
                           case 0:
                                   VERB(1) printf("Welcome into darkness ...\n");
   
                                   setsid();
                                   chdir("/");
   
                                   mode = open(_PATH_DEVNULL, O_RDWR);
                                   if (mode > 2) {
                                           dup2(mode, STDIN_FILENO);
                                           dup2(mode, STDOUT_FILENO);
                                           dup2(mode, STDERR_FILENO);
                                           close(mode);
                                   }
                                   break;
                           default:
                                   VERB(1) printf("PCENG Going to shadow land ...\n");
                                   goto end;
                   }
   
           Run(io);
   
   end:
           if (io > 2)
                   close(io);
         UnloadConfig(&cfg);          UnloadConfig(&cfg);
           closelog();
         return 0;          return 0;
 }  }

Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>