1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <time.h>
#include <sys/file.h>
#include "config.h"
#include "io.h"
#include "node.h"
static char buf[256];
void node_msg(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
tprintf("%s} %s\n", NodeId, buf);
}
void node_perror(char *str, int err)
{
int oldmode;
oldmode = set_eolmode(User.fd, EOLMODE_TEXT);
buf[0] = 0;
if (str)
strcpy(buf, str);
if (str && err != -1)
strcat(buf, ": ");
if (err != -1)
strcat(buf, strerror(err));
tprintf("%s} %s\n", NodeId, buf);
usflush(User.fd);
set_eolmode(User.fd, oldmode);
log(LOGLVL_ERROR, buf);
}
char *print_node(const char *alias, const char *call)
{
static char node[17];
sprintf(node, "%s%s%s",
!strcmp(alias, "*") ? "" : alias,
!strcmp(alias, "*") ? "" : ":",
call);
return node;
}
void log(int loglevel, const char *fmt, ...)
{
va_list args;
int pri;
static int opened = 0;
if (LogLevel < loglevel)
return;
if (!opened) {
openlog("node", LOG_PID, LOG_LOCAL7);
opened = 1;
}
switch (loglevel) {
case LOGLVL_ERROR:
pri = LOG_ERR;
break;
case LOGLVL_LOGIN:
pri = LOG_NOTICE;
break;
case LOGLVL_GW:
pri = LOG_INFO;
break;
default:
pri = LOG_INFO;
break;
}
va_start(args, fmt);
vsprintf(buf, fmt, args);
syslog(pri, buf);
va_end(args);
}
|