Re: glob in Safe compartment allows shell access
[p5sagit/p5-mst-13.2.git] / ext / DynaLoader / dl_dlopen.xs
index ffd3dbc..5dfe5c1 100644 (file)
@@ -34,7 +34,7 @@
      error.
 
      The mode parameter must be set to 1 for Solaris 1 and to
-     RTLD_LAZY on Solaris 2.
+     RTLD_LAZY (==2) on Solaris 2.
 
 
    dlsym
@@ -74,7 +74,7 @@
    Dean Roerich's Perl 5 API document. Also, have a look in the typemap 
    file (in the ext directory) for a fairly comprehensive list of types 
    that are already supported. If you are completely stuck, I suggest you
-   post a message to perl5-porters, comp.lang.perl or if you are really 
+   post a message to perl5-porters, comp.lang.perl.misc or if you are really 
    desperate to me.
 
    Remember when you are making any changes that the return value from 
 #include <link.h>
 #endif
 
+#ifndef RTLD_LAZY
+# define RTLD_LAZY 1   /* Solaris 1 */
+#endif
+
 #ifndef HAS_DLERROR
-#define dlerror() "Unknown error - dlerror() not implemented"
+# ifdef __NetBSD__
+#  define dlerror() strerror(errno)
+# else
+#  define dlerror() "Unknown error - dlerror() not implemented"
+# endif
 #endif
 
 
@@ -138,13 +146,14 @@ void *
 dl_load_file(filename)
     char *             filename
     CODE:
-    int mode = 1;     /* Solaris 1 */
-#ifdef RTLD_LAZY
-    mode = RTLD_LAZY; /* Solaris 2 */
+    int mode = RTLD_LAZY;
+#ifdef RTLD_NOW
+    if (dl_nonlazy)
+       mode = RTLD_NOW;
 #endif
-    DLDEBUG(1,fprintf(stderr,"dl_load_file(%s):\n", filename));
+    DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dl_load_file(%s):\n", filename));
     RETVAL = dlopen(filename, mode) ;
-    DLDEBUG(2,fprintf(stderr," libref=%x\n", RETVAL));
+    DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), " libref=%x\n", RETVAL));
     ST(0) = sv_newmortal() ;
     if (RETVAL == NULL)
        SaveError("%s",dlerror()) ;
@@ -161,10 +170,10 @@ dl_find_symbol(libhandle, symbolname)
     char symbolname_buf[1024];
     symbolname = dl_add_underscore(symbolname, symbolname_buf);
 #endif
-    DLDEBUG(2,fprintf(stderr,"dl_find_symbol(handle=%x, symbol=%s)\n",
+    DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "dl_find_symbol(handle=%x, symbol=%s)\n",
        libhandle, symbolname));
     RETVAL = dlsym(libhandle, symbolname);
-    DLDEBUG(2,fprintf(stderr,"  symbolref = %x\n", RETVAL));
+    DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "  symbolref = %x\n", RETVAL));
     ST(0) = sv_newmortal() ;
     if (RETVAL == NULL)
        SaveError("%s",dlerror()) ;
@@ -186,7 +195,7 @@ dl_install_xsub(perl_name, symref, filename="$Package")
     void *             symref 
     char *             filename
     CODE:
-    DLDEBUG(2,fprintf(stderr,"dl_install_xsub(name=%s, symref=%x)\n",
+    DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "dl_install_xsub(name=%s, symref=%x)\n",
                perl_name, symref));
     ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)())symref, filename)));