Avoid crashes after running mmap () on a file that is unmounted

I make mmap () in a file that can be unmounted (the file is on a USB device that the user can delete at any time), and my application crashes if the file is unmounted, and then I try to access any element in the buffer.

Any solutions for this?

+5
source share
4 answers

First of all, I would like to say that this should serve as a good argument not to use mmap unnecessarily as “optimized reading” or the like. In addition to removing the device, issues such as file truncation by other processes can cause access to failures SIGBUS.

mmap, SIGBUS. :

  • ( -, ), , SIGBUS, .
  • mmap MAP_FIXED, . , , , ; 1 .

( -) jmp_buf longjmp.

, mmap, longjmp , SIGBUS ( , , , - - , sscanf). , , , . mmap async- / , , .

+6

- , , mmap ed.

sigaction , signal, sigaction struct __siginfo *, . , , mmap ed.

mmap , / , () - - . read/write errno , . .

, setjmp longjmp/siglongjmp - , this

+2

, . , , , .

-1

you can be notified of any changes to the dir (s) files using http://linux.die.net/man/7/inotify . you can use IN_DELETE.

-1
source

All Articles