libassa
3.5.1
assa
PidFileLock.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// PidFileLock.h
4
//------------------------------------------------------------------------------
5
// $Id: PidFileLock.h,v 1.7 2006/07/20 02:30:54 vlg Exp $
6
//------------------------------------------------------------------------------
7
// Copyright (C) 1997-2002,2005 Vladislav Grinchenko
8
//
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Library General Public
11
// License as published by the Free Software Foundation; either
12
// version 2 of the License, or (at your option) any later version.
13
//------------------------------------------------------------------------------
14
#ifndef FILE_LOCK_H
15
#define FILE_LOCK_H
16
17
//System Includes
18
#include <sys/types.h>
19
20
#include "
assa/Assure.h
"
21
22
//STL
23
#include <string>
24
using
std::string;
25
26
#if defined(WIN32)
27
struct
flock {
28
off_t l_start;
29
off_t l_len;
30
pid_t l_pid;
31
short
l_type;
32
short
l_whence;
33
};
34
#endif
35
36
namespace
ASSA
{
37
43
class
PidFileLock
:
public
flock
44
{
45
public
:
47
PidFileLock
();
48
52
~
PidFileLock
();
53
57
bool
lock (
const
string
& filename_);
58
62
int
get_error ()
const
;
63
67
const
char
* get_error_msg ()
const
;
68
72
void
dump ();
73
74
private
:
77
pid_t open_pid_file (
const
std::string& fname_);
78
83
int
lock_region ();
84
89
int
lock_region_exclusive ();
90
94
int
unlock_region ();
95
100
int
get_lock_status ();
101
102
106
int
write_pid ();
107
112
pid_t test_region ();
113
116
void
log_error (
const
char
* msg_);
117
118
private
:
120
string
m_filename
;
121
123
int
m_fd
;
124
126
int
m_error
;
127
129
string
m_error_msg
;
130
};
131
132
inline
int
133
PidFileLock::
134
get_error ()
const
135
{
136
return
m_error;
137
}
138
139
inline
const
char
*
140
PidFileLock::
141
get_error_msg ()
const
142
{
143
return
m_error_msg.c_str ();
144
}
145
146
}
// end namespace ASSA
147
148
#endif
/* FILE_LOCK_H */
ASSA
Definition:
Acceptor.h:40
ASSA::PidFileLock::m_error
int m_error
Last system call error.
Definition:
PidFileLock.h:126
ASSA::PidFileLock::m_filename
string m_filename
Lock file name.
Definition:
PidFileLock.h:120
Assure.h
A collection of assert function wrappers.
ASSA::PidFileLock::m_fd
int m_fd
Lock file descriptor.
Definition:
PidFileLock.h:123
ASSA::PidFileLock
Definition:
PidFileLock.h:43
ASSA::PidFileLock::m_error_msg
string m_error_msg
Error explanation.
Definition:
PidFileLock.h:129
Generated by
1.8.13