Fixed nodes logging

This commit is contained in:
Michiel Broek 2002-12-28 20:29:26 +00:00
parent 02e99d131e
commit fbe81bfa68
4 changed files with 196 additions and 174 deletions

View File

@ -78,7 +78,7 @@ int check_calllist(void)
} }
} }
if (!found) { if (!found) {
Syslog('c', "Removing slot %d node %s from calllist", i, ascfnode(calllist[i].addr, 0x0f)); Syslog('c', "Removing slot %d node %s from calllist", i, fido2str(calllist[i].addr, 0x0f));
memset(&calllist[i], 0, sizeof(tocall)); memset(&calllist[i], 0, sizeof(tocall));
} }
} }
@ -113,7 +113,7 @@ int check_calllist(void)
if (!found) { if (!found) {
for (i = 0; i < MAXTASKS; i++) { for (i = 0; i < MAXTASKS; i++) {
if (!calllist[i].addr.zone) { if (!calllist[i].addr.zone) {
Syslog('c', "Adding %s to calllist slot %d", ascfnode(tmp->addr, 0x1f), i); Syslog('c', "Adding %s to calllist slot %d", fido2str(tmp->addr, 0x1f), i);
calllist[i].addr = tmp->addr; calllist[i].addr = tmp->addr;
calllist[i].cst = tmp->cst; calllist[i].cst = tmp->cst;
calllist[i].callmode = tmp->callmode; calllist[i].callmode = tmp->callmode;
@ -142,7 +142,7 @@ int check_calllist(void)
call_work++; call_work++;
Syslog('c', "%4d %s %5d %3d %s %s %08x %08x %08x %s", i, calllist[i].calling?"true ":"false", calllist[i].taskpid, Syslog('c', "%4d %s %5d %3d %s %s %08x %08x %08x %s", i, calllist[i].calling?"true ":"false", calllist[i].taskpid,
calllist[i].cst.tryno, callstatus(calllist[i].cst.trystat), callmode(calllist[i].callmode), calllist[i].cst.tryno, callstatus(calllist[i].cst.trystat), callmode(calllist[i].callmode),
calllist[i].moflags, calllist[i].diflags, calllist[i].ipflags, ascfnode(calllist[i].addr, 0x1f)); calllist[i].moflags, calllist[i].diflags, calllist[i].ipflags, fido2str(calllist[i].addr, 0x1f));
} }
} }

View File

@ -516,7 +516,7 @@ int outstat()
* Here we are out of options, clear callflag. * Here we are out of options, clear callflag.
*/ */
if (tmp->callmode == CM_NONE) { if (tmp->callmode == CM_NONE) {
Syslog('!', "No method to call %s available", ascfnode(tmp->addr, 0x0f)); Syslog('!', "No method to call %s available", fido2str(tmp->addr, 0x0f));
tmp->flavors &= ~F_CALL; tmp->flavors &= ~F_CALL;
} }
} }
@ -535,7 +535,7 @@ int outstat()
sprintf(temp, "%s %8s %08x %08x %08x %08x %5d %s %s %s", flstr, size_str(tmp->size), sprintf(temp, "%s %8s %08x %08x %08x %08x %5d %s %s %s", flstr, size_str(tmp->size),
(unsigned int)tmp->olflags, (unsigned int)tmp->moflags, (unsigned int)tmp->olflags, (unsigned int)tmp->moflags,
(unsigned int)tmp->diflags, (unsigned int)tmp->ipflags, (unsigned int)tmp->diflags, (unsigned int)tmp->ipflags,
tmp->cst.tryno, callstatus(tmp->cst.trystat), callmode(tmp->callmode), ascfnode(tmp->addr, 0x0f)); tmp->cst.tryno, callstatus(tmp->cst.trystat), callmode(tmp->callmode), fido2str(tmp->addr, 0x0f));
Syslog('+', "%s", temp); Syslog('+', "%s", temp);
} /* All nodes scanned. */ } /* All nodes scanned. */
@ -591,6 +591,7 @@ int each(faddr *addr, char flavor, int isflo, char *fname)
(strcasecmp((*tmp)->addr.domain,addr->domain) == 0))) (strcasecmp((*tmp)->addr.domain,addr->domain) == 0)))
break; break;
if (*tmp == NULL) { if (*tmp == NULL) {
Syslog('-', "%s", ascfnode(addr, 0xff));
nlent = getnlent(addr); nlent = getnlent(addr);
*tmp = (struct _alist *)malloc(sizeof(struct _alist)); *tmp = (struct _alist *)malloc(sizeof(struct _alist));
(*tmp)->next = NULL; (*tmp)->next = NULL;

View File

@ -67,15 +67,15 @@ static char *mon[] = {
char *date(void); char *date(void);
char *date(void) char *date(void)
{ {
struct tm ptm; struct tm ptm;
time_t now; time_t now;
static char buf[20]; static char buf[20];
now = time(NULL); now = time(NULL);
ptm = *localtime(&now); ptm = *localtime(&now);
sprintf(buf,"%02d-%s-%04d %02d:%02d:%02d", ptm.tm_mday, mon[ptm.tm_mon], ptm.tm_year+1900, sprintf(buf,"%02d-%s-%04d %02d:%02d:%02d", ptm.tm_mday, mon[ptm.tm_mon], ptm.tm_year+1900,
ptm.tm_hour, ptm.tm_min, ptm.tm_sec); ptm.tm_hour, ptm.tm_min, ptm.tm_sec);
return(buf); return(buf);
} }
@ -100,56 +100,56 @@ void WriteError(const char *format, ...)
*/ */
void Syslog(int grade, const char *format, ...) void Syslog(int grade, const char *format, ...)
{ {
va_list va_ptr; va_list va_ptr;
char outstr[1024]; char outstr[1024];
int oldmask; int oldmask;
FILE *logfile; FILE *logfile;
char *logname; char *logname;
if (grade == '+' || grade == '-' || grade == '!' || grade == '?' || grade == ' ' || TCFG.debug) { if (grade == '+' || grade == '-' || grade == '!' || grade == '?' || grade == ' ' || TCFG.debug) {
va_start(va_ptr, format); va_start(va_ptr, format);
vsprintf(outstr, format, va_ptr); vsprintf(outstr, format, va_ptr);
va_end(va_ptr); va_end(va_ptr);
tcrc = StringCRC32(outstr); tcrc = StringCRC32(outstr);
if (tcrc == lcrc) { if (tcrc == lcrc) {
lcnt++; lcnt++;
return; return;
}
lcrc = tcrc;
logname = calloc(PATH_MAX, sizeof(char));
oldmask=umask(066);
sprintf(logname, "%s/log/mbtask.log", getenv("MBSE_ROOT"));
logfile = fopen(logname, "a");
umask(oldmask);
if (logfile == NULL) {
printf("Cannot open logfile \"%s\"\n", logname);
free(logname);
return;
}
if ((lcnt) && ((lchr == '+') || (lchr == '-') || (lchr == '!') || (lchr == '?') || (lchr == ' ') || TCFG.debug)) {
lcnt++;
fprintf(logfile, "%c %s mbtask[%d] last message repeated %d times\n", lchr, date(), getpid(), lcnt);
}
lcnt = 0;
fprintf(logfile, "%c %s mbtask[%d] ", grade, date(), getpid());
fprintf(logfile, *outstr == '$' ? outstr+1 : outstr);
if (*outstr == '$')
fprintf(logfile, ": %s\n", strerror(errno));
else
fprintf(logfile, "\n");
fflush(logfile);
if (fclose(logfile) != 0)
printf("Cannot close logfile \"%s\"\n", logname);
lchr = grade;
free(logname);
} }
return; lcrc = tcrc;
logname = calloc(PATH_MAX, sizeof(char));
oldmask=umask(066);
sprintf(logname, "%s/log/mbtask.log", getenv("MBSE_ROOT"));
logfile = fopen(logname, "a");
umask(oldmask);
if (logfile == NULL) {
printf("Cannot open logfile \"%s\"\n", logname);
free(logname);
return;
}
if ((lcnt) && ((lchr == '+') || (lchr == '-') || (lchr == '!') || (lchr == '?') || (lchr == ' ') || TCFG.debug)) {
lcnt++;
fprintf(logfile, "%c %s mbtask[%d] last message repeated %d times\n", lchr, date(), getpid(), lcnt);
}
lcnt = 0;
fprintf(logfile, "%c %s mbtask[%d] ", grade, date(), getpid());
fprintf(logfile, *outstr == '$' ? outstr+1 : outstr);
if (*outstr == '$')
fprintf(logfile, ": %s\n", strerror(errno));
else
fprintf(logfile, "\n");
fflush(logfile);
if (fclose(logfile) != 0)
printf("Cannot close logfile \"%s\"\n", logname);
lchr = grade;
free(logname);
}
return;
} }
@ -159,117 +159,117 @@ void Syslog(int grade, const char *format, ...)
*/ */
int ulog(char *fn, char *grade, char *prname, char *prpid, char *format) int ulog(char *fn, char *grade, char *prname, char *prpid, char *format)
{ {
int oldmask; int oldmask;
FILE *log; FILE *log;
oldmask = umask(066); oldmask = umask(066);
log = fopen(fn, "a"); log = fopen(fn, "a");
umask(oldmask); umask(oldmask);
if (log == NULL) { if (log == NULL) {
oserr = errno; oserr = errno;
Syslog('!', "$Cannot open user logfile %s", fn); Syslog('!', "$Cannot open user logfile %s", fn);
return -1; return -1;
} }
fprintf(log, "%s %s %s[%s] ", grade, date(), prname, prpid); fprintf(log, "%s %s %s[%s] ", grade, date(), prname, prpid);
fwrite(format, strlen(format), 1, log); fwrite(format, strlen(format), 1, log);
fprintf(log, "\n"); fprintf(log, "\n");
fflush(log); fflush(log);
if (fclose(log) != 0) { if (fclose(log) != 0) {
oserr = errno; oserr = errno;
Syslog('!', "$Cannot close user logfile %s", fn); Syslog('!', "$Cannot close user logfile %s", fn);
return -1; return -1;
} }
return 0; return 0;
} }
char *xstrcpy(char *src) char *xstrcpy(char *src)
{ {
char *tmp; char *tmp;
if (src == NULL) if (src == NULL)
return(NULL); return(NULL);
tmp = malloc(strlen(src)+1); tmp = malloc(strlen(src)+1);
strcpy(tmp, src); strcpy(tmp, src);
return tmp; return tmp;
} }
char *xstrcat(char *src, char *add) char *xstrcat(char *src, char *add)
{ {
char *tmp; char *tmp;
size_t size = 0; size_t size = 0;
if ((add == NULL) || (strlen(add) == 0)) if ((add == NULL) || (strlen(add) == 0))
return src; return src;
if (src) if (src)
size = strlen(src); size = strlen(src);
size += strlen(add); size += strlen(add);
tmp = malloc(size + 1); tmp = malloc(size + 1);
*tmp = '\0'; *tmp = '\0';
if (src) { if (src) {
strcpy(tmp, src); strcpy(tmp, src);
free(src); free(src);
} }
strcat(tmp, add); strcat(tmp, add);
return tmp; return tmp;
} }
void CreateSema(char *sem) void CreateSema(char *sem)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
int fd; int fd;
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
if (access(temp, F_OK) == 0) if (access(temp, F_OK) == 0)
return; return;
if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0) if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0)
close(fd); close(fd);
else else
Syslog('?', "Can't create semafore %s", temp); Syslog('?', "Can't create semafore %s", temp);
} }
void TouchSema(char *sem) void TouchSema(char *sem)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
int fd; int fd;
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0) { if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0) {
close(fd); close(fd);
} else } else
Syslog('?', "Can't touch semafore %s", temp); Syslog('?', "Can't touch semafore %s", temp);
} }
void RemoveSema(char *sem) void RemoveSema(char *sem)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
if (access(temp, F_OK)) if (access(temp, F_OK))
return; return;
if (unlink(temp) == -1) if (unlink(temp) == -1)
Syslog('?', "Can't remove semafore %s", temp); Syslog('?', "Can't remove semafore %s", temp);
} }
int IsSema(char *sem) int IsSema(char *sem)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
return (access(temp, F_OK) == 0); return (access(temp, F_OK) == 0);
} }
@ -283,10 +283,10 @@ int IsSema(char *sem)
*/ */
int file_exist(char *path, int mode) int file_exist(char *path, int mode)
{ {
if (access(path, mode) != 0) if (access(path, mode) != 0)
return errno; return errno;
return 0; return 0;
} }
@ -295,32 +295,32 @@ int file_exist(char *path, int mode)
*/ */
int mkdirs(char *name, mode_t mode) int mkdirs(char *name, mode_t mode)
{ {
char buf[PATH_MAX], *p, *q; char buf[PATH_MAX], *p, *q;
int rc, last = 0, oldmask; int rc, last = 0, oldmask;
memset(&buf, 0, sizeof(buf)); memset(&buf, 0, sizeof(buf));
strncpy(buf, name, sizeof(buf)-1); strncpy(buf, name, sizeof(buf)-1);
buf[sizeof(buf)-1] = '\0'; buf[sizeof(buf)-1] = '\0';
p = buf+1; p = buf+1;
oldmask = umask(000); oldmask = umask(000);
while ((q = strchr(p, '/'))) { while ((q = strchr(p, '/'))) {
*q = '\0'; *q = '\0';
rc = mkdir(buf, mode); rc = mkdir(buf, mode);
last = errno; last = errno;
*q = '/'; *q = '/';
p = q+1; p = q+1;
} }
umask(oldmask); umask(oldmask);
if ((last == 0) || (last == EEXIST)) { if ((last == 0) || (last == EEXIST)) {
return TRUE; return TRUE;
} else { } else {
Syslog('?', "$mkdirs(%s)", name); Syslog('?', "$mkdirs(%s)", name);
return FALSE; return FALSE;
} }
} }
@ -330,12 +330,12 @@ int mkdirs(char *name, mode_t mode)
*/ */
long file_size(char *path) long file_size(char *path)
{ {
static struct stat sb; static struct stat sb;
if (stat(path, &sb) == -1) if (stat(path, &sb) == -1)
return -1; return -1;
return sb.st_size; return sb.st_size;
} }
@ -347,39 +347,59 @@ long file_size(char *path)
*/ */
time_t file_time(char *path) time_t file_time(char *path)
{ {
static struct stat sb; static struct stat sb;
if (stat(path, &sb) == -1) if (stat(path, &sb) == -1)
return -1; return -1;
return sb.st_mtime; return sb.st_mtime;
} }
/* /*
* Return ASCII string for node, the bits in 'fl' set the * Return ASCII string for node, the bits in 'fl' set the output format.
* output format.
*/ */
char *ascfnode(fidoaddr a, int fl) char *ascfnode(faddr *a, int fl)
{ {
static char buf[128]; static char buf[128];
buf[0] = '\0'; buf[0] = '\0';
if ((fl & 0x08) && (a.zone)) if ((fl & 0x08) && (a->zone))
sprintf(buf+strlen(buf),"%u:",a.zone); sprintf(buf+strlen(buf),"%u:",a->zone);
if (fl & 0x04) if (fl & 0x04)
sprintf(buf+strlen(buf),"%u/",a.net); sprintf(buf+strlen(buf),"%u/",a->net);
if (fl & 0x02) if (fl & 0x02)
sprintf(buf+strlen(buf),"%u",a.node); sprintf(buf+strlen(buf),"%u",a->node);
if ((fl & 0x01) && (a.point)) if ((fl & 0x01) && (a->point))
sprintf(buf+strlen(buf),".%u",a.point); sprintf(buf+strlen(buf),".%u",a->point);
if ((fl & 0x10) && (strlen(a.domain))) if ((fl & 0x10) && (strlen(a->domain)))
sprintf(buf+strlen(buf),"@%s",a.domain); sprintf(buf+strlen(buf),"@%s",a->domain);
return buf; return buf;
} }
/*
* Return ASCII string for node, the bits in 'fl' set the output format.
*/
char *fido2str(fidoaddr a, int fl)
{
static char buf[128];
buf[0] = '\0';
if ((fl & 0x08) && (a.zone))
sprintf(buf+strlen(buf),"%u:",a.zone);
if (fl & 0x04)
sprintf(buf+strlen(buf),"%u/",a.net);
if (fl & 0x02)
sprintf(buf+strlen(buf),"%u",a.node);
if ((fl & 0x01) && (a.point))
sprintf(buf+strlen(buf),".%u",a.point);
if ((fl & 0x10) && (strlen(a.domain)))
sprintf(buf+strlen(buf),"@%s",a.domain);
return buf;
}
char *Dos2Unix(char *dosname) char *Dos2Unix(char *dosname)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];

View File

@ -34,7 +34,8 @@ int file_exist(char *, int);
int mkdirs(char *, mode_t); int mkdirs(char *, mode_t);
long file_size(char *); long file_size(char *);
time_t file_time(char *); time_t file_time(char *);
char *ascfnode(fidoaddr, int); char *ascfnode(faddr *, int);
char *fido2str(fidoaddr, int);
char *Dos2Unix(char *); char *Dos2Unix(char *);
char *dayname(void); char *dayname(void);
void InitFidonet(void); void InitFidonet(void);