XRootD
XrdSutFileLocker Class Reference

#include <XrdSutAux.hh>

+ Collaboration diagram for XrdSutFileLocker:

Public Types

enum  ELockType {
  kShared = 0 ,
  kExcl = 1
}
 

Public Member Functions

 XrdSutFileLocker (int fd, ELockType lock)
 
 ~XrdSutFileLocker ()
 
bool IsValid () const
 

Detailed Description

Definition at line 238 of file XrdSutAux.hh.

Member Enumeration Documentation

◆ ELockType

Enumerator
kShared 
kExcl 

Definition at line 243 of file XrdSutAux.hh.

243 { kShared = 0, kExcl = 1 };

Constructor & Destructor Documentation

◆ XrdSutFileLocker()

XrdSutFileLocker::XrdSutFileLocker ( int  fd,
ELockType  lock 
)

Definition at line 615 of file XrdSutAux.cc.

616 {
617  // Constructor: locks the file in 'lock' mode.
618  // Use IsValid() to test success.
619 
620  valid = 0;
621  fdesk = fd;
622 
623  // Exclusive lock of the whole file
624  int lockmode = (lock == XrdSutFileLocker::kExcl) ? (F_WRLCK | F_RDLCK)
625  : F_RDLCK;
626  struct flock flck;
627  memset(&flck, 0, sizeof(flck));
628  flck.l_type = lockmode;
629  flck.l_whence = SEEK_SET;
630  if (fcntl(fdesk, F_SETLK, &flck) != 0)
631  // Failure
632  return;
633 
634  // Success
635  valid = 1;
636 }
int fcntl(int fd, int cmd,...)

References fcntl(), and kExcl.

+ Here is the call graph for this function:

◆ ~XrdSutFileLocker()

XrdSutFileLocker::~XrdSutFileLocker ( )

Definition at line 638 of file XrdSutAux.cc.

639 {
640  // Destructor: unlocks the file if locked.
641 
642  if (fdesk < 0 || !IsValid())
643  return;
644  //
645  // Unlock the file
646  struct flock flck = {F_UNLCK, SEEK_SET, 0, 0, 0};
647  memset(&flck, 0, sizeof(flck));
648  flck.l_type = F_UNLCK;
649  flck.l_whence = SEEK_SET;
650  fcntl(fdesk, F_SETLK, &flck);
651 }
bool IsValid() const
Definition: XrdSutAux.hh:246

References fcntl(), and IsValid().

+ Here is the call graph for this function:

Member Function Documentation

◆ IsValid()

bool XrdSutFileLocker::IsValid ( ) const
inline

Definition at line 246 of file XrdSutAux.hh.

246 { return valid; }

Referenced by ~XrdSutFileLocker(), and XrdCryptosslX509ChainToFile().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: