Commit 95d78166 authored by Ramon Nou's avatar Ramon Nou
Browse files

Avoid flock declaration conflict in journal lock

parent 09213be9
Loading
Loading
Loading
Loading
Loading
+12 −3
Changes for include/client/rpc/repair_journal_lock.hpp: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
#include <common/unique_fd.hpp>

#include <fcntl.h>
#include <sys/file.h>
#include <unistd.h>

#include <cerrno>
@@ -66,7 +65,12 @@ public:
        }
        gkfs::utils::unique_fd candidate(fd);

        if(::flock(candidate.get(), LOCK_EX | LOCK_NB) != 0) {
        struct flock lock{};
        lock.l_type = F_WRLCK;
        lock.l_whence = SEEK_SET;
        lock.l_start = 0;
        lock.l_len = 0;
        if(::fcntl(candidate.get(), F_OFD_SETLK, &lock) != 0) {
            const auto error = errno;
            if(error == EWOULDBLOCK || error == EAGAIN) {
                throw std::runtime_error(
@@ -110,7 +114,12 @@ public:
    void
    release() noexcept {
        if(fd_) {
            ::flock(fd_.get(), LOCK_UN);
            struct flock lock{};
            lock.l_type = F_UNLCK;
            lock.l_whence = SEEK_SET;
            lock.l_start = 0;
            lock.l_len = 0;
            ::fcntl(fd_.get(), F_OFD_SETLK, &lock);
            fd_.reset();
        }
        lock_path_.clear();