17inline void err_exit(
const char *str =
nullptr) {
26 if (error) exit(EXIT_FAILURE);
29inline void bzero(
void *p,
size_t n) { memset(p, 0, n); }
33#define BD_NO_CLOSE_FILES 2
34#define BD_NO_REOPEN_STD_FDS 4
36#define BD_MAX_CLOSE 8192
41 bool fail = !lock_file_path;
43 int fd = open(lock_file_path, O_RDWR | O_CREAT, 0664);
46 std::cerr << format(
"open {} fail: {}\n", lock_file_path, std::strerror(errno));
47 }
else if (flock(fd, LOCK_EX | LOCK_NB) != 0) {
49 std::cerr <<
"another proc lock the file\n";
54 if (fail && exit) ::exit(EXIT_FAILURE);
Definition: algorithm.h:10
void err_exit(const char *str=nullptr)
Definition: process.h:17
bool single_proc(const char *lock_file_path, bool exit)
Definition: process.h:40
int become_daemon(int flags)
void bzero(void *p, size_t n)
Definition: process.h:29
void err_exit_if(bool error)
Definition: process.h:25