tags:

views:

4064

answers:

7

Hi All,

I have a perl script running in a aix box.

The script tries to open a file from a certain directory and it fails to read the file because file has no read permission. but i get a different error saying "inappropriate ioctl for device" Shouldn't it say something like file doesn't have read permission or something?

What does this ""inappropriate ioctl for device" message mean? How can I fix it?

EDIT: This is what I found when I did strace.

open("/local/logs/xxx/xxxxServer.log", O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, 
    0666) = 4 _llseek(4, 0, [77146], SEEK_END) = 0
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbffc14f8) = -1 ENOTTY 
    (Inappropriate ioctl for  device)
A: 

Did you try fixing the read permission on the file?

Are you sure that you are reading from a file? Could you perhaps be reading from stdin or anoher filehandle that isn't actually connected? That's generally what that error message means.

Ether
yes , i gave read permission and it worked.but why "inappropriate ioctl for device" message..
someguy
A: 

Who knows what the Perl interpreter is doing, apparently at least one pointless ioctl, but to answer your question, ioctl ops at low levels are specific to each device driver. Perl seems to have fired one off and hit an innocent bystander. A driver is reporting that it doesn't understand the ioctl code.

DigitalRoss
+2  A: 

"inappropriate ioctl for device" is the error string for the ENOTTY error. It used to be triggerred primarily by attempts to configure terminal properties (e.g. echo mode) on a file descriptor that was no terminal (but, say, a regular file), hence ENOTTY. More generally, it is triggered when doing an ioctl on a device that does not support that ioctl, hence the error string.

To find out what ioctl is being made that fails, and on what file descriptor, run the script under strace/truss. You'll recognize ENOTTY, followed by the actual printing of the error message. Then find out what file number was used, and what open() call returned that file number.

Martin v. Löwis
+1  A: 

"files" in *nix type systems are very much an abstract concept.

They can be areas on disk organised by a file system, but they could equally well be a network connection, a bit of shared memory, the buffer output from another process, a screen or a keyboard.

In order for perl to be really useful it mirrors this model very closely, and does not treat files by emulating a magnetic tape as many 4gls do.

So it tried an "IOCTL" oepration 'open for write' on a file handle which does not allow write operations which is an inapropriate IOCTL operation for that device/file.

The esiaest thing to do is stick an " or die 'Cannot open $myfile' statement at the end of you open and you can choose your own meaningful message.

James Anderson
+4  A: 

Odd errors like "inappropriate ioctl for device" are usually a result of checking $! at some point other than just after a system call failed. If you'd show your code, I bet someone would rapidly point out your error.

ysth
+4  A: 

Most likely it means that the open didn't fail.

When Perl opens a file, it checks whether or not the terminal is a TTY (so that it can answer the -T $fh filetest operator) by issuing the TCGETS ioctl against it. If the file is a regular file and not a tty, the ioctl fails and sets errno to ENOTTY (string value: "Inappropriate ioctl for device"). As ysth says, the most common reason for seeing an unexpected value in $! is checking it when it's not valid -- that is, anywhere other than immediately after a syscall failed, so testing the result codes of your operations is critically important.

If open actually did return false for you, and you found ENOTTY in $! then I would consider this a small bug (giving a useless value of $!) but I would also be very curious as to how it happened. Code and/or truss output would be nifty.

hobbs
A: 

Eureka moment!

I have had this error before.

Did you invoke the perl debugger with something like :-

perl -d yourprog.pl > log.txt

If so whats going on is perl debug tries to query and perhaps reset the terminal width. When stdout is not a terminal this fails with the IOCTL message.

The alternative would be for your debug session to hang forever because you did not see the prompt for instructions.

James Anderson
No, I am not doing anything like this..
someguy