From: Stephen D. <sd...@us...> - 2005-07-22 06:47:20
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28940/nsd Modified Files: modload.c nsd.h Log Message: * include/ns.h: * nsd/nsd.h: * nsd/modload.c: Untabify and reformat. Add CONST declarations. Index: modload.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/modload.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** modload.c 10 Jun 2005 17:58:39 -0000 1.2 --- modload.c 22 Jul 2005 06:46:40 -0000 1.3 *************** *** 1,7 **** /* ! * The contents of this file are subject to the AOLserver Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at ! * http://aolserver.com/. * * Software distributed under the License is distributed on an "AS IS" --- 1,7 ---- /* ! * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at ! * http://mozilla.org/. * * Software distributed under the License is distributed on an "AS IS" *************** *** 32,36 **** * modload.c -- * ! * Load .so files into the server and initialize them. */ --- 32,36 ---- * modload.c -- * ! * Load .so files into the server and initialize them. */ *************** *** 39,61 **** NS_RCSID("@(#) $Header$"); #if defined(USE_DLSHL) ! #include <dl.h> #elif defined(USE_DYLD) ! #include <mach-o/dyld.h> ! static char *dylderr = ""; #elif !defined(_WIN32) ! #include <dlfcn.h> ! #ifdef USE_RTLD_LAZY ! #ifdef RTLD_NOW ! #undef RTLD_NOW ! #endif ! #define RTLD_NOW RTLD_LAZY ! #endif ! #ifndef RTLD_GLOBAL ! #define RTLD_GLOBAL 0 ! #endif ! #ifndef RTLD_NOW ! #define RTLD_NOW 0 ! #endif #endif --- 39,62 ---- NS_RCSID("@(#) $Header$"); + #if defined(USE_DLSHL) ! # include <dl.h> #elif defined(USE_DYLD) ! # include <mach-o/dyld.h> ! static char *dylderr = ""; #elif !defined(_WIN32) ! # include <dlfcn.h> ! # ifdef USE_RTLD_LAZY ! # ifdef RTLD_NOW ! # undef RTLD_NOW ! # endif ! # define RTLD_NOW RTLD_LAZY ! # endif ! # ifndef RTLD_GLOBAL ! # define RTLD_GLOBAL 0 ! # endif ! # ifndef RTLD_NOW ! # define RTLD_NOW 0 ! # endif #endif *************** *** 65,83 **** typedef struct Module { ! struct Module *nextPtr; ! char *name; Ns_ModuleInitProc *proc; } Module; /* ! * Static variables defined in this file. */ ! static Tcl_HashTable modulesTable; ! static void *DlOpen(char *file); ! static void *DlSym(void *handle, char *name); ! static void *DlSym2(void *handle, char *name); static char *DlError(void); ! static Module *firstPtr; --- 66,89 ---- typedef struct Module { ! struct Module *nextPtr; ! char *name; Ns_ModuleInitProc *proc; } Module; /* ! * Static functions defined in this file. */ ! static void *DlOpen(CONST char *file); ! static void *DlSym(void *handle, CONST char *name); ! static void *DlSym2(void *handle, CONST char *name); static char *DlError(void); ! ! /* ! * Static variables defined in this file. ! */ ! ! static Tcl_HashTable modulesTable; /* Table of loaded, loadable modules. */ ! static Module *firstPtr; /* List of static modules to be initilaized. */ *************** *** 87,97 **** * NsInitModLoad -- * ! * Initialize module table. * * Results: ! * None. * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 93,103 ---- * NsInitModLoad -- * ! * Initialize module table. * * Results: ! * None. * * Side effects: ! * None. * *---------------------------------------------------------------------- *************** *** 114,127 **** * Ns_RegisterModule -- * ! * Register a static module. This routine can only be called from ! * a Ns_ServerInitProc passed to Ns_Main or within the Ns_ModuleInit ! * proc of a loadable module. It registers a module callback for ! * for the currently initializing server. * * Results: ! * None. * * Side effects: ! * Proc will be called after dynamic modules are loaded. * *---------------------------------------------------------------------- --- 120,133 ---- * Ns_RegisterModule -- * ! * Register a static module. This routine can only be called from ! * a Ns_ServerInitProc passed to Ns_Main or within the Ns_ModuleInit ! * proc of a loadable module. It registers a module callback for ! * for the currently initializing server. * * Results: ! * None. * * Side effects: ! * Proc will be called after dynamic modules are loaded. * *---------------------------------------------------------------------- *************** *** 129,133 **** void ! Ns_RegisterModule(char *name, Ns_ModuleInitProc *proc) { Module *modPtr, **nextPtrPtr; --- 135,139 ---- void ! Ns_RegisterModule(CONST char *name, Ns_ModuleInitProc *proc) { Module *modPtr, **nextPtrPtr; *************** *** 139,143 **** nextPtrPtr = &firstPtr; while (*nextPtrPtr != NULL) { ! nextPtrPtr = &((*nextPtrPtr)->nextPtr); } *nextPtrPtr = modPtr; --- 145,149 ---- nextPtrPtr = &firstPtr; while (*nextPtrPtr != NULL) { ! nextPtrPtr = &((*nextPtrPtr)->nextPtr); } *nextPtrPtr = modPtr; *************** *** 150,161 **** * Ns_ModuleLoad -- * ! * Load a module and initialize it. The result code from modules ! * without the version symbol are ignored. * * Results: ! * NS_OK or NS_ERROR * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 156,167 ---- * Ns_ModuleLoad -- * ! * Load a module and initialize it. The result code from modules ! * without the version symbol are ignored. * * Results: ! * NS_OK or NS_ERROR. * * Side effects: ! * None. * *---------------------------------------------------------------------- *************** *** 163,167 **** int ! Ns_ModuleLoad(char *server, char *module, char *file, char *init) { Ns_ModuleInitProc *initProc; --- 169,174 ---- int ! Ns_ModuleLoad(CONST char *server, CONST char *module, CONST char *file, ! CONST char *init) { Ns_ModuleInitProc *initProc; *************** *** 171,175 **** initProc = Ns_ModuleSymbol(file, init); if (initProc == NULL) { ! return NS_ERROR; } verPtr = Ns_ModuleSymbol(file, "Ns_ModuleVersion"); --- 178,182 ---- initProc = Ns_ModuleSymbol(file, init); if (initProc == NULL) { ! return NS_ERROR; } verPtr = Ns_ModuleSymbol(file, "Ns_ModuleVersion"); *************** *** 178,183 **** status = NS_OK; } else if (status != NS_OK) { ! Ns_Log(Error, "modload: init %s of %s returned: %d", file, init, status); } return status; } --- 185,191 ---- status = NS_OK; } else if (status != NS_OK) { ! Ns_Log(Error, "modload: init %s of %s returned: %d", file, init, status); } + return status; } *************** *** 189,200 **** * Ns_ModuleSymbol -- * ! * Load a module if it's not already loaded, and extract a ! * requested symbol from it. * * Results: ! * A pointer to the symbol's value. * * Side effects: ! * May load the module if it hasn't been loaded yet. * *---------------------------------------------------------------------- --- 197,208 ---- * Ns_ModuleSymbol -- * ! * Load a module if it's not already loaded, and extract the ! * requested symbol from it. * * Results: ! * A pointer to the symbol's value. * * Side effects: ! * May load the module if it hasn't been loaded yet. * *---------------------------------------------------------------------- *************** *** 202,215 **** void * ! Ns_ModuleSymbol(char *file, char *name) { Tcl_HashEntry *hPtr; Ns_DString ds; ! int new; ! void *module; void *symbol; struct stat st; #ifndef _WIN32 ! FileKey key; #endif --- 210,223 ---- void * ! Ns_ModuleSymbol(CONST char *file, CONST char *name) { Tcl_HashEntry *hPtr; Ns_DString ds; ! int new; ! void *module; void *symbol; struct stat st; #ifndef _WIN32 ! FileKey key; #endif *************** *** 220,225 **** } if (stat(file, &st) != 0) { ! Ns_Log(Notice, "modload: stat(%s) failed: %s", file, strerror(errno)); ! goto done; } #ifdef _WIN32 --- 228,233 ---- } if (stat(file, &st) != 0) { ! Ns_Log(Notice, "modload: stat(%s) failed: %s", file, strerror(errno)); ! goto done; } #ifdef _WIN32 *************** *** 233,251 **** module = Tcl_GetHashValue(hPtr); } else { ! Ns_Log(Notice, "modload: loading '%s'", file); ! module = DlOpen(file); ! if (module == NULL) { Ns_Log(Warning, "modload: could not load %s: %s", file, DlError()); Tcl_DeleteHashEntry(hPtr); ! goto done; ! } Tcl_SetHashValue(hPtr, module); } symbol = DlSym(module, name); if (symbol == NULL) { ! Ns_Log(Warning, "modload: could not find %s in %s", name, file); } ! done: Ns_DStringFree(&ds); return symbol; } --- 241,261 ---- module = Tcl_GetHashValue(hPtr); } else { ! Ns_Log(Notice, "modload: loading '%s'", file); ! module = DlOpen(file); ! if (module == NULL) { Ns_Log(Warning, "modload: could not load %s: %s", file, DlError()); Tcl_DeleteHashEntry(hPtr); ! goto done; ! } Tcl_SetHashValue(hPtr, module); } symbol = DlSym(module, name); if (symbol == NULL) { ! Ns_Log(Warning, "modload: could not find %s in %s", name, file); } ! ! done: Ns_DStringFree(&ds); + return symbol; } *************** *** 257,270 **** * Ns_ModuleGetSymbol -- * ! * Locate a given symbol in the program's symbol table and ! * return the address of it. This differs from the other Module ! * functions in that it doesn't require the shared library file ! * name - this should sniff the entire symbol space. * * Results: ! * A pointer to the requested symbol's value. * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 267,280 ---- * Ns_ModuleGetSymbol -- * ! * Locate a given symbol in the program's symbol table and ! * return the address of it. This differs from the other Module ! * functions in that it doesn't require the shared library file ! * name - this should sniff the entire symbol space. * * Results: ! * A pointer to the requested symbol's value. * * Side effects: ! * None. * *---------------------------------------------------------------------- *************** *** 272,276 **** void * ! Ns_ModuleGetSymbol(char *name) { return DlSym(NULL, name); --- 282,286 ---- void * ! Ns_ModuleGetSymbol(CONST char *name) { return DlSym(NULL, name); *************** *** 283,293 **** * NsLoadModules -- * ! * Load all modules for given server. * * Results: ! * None. * * Side effects: ! * Will load and initialize modules. * *---------------------------------------------------------------------- --- 293,303 ---- * NsLoadModules -- * ! * Load all modules for given server. * * Results: ! * None. * * Side effects: ! * Will load and initialize modules. * *---------------------------------------------------------------------- *************** *** 295,299 **** void ! NsLoadModules(char *server) { Ns_Set *modules; --- 305,309 ---- void ! NsLoadModules(CONST char *server) { Ns_Set *modules; *************** *** 304,318 **** modules = Ns_ConfigGetSection(Ns_ConfigGetPath(server, NULL, "modules", NULL)); for (i = 0; modules != NULL && i < Ns_SetSize(modules); ++i) { ! module = Ns_SetKey(modules, i); file = Ns_SetValue(modules, i); ! /* ! * Check for specific module init after filename. ! */ s = strchr(file, '('); if (s == NULL) { ! init = "Ns_ModuleInit"; ! } else { *s = '\0'; init = s + 1; --- 314,328 ---- modules = Ns_ConfigGetSection(Ns_ConfigGetPath(server, NULL, "modules", NULL)); for (i = 0; modules != NULL && i < Ns_SetSize(modules); ++i) { ! module = Ns_SetKey(modules, i); file = Ns_SetValue(modules, i); ! /* ! * Check for specific module init after filename. ! */ s = strchr(file, '('); if (s == NULL) { ! init = "Ns_ModuleInit"; ! } else { *s = '\0'; init = s + 1; *************** *** 321,337 **** *e = '\0'; } ! } ! /* ! * Load the module if it's not the reserved "tcl" name. ! */ ! ! if (!STRIEQ(file, "tcl") && Ns_ModuleLoad(server, module, file, init) != NS_OK) { ! Ns_Fatal("modload: failed to load module '%s'", file); } ! /* ! * Add this module to the server Tcl init list. ! */ Ns_TclInitModule(server, module); --- 331,347 ---- *e = '\0'; } ! } ! /* ! * Load the module if it's not the reserved "tcl" name. ! */ ! ! if (!STRIEQ(file, "tcl") && Ns_ModuleLoad(server, module, file, init) != NS_OK) { ! Ns_Fatal("modload: failed to load module '%s'", file); } ! /* ! * Add this module to the server Tcl init list. ! */ Ns_TclInitModule(server, module); *************** *** 352,367 **** while (firstPtr != NULL) { ! modPtr = firstPtr; ! firstPtr = NULL; ! while (modPtr != NULL) { ! nextPtr = modPtr->nextPtr; ! Ns_Log(Notice, "modload: initializing module '%s'", modPtr->name); ! if ((*modPtr->proc)(server, modPtr->name) != NS_OK) { ! Ns_Fatal("modload: failed to initialize %s", modPtr->name); ! } ! ns_free(modPtr->name); ! ns_free(modPtr); ! modPtr = nextPtr; ! } } } --- 362,377 ---- while (firstPtr != NULL) { ! modPtr = firstPtr; ! firstPtr = NULL; ! while (modPtr != NULL) { ! nextPtr = modPtr->nextPtr; ! Ns_Log(Notice, "modload: initializing module '%s'", modPtr->name); ! if ((*modPtr->proc)(server, modPtr->name) != NS_OK) { ! Ns_Fatal("modload: failed to initialize %s", modPtr->name); ! } ! ns_free(modPtr->name); ! ns_free(modPtr); ! modPtr = nextPtr; ! } } } *************** *** 373,383 **** * DlOpen -- * ! * Load a dynamic library * * Results: ! * An Ns_ModHandle, or NULL on failure. * * Side effects: ! * See shl_load * *---------------------------------------------------------------------- --- 383,393 ---- * DlOpen -- * ! * Load a dynamic library. * * Results: ! * An Ns_ModHandle, or NULL on failure. * * Side effects: ! * See shl_load. * *---------------------------------------------------------------------- *************** *** 385,389 **** static void * ! DlOpen(char *file) { #if defined(USE_DYLD) --- 395,399 ---- static void * ! DlOpen(CONST char *file) { #if defined(USE_DYLD) *************** *** 391,395 **** NSObjectFileImage image; NSModule module; ! NSObjectFileImageReturnCode err; module = NULL; --- 401,405 ---- NSObjectFileImage image; NSModule module; ! NSObjectFileImageReturnCode err; module = NULL; *************** *** 398,433 **** err = NSCreateObjectFileImageFromFile(file, &image); switch (err) { ! case NSObjectFileImageSuccess: module = NSLinkModule(image, file, TRUE); ! break; ! case NSObjectFileImageInappropriateFile: ! dylderr = "Inappropriate Mach-O file"; ! retry = 1; ! break; ! case NSObjectFileImageArch: ! dylderr = "Inappropriate Mach-O architecture"; ! break; ! case NSObjectFileImageFormat: ! dylderr = "Invalid Mach-O file format"; ! retry = 1; ! break; ! case NSObjectFileImageAccess: ! dylderr = "Permission denied"; ! break; ! default: ! dylderr = "Unknown error"; ! break; } if (retry) { ! /* ! * Fallback to open shared library. ! */ ! module = (void *)NSAddImage(file, ! NSADDIMAGE_OPTION_WITH_SEARCHING | ! NSADDIMAGE_OPTION_RETURN_ON_ERROR); } return (void *) module; #elif defined(_WIN32) return (void *) LoadLibrary(file); --- 408,446 ---- err = NSCreateObjectFileImageFromFile(file, &image); switch (err) { ! case NSObjectFileImageSuccess: module = NSLinkModule(image, file, TRUE); ! break; ! case NSObjectFileImageInappropriateFile: ! dylderr = "Inappropriate Mach-O file"; ! retry = 1; ! break; ! case NSObjectFileImageArch: ! dylderr = "Inappropriate Mach-O architecture"; ! break; ! case NSObjectFileImageFormat: ! dylderr = "Invalid Mach-O file format"; ! retry = 1; ! break; ! case NSObjectFileImageAccess: ! dylderr = "Permission denied"; ! break; ! default: ! dylderr = "Unknown error"; ! break; } + if (retry) { ! /* ! * Fallback to open shared library. ! */ ! module = (void *) NSAddImage(file, ! NSADDIMAGE_OPTION_WITH_SEARCHING ! | NSADDIMAGE_OPTION_RETURN_ON_ERROR); } + return (void *) module; + #elif defined(_WIN32) return (void *) LoadLibrary(file); *************** *** 445,455 **** * DlSym -- * ! * Load a symbol from a shared object * * Results: ! * A symbol pointer or null on error. * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 458,468 ---- * DlSym -- * ! * Load a symbol from a shared object. * * Results: ! * A symbol pointer or null on error. * * Side effects: ! * None. * *---------------------------------------------------------------------- *************** *** 457,461 **** static void * ! DlSym(void *handle, char *name) { Ns_DString ds; --- 470,474 ---- static void * ! DlSym(void *handle, CONST char *name) { Ns_DString ds; *************** *** 480,484 **** static void * ! DlSym2(void *handle, char *name) { void *symbol = NULL; --- 493,497 ---- static void * ! DlSym2(void *handle, CONST char *name) { void *symbol = NULL; *************** *** 489,497 **** } #elif defined(_WIN32) ! symbol = (void *) GetProcAddress((HMODULE) handle, name); #elif (USE_DYLD) symbol = (void *) NSLookupSymbolInModule(handle, name); if (symbol == NULL) { ! /* * Fallback to get symbol from shared library --- 502,510 ---- } #elif defined(_WIN32) ! symbol = (void *) GetProcAddress((HMODULE) handle, name); #elif (USE_DYLD) symbol = (void *) NSLookupSymbolInModule(handle, name); if (symbol == NULL) { ! /* * Fallback to get symbol from shared library *************** *** 499,511 **** symbol = (void *) NSLookupSymbolInImage(handle, name, ! NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | ! NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); } if (symbol != NULL) { ! symbol = (void *) NSAddressOfSymbol(symbol); } #else symbol = dlsym(handle, name); #endif return symbol; } --- 512,525 ---- symbol = (void *) NSLookupSymbolInImage(handle, name, ! NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW ! | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); } if (symbol != NULL) { ! symbol = (void *) NSAddressOfSymbol(symbol); } #else symbol = dlsym(handle, name); #endif + return symbol; } *************** *** 517,527 **** * DlError -- * ! * Return the error code from trying to load a shared object * * Results: ! * A string error. * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 531,541 ---- * DlError -- * ! * Return the error code from trying to load a shared object. * * Results: ! * A string error. * * Side effects: ! * None. * *---------------------------------------------------------------------- Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** nsd.h 22 Jul 2005 06:41:28 -0000 1.25 --- nsd.h 22 Jul 2005 06:46:40 -0000 1.26 *************** *** 954,958 **** extern void NsTclInitServer(CONST char *server) NS_GNUC_NONNULL(1); ! extern void NsLoadModules(char *server); extern struct Bucket *NsTclCreateBuckets(char *server, int nbuckets); --- 954,958 ---- extern void NsTclInitServer(CONST char *server) NS_GNUC_NONNULL(1); ! extern void NsLoadModules(CONST char *server); extern struct Bucket *NsTclCreateBuckets(char *server, int nbuckets); |