Tor 0.4.9.0-alpha-dev
Data Structures | Functions
lockfile.c File Reference

Implements lock files to prevent two Tor processes from using the same data directory at the same time. More...

#include "orconfig.h"
#include "lib/fs/files.h"
#include "lib/fs/lockfile.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/malloc/malloc.h"
#include <errno.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  tor_lockfile_t
 

Functions

tor_lockfile_ttor_lockfile_lock (const char *filename, int blocking, int *locked_out)
 
void tor_lockfile_unlock (tor_lockfile_t *lockfile)
 

Detailed Description

Implements lock files to prevent two Tor processes from using the same data directory at the same time.

Definition in file lockfile.c.

Function Documentation

◆ tor_lockfile_lock()

tor_lockfile_t * tor_lockfile_lock ( const char *  filename,
int  blocking,
int *  locked_out 
)

Try to get a lock on the lockfile filename, creating it as necessary. If someone else has the lock and blocking is true, wait until the lock is available. Otherwise return immediately whether we succeeded or not.

Set *locked_out to true if somebody else had the lock, and to false otherwise.

Return a tor_lockfile_t on success, NULL on failure.

(Implementation note: because we need to fall back to fcntl on some platforms, these locks are per-process, not per-thread. If you want to do in-process locking, use tor_mutex_t like a normal person. On Windows, when blocking is true, the maximum time that is actually waited is 10 seconds, after which NULL is returned and locked_out is set to 1.)

Definition at line 63 of file lockfile.c.

◆ tor_lockfile_unlock()

void tor_lockfile_unlock ( tor_lockfile_t lockfile)

Release the lock held as lockfile.

Definition at line 121 of file lockfile.c.

Referenced by release_lockfile().