file-dotlock.c revision 021665c0147e5c655efb2c3f0eff2549b31f6b5a
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina/* Copyright (c) 2003-2008 Dovecot authors, see the included COPYING file */
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina/* 0.1 .. 0.2msec */
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000)
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina/* If the dotlock is newer than this, don't verify that the PID it contains
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina is valid (since it most likely is). */
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina/* Maximum difference between current time and create file's ctime before
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina logging a warning. Should be less than a second in normal operation. */
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březinastatic struct dotlock *
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březinafile_dotlock_alloc(const struct dotlock_settings *settings)
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina dotlock->settings.lock_suffix = DEFAULT_LOCK_SUFFIX;
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březinastatic pid_t read_local_pid(const char *lock_path)
f8c829e72968b574e1c9bda96f4d5f206622358fPavel Březina /* read line */
ret--;
if (pid <= 0)
return pid;
return TRUE;
return FALSE;
bool *changed_r)
bool changed;
int ret;
return ret;
return ret;
if (!changed) {
if (stale_timeout == 0) {
const char *str;
if (p != NULL) {
if (write_pid) {
int fd;
if (write_pid) {
case IO_NOTIFY_ADDED:
case IO_NOTIFY_NOTFOUND:
case IO_NOTIFY_DISABLED:
const char **lock_path_r)
const char *lock_path;
unsigned int stale_notify_threshold;
int ret;
bool do_wait;
if (do_wait) {
if (ret < 0)
tmp_path);
if (ret != 0)
unsigned int secs_left =
if (ret > 0) {
if (ret == 0)
return ret;
int old_errno;
const char *lock_path;
return ret;
int ret;
return ret;
const char *lock_path;
int ret;
const char *lock_path;
if (ret <= 0) {
const char *lock_path;
int fd;
int ret = 0;
return ret;
const char *lock_path;
return FALSE;
return FALSE;