BashLoadable_diff_4 - آموزش اسکریپت نویسی
X
تبلیغات
رایتل

آموزش اسکریپت نویسی

آموزش اسکریپت نویسی پوسته گنو-لینوکس

#!/bin/bash

BashLoadable_diff_4

پیوست BashLoadable

پیوست ‎'bash-4.0-shl.diff'‎

دانلود

   1 This patch adds shl_load (old HP-UX) support to bash 4.0 for enabling
   2 loadable builtins.  In order for bash on HP-UX to actually load most of
   3 the builtins, it must be linked with the linker's -E flag as well, so
   4 you'll need to do something like this:
   5 
   6  .../bash-4.0$ patch -p1 < ../bash-4.0-shl.diff
   7  .../bash-4.0$ autoconf
   8  .../bash-4.0$ CC=gcc LDFLAGS=-Wl,-E ./configure
   9  .../bash-4.0$ make
  10 
  11 If you're using the native HP-UX compiler, then the options may differ.
  12 
  13 --- bash-4.0/config.h.in	Sun Feb  1 17:07:23 2009
  14 +++ bash-4.0-shl/config.h.in	Tue Feb 24 08:57:52 2009
  15 @@ -537,6 +537,15 @@
  16  /* Define if you have the dlsym function.  */
  17  #undef HAVE_DLSYM
  18  
  19 +/* Define if you have the shl_load function. */
  20 +#undef HAVE_SHL_LOAD
  21 +
  22 +/* Define if you have the shl_unload function. */
  23 +#undef HAVE_SHL_UNLOAD
  24 +
  25 +/* Define if you have the shl_findsym function. */
  26 +#undef HAVE_SHL_FINDSYM
  27 +
  28  /* Define if you don't have vprintf but do have _doprnt.  */
  29  #undef HAVE_DOPRNT
  30  
  31 @@ -853,6 +862,9 @@
  32  
  33  /* Define if you have the <dirent.h> header file.  */
  34  #undef HAVE_DIRENT_H
  35 +
  36 +/* Define if you have the <dl.h> header file.  */
  37 +#undef HAVE_DL_H
  38  
  39  /* Define if you have the <dlfcn.h> header file.  */
  40  #undef HAVE_DLFCN_H
  41 --- bash-4.0/configure.in	Fri Feb  6 12:03:44 2009
  42 +++ bash-4.0-shl/configure.in	Tue Feb 24 08:58:49 2009
  43 @@ -650,7 +650,7 @@
  44  BASH_HEADER_INTTYPES
  45  
  46  AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
  47 -		 memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
  48 +		 memory.h locale.h termcap.h termio.h termios.h dl.h dlfcn.h \
  49  		 stddef.h stdint.h netdb.h pwd.h grp.h strings.h regex.h)
  50  AC_CHECK_HEADERS(sys/pte.h sys/stream.h sys/select.h sys/file.h \
  51  		 sys/resource.h sys/param.h sys/socket.h sys/stat.h \
  52 @@ -798,6 +798,8 @@
  53  if test "$opt_static_link" != yes; then
  54  AC_CHECK_LIB(dl, dlopen)
  55  AC_CHECK_FUNCS(dlopen dlclose dlsym)
  56 +AC_CHECK_LIB(dld, shl_load)
  57 +AC_CHECK_FUNCS(shl_load shl_unload shl_findsym)
  58  fi
  59  
  60  dnl this defines HAVE_DECL_SYS_SIGLIST
  61 @@ -1062,7 +1064,8 @@
  62  # Shared object configuration section.  These values are generated by
  63  # ${srcdir}/support/shobj-conf
  64  #
  65 -if test "$ac_cv_func_dlopen" = "yes" && test -f ${srcdir}/support/shobj-conf
  66 +if ( test "$ac_cv_func_dlopen" = "yes" || test "$ac_cv_func_shl_load" = "yes" )\
  67 +  && test -f ${srcdir}/support/shobj-conf
  68  then
  69  	AC_MSG_CHECKING(shared object configuration for loadable builtins)
  70  	eval `${CONFIG_SHELL-/bin/sh} ${srcdir}/support/shobj-conf -C "${CC}" -c "${host_cpu}" -o "${host_os}" -v "${host_vendor}"`
  71 --- bash-4.0/builtins/enable.def	Sun Jan  4 14:32:22 2009
  72 +++ bash-4.0-shl/builtins/enable.def	Tue Feb 24 12:39:24 2009
  73 @@ -82,11 +82,11 @@
  74  #define PFLAG	0x10
  75  #define SFLAG	0x20
  76  
  77 -#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
  78 +#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined (HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
  79  static int dyn_load_builtin __P((WORD_LIST *, int, char *));
  80  #endif
  81  
  82 -#if defined (HAVE_DLCLOSE)
  83 +#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
  84  static int dyn_unload_builtin __P((char *));
  85  static void delete_builtin __P((struct builtin *));
  86  static int local_dlclose __P((void *));
  87 @@ -104,7 +104,7 @@
  88  {
  89    int result, flags;
  90    int opt, filter;
  91 -#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
  92 +#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined (HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
  93    char *filename;
  94  #endif
  95  
  96 @@ -129,7 +129,7 @@
  97  	  flags |= SFLAG;
  98  	  break;
  99  	case 'f':
 100 -#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
 101 +#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined (HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
 102  	  flags |= FFLAG;
 103  	  filename = list_optarg;
 104  	  break;
 105 @@ -137,7 +137,7 @@
 106  	  builtin_error (_("dynamic loading not available"));
 107  	  return (EX_USAGE);
 108  #endif
 109 -#if defined (HAVE_DLCLOSE)
 110 +#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
 111  	case 'd':
 112  	  flags |= DFLAG;
 113  	  break;
 114 @@ -172,7 +172,7 @@
 115  
 116        list_some_builtins (filter);
 117      }
 118 -#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
 119 +#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined (HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
 120    else if (flags & FFLAG)
 121      {
 122        filter = (flags & NFLAG) ? DISABLED : ENABLED;
 123 @@ -185,7 +185,7 @@
 124  #endif
 125      }
 126  #endif
 127 -#if defined (HAVE_DLCLOSE)
 128 +#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
 129    else if (flags & DFLAG)
 130      {
 131        while (list)
 132 @@ -275,11 +275,17 @@
 133    return (EXECUTION_SUCCESS);
 134  }
 135  
 136 -#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
 137 +#if (defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)) || (defined (HAVE_SHL_LOAD) && defined (HAVE_SHL_FINDSYM))
 138  
 139  #if defined (HAVE_DLFCN_H)
 140  #  include <dlfcn.h>
 141  #endif
 142 +#if defined (HAVE_DL_H)
 143 +#  include <dl.h>
 144 +#endif
 145 +#if defined (HAVE_ERRNO_H)
 146 +#  include <errno.h>
 147 +#endif
 148  
 149  static int
 150  dyn_load_builtin (list, flags, filename)
 151 @@ -288,7 +294,11 @@
 152       char *filename;
 153  {
 154    WORD_LIST *l;
 155 +#if defined (HAVE_DLOPEN)
 156    void *handle;
 157 +#elif defined (HAVE_SHL_LOAD)
 158 +  shl_t handle;
 159 +#endif
 160    
 161    int total, size, new, replaced;
 162    char *struct_name, *name;
 163 @@ -301,15 +311,22 @@
 164  #define RTLD_LAZY 1
 165  #endif
 166  
 167 -#if defined (_AIX)
 168 +#if defined (HAVE_DLOPEN) && defined (_AIX)
 169    handle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL);
 170 -#else
 171 +#elif defined (HAVE_DLOPEN)
 172    handle = dlopen (filename, RTLD_LAZY);
 173 +#elif defined (HAVE_SHL_LOAD)
 174 +  handle = shl_load (filename, BIND_IMMEDIATE | BIND_VERBOSE, 0L);
 175  #endif /* !_AIX */
 176  
 177    if (handle == 0)
 178      {
 179 -      builtin_error (_("cannot open shared object %s: %s"), filename, dlerror ());
 180 +      builtin_error (_("cannot open shared object %s: %s"), filename,
 181 +#if defined (HAVE_DLOPEN)
 182 +        dlerror ());
 183 +#elif defined (HAVE_SHL_LOAD)
 184 +        strerror (errno));
 185 +#endif
 186        return (EXECUTION_FAILURE);
 187      }
 188  
 189 @@ -329,11 +346,20 @@
 190        strcpy (struct_name, name);
 191        strcpy (struct_name + size, "_struct");
 192  
 193 +#if defined (HAVE_DLSYM)
 194        b = (struct builtin *)dlsym (handle, struct_name);
 195        if (b == 0)
 196 +#elif defined (HAVE_SHL_FINDSYM)
 197 +      if (0 != shl_findsym (&handle, struct_name, TYPE_UNDEFINED, (void *) &b))
 198 +#endif
 199  	{
 200  	  builtin_error (_("cannot find %s in shared object %s: %s"),
 201 -			  struct_name, filename, dlerror ());
 202 +			  struct_name, filename,
 203 +#if defined (HAVE_DLOPEN)
 204 +			  dlerror ());
 205 +#elif defined (HAVE_SHL_LOAD)
 206 +			  strerror (errno));
 207 +#endif
 208  	  free (struct_name);
 209  	  continue;
 210  	}
 211 @@ -357,7 +383,11 @@
 212    if (replaced == 0 && new == 0)
 213      {
 214        free (new_builtins);
 215 +#if defined (HAVE_DLCLOSE)
 216        dlclose (handle);
 217 +#elif defined (HAVE_SHL_UNLOAD)
 218 +      shl_unload (handle);
 219 +#endif
 220        return (EXECUTION_FAILURE);
 221      }
 222  
 223 @@ -391,7 +421,7 @@
 224  }
 225  #endif
 226  
 227 -#if defined (HAVE_DLCLOSE)
 228 +#if defined (HAVE_DLCLOSE) || defined (HAVE_SHL_UNLOAD)
 229  static void
 230  delete_builtin (b)
 231       struct builtin *b;
 232 @@ -432,12 +462,16 @@
 233  local_dlclose (handle)
 234       void *handle;
 235  {
 236 +#if defined (HAVE_DLCLOSE)
 237  #if !defined (__MACHTEN__)
 238    return (dlclose (handle));
 239  #else /* __MACHTEN__ */
 240    dlclose (handle);
 241    return ((dlerror () != NULL) ? -1 : 0);    
 242  #endif /* __MACHTEN__ */
 243 +#elif defined (HAVE_SHL_UNLOAD)
 244 +  return (shl_unload (handle));
 245 +#endif /* HAVE_DLCLOSE or HAVE_SHL_UNLOAD */
 246  }
 247  
 248  static int
 249 @@ -471,7 +505,12 @@
 250       using it drops to zero. */
 251    if (ref == 1 && local_dlclose (handle) != 0)
 252      {
 253 -      builtin_error (_("%s: cannot delete: %s"), name, dlerror ());
 254 +      builtin_error (_("%s: cannot delete: %s"), name,
 255 +#if defined (HAVE_DLOPEN)
 256 +        dlerror ());
 257 +#elif defined (HAVE_SHL_LOAD)
 258 +        strerror (errno));
 259 +#endif
 260        return (EXECUTION_FAILURE);
 261      }
 262