| 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 2 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, write to the Free Software
|
|---|
| 17 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 18 |
|
|---|
| 19 | tempdir=`mktemp -d /tmp/dlopenXXXXXX`
|
|---|
| 20 | test -n "$tempdir" || exit 1
|
|---|
| 21 | cat >> $tempdir/dlopen.c << _EOF
|
|---|
| 22 | #include <dlfcn.h>
|
|---|
| 23 | #include <stdio.h>
|
|---|
| 24 | #include <limits.h>
|
|---|
| 25 | #include <sys/stat.h>
|
|---|
| 26 | /* Simple program to see if dlopen() would succeed. */
|
|---|
| 27 | int main(int argc, char **argv)
|
|---|
| 28 | {
|
|---|
| 29 | int i;
|
|---|
| 30 | struct stat st;
|
|---|
| 31 | char buf[PATH_MAX];
|
|---|
| 32 | for (i = 1; i < argc; i++) {
|
|---|
| 33 | if (dlopen(argv[i], RTLD_NOW)) {
|
|---|
| 34 | fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
|
|---|
| 35 | argv[i]);
|
|---|
| 36 | } else {
|
|---|
| 37 | snprintf(buf, sizeof(buf), "./%s", argv[i]);
|
|---|
| 38 | if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
|
|---|
| 39 | fprintf(stdout, "dlopen() of \"./%s\" "
|
|---|
| 40 | "succeeded.\n", argv[i]);
|
|---|
| 41 | } else {
|
|---|
| 42 | fprintf(stdout, "dlopen() of \"%s\" failed: "
|
|---|
| 43 | "%s\n", argv[i], dlerror());
|
|---|
| 44 | return 1;
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | return 0;
|
|---|
| 49 | }
|
|---|
| 50 | _EOF
|
|---|
| 51 |
|
|---|
| 52 | for arg in $@ ; do
|
|---|
| 53 | case "$arg" in
|
|---|
| 54 | "")
|
|---|
| 55 | ;;
|
|---|
| 56 | -I*|-D*|-f*|-m*|-g*|-O*|-W*)
|
|---|
| 57 | cflags="$cflags $arg"
|
|---|
| 58 | ;;
|
|---|
| 59 | -l*|-L*)
|
|---|
| 60 | ldflags="$ldflags $arg"
|
|---|
| 61 | ;;
|
|---|
| 62 | /*)
|
|---|
| 63 | modules="$modules $arg"
|
|---|
| 64 | ;;
|
|---|
| 65 | *)
|
|---|
| 66 | modules="$modules $arg"
|
|---|
| 67 | ;;
|
|---|
| 68 | esac
|
|---|
| 69 | done
|
|---|
| 70 |
|
|---|
| 71 | ${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags -ldl
|
|---|
| 72 |
|
|---|
| 73 | retval=0
|
|---|
| 74 | for module in $modules ; do
|
|---|
| 75 | case "$module" in
|
|---|
| 76 | "")
|
|---|
| 77 | ;;
|
|---|
| 78 | /*)
|
|---|
| 79 | $tempdir/dlopen "$module"
|
|---|
| 80 | retval=$?
|
|---|
| 81 | ;;
|
|---|
| 82 | *)
|
|---|
| 83 | $tempdir/dlopen ./"$module"
|
|---|
| 84 | retval=$?
|
|---|
| 85 | ;;
|
|---|
| 86 | esac
|
|---|
| 87 | done
|
|---|
| 88 |
|
|---|
| 89 | rm -f $tempdir/dlopen $tempdir/dlopen.c
|
|---|
| 90 | rmdir $tempdir
|
|---|
| 91 | exit $retval
|
|---|