Mercurial > trustbridge
diff common/linuxlockfile.h @ 782:20ca94680003
Implemented detection of running instance on linux using a lock file.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Mon, 14 Jul 2014 12:46:47 +0200 |
parents | |
children | 78798d3af8f0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/linuxlockfile.h Mon Jul 14 12:46:47 2014 +0200 @@ -0,0 +1,38 @@ +/** + * @file linuxlockfile.h + * @brief Linux specific functions for lock file handling. + * @details Functions to handle procsss specific lock files, these are + * only used on GNU Linux as on windows different mechanisms are + * utilized to ensure only a single instance runs at a time. + */ + +#ifndef LINUXLOCKFILE_H +#define LINUXLOCKFILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief create a lockfile + * @details create and lock a lockfile containing the pid of the + * current process. fcntl is used for locking, to work in most cases + * (e.g. NFS). + * @param[in] path to the lockfile + * @returns the file descriptor of the lockfile or -1 on error + */ +int open_lockfile(char *path); + +/** + * @brief close a lockfile + * @details unlock and close a lockfile for the given file descriptor. + * @param[in] path to the lockfile + * @returns the file descriptor of the lockfile or -1 on error + */ +void close_lockfile(int fd); + +#ifdef __cplusplus +} +#endif + +#endif