Return-Path: Delivered-To: apmail-httpd-test-dev-archive@httpd.apache.org Received: (qmail 24296 invoked by uid 500); 29 Jan 2003 05:45:29 -0000 Mailing-List: contact test-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: test-dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list test-dev@httpd.apache.org Delivered-To: moderator for test-dev@httpd.apache.org Received: (qmail 60188 invoked from network); 29 Jan 2003 01:56:20 -0000 To: test-dev@httpd.apache.org From: ptran@pobox.com Reply-To: ptran@pobox.com Subject: [PATCH] flood: Added error handling for failed config-file open Date: Tue, 28 Jan 2003 17:56:24 -0800 Sender: ptran@chickenfeet.org Message-Id: <20030129015629.E9AC9194A9@chickenfeet.org> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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);