httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject [PATCH] ap_strerror()
Date Wed, 29 Mar 2000 11:12:30 GMT
handle these types of ap_status_t values on this pass:

. errno
. APR errors (APR_ENOSTAT, APR_ENOPOOL, etc.) and status codes
. OS-specific primary error codes
  + Win32: Windows errors (ERROR_INVALID_FUNCTION, ERROR_FILE_NOT_FOUND, etc.)

libtool codes not supported yet, but only a tweak or two required; let's
get something agreeable and workable first

ranges:

0
1..APR_OS_START_ERROR-1                       errno
APR_OS_START_ERROR..APR_OS_START_STATUS-1     APR error codes
APR_OS_START_STATUS..APR_OS_START_SYSERR-1    APR status codes
APR_OS_START_SYSERR..APR_OS_START_USEERR-1    OS-specific primary error codes
APR_OS_START_USEERR..whatever                 other-library primary error codes

code that returns an ap_status_t...

  if from errno, return it as-is

  if a special APR error or status code, return it as-is because the definition of 
    the constant puts it in the correct range

  if an operating system-specific primary error code, add APR_OS_START_SYSERR
    to it to get ap_status_t

to resolve:

  Win32 build - the makefile exported from my updated aprlib.dsp doesn't clean properly
  Makefile.in: are dependencies at the bottom built automatically?  do I hard-code there?

  get serious about maintaining ap_status_t properly:
    Win32: gotta be serious about this and return APR_OS_START_SYSERR+GetLastError() from
           APR functions; don't be passing GetLastError() to ap_log_error() anywhere
    anybody: don't be passing errno to ap_log_error() anywhere after an APR function fails

not finished:

  test Win32 support better
  flush out apr_error_str() and apr_status_str()
  change Win32 APR code to build ap_status_t properly when starting
    with a Windows error code

    possible macro: #define AP_STATUS_FROM_SYSERR(x) ((x)+APR_OS_START_SYSERR)

? lib/apr/lib/apr_strerr.c
/* ====================================================================
 * Copyright (c) 1995-2000 The Apache Software Foundation.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the Apache Software Foundation
 *    for use in the Apache HTTP server project (http://www.apache.org/)."
 *
 * 4. The names "Apache Server" and "Apache Software Foundation" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache"
 *    nor may "Apache" appear in their names without prior written
 *    permission of the Apache Software Foundation.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the Apache Software Foundation
 *    for use in the Apache HTTP server project (http://www.apache.org/)."
 *
 * THIS SOFTWARE IS PROVIDED BY THE Apache Software Foundation ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE Apache Software Foundation OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was originally based
 * on public domain software written at the National Center for
 * Supercomputing Applications, University of Illinois, Urbana-Champaign.
 * For more information on the Apache Software Foundation and the Apache HTTP server
 * project, please see <http://www.apache.org/>.
 *
 */

#ifndef WIN32
#include "apr_config.h"
#else
#include "apr_winconfig.h"
#endif

#include "apr_general.h"
#include "apr_lib.h"

#include <string.h>

static char *apr_error_str(ap_status_t status)
{
    switch(status) {
    case APR_ENOSTAT:
        return "stat() failed";
    case APR_ENOPOOL:
        return "a pool could not be created";

        /* ... forever ... */
    }

    return "unknown APR error";
}

static char *apr_status_str(ap_status_t status)
{
    switch(status) {
    case APR_INCHILD:
        return "in child";
    case APR_INPARENT:
        return "in parent";

        /* ... forever ... */
    }

    return "unknown APR status";
}

/* ***APRDOC********************************************************
 * char *ap_strerror(ap_status_t status)
 *    Obtain a printable description of status.  This is similar to
 *    the C Standard Library function strerror().
 * arg 1) The APR status/error code variable to describe.
 * arg 2) Pointer to buffer to contain the description.  This is the
 *        returned value.  A terminating '\0' is always stored, even
 *        if there is not enough room for the entire description.
 * arg 3) Size of buffer pointed to by arg 2.
 */           
char *ap_strerror(ap_status_t status, char *buf, size_t buf_size)
{
    char *msg = NULL;

    if (!msg && status < 0) {
        msg = "negative ap_status_t";
    }

    if (!msg && status == 0) {
        msg = "no error occurred";
    }

    if (!msg && status < APR_OS_START_ERROR) {
        msg = strerror(status);
    }

    if (!msg && status < APR_OS_START_STATUS) {
        msg = apr_error_str(status);
    }

    if (!msg && status < APR_OS_START_SYSERR) {
        msg = apr_status_str(status);
    }

#if defined(WIN32)
    if (!msg)
    {
        LPVOID ptr = 0;

        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                      FORMAT_MESSAGE_FROM_SYSTEM,
                      NULL, status - APR_OS_START_SYSERR,
                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                      (LPTSTR)&ptr, 0, NULL);

        if (ptr) {
            ap_cpystrn(buf, ptr, buf_size);
            LocalFree(ptr);
            return buf;
        }
    }
#endif

    if (!msg) {
        msg = "unknown error";
    }
    ap_cpystrn(buf, msg, buf_size);
    return buf;
}

Index: lib/apr/aprlib.def
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/aprlib.def,v
retrieving revision 1.14
diff -u -r1.14 aprlib.def
--- aprlib.def	2000/03/28 22:59:02	1.14
+++ aprlib.def	2000/03/29 05:12:55
@@ -237,4 +237,5 @@
       ap_open_stderr @216
         ap_set_pipe_timeout   @217
         ap_terminate @218
+        ap_strerror @219
 
Index: lib/apr/include/apr_errno.h
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/include/apr_errno.h,v
retrieving revision 1.15
diff -u -r1.15 apr_errno.h
--- apr_errno.h	2000/03/27 19:02:18	1.15
+++ apr_errno.h	2000/03/29 05:12:56
@@ -82,13 +82,12 @@
 #define APR_OS_START_SYSERR  (APR_OS_START_STATUS + 500)
 #endif
 #ifndef APR_OS_START_USEERR
-#define APR_OS_START_USEERR  (APR_OS_START_SYSERR + 500)
+#define APR_OS_START_USEERR  (APR_OS_START_SYSERR + 10000)
 #endif
 
-/* If this definition of APRStatus changes, then we can remove this, but right
- * now, the decision was to use an errno-like implementation.
- */
 typedef int ap_status_t;
+
+char *ap_strerror(ap_status_t status, char *buf, size_t buf_size);
 
 #define APR_SUCCESS 0
 
Index: lib/apr/lib/Makefile.in
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/lib/Makefile.in,v
retrieving revision 1.10
diff -u -r1.10 Makefile.in
--- Makefile.in	2000/03/18 12:32:17	1.10
+++ Makefile.in	2000/03/29 05:12:56
@@ -25,7 +25,8 @@
 	apr_slack.o \
 	apr_snprintf.o \
 	apr_tables.o \
-	apr_getpass.o
+	apr_getpass.o \
+	apr_strerr.o
 
 .c.o:
 	$(CC) $(CFLAGS) -c $(INCLUDES) $<
Index: main/http_log.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/main/http_log.c,v
retrieving revision 1.35
diff -u -r1.35 http_log.c
--- http_log.c	2000/03/13 20:27:19	1.35
+++ http_log.c	2000/03/29 05:12:58
@@ -411,11 +411,12 @@
 	len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
 		"[client %s] ", r->connection->remote_ip);
     }
-    /* XXX - need an APRized strerror() */
     if (!(level & APLOG_NOERRNO)
 	&& (status != 0)) {
+        char desc[80];
+        ap_strerror(status, desc, sizeof (desc));
 	len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
-		"(%d)%s: ", status, strerror(status));
+		"(%d)%s: ", status, desc);
     }
 
     len += ap_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);


-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message