本文介绍了“设备的 ioctl 不合适"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 AIX 机器中运行的 Perl 脚本.

脚本试图从某个目录打开一个文件,但它无法读取该文件,因为文件没有读取权限,但我收到一个不同的错误,说设备的 ioctl 不合适.

它不应该说没有文件的读取权限或类似的东西吗?

这个不适合设备的ioctl消息是什么意思?

我该如何解决?

这是我在执行 strace 时发现的.

open("/local/logs/xxx/xxxxServer.log", O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE,0666) = 4 _llseek(4, 0, [77146], SEEK_END) = 0ioctl(4, SNDCTL_TMR_TIMEBASE 或 TCGETS, 0xbffc14f8) = -1 ENOTTY(设备的 ioctl 不合适)
解决方案

很可能意味着开放没有失败.

当 Perl 打开一个文件时,它通过发出 TCGETS-T $fh filetest 操作符)> ioctl 反对它.如果文件是常规文件而不是 tty,ioctl 将失败并将 errno 设置为 ENOTTY(字符串值:设备的 ioctl 不合适").正如 ysth 所说,在 $! 中看到意外值的最常见原因是在它无效时检查它——也就是说,在系统调用失败后立即进行的任何其他,因此测试操作的结果代码至关重要.

如果 open 实际上确实为您返回了 false,并且您在 $! 中找到了 ENOTTY 那么我会认为这是一个小错误(给$! 的无用值),但我也很好奇它是如何发生的.代码和/或桁架输出会很漂亮.

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)
解决方案

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 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.

这篇关于“设备的 ioctl 不合适"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 22:56