Summary: * 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. . Index: flood.c =================================================================== RCS file: /home/cvspublic/httpd-test/flood/flood.c,v retrieving revision 1.8 diff -u -r1.8 flood.c --- flood.c 31 May 2002 07:59:26 -0000 1.8 +++ flood.c 29 Jan 2003 00:09:37 -0000 @@ -144,16 +144,20 @@ ssl_init_socket(local_pool); #endif /* FLOOD_HAS_OPENSSL */ + 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);