summaryrefslogtreecommitdiff
path: root/source3/script/tests/dlopen.sh
blob: 6412bc5fcd42968e7509d8938ce2be0470a74654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
#
# Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

tempdir=`mktemp -d /tmp/dlopenXXXXXX`
test -n "$tempdir" || exit 1
cat >> $tempdir/dlopen.c << _EOF
#include <dlfcn.h>
#include <stdio.h>
#include <limits.h>
#include <sys/stat.h>
/* Simple program to see if dlopen() would succeed. */
int main(int argc, char **argv)
{
	int i;
	struct stat st;
	char buf[PATH_MAX];
	for (i = 1; i < argc; i++) {
		if (dlopen(argv[i], RTLD_NOW)) {
			fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
				argv[i]);
		} else {
			snprintf(buf, sizeof(buf), "./%s", argv[i]);
			if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
				fprintf(stdout, "dlopen() of \"./%s\" "
					"succeeded.\n", argv[i]);
			} else {
				fprintf(stdout, "dlopen() of \"%s\" failed: "
					"%s\n", argv[i], dlerror());
				return 1;
			}
		}
	}
	return 0;
}
_EOF

for arg in $@ ; do
	case "$arg" in
	"")
		;;
	-I*|-D*|-f*|-m*|-g*|-O*|-W*)
		cflags="$cflags $arg"
		;;
	-l*|-L*)
		ldflags="$ldflags $arg"
		;;
	/*)
		modules="$modules $arg"
		;;
	*)
		modules="$modules $arg"
		;;
	esac
done

${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags

retval=0
for module in $modules ; do
	case "$module" in
	"")
		;;
	/*)
		$tempdir/dlopen "$module"
		retval=$?
		;;
	*)
		$tempdir/dlopen ./"$module"
		retval=$?
		;;
	esac
done

rm -f $tempdir/dlopen $tempdir/dlopen.c
rmdir $tempdir
exit $retval