2000-01-19 23:07:00 +08: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-28 06:00:19 +08:00
|
|
|
#include "lib/string.h"
|
2000-01-19 23:07:00 +08:00
|
|
|
#include "client/client.h"
|
|
|
|
|
|
|
|
/* Client versions of logging functions */
|
|
|
|
|
2000-02-28 06:00:19 +08:00
|
|
|
static void
|
2014-12-03 17:57:31 +08:00
|
|
|
vlog(const char *msg, va_list args)
|
2000-02-28 06:00:19 +08:00
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
2016-05-13 03:29:04 +08:00
|
|
|
int n = vsnprintf(buf, sizeof(buf), msg, args);
|
|
|
|
if (n < 0)
|
|
|
|
snprintf(buf, sizeof(buf), "???");
|
2016-10-14 21:37:04 +08:00
|
|
|
else if (n >= (int) sizeof(buf))
|
2016-05-13 03:29:04 +08:00
|
|
|
snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>");
|
2000-02-28 06:00:19 +08:00
|
|
|
fputs(buf, stderr);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
}
|
2000-02-15 20:18:37 +08:00
|
|
|
|
2000-01-19 23:07:00 +08:00
|
|
|
void
|
2014-12-03 17:57:31 +08:00
|
|
|
bug(const char *msg, ...)
|
2000-01-19 23:07:00 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
2000-02-15 20:18:37 +08:00
|
|
|
cleanup();
|
2000-01-19 23:07:00 +08:00
|
|
|
fputs("Internal error: ", stderr);
|
2000-02-28 06:00:19 +08:00
|
|
|
vlog(msg, args);
|
2000-01-19 23:07:00 +08:00
|
|
|
vfprintf(stderr, msg, args);
|
2016-03-29 16:37:31 +08:00
|
|
|
va_end(args);
|
2000-01-19 23:07:00 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-03 17:57:31 +08:00
|
|
|
die(const char *msg, ...)
|
2000-01-19 23:07:00 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
2000-02-15 20:18:37 +08:00
|
|
|
cleanup();
|
2000-02-28 06:00:19 +08:00
|
|
|
vlog(msg, args);
|
2016-03-29 16:37:31 +08:00
|
|
|
va_end(args);
|
2000-01-19 23:07:00 +08:00
|
|
|
exit(1);
|
|
|
|
}
|