I have a Perl script running in an 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 no read permissions for file
or something similar?
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)
I just fixed this perl bug. See https://rt.perl.org/Ticket/Display.html?id=124232
When we push the buffer layer to PerlIO and do a failing isatty() check which obviously fails on all normal files, ignore the wrong errno ENOTTY.
I tried the following code that seemed to work:
Eureka moment!
I have had this error before.
Did you invoke the perl debugger with something like :-
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.
Most likely it means that the open didn't fail.
When Perl opens a file, it checks whether or not the file is a TTY (so that it can answer the
-T $fh
filetest operator) by issuing theTCGETS
ioctl against it. If the file is a regular file and not a tty, the ioctl fails and sets errno toENOTTY
(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 foundENOTTY
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."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.
Ran into this error today while trying to use code to delete a folder/files that are living on a Windoze 7 box that's mounted as a share on a Centos server. Got the inappropriate icotl for device error and tried everything that came to mind. Read just about every post on the net related to this.
Obviously the problem was isolated to the mounted Windoze share on the Linux server. Looked at the file permissions on the Windoze box and noted the files had their permissions set to read only.
Changed those, went back to the Linux server and all worked as expected. This may not be the solution for most but hopefully it saves someone some time.