What are the unwanted side effects of open in ioctl?

According to man ioctl, opening file descriptors with opencan lead to unwanted side effects. The manual also states that opening with O_NONBLOCKresolves these unwanted problems, but I cannot find the reason for this and what are the actual side effects. Can someone shed some light on this? Since ioctlit always possible, and equivalent to * open file descriptors using O_NONBLOCK?

NOTES (from man ioctl)

To use this call, you need an open file descriptor. Often an open (2) call has undesirable side effects, which can be avoided under Linux by assigning it the O_NONBLOCK flag.

(* I know what it means O_NONBLOCK, but I don’t know if it affects the ioctlway it affects other system calls. My program, which uses ioctlto write and read from SPI, works fine with the flag turned on.)

+4
source share
2 answers

The obvious place to look for an answer would be the open (2) man page, which, under the heading O_NONBLOCK, says:

When possible, the file opens in non-blocking mode. Neither open (), nor any subsequent file operations, the handle that is returned will cause the call process to wait.

[...]

FIFO ( ) . fifo (7).    O_NONBLOCK    , . fcntl (2).

, , , fifo (7) fcntl (2) :

, FIFO, .

FIFO .    ,    ENXIO (    ), .

Linux, FIFO    . POSIX undefined.

, " ": FIFO , O_NONBLOCK open() ( ).

fcntl? open (2), , , - " " " ". , , , , , :

   (, (2) (2)) ,    , ,    O_NONBLOCK.    O_NONBLOCK , ,    ,   .

?

( " " ) (2)   truncate (2), , F_SETLEASE,    , ​​   , ( SIGIO). [...]

  , , ,    , ​​   .

[...]    O_NONBLOCK open (2),    EWOULDBLOCK,    , .

, : , , , open() , .

" ", , O_NONBLOCK open(), , open() , - . - , man-, .

+5

Linux System Programming, 2nd Edition, R. Love ( ):

O_NONBLOCK , . open(), () -. FIFO.

, read() , . , , . -; -, , , , , .

, errno: EAGAIN.

. .

+1

Source: https://habr.com/ru/post/1662684/


All Articles