Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2003 14:17:46 +0100
From:      "Simon 'corecode' Schubert" <corecode@corecode.ath.cx>
To:        "Daniel O'Connor" <doconnor@gsoft.com.au>
Cc:        freebsd-ports-bugs@freebsd.org
Subject:   Re: ports/47348: New port for TeamSpeak
Message-ID:  <20030123141746.2c5ccf95.corecode@corecode.ath.cx>
In-Reply-To: <1043317182.45633.1.camel@chowder.dons.net.au>
References:  <200301222310.h0MNA3Vd075145@freefall.freebsd.org> <20030123110828.1836d662.corecode@corecode.ath.cx> <1043317182.45633.1.camel@chowder.dons.net.au>

next in thread | previous in thread | raw e-mail | index | archive | help
--=.6MjfO3HDTA53G_
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Lately Daniel O'Connor told:

> > working. how about a (linux-so)library to preload that intercepts just
> > ioctl and tests for this specific request (and then just returns 0)?
> Hmm, well the idea has merit :)
> 
> I'm not sure I'm that enthusiastic..
> 
> IMHO it's fine to require a certain FreeBSD version to run something.
> 
> Do you have an example I could copy?

*scribble* *code*
uhm, yea. just wrote one:

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	testpreloadioctl
#	testpreloadioctl/testioctl.c
#	testpreloadioctl/Makefile.lib
#	testpreloadioctl/testioctl.h
#	testpreloadioctl/preloadioctl.c
#	testpreloadioctl/Makefile
#	testpreloadioctl/Makefile.bin
#
echo c - testpreloadioctl
mkdir -p testpreloadioctl > /dev/null 2>&1
echo x - testpreloadioctl/testioctl.c
sed 's/^X//' >testpreloadioctl/testioctl.c << 'END-of-testpreloadioctl/testioctl.c'
X#include <sys/ioctl.h>
X
X#include <errno.h>
X#include <fcntl.h>
X#include <stdio.h>
X#include <string.h>
X
X#include "testioctl.h"
X
Xvoid usage();
X
Xint main(int argc, char *argv[])
X{
X	int fd;
X	int one = 1;
X	int ret = 1;
X
X	if (argc != 2) {
X		usage(argv[0]);
X		/* NOTREACHED */
X	}
X
X	if ((fd = open(argv[1], O_RDONLY)) == -1) {
X		perror(NULL);
X		exit(1);
X		/* NOTREACHED */
X	}
X
X	if (ioctl(fd, TESTIOCTL_REQ, &one) == -1)
X		fprintf(stderr, "error issuing TESTIOCTL_REQ: %s\n", strerror(errno));
X	else {
X		printf("TESTIOCTL_REQ succeeded!\n");
X		ret = 0;
X	}
X
X	close(fd);
X	return ret;
X}
X
Xvoid usage()
X{
X	fprintf(stderr, "usage: testioctl <testdev>\n");
X	exit(1);
X}
END-of-testpreloadioctl/testioctl.c
echo x - testpreloadioctl/Makefile.lib
sed 's/^X//' >testpreloadioctl/Makefile.lib << 'END-of-testpreloadioctl/Makefile.lib'
XSRCS=	preloadioctl.c
XSHLIB_NAME?=	preloadioctl.so
X
X.include <bsd.lib.mk>
END-of-testpreloadioctl/Makefile.lib
echo x - testpreloadioctl/testioctl.h
sed 's/^X//' >testpreloadioctl/testioctl.h << 'END-of-testpreloadioctl/testioctl.h'
X#ifndef	TESTIOCTL_REQ
X#  define TESTIOCTL_REQ	0x7654		/* some random number */
X#endif	/* TESTIOCTL_REQ */
END-of-testpreloadioctl/testioctl.h
echo x - testpreloadioctl/preloadioctl.c
sed 's/^X//' >testpreloadioctl/preloadioctl.c << 'END-of-testpreloadioctl/preloadioctl.c'
X#include <dlfcn.h>
X#include <errno.h>
X#include <stdio.h>
X
X#include "testioctl.h"
X
Xint ioctl(int fd, unsigned long req, char *param)
X{
X	if (req == TESTIOCTL_REQ)
X		return 0;
X		/* NOTREACHED */
X	else {
X		static int (*orig_ioctl)(int, unsigned long, char *) = NULL;
X
X		if (orig_ioctl == NULL) {
X			if ((orig_ioctl = (int(*)(int, unsigned long, char *))
X						dlfunc(RTLD_NEXT, "ioctl")) == NULL) {
X				fprintf(stderr, "preloadioctl: %s\n", dlerror());
X				return ENOSYS;
X			}
X		}
X
X		return orig_ioctl(fd, req, param);
X		/* NOTREACHED */
X	}
X}
END-of-testpreloadioctl/preloadioctl.c
echo x - testpreloadioctl/Makefile
sed 's/^X//' >testpreloadioctl/Makefile << 'END-of-testpreloadioctl/Makefile'
XPROG=	testioctl
XSHLIB_NAME=	preloadioctl.so
X
XTESTDEV?=	/dev/dsp
X
X.DEFAULT: .MAKE
X.for file in Makefile.lib Makefile.bin
X	${MAKE} -f ${file} ${MAKEFLAGS} DEPENDFILE=.depend.${file} ${.TARGETS}
X.endfor
X
Xtest: all
X	@${ECHO} "===> Testing without preload"
X	-${.CURDIR}/${PROG} ${TESTDEV}
X	@${ECHO} "===> Testing with preload"
X	-${ENV} LD_PRELOAD=${.CURDIR}/${SHLIB_NAME} ${.CURDIR}/${PROG} ${TESTDEV}
X
END-of-testpreloadioctl/Makefile
echo x - testpreloadioctl/Makefile.bin
sed 's/^X//' >testpreloadioctl/Makefile.bin << 'END-of-testpreloadioctl/Makefile.bin'
XPROG?=	testioctl
XSRCS=	testioctl.c
XNOMAN=	yes
X
X.include <bsd.prog.mk>
END-of-testpreloadioctl/Makefile.bin
exit

have fun

cheers
  simon

-- 
/"\   http://corecode.ath.cx/#donate
\ /
 \     ASCII Ribbon Campaign
/ \  Against HTML Mail and News

--=.6MjfO3HDTA53G_
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+L+t9r5S+dk6z85oRAhMKAKCeExMcSKoiWYQRxo1njDs01kx2TgCg+ycS
P3aJvy4MUIojQGxZIuRn88E=
=KGru
-----END PGP SIGNATURE-----

--=.6MjfO3HDTA53G_--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030123141746.2c5ccf95.corecode>