[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[or-cvs] added error checking into getoptions()



Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/tmp/cvs-serv13157/src/or

Modified Files:
	config.c 
Log Message:
added error checking into getoptions()


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- config.c	3 Jul 2002 16:31:22 -0000	1.2
+++ config.c	3 Jul 2002 16:53:34 -0000	1.3
@@ -8,6 +8,9 @@
 /*
  * Changes :
  * $Log$
+ * Revision 1.3  2002/07/03 16:53:34  montrose
+ * added error checking into getoptions()
+ *
  * Revision 1.2  2002/07/03 16:31:22  montrose
  * Added getoptions() and made minor adjustment to poptReadDefaultOptions()
  *
@@ -95,28 +98,34 @@
    bzero(options,sizeof(or_options_t));   /* zero out options initially */
 
    code = poptGetNextOpt(optCon);         /* first we handle command-line args */
-
-   if ( ConfigFile )                      /* handle user-specified config file if any */
-   {
-      code = poptReadOptions(optCon,ConfigFile);
-      if ( code < -1 ) return code;
-   }
-   else                                   /* load Default configuration files */
+   if ( code == -1 )
    {
-      code = poptReadDefaultOptions(cmd,optCon);
-      if ( code < -1 ) return code;
+      if ( ConfigFile )                   /* handle user-specified config file if any */
+         code = poptReadOptions(optCon,ConfigFile);
+      else                                /* load Default configuration files */
+         code = poptReadDefaultOptions(cmd,optCon);
+   
+      if ( Verbose )                      /* display options upon user request */
+      {
+         printf("\nLogLevel=%s\n",options->LogLevel);
+         printf("RouterFile=%s, PrivateKeyFile=%s\n",options->RouterFile,options->PrivateKeyFile);
+         printf("ORPort=%d, OPPort=%d, APPort=%d\n",options->ORPort,options->OPPort,options->APPort);
+         printf("CoinWeight=%6.4f, MaxConn=%d, TrafficShaping=%d\n\n",options->CoinWeight,options->MaxConn,options->TrafficShaping);
+      }
    }
 
-   if ( Verbose )                         /* display options upon user request */
+   switch(code)                           /* error checking */
    {
-      printf("\nLogLevel=%s\n",options->LogLevel);
-      printf("RouterFile=%s, PrivateKeyFile=%s\n",options->RouterFile,options->PrivateKeyFile);
-      printf("ORPort=%d, OPPort=%d, APPort=%d\n",options->ORPort,options->OPPort,options->APPort);
-      printf("CoinWeight=%6.4f, MaxConn=%d, TrafficShaping=%d\n\n",options->CoinWeight,options->MaxConn,options->TrafficShaping);
+   case INT_MIN:
+      fprintf(stderr, "%s: Unable to open configuration file.\n", ConfigFile);
+   case -1:
+      code = 0;
+   default:
+      fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(code));
    }
 
    poptFreeContext(optCon);
 
-   return 0;
+   return code;
 }