Loading...
Searching...
No Matches
PidFileLock.h
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// PidFileLock.h
//------------------------------------------------------------------------------
// $Id: PidFileLock.h,v 1.7 2006/07/20 02:30:54 vlg Exp $
//------------------------------------------------------------------------------
// Copyright (C) 1997-2002,2005 Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
#ifndef FILE_LOCK_H
#define FILE_LOCK_H
//System Includes
#include <sys/types.h>
#include "assa/Assure.h"
//STL
#include <string>
using std::string;
#if defined(WIN32)
struct flock {
off_t l_start;
off_t l_len;
pid_t l_pid;
short l_type;
short l_whence;
};
#endif
namespace ASSA {
class PidFileLock : public flock
{
public:
PidFileLock ();
~PidFileLock ();
bool lock (const string& filename_);
int get_error () const;
const char* get_error_msg () const;
void dump ();
private:
pid_t open_pid_file (const std::string& fname_);
int lock_region ();
int lock_region_exclusive ();
int unlock_region ();
int get_lock_status ();
int write_pid ();
pid_t test_region ();
void log_error (const char* msg_);
private:
string m_filename;
int m_fd;
int m_error;
string m_error_msg;
};
inline int
PidFileLock::
get_error () const
{
return m_error;
}
inline const char*
PidFileLock::
get_error_msg () const
{
return m_error_msg.c_str ();
}
} // end namespace ASSA
#endif /* FILE_LOCK_H */
Assure.h
A collection of assert function wrappers.
ASSA::PidFileLock::get_lock_status
int get_lock_status()
Retrieve lock status.
Definition PidFileLock.cpp:294
ASSA::PidFileLock::~PidFileLock
~PidFileLock()
Destructor.
Definition PidFileLock.cpp:44
ASSA::PidFileLock::write_pid
int write_pid()
Write our process pid to the lock file.
Definition PidFileLock.cpp:132
ASSA::PidFileLock::open_pid_file
pid_t open_pid_file(const std::string &fname_)
Open pid file in a cross-platform way.
Definition PidFileLock.cpp:435
ASSA::PidFileLock::m_error
int m_error
Last system call error.
Definition PidFileLock.h:126
ASSA::PidFileLock::get_error_msg
const char * get_error_msg() const
In case of error, return a verbal description of the last error.
Definition PidFileLock.h:141
ASSA::PidFileLock::PidFileLock
PidFileLock()
Constructor.
Definition PidFileLock.cpp:32
ASSA::PidFileLock::get_error
int get_error() const
Return last errno value.
Definition PidFileLock.h:134
ASSA::PidFileLock::log_error
void log_error(const char *msg_)
Log an error message to the log file and set internal error to errno.
Definition PidFileLock.cpp:421
ASSA::PidFileLock::m_error_msg
string m_error_msg
Error explanation.
Definition PidFileLock.h:129
ASSA::PidFileLock::test_region
pid_t test_region()
Test if file is unlocked.
Definition PidFileLock.cpp:355
ASSA::PidFileLock::m_filename
string m_filename
Lock file name.
Definition PidFileLock.h:120
ASSA::PidFileLock::m_fd
int m_fd
Lock file descriptor.
Definition PidFileLock.h:123
ASSA::PidFileLock::dump
void dump()
Write the state of the lock to debug file.
Definition PidFileLock.cpp:384
ASSA::PidFileLock::lock
bool lock(const string &filename_)
Lock the file.
Definition PidFileLock.cpp:62
ASSA::PidFileLock::lock_region
int lock_region()
Lock the entire file.
Definition PidFileLock.cpp:178
ASSA::PidFileLock::lock_region_exclusive
int lock_region_exclusive()
Lock the entire file (only under Cygwin).
Definition PidFileLock.cpp:212
ASSA::PidFileLock::unlock_region
int unlock_region()
Unlock the entire file.
Definition PidFileLock.cpp:239
ASSA
Definition Acceptor.h:40