diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-04-03 19:44:08 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-04-03 19:44:08 -0700 |
commit | 1f52d5148d3191f970f7af8ed0704b5e0c7ac06b (patch) | |
tree | f135405f17ba8396e44a346df5310a9a669a9736 | |
parent | 213fe380e3d36257772c9d6de696521831b735e0 (diff) | |
download | quagga-debian/0.99.9-4.tar.bz2 quagga-debian/0.99.9-4.tar.xz |
add locking to prevent file update problemsdebian/0.99.9-4
The vyatta-interfaces script needs to update the linkstatus file,
so locking is needed to prevent concurrent read/update problems.
-rw-r--r-- | watchlink/netlink_linkstatus.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/watchlink/netlink_linkstatus.cc b/watchlink/netlink_linkstatus.cc index 191625f7..9dd26fbd 100644 --- a/watchlink/netlink_linkstatus.cc +++ b/watchlink/netlink_linkstatus.cc @@ -8,9 +8,12 @@ */ #include <stdio.h> #include <sys/socket.h> +#include <sys/file.h> #include <iostream> #include <string> #include <syslog.h> +#include <errno.h> + #include "rl_str_proc.hh" #include "netlink_send.hh" #include "netlink_event.hh" @@ -138,11 +141,19 @@ NetlinkLinkStatus::process_going_up(const NetlinkEvent &event) string file = _link_dir + "/" + buf; FILE *fp = fopen(file.c_str(), "r"); if (fp == NULL) { - syslog(LOG_INFO,"NetlinkLinkStatus::process_going_up(), failed to open state file"); + syslog(LOG_INFO,"NetlinkLinkStatus::process_going_up(), failed to open state file: %s", + strerror(errno)); // cerr << "NetlinkLinkStatus::process_going_up(), failed to open state file" << endl; return -1; //means we are still up, ignore... } + if (flock(fileno(fp), LOCK_SH)) { + syslog(LOG_INFO, "NetlinkLinkStatus::process_going_up() failed to acquire lock: %s", + strerror(errno)); + fclose(fp); + return -1; + } + char str[1025]; while (fgets(str, 1024, fp)) { string line(str); @@ -233,6 +244,13 @@ NetlinkLinkStatus::process_down(const NetlinkEvent &event) return -1; } + if (flock(fileno(fp), LOCK_EX)) { + syslog(LOG_INFO, "NetlinkLinkStatus::process_down() failed to acquire lock: %s", + strerror(errno)); + fclose(fp); + return -1; + } + int ifindex = event.get_index(); uint32_t local_addr = event.get_local_addr().get(); int mask_len = event.get_mask_len(); |