summaryrefslogtreecommitdiff
path: root/bgpd
diff options
context:
space:
mode:
authorDaniel Kozlowski <dkozlowski@sevone.com>2012-09-26 12:01:24 +0000
committerDavid Lamparter <equinox@opensourcerouting.org>2012-11-01 22:58:38 -0700
commitb07458a055493dd37cb955ae90f11ae8bc334d3a (patch)
treed0bc403501b7cc8f7be805da9dd5d6d29846af20 /bgpd
parent3f0bfc9e82e0d735be2cb06d5c4a3028650637bf (diff)
bgpd: flock() dump files (BZ#742)
flock()ing the BGP dump files helps consumers determine when they're safe to read. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/bgp_dump.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index edb725a9..77548601 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -95,6 +95,7 @@ static FILE *
bgp_dump_open_file (struct bgp_dump *bgp_dump)
{
int ret;
+ int fd;
time_t clock;
struct tm *tm;
char fullpath[MAXPATHLEN];
@@ -131,6 +132,16 @@ bgp_dump_open_file (struct bgp_dump *bgp_dump)
umask(oldumask);
return NULL;
}
+ else
+ {
+ fd = fileno(bgp_dump->fp);
+ ret = flock( fd, LOCK_EX );
+ if (ret != 0)
+ {
+ zlog_warn ("bgp_dump_open_file: Unable to flock() file %s: %s", realpath, strerror (errno));
+ }
+ }
+
umask(oldumask);
return bgp_dump->fp;
@@ -195,6 +206,7 @@ bgp_dump_set_size (struct stream *s, int type)
static void
bgp_dump_routes_index_table(struct bgp *bgp)
{
+ int ret;
struct peer *peer;
struct listnode *node;
uint16_t peerno = 0;
@@ -266,7 +278,11 @@ bgp_dump_routes_index_table(struct bgp *bgp)
bgp_dump_set_size(obuf, MSG_TABLE_DUMP_V2);
- fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_routes.fp);
+ ret = fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_routes.fp);
+ if (ret != 1)
+ {
+ zlog_warn ("bgp_dump_routes_index_table: fwrite returned %d, expected 1: %s", ret, strerror (errno));
+ }
fflush (bgp_dump_routes.fp);
}
@@ -275,6 +291,7 @@ bgp_dump_routes_index_table(struct bgp *bgp)
static unsigned int
bgp_dump_routes_func (int afi, int first_run, unsigned int seq)
{
+ int ret;
struct stream *obuf;
struct bgp_info *info;
struct bgp_node *rn;
@@ -373,8 +390,11 @@ bgp_dump_routes_func (int afi, int first_run, unsigned int seq)
seq++;
bgp_dump_set_size(obuf, MSG_TABLE_DUMP_V2);
- fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_routes.fp);
-
+ ret = fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_routes.fp);
+ if (ret != 1)
+ {
+ zlog_warn ("bgp_dump_routes_func: fwrite returned %d, expected 1: %s", ret, strerror (errno));
+ }
}
fflush (bgp_dump_routes.fp);
@@ -464,6 +484,7 @@ bgp_dump_common (struct stream *obuf, struct peer *peer, int forceas4)
void
bgp_dump_state (struct peer *peer, int status_old, int status_new)
{
+ int ret;
struct stream *obuf;
/* If dump file pointer is disabled return immediately. */
@@ -484,7 +505,11 @@ bgp_dump_state (struct peer *peer, int status_old, int status_new)
bgp_dump_set_size (obuf, MSG_PROTOCOL_BGP4MP);
/* Write to the stream. */
- fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_all.fp);
+ ret = fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump_all.fp);
+ if (ret != 1)
+ {
+ zlog_warn ("bgp_dump_state: fwrite returned %d, expected 1: %s", ret, strerror (errno));
+ }
fflush (bgp_dump_all.fp);
}
@@ -492,6 +517,7 @@ static void
bgp_dump_packet_func (struct bgp_dump *bgp_dump, struct peer *peer,
struct stream *packet)
{
+ int ret;
struct stream *obuf;
/* If dump file pointer is disabled return immediately. */
@@ -520,7 +546,11 @@ bgp_dump_packet_func (struct bgp_dump *bgp_dump, struct peer *peer,
bgp_dump_set_size (obuf, MSG_PROTOCOL_BGP4MP);
/* Write to the stream. */
- fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump->fp);
+ ret = fwrite (STREAM_DATA (obuf), stream_get_endp (obuf), 1, bgp_dump->fp);
+ if (ret != 1)
+ {
+ zlog_warn ("bgp_dump_packet_func: fwrite returned %d, expected 1: %s", ret, strerror (errno));
+ }
fflush (bgp_dump->fp);
}