You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by je...@apache.org on 2003/01/29 07:13:27 UTC

cvs commit: httpd-test/flood CHANGES flood.c

jerenkrantz    2003/01/28 22:13:27

  Modified:    flood    CHANGES flood.c
  Log:
  Added error handling for failed config-file open.
  
  This patch adds error handling to the code that opens the
  configuration file.  When you specify an argument to the flood
  program, it attempts to open it to read in configuration
  information.  Previously, there was no error handling, so
  the code proceeded to use an invalid file handle when the
  file open fails.  The code now detects the failure and displays
  an error message.
  
  The standard error and output file-opens were moved earlier
  in the program in case we need to display error messages
  to standard error.
  
  On Windows, using the invalid file handle results in an
  access violation.  The program now displays a message like
  this:
    Error opening configuration file: The system cannot find
    the file specified.  .
  
  Submitted by: Phi-Long Tran <pt...@pobox.com>
  Reviewed by: Justin Erenkrantz (minor formatting tweak)
  
  Revision  Changes    Path
  1.43      +3 -0      httpd-test/flood/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-test/flood/CHANGES,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -u -r1.42 -r1.43
  --- CHANGES	29 Jan 2003 06:07:49 -0000	1.42
  +++ CHANGES	29 Jan 2003 06:13:27 -0000	1.43
  @@ -1,5 +1,8 @@
   Changes since 1.0:
   
  +* Added error handling for failed config-file open.
  +  [Phi-Long Tran <pt...@pobox.com>]
  +
   * Fix Win32 crash resulting from strtoll() macro
     [Phi-Long Tran <pt...@pobox.com>]
   
  
  
  
  1.9       +13 -7     httpd-test/flood/flood.c
  
  Index: flood.c
  ===================================================================
  RCS file: /home/cvs/httpd-test/flood/flood.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -u -r1.8 -r1.9
  --- flood.c	31 May 2002 07:59:26 -0000	1.8
  +++ flood.c	29 Jan 2003 06:13:27 -0000	1.9
  @@ -144,16 +144,22 @@
       ssl_init_socket(local_pool);
   #endif /* FLOOD_HAS_OPENSSL */
      
  -    if (argc == 1)
  +    apr_file_open_stdout(&local_stdout, local_pool);
  +    apr_file_open_stderr(&local_stderr, local_pool);
  +
  +    if (argc == 1) {
           apr_file_open_stdin(&local_stdin, local_pool);
  -    else
  +    }
  +    else if ((stat = apr_file_open(&local_stdin, argv[1], APR_READ,
  +                         APR_OS_DEFAULT, local_pool)) != APR_SUCCESS)
       {
  -        apr_file_open(&local_stdin, argv[1], APR_READ, APR_OS_DEFAULT, 
  -                      local_pool);
  +        char buf[256];
  +        apr_strerror(stat, (char*) &buf, sizeof(buf));
  +        apr_file_printf(local_stderr,
  +                        "Error opening configuration file: %s.\n",
  +                        (char*)&buf);
  +        exit(-1);
       }
  -
  -    apr_file_open_stdout(&local_stdout, local_pool);
  -    apr_file_open_stderr(&local_stderr, local_pool);
   
       /* parse the config */
       config = parse_config(local_stdin, local_pool);