2000-01-19 15:07:00 +00:00
|
|
|
/*
|
|
|
|
* BIRD Client -- Utility Functions
|
|
|
|
*
|
|
|
|
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
2000-02-27 22:00:19 +00:00
|
|
|
#include "lib/string.h"
|
2000-01-19 15:07:00 +00:00
|
|
|
#include "client/client.h"
|
|
|
|
|
|
|
|
/* Client versions of logging functions */
|
|
|
|
|
2000-02-27 22:00:19 +00:00
|
|
|
static void
|
2024-11-14 20:20:49 +00:00
|
|
|
vlog_cli(const char *msg, va_list args)
|
2000-02-27 22:00:19 +00:00
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
2016-05-12 19:29:04 +00:00
|
|
|
int n = vsnprintf(buf, sizeof(buf), msg, args);
|
|
|
|
if (n < 0)
|
|
|
|
snprintf(buf, sizeof(buf), "???");
|
2016-10-14 13:37:04 +00:00
|
|
|
else if (n >= (int) sizeof(buf))
|
2016-05-12 19:29:04 +00:00
|
|
|
snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>");
|
2000-02-27 22:00:19 +00:00
|
|
|
fputs(buf, stderr);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
}
|
2000-02-15 12:18:37 +00:00
|
|
|
|
2000-01-19 15:07:00 +00:00
|
|
|
void
|
2014-12-03 09:57:31 +00:00
|
|
|
bug(const char *msg, ...)
|
2000-01-19 15:07:00 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
2000-02-15 12:18:37 +00:00
|
|
|
cleanup();
|
2000-01-19 15:07:00 +00:00
|
|
|
fputs("Internal error: ", stderr);
|
2024-11-14 20:20:49 +00:00
|
|
|
vlog_cli(msg, args);
|
2000-01-19 15:07:00 +00:00
|
|
|
vfprintf(stderr, msg, args);
|
2016-03-29 08:37:31 +00:00
|
|
|
va_end(args);
|
2000-01-19 15:07:00 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-03 09:57:31 +00:00
|
|
|
die(const char *msg, ...)
|
2000-01-19 15:07:00 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
2000-02-15 12:18:37 +00:00
|
|
|
cleanup();
|
2024-11-14 20:20:49 +00:00
|
|
|
vlog_cli(msg, args);
|
2016-03-29 08:37:31 +00:00
|
|
|
va_end(args);
|
2000-01-19 15:07:00 +00:00
|
|
|
exit(1);
|
|
|
|
}
|