diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2018-09-12 21:58:39 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2018-09-12 21:58:39 +0200 |
| commit | e991eff5b5773e8a85c3f4c4f92c09fe30cf680b (patch) | |
| tree | ab98bf44cfc7611ad7cc699396674554f150db43 /lib/libfrr.c | |
| parent | 364fed6b074a702f21e190cb7aff33e13c65e808 (diff) | |
| parent | 7aab2afbad2f25c128e9e608766b407f6bd34c89 (diff) | |
Merge remote-tracking branch 'frr/master' into warnings
Conflicts:
zebra/if_ioctl_solaris.c
zebra/rtread_getmsg.c
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/libfrr.c')
| -rw-r--r-- | lib/libfrr.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c index 18e2636560..ecdc277572 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -262,6 +262,32 @@ bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len, 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(LIB_ERR_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(LIB_ERR_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; @@ -591,6 +617,9 @@ struct thread_master *frr_init(void) 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); |
