0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 18:08:45 +00:00

MRT Table Dump: Bugfix creating filename from fmt

- At *BSD systems a command 'date +%f' returns only 'f' without percent
- Small fixes for *BSD systems
This commit is contained in:
Pavel Tvrdík 2015-08-03 13:06:55 +02:00
parent 0722998578
commit 2d2d8293b7
3 changed files with 17 additions and 16 deletions

View File

@ -170,8 +170,9 @@ mrt_peer_index_table_add_peer(struct mrt_peer_index_table *state, u32 peer_bgp_i
struct mrt_buffer *msg = &state->msg;
u8 peer_type = MRT_PEER_TYPE_32BIT_ASN;
if (sizeof(peer_ip_addr) > sizeof(ip4_addr))
#ifdef IPV6
peer_type |= MRT_PEER_TYPE_IPV6;
#endif
mrt_buffer_put_var_autosize(msg, peer_type);
mrt_buffer_put_var_autosize(msg, peer_bgp_id);

View File

@ -17,8 +17,8 @@
#include "lib/event.h"
#define MRT_HDR_LENGTH 12 /* MRT Timestamp + MRT Type + MRT Subtype + MRT Load Length */
#define MRT_PEER_TYPE_32BIT_ASN 0b00000010 /* MRT Table Dump: Peer Index Table: Peer Type: Use 32bit ASN */
#define MRT_PEER_TYPE_IPV6 0b00000001 /* MRT Table Dump: Peer Index Table: Peer Type: Use IPv6 IP Address */
#define MRT_PEER_TYPE_32BIT_ASN 2 /* MRT Table Dump: Peer Index Table: Peer Type: Use 32bit ASN */
#define MRT_PEER_TYPE_IPV6 1 /* MRT Table Dump: Peer Index Table: Peer Type: Use IPv6 IP Address */
#ifdef PATH_MAX
#define BIRD_PATH_MAX PATH_MAX

View File

@ -2858,7 +2858,7 @@ mrt_str_replace(const char *orig, const char *rep, const char *with)
* ins points to the next occurrence of rep in orig
* orig points to the remainder of orig after "end of rep"
*/
tmp = result = mb_alloc(&root_pool, strlen(orig) + (len_with - len_rep) * num_of_replacements + 1);
tmp = result = mb_alloc(rt_table_pool, strlen(orig) + (len_with - len_rep) * num_of_replacements + 1);
if (!result)
return NULL;
@ -2889,18 +2889,18 @@ mrt_table_dump_get_realpath(const char *filename)
void
mrt_table_dump_init_file_descriptor(struct mrt_table_dump_ctx *state)
{
char *tablename = state->config.table_cf->name;
char *filename_fmt = mrt_str_replace(mrt_table_dump_config_get_filename_fmt(state), "%f", tablename);
if (filename_fmt)
{
struct timeformat timestamp_fmt = {
.fmt1 = mrt_table_dump_config_get_filename_fmt(state),
.fmt1 = filename_fmt,
};
char timestamp[TM_DATETIME_BUFFER_SIZE];
tm_format_datetime(timestamp, &timestamp_fmt, now);
char *tablename = state->config.table_cf->name;
char *filename = mrt_str_replace(timestamp, "%f", tablename);
if (filename)
{
char filename[TM_DATETIME_BUFFER_SIZE];
tm_format_datetime(filename, &timestamp_fmt, now);
state->rfile = tracked_fopen(rt_table_pool, filename, "a");
const char *filename_fullpath = mrt_table_dump_get_realpath(filename);
@ -2923,14 +2923,14 @@ mrt_table_dump_init_file_descriptor(struct mrt_table_dump_ctx *state)
cli_msg(13, "Dump of table %s is saving into file \"%s\"", tablename, state->file_path);
}
}
mb_free(filename);
mb_free(filename_fmt);
}
else
{
log(L_ERR "Parsing MRT dump filename format \"%s\" for table %s failed", timestamp_fmt.fmt1, tablename);
log(L_ERR "Parsing MRT dump filename filename_fmt \"%s\" for table %s failed", mrt_table_dump_config_get_filename_fmt(state), tablename);
if (state->config.c.cli)
{
cli_msg(13, "Parsing filename format \"%s\" for table %s failed", timestamp_fmt.fmt1, tablename);
cli_msg(13, "Parsing filename filename_fmt \"%s\" for table %s failed", mrt_table_dump_config_get_filename_fmt(state), tablename);
}
}
}