Skip to content
Advertisement

POSIX open() hangs on SMB share

I have a problem where I mount a Windows SMB share under linux with mount.cifs and write to files from my C++ program. This works fine, but as soon as network problems arise (i.e. Windows server disconnect), opening the file with POSIX open() will hang indefinitely. The same happens for the POSIX close() call if the share disconnects while the file is open. Using std::ofstream reveals a similar problem.

Is there

  • another version of open() / close() which returns after a timeout?
  • a way to release the open call from another thread without killing the one that tries to open?
  • a way to test beforehand if the call will hang?

Advertisement

Answer

Syscalls are interrupted when a signal arrives; errno will return EINTR.

You can use alarm() before the syscall to schedule SIGALRM after a time-out period.

You can also use alarm() to cancel a pending SIGARLM if the syscalls returns successfully before the time-out period expires.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement