1828632 Members
8888 Online
109983 Solutions
New Discussion

ioctl problem

 
SOLVED
Go to solution
Paul Blake_2
New Member

ioctl problem

Some colleagues and I are attempting (with limited Unix experience) to port a set of bespoke programs from an HP9000 D200 server running HP-UX 10.1 to a new HP workstation running 11.23. The server is accessed remotely using a telnet type interface, and one of the programs we are trying to port is a word-processing package. The package makes use of a termio structure SS to store the original terminal settings, obtained with an ioctl call

ioctl(file_num,TCGETA,&SS)

where the value of file_num is obtained by the sequence:

screen = fopen(ttyname(0),"w");
file_num = fileno(screen);

Some of the values in the structure SS are then modified, and the new values written back by

ioctl(file_num,TCSETAF,&SS);

On the old server this works perfectly well. On the new one this last ioctl call fails, setting errno to EPERM, unless you run the program as superuser.

It is obviously an issue of permissions somewhere, but we can't figure out where. Anyone got any ideas what we need to change? The only obvious difference that I can see between the way the 2 systems are handling terminals is that the pseudoterminal on the old HP is /dev/ttyp[1-f] whereas on the new one it seems to be /dev/pts/t[1-f] but it clearly isn't to do with the permissions of the devices in the /dev/pts directory because we tried changing those to no avail.

all contributions gratefully received!

paul

4 REPLIES 4
Rick Garland
Honored Contributor

Re: ioctl problem

In migrating from HPUX 10.1 to HPUX 11.23, you sure that no upgrades in the application are required? This is a big jump between OS versions.

Paul Blake_2
New Member

Re: ioctl problem

sorry, perhaps I should have been clearer. The WP package is something written in house by a programmer who is no longer available, and we are trying to recompile it from the source code, which contains the statements above. It compiles ok, but fails as described unless the person running it is superuser

paul
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: ioctl problem

The problem stems from this:

screen = fopen(ttyname(0),"w");
change it to:
screen = fopen(ttyname(0),"w+");

Hint: Think about what is involved in flushing and draining --- and before you say it, the old code was working by accident.

However, if this were me, I wouldn't bother with this file_num nonsense since all you are really doing (and doing it not quite right) is copying file descriptor 0 (stdin).

I would do this:

#define STDIN_FDES 0

and replace every instance of file_num with STDIN_FDES and get rid of the fopen() and the fileno() functions.
If it ain't broke, I can fix that.
Paul Blake_2
New Member

Re: ioctl problem

brilliant, thank you very much

paul