| 1 | #!/bin/sh
 | 
|---|
| 2 | #
 | 
|---|
| 3 | # Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003
 | 
|---|
| 4 | #
 | 
|---|
| 5 | # This program is free software; you can redistribute it and/or modify
 | 
|---|
| 6 | # it under the terms of the GNU General Public License as published by
 | 
|---|
| 7 | # the Free Software Foundation; either version 3 of the License, or
 | 
|---|
| 8 | # (at your option) any later version.
 | 
|---|
| 9 | #
 | 
|---|
| 10 | # This program is distributed in the hope that it will be useful,
 | 
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 13 | # GNU General Public License for more details.
 | 
|---|
| 14 | #
 | 
|---|
| 15 | # You should have received a copy of the GNU General Public License
 | 
|---|
| 16 | # along with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 17 | 
 | 
|---|
| 18 | tempdir=`mktemp -d /tmp/dlopenXXXXXX`
 | 
|---|
| 19 | test -n "$tempdir" || exit 1
 | 
|---|
| 20 | cat >> $tempdir/dlopen.c << _EOF
 | 
|---|
| 21 | #include <dlfcn.h>
 | 
|---|
| 22 | #include <stdio.h>
 | 
|---|
| 23 | #include <limits.h>
 | 
|---|
| 24 | #include <sys/stat.h>
 | 
|---|
| 25 | /* Simple program to see if dlopen() would succeed. */
 | 
|---|
| 26 | int main(int argc, char **argv)
 | 
|---|
| 27 | {
 | 
|---|
| 28 |         int i;
 | 
|---|
| 29 |         struct stat st;
 | 
|---|
| 30 |         char buf[PATH_MAX];
 | 
|---|
| 31 |         for (i = 1; i < argc; i++) {
 | 
|---|
| 32 |                 if (dlopen(argv[i], RTLD_NOW)) {
 | 
|---|
| 33 |                         fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
 | 
|---|
| 34 |                                 argv[i]);
 | 
|---|
| 35 |                 } else {
 | 
|---|
| 36 |                         snprintf(buf, sizeof(buf), "./%s", argv[i]);
 | 
|---|
| 37 |                         if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
 | 
|---|
| 38 |                                 fprintf(stdout, "dlopen() of \"./%s\" "
 | 
|---|
| 39 |                                         "succeeded.\n", argv[i]);
 | 
|---|
| 40 |                         } else {
 | 
|---|
| 41 |                                 fprintf(stdout, "dlopen() of \"%s\" failed: "
 | 
|---|
| 42 |                                         "%s\n", argv[i], dlerror());
 | 
|---|
| 43 |                                 return 1;
 | 
|---|
| 44 |                         }
 | 
|---|
| 45 |                 }
 | 
|---|
| 46 |         }
 | 
|---|
| 47 |         return 0;
 | 
|---|
| 48 | }
 | 
|---|
| 49 | _EOF
 | 
|---|
| 50 | 
 | 
|---|
| 51 | for arg in $@ ; do
 | 
|---|
| 52 |         case "$arg" in
 | 
|---|
| 53 |         "")
 | 
|---|
| 54 |                 ;;
 | 
|---|
| 55 |         -I*|-D*|-f*|-m*|-g*|-O*|-W*)
 | 
|---|
| 56 |                 cflags="$cflags $arg"
 | 
|---|
| 57 |                 ;;
 | 
|---|
| 58 |         -l*|-L*)
 | 
|---|
| 59 |                 ldflags="$ldflags $arg"
 | 
|---|
| 60 |                 ;;
 | 
|---|
| 61 |         /*)
 | 
|---|
| 62 |                 modules="$modules $arg"
 | 
|---|
| 63 |                 ;;
 | 
|---|
| 64 |         *)
 | 
|---|
| 65 |                 modules="$modules $arg"
 | 
|---|
| 66 |                 ;;
 | 
|---|
| 67 |         esac
 | 
|---|
| 68 | done
 | 
|---|
| 69 | 
 | 
|---|
| 70 | ${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags
 | 
|---|
| 71 | 
 | 
|---|
| 72 | retval=0
 | 
|---|
| 73 | for module in $modules ; do
 | 
|---|
| 74 |         case "$module" in
 | 
|---|
| 75 |         "")
 | 
|---|
| 76 |                 ;;
 | 
|---|
| 77 |         /*)
 | 
|---|
| 78 |                 $tempdir/dlopen "$module"
 | 
|---|
| 79 |                 retval=$?
 | 
|---|
| 80 |                 ;;
 | 
|---|
| 81 |         *)
 | 
|---|
| 82 |                 $tempdir/dlopen ./"$module"
 | 
|---|
| 83 |                 retval=$?
 | 
|---|
| 84 |                 ;;
 | 
|---|
| 85 |         esac
 | 
|---|
| 86 | done
 | 
|---|
| 87 | 
 | 
|---|
| 88 | rm -f $tempdir/dlopen $tempdir/dlopen.c
 | 
|---|
| 89 | rmdir $tempdir
 | 
|---|
| 90 | exit $retval
 | 
|---|