httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Havard" <bri...@kheldar.apana.org.au>
Subject Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Date Mon, 29 May 2000 09:24:31 GMT
On Sat, 27 May 2000 17:54:31 -0700 (PDT), rbb@covalent.net wrote:

>
>> >And that information can be retrieved with the current code.  Just change
>> >the API if a platform needs to get a buffer returned from ap_dso_error.
>> 
>> Well, the way it is ap_dso_error() is pointless and will never be used on
>> OS/2 and, I suspect, any other non-dl platforms. I figured it was more
>> useful as an ap_strerror() enhanced for dso.
>
>I'll change the API tonight to try to make it more useful for OS/2
>tonight.  If I make the wrong API change, please fix it.

Well, by itself what you've done doesn't really help any and, as OtherBill 
pointed out, is invalid due to the non-static buffer.



On Sun, 28 May 2000 23:10:39 -0500, William A. Rowe, Jr. wrote:

>I respectfully suggest that this is a classic case where an #IFDEF
>is entirely in order, and that ap_dso_error() should go away.
>dlerror() was just fine.  I'd suggest a simple
>#define HAVE_DLERROR
>and include this only if we are building the stock unix dso support 
>into apr (as opposed to the linux build Jeff(?) was playing with).

I tend to aggree with this. Here's what I'd like to do. I know you want to use 
ap_strerror() for everything but that restricts error messages to those that 
can be derived purely from ap_status_t unless you use hacks like global 
variables. I don't see the harm in having a special dso aware version of 
ap_strerror() if ap_strerror() still works.



Index: lib/apr/dso/os2/dso.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/dso/os2/dso.c,v
retrieving revision 1.8
diff -u -r1.8 dso.c
--- lib/apr/dso/os2/dso.c	2000/05/29 02:18:41	1.8
+++ lib/apr/dso/os2/dso.c	2000/05/29 09:17:38
@@ -73,20 +73,22 @@
 
 ap_status_t ap_dso_load(ap_dso_handle_t **res_handle, const char *path, ap_pool_t *ctx)
 {
-    char failed_module[1024];
+    char failed_module[20];
     HMODULE handle;
     int rc;
 
     *res_handle = ap_pcalloc(ctx, sizeof(*res_handle));
+    (*res_handle)->cont = ctx;
+    (*res_handle)->load_error = APR_SUCCESS;
+    (*res_handle)->failed_module = NULL;
 
     if ((rc = DosLoadModule(failed_module, sizeof(failed_module), path, &handle)) !=
0) {
+        (*res_handle)->load_error = APR_OS2_STATUS(rc);
         (*res_handle)->failed_module = ap_pstrdup(ctx, failed_module);
         return APR_OS2_STATUS(rc);
     }
 
     (*res_handle)->handle  = handle;
-    (*res_handle)->cont    = ctx;
-    (*res_handle)->failed_module = NULL;
     ap_register_cleanup(ctx, *res_handle, dso_cleanup, ap_null_cleanup);
     return APR_SUCCESS;
 }
@@ -129,8 +131,13 @@
 
 
 
-/* Just a stub, it will never be called because we never return APR_EDSOOPEN */
-char *ap_dso_error(char *buf, int bufsize, ap_status_t errcode)
+char *ap_dso_error(ap_dso_handle_t *dso, char *buffer, ap_size_t buflen)
 {
-    return NULL;
+    char message[200];
+    ap_strerror(dso->load_error, message, sizeof(message));
+    strcat(message, " (");
+    strcat(message, dso->failed_module);
+    strcat(message, ")");
+    ap_cpystrn(buffer, message, buflen);
+    return buffer;
 }
Index: lib/apr/dso/os2/dso.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/dso/os2/dso.h,v
retrieving revision 1.8
diff -u -r1.8 dso.h
--- lib/apr/dso/os2/dso.h	2000/04/22 06:16:16	1.8
+++ lib/apr/dso/os2/dso.h	2000/05/29 08:49:49
@@ -66,6 +66,7 @@
 struct ap_dso_handle_t {
     ap_pool_t  *cont;       /* Context for returning error strings */
     HMODULE       handle;     /* Handle to the DSO loaded            */
+    ap_status_t   load_error;
     char          *failed_module;
 };
 
Index: lib/apr/dso/unix/dso.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/dso/unix/dso.c,v
retrieving revision 1.15
diff -u -r1.15 dso.c
--- lib/apr/dso/unix/dso.c	2000/05/29 02:18:41	1.15
+++ lib/apr/dso/unix/dso.c	2000/05/29 08:49:51
@@ -70,16 +70,20 @@
     void *os_handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
 #endif    
 
-    if(os_handle == NULL)
+    if(os_handle == NULL) {
 #if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
+        (*res_handle)->errormsg = strerror(errno);
         return errno;
 #else
+        (*res_handle)->errormsg = dlerror();
         return APR_EDSOOPEN;
 #endif
+    }
 
     *res_handle = ap_pcalloc(ctx, sizeof(*res_handle));
     (*res_handle)->handle = (void*)os_handle;
     (*res_handle)->cont = ctx;
+    (*res_handle)->errormsg = NULL;
     return APR_SUCCESS;
 }
     
@@ -134,13 +138,9 @@
     return APR_SUCCESS;
 }
 
-char *ap_dso_error(char *buf, int bufsize, ap_status_t errcode)
+char *ap_dso_error(ap_dso_handle_t *dso, char *buffer, ap_size_t buflen)
 {
-#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
-    return strerror(errno);
-#elif defined(HAVE_DYLD)
-    return NULL;
-#else
-    return dlerror();
-#endif
+    if (dso->errormsg)
+        return dso->errormsg;
+    return "No Error";
 }
Index: lib/apr/dso/unix/dso.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/dso/unix/dso.h,v
retrieving revision 1.7
diff -u -r1.7 dso.h
--- lib/apr/dso/unix/dso.h	2000/04/22 06:16:16	1.7
+++ lib/apr/dso/unix/dso.h	2000/05/29 08:49:51
@@ -85,6 +85,7 @@
 struct ap_dso_handle_t {
     ap_pool_t  *cont;
     void          *handle;
+    char          *errormsg;
 };
 
 #endif
Index: lib/apr/dso/win32/dso.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/dso/win32/dso.c,v
retrieving revision 1.5
diff -u -r1.5 dso.c
--- lib/apr/dso/win32/dso.c	2000/05/29 02:18:42	1.5
+++ lib/apr/dso/win32/dso.c	2000/05/29 08:49:52
@@ -62,13 +62,16 @@
                         ap_pool_t *ctx)
 {
     HINSTANCE os_handle = LoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+    *res_handle = ap_pcalloc(ctx, sizeof(*res_handle));
+
     if(os_handle == NULL) {
-        return GetLastError();
+        (*res_handle)->load_error = GetLastError();
+        return (*res_handle)->load_error;
     }
 
-    *res_handle = ap_pcalloc(ctx, sizeof(*res_handle));
     (*res_handle)->handle = (void*)os_handle;
     (*res_handle)->cont = ctx;
+    (*res_handle)->load_error = APR_SUCCESS;
     return APR_SUCCESS;
 }
     
@@ -94,7 +97,7 @@
     return APR_SUCCESS;
 }
 
-char *ap_dso_error(char *buf, int bufsize, ap_status_t errcode)
+char *ap_dso_error(ap_dso_handle_t *dso, char *buf, ap_size_t bufsize)
 {
-    return "An error occured loading a DLL.";
+    return ap_strerror(dso->load_error, buf, bufsize);
 }
Index: lib/apr/dso/win32/dso.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/dso/win32/dso.h,v
retrieving revision 1.3
diff -u -r1.3 dso.h
--- lib/apr/dso/win32/dso.h	2000/04/22 06:16:17	1.3
+++ lib/apr/dso/win32/dso.h	2000/05/29 08:49:52
@@ -63,6 +63,7 @@
 struct ap_dso_handle_t {
     ap_pool_t  *cont;
     void          *handle;
+    ap_status_t   load_error;
 };
 
 #endif
Index: lib/apr/include/apr_dso.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_dso.h,v
retrieving revision 1.12
diff -u -r1.12 apr_dso.h
--- lib/apr/include/apr_dso.h	2000/05/29 02:18:43	1.12
+++ lib/apr/include/apr_dso.h	2000/05/29 08:49:52
@@ -117,7 +117,7 @@
 ap_status_t ap_dso_sym(ap_dso_handle_sym_t *ressym, ap_dso_handle_t *handle, 
                        const char *symname);
 
-char *ap_dso_error(char *buf, int bufsize, ap_status_t errcode);
+char *ap_dso_error(ap_dso_handle_t *dso, char *buf, ap_size_t bufsize);
 
 #ifdef __cplusplus
 }
Index: lib/apr/misc/unix/errorcodes.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/errorcodes.c,v
retrieving revision 1.18
diff -u -r1.18 errorcodes.c
--- lib/apr/misc/unix/errorcodes.c	2000/05/29 02:18:44	1.18
+++ lib/apr/misc/unix/errorcodes.c	2000/05/29 08:49:54
@@ -74,7 +74,6 @@
 
 static char *apr_error_string(ap_status_t statcode)
 {
-    char buf[256];
     switch (statcode) {
     case APR_ENOPOOL:
         return "A new pool could not be created.";
@@ -103,7 +102,11 @@
     case APR_ENOSHMAVAIL:
         return "No shared memory is currently available";
     case APR_EDSOOPEN:
-        return ap_dso_error(buf, sizeof(buf), APR_EDSOOPEN);
+#ifdef HAVE_LIBDL
+        return dlerror();
+#else
+        return "DSO load failed";
+#endif
     case APR_INCHILD:
         return
 	    "Your code just forked, and you are currently executing in the "
Index: modules/standard/mod_so.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_so.c,v
retrieving revision 1.20
diff -u -r1.20 mod_so.c
--- modules/standard/mod_so.c	2000/05/27 22:40:37	1.20
+++ modules/standard/mod_so.c	2000/05/29 08:50:11
@@ -260,7 +260,7 @@
 
         return ap_pstrcat(cmd->pool, "Cannot load ", szModuleFile,
 			  " into server: ",
-			  ap_strerror(status, my_error, sizeof(my_error)),
+			  ap_dso_error(modhandle, my_error, sizeof(my_error)),
 			  NULL);
     }
     ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL,

-- 
 ______________________________________________________________________________
 |  Brian Havard                 |  "He is not the messiah!                   |
 |  brianh@kheldar.apana.org.au  |  He's a very naughty boy!" - Life of Brian |
 ------------------------------------------------------------------------------


Mime
View raw message