Opened 6 years ago

#12489 new Bugs

file_lock and fstream read causes "permission denied"

Reported by: anonymous Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

The following code causes an exception in the std::getline. The error message received by strerror() is "permission denied".

The exception goes away by removing the lock and unlock line.

This issue is related to to https://svn.boost.org/trac/boost/ticket/2796 which focuses on writing to the filelock. A "workaround" for that issue is to unlock before flushing the stream. It is not an option to read file before locking it.

How can this issue be fixed? Any possible workaround?

#include "stdafx.h"

#include <iostream>

#include <fstream>

#include <boost/interprocess/sync/file_lock.hpp>

int main(int argc, char* argv[])

{

std::fstream stream("lock", std::fstream::in | std::fstream::out);

stream.exceptions(std::fstream::badbit | std::fstream::failbit);

boost::interprocess::file_lock lock("lock");

lock.lock();

std::string content; try {

std::getline(stream, content);

} catch (std::exception) {

auto desc = strerror(errno);

}

std::cout << content << std::endl;

lock.unlock();

stream.close();

return 0;

}

Change History (0)

Note: See TracTickets for help on using tickets.