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

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

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

#!/bin/bash

BashLoadable_diff_4_2

پیوست BashLoadable

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

دانلود

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