Subject: [Boost-bugs] [Boost C++ Libraries] #12489: file_lock and fstream read causes "permission denied"
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-09-28 09:34:18
#12489: file_lock and fstream read causes "permission denied"
------------------------------+--------------------------
Reporter: anonymous | Owner: igaztanaga
Type: Bugs | Status: new
Milestone: To Be Determined | Component: interprocess
Version: Boost 1.61.0 | Severity: Problem
Keywords: |
------------------------------+--------------------------
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;
}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12489> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC