Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
edited by

I have a Perl script running in my AIX box.

The script tries to open the file from my directory and it fails to read my file because my file has no read permission, but I am getting a different error saying Inappropriate ioctl for the device.

Shouldn't it say something like no read permissions for the file or something similar?

What does this inappropriate the ioctl for the device message mean?

How do I fix it?

EDIT: When I was working on it, I found the 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)

1 Answer

0 votes
by (36.8k points)

It means that the file doesn't fail to open.

When the Perl opens my file, it checks whether or not my file is the TTY (so that it can answer this -T $fh filetest operator) by issuing the TCGETS ioctl against it. If your file is a regular file and not a tty, the ioctl fails and sets errno to ENOTTY (string value: "Inappropriate ioctl for device"). As the ysth says, the most common reason for seeing an unexpected value in $! will check 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 did return false for you, and you found ENOTTY in $! then you can 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.

Come and join Linux training to gain great knowledge. 

Do check out the video below

Related questions

0 votes
1 answer
asked Dec 15, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...