Exemple #1
0
int main(int argc, char *argv[])
{  Cs2ethStruct *Cs2eth;
   ConfigStruct *Config;
   pid_t ChildPid;
   time_t Now;
   int Ret, NumArgs;
   char **ValArgs;

   Config = ConfigCreate();
   if (Config != (ConfigStruct *)NULL)
   {
      NumArgs = argc;
      ValArgs = argv;
      ConfigInit(Config, MRSYSTEM_CONFIG_FILE);
      ConfigReadfile(Config);
#ifdef TRACE
      ConfigCmdLine(Config, "a:b:p:ftv?", NumArgs, ValArgs);
#else
      ConfigCmdLine(Config, "a:b:p:fv?", NumArgs, ValArgs);
#endif
      if (ConfigGetIntVal(Config, CfgUsageVal))
      {
         usage(argv[0]);
         Ret = 1;
      }
      else if (ConfigGetIntVal(Config, CfgForkVal))
      {
         ChildPid = fork();
         if (ChildPid == -1)
         {
            if (ConfigGetIntVal(Config, CfgVerboseVal))
               puts("ERROR: can not go to backgound");
            ConfigExit(Config);
            ConfigDestroy(Config);
            Ret = 4;
         }
         else if (ChildPid == 0)
         {
            if (ConfigGetIntVal(Config, CfgVerboseVal))
               puts("child running");
            Cs2eth = Cs2ethCreate();
            if (Cs2eth != (Cs2ethStruct *)NULL)
            {
               Cs2ethInit(Cs2eth, ConfigGetIntVal(Config, CfgVerboseVal),
                          ConfigGetStrVal(Config, CfgIfaceVal),
                          ConfigGetStrVal(Config, CfgAddrVal),
                          ConfigGetIntVal(Config, CfgPortVal),
                          ConfigGetIntVal(Config, CfgBcVal),
                          ConfigGetStrVal(Config, CfgUdpBcVal)
#ifdef TRACE
                          , ConfigGetIntVal(Config, CfgTraceVal)
#endif
                          );
               Cs2ethRun(Cs2eth);
               Cs2ethDestroy(Cs2eth);
               Ret = 0;
            }
            else
            {
               Ret = 2;
            }
         }
         else
         {
            if (ConfigGetIntVal(Config, CfgVerboseVal))
               puts("parent terminates");
            signal(SIGCHLD, SIG_IGN);
            Ret = 0;
         }
      }
      else
      {
         Now = time(NULL);
         if (ConfigGetIntVal(Config, CfgVerboseVal))
            printf("start with no fork at %s\n", asctime(localtime(&Now)));
         Cs2eth = Cs2ethCreate();
         if (Cs2eth != (Cs2ethStruct *)NULL)
         {
            Cs2ethInit(Cs2eth, ConfigGetIntVal(Config, CfgVerboseVal),
                       ConfigGetStrVal(Config, CfgIfaceVal),
                       ConfigGetStrVal(Config, CfgAddrVal),
                       ConfigGetIntVal(Config, CfgPortVal),
                       ConfigGetIntVal(Config, CfgBcVal),
                       ConfigGetStrVal(Config, CfgUdpBcVal)
#ifdef TRACE
                       , ConfigGetIntVal(Config, CfgTraceVal)
#endif
                      );
            Cs2ethRun(Cs2eth);
            Cs2ethDestroy(Cs2eth);
            Ret = 0;
         }
         else
         {
            Ret = 2;
         }
      }
      ConfigExit(Config);
      ConfigDestroy(Config);
   }
   else
   {
      Ret = 3;
   }
   return(Ret);
}
Exemple #2
0
int main(int argc, char *argv[])
{  Ms2Struct *Ms2Client;
   IoFktStruct *IoFunctions;
   ConfigStruct *Config;
   pid_t ChildPid;
   time_t Now;
   int Ret, NumArgs;
   char **ValArgs;

   Config = ConfigCreate();
   if (Config != (ConfigStruct *)NULL)
   {
      NumArgs = argc;
      ValArgs = argv;
      ConfigInit(Config, MRSYSTEM_CONFIG_FILE);
      ConfigReadfile(Config);
      ConfigCmdLine(Config, "a:i:p:c:fs:vz:?", NumArgs, ValArgs);
      if (ConfigGetIntVal(Config, CfgUsageVal))
      {
         usage(argv[0]);
         Ret = 1;
      }
      else if (ConfigGetIntVal(Config, CfgForkVal))
      {
         ChildPid = fork();
         if (ChildPid == -1)
         {
            puts("ERROR: can not go to backgound");
            Ret = 4;
         }
         else if (ChildPid == 0)
         {
            if (ConfigGetIntVal(Config, CfgVerboseVal))
               puts("child running");
            IoFunctions = CanClientInit(ConfigGetIntVal(Config, CfgVerboseVal),
                                        ConfigGetStrVal(Config, CfgCanIfVal));
            if (IoFunctions != (IoFktStruct *)NULL)
            {
               Ms2Client = Ms2Create();
               if (Ms2Client != (Ms2Struct *)NULL)
               {
                  Ms2Init(Ms2Client, ConfigGetIntVal(Config, CfgVerboseVal),
                          ConfigGetStrVal(Config, CfgIfaceVal),
                          ConfigGetStrVal(Config, CfgAddrVal),
                          ConfigGetIntVal(Config, CfgPortVal),
                          ConfigGetIntVal(Config, CfgZentraleVal),
                          IoFunctions);
                  Ms2Run(Ms2Client);
                  Ms2Destroy(Ms2Client);
                  Ret = 0;
               }
               else
               {
                  puts("ERROR: can not create Ms2Client module");
                  Ret = 1;
               }
               CanClientExit(IoFunctions);
            }
            else
            {
               puts("ERROR: can not create IoFunctions module");
               Ret = 1;
            }
         }
         else
         {
            puts("parent terminates");
            signal(SIGCHLD, SIG_IGN);
            Ret = 0;
         }
      }
      else
      {
         Now = time(NULL);
         if (ConfigGetIntVal(Config, CfgVerboseVal))
            printf("start with no fork at %s\n", asctime(localtime(&Now)));
         IoFunctions = CanClientInit(ConfigGetIntVal(Config, CfgVerboseVal),
                                     ConfigGetStrVal(Config, CfgCanIfVal));
         if (IoFunctions != (IoFktStruct *)NULL)
         {
            Ms2Client = Ms2Create();
            if (Ms2Client != (Ms2Struct *)NULL)
            {
               Ms2Init(Ms2Client, ConfigGetIntVal(Config, CfgVerboseVal),
                       ConfigGetStrVal(Config, CfgIfaceVal),
                       ConfigGetStrVal(Config, CfgAddrVal),
                       ConfigGetIntVal(Config, CfgPortVal),
                       ConfigGetIntVal(Config, CfgZentraleVal),
                       IoFunctions);
               Ms2Run(Ms2Client);
               Ms2Destroy(Ms2Client);
               Ret = 0;
            }
            else
            {
               puts("ERROR: can not create Ms2Client module");
               Ret = 1;
            }
            CanClientExit(IoFunctions);
         }
         else
         {
            puts("ERROR: can not create IoFunctions module");
            Ret = 1;
         }
      }
      ConfigExit(Config);
      ConfigDestroy(Config);
   }
   else
   {
      puts("ERROR: can not create Config module");
      Ret = 3;
   }
   return(Ret);
}