static struct frr_daemon_info *di = NULL;
-static void frr_guard_daemon(void)
-{
- int fd;
- struct flock lock;
- const char *path = di->pid_file;
-
- fd = open(path, O_RDWR);
- if (fd != -1) {
- memset(&lock, 0, sizeof(lock));
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- if (fcntl(fd, F_GETLK, &lock) < 0) {
- flog_err_sys(
- EC_LIB_SYSTEM_CALL,
- "Could not do F_GETLK pid_file %s (%s), exiting",
- path, safe_strerror(errno));
- exit(1);
- } else if (lock.l_type == F_WRLCK) {
- flog_err_sys(
- EC_LIB_SYSTEM_CALL,
- "Process %d has a write lock on file %s already! Error: (%s)",
- lock.l_pid, path, safe_strerror(errno));
- exit(1);
- }
- close(fd);
- }
-}
-
void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv)
{
di = daemon;
zprivs_init(di->privs);
- /* Guard to prevent a second instance of this daemon */
- frr_guard_daemon();
-
master = thread_master_create(NULL);
signal_init(master, di->n_signals, di->signals);