Files
xen/tools/xenstore/utils.c
T
Juergen Gross cbc86340ac tools/xenstore: switch barf[_perror]() to use syslog()
When xenstored crashes due to an unrecoverable condition it is calling
either barf() or barf_perror() to issue a message and then exit().

Make sure the message is visible somewhere by using syslog()
additionally to xprintf(), as the latter will be visible only with
tracing active.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2020-12-17 15:04:43 +00:00

65 lines
1.1 KiB
C

#define _GNU_SOURCE
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <signal.h>
#include "utils.h"
static void default_xprintf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fflush(stderr);
}
void (*xprintf)(const char *fmt, ...) = default_xprintf;
void barf(const char *fmt, ...)
{
char *str;
int bytes;
va_list arglist;
xprintf("FATAL: ");
va_start(arglist, fmt);
bytes = vasprintf(&str, fmt, arglist);
va_end(arglist);
if (bytes >= 0) {
syslog(LOG_CRIT, "%s\n", str);
xprintf("%s\n", str);
free(str);
}
exit(1);
}
void barf_perror(const char *fmt, ...)
{
char *str;
int bytes, err = errno;
va_list arglist;
xprintf("FATAL: ");
va_start(arglist, fmt);
bytes = vasprintf(&str, fmt, arglist);
va_end(arglist);
if (bytes >= 0) {
syslog(LOG_CRIT, "%s: %s\n", str, strerror(err));
xprintf("%s: %s\n", str, strerror(err));
free(str);
}
exit(1);
}