ioctl in perl (was: using System V 'cu')

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Wed Nov 30 16:51:33 AEST 1988


Leslie Mikesell writes:
: Perhaps the reason is that it is not compiled into the official AT&T
: release, at least not up to SysVr3.1 on the 3B2's.  It would be extremely
: useful, though, as would the ability to execute a script like that
: found in the Dialers file at an arbitrary time (i.e. after the connection
: is made).  The code is obviously already there.  Is Larry Wall listening?
: How about adding ioctl() to perl so we can use it instead?

Er, um, that's kinda hard.  But I been thinkin' about it.

In the meantime, if it's something that stty knows about you can just
fork one off to do whatever you want after making sure you have the tty
open on stdout (stdin on some systems).

	open(TTY,"/dev/tty07");
	...
	open(dupout,">&stdout");	# dup stdout
	close stdout;
	open(stdout,">&TTY");		# dup filehandle TTY
	system 'stty', '-echo', 'raw';
	close stdout;
	open(stdout,">&dupout");	# restore stdout
	close dupout;

If efficiency isn't as important you can just say

	system 'stty -echo raw >/dev/tty07';

To do ioctl in perl I'd have to have a way to supply variable sized 3rd
arguments to ioctl.  I figure I could do that with a pre-sized array, with
extra information to say whether it is to be interpreted as bytes, shorts
or longs.  A scalar could likely substitute for a single element array.

The main problem with doing ioctl in perl is not the 3rd argument as much
as the 2nd.  Have you looked at the shenanigans they do in sys/ioctl.h?
(On BSD and Sun at least--I don't know about Sys V.)  Those cute little
identifiers you feed to the 2nd argument are awful.  You say, in C,
something polite like:

	ioctl(0,FIONREAD,&cnt);

and cpp turns that into the following mishmash

	ioctl(0,(0x40000000|((sizeof(int)&0x1fff)<<16)|('f'<<8)|127),&cnt);

So if I'm gonna let you write, in perl,

	ioctl(stdin,$FIONREAD,$cnt);

I've gotta have some way of teaching perl about the gobbledygook above.
Anyway, I'm thinking about it.  Adding chroot() would be much easier.
And maybe getppid().  I think I'll make the current priority a variable,
usable only if your system supports getpriority/setpriority:

	$" -= 20;	# grab that CPU!

The nice program could then be written like this:

	#!/usr/bin/perl
	$diff = ($ARGV[0] =~ s/^-(-?\d+)/$1/) ? shift : 10;
	$" += $diff;
	exec @ARGV;

Is this reasonable?

I'm still thinking about that ioctl...

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
"So many programs, so little time..."



More information about the Comp.unix.wizards mailing list