From fbe81bfa68971f79a4c51539d563f99fc71ff9ec Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 28 Dec 2002 20:29:26 +0000 Subject: [PATCH] Fixed nodes logging --- mbtask/calllist.c | 6 +- mbtask/outstat.c | 5 +- mbtask/taskutil.c | 356 ++++++++++++++++++++++++---------------------- mbtask/taskutil.h | 3 +- 4 files changed, 196 insertions(+), 174 deletions(-) diff --git a/mbtask/calllist.c b/mbtask/calllist.c index d569cef1..6819e750 100644 --- a/mbtask/calllist.c +++ b/mbtask/calllist.c @@ -78,7 +78,7 @@ int check_calllist(void) } } 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)); } } @@ -113,7 +113,7 @@ int check_calllist(void) if (!found) { for (i = 0; i < MAXTASKS; i++) { 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].cst = tmp->cst; calllist[i].callmode = tmp->callmode; @@ -142,7 +142,7 @@ int check_calllist(void) call_work++; 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].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)); } } diff --git a/mbtask/outstat.c b/mbtask/outstat.c index bfa7ded0..509d456d 100644 --- a/mbtask/outstat.c +++ b/mbtask/outstat.c @@ -516,7 +516,7 @@ int outstat() * Here we are out of options, clear callflag. */ 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; } } @@ -535,7 +535,7 @@ int outstat() 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->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); } /* All nodes scanned. */ @@ -591,6 +591,7 @@ int each(faddr *addr, char flavor, int isflo, char *fname) (strcasecmp((*tmp)->addr.domain,addr->domain) == 0))) break; if (*tmp == NULL) { + Syslog('-', "%s", ascfnode(addr, 0xff)); nlent = getnlent(addr); *tmp = (struct _alist *)malloc(sizeof(struct _alist)); (*tmp)->next = NULL; diff --git a/mbtask/taskutil.c b/mbtask/taskutil.c index 82a73f07..1fc4863b 100644 --- a/mbtask/taskutil.c +++ b/mbtask/taskutil.c @@ -67,15 +67,15 @@ static char *mon[] = { char *date(void); char *date(void) { - struct tm ptm; - time_t now; - static char buf[20]; + struct tm ptm; + time_t now; + static char buf[20]; - now = time(NULL); - ptm = *localtime(&now); - sprintf(buf,"%02d-%s-%04d %02d:%02d:%02d", ptm.tm_mday, mon[ptm.tm_mon], ptm.tm_year+1900, + now = time(NULL); + ptm = *localtime(&now); + 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); - return(buf); + return(buf); } @@ -100,56 +100,56 @@ void WriteError(const char *format, ...) */ void Syslog(int grade, const char *format, ...) { - va_list va_ptr; - char outstr[1024]; - int oldmask; - FILE *logfile; - char *logname; + va_list va_ptr; + char outstr[1024]; + int oldmask; + FILE *logfile; + char *logname; - if (grade == '+' || grade == '-' || grade == '!' || grade == '?' || grade == ' ' || TCFG.debug) { - va_start(va_ptr, format); - vsprintf(outstr, format, va_ptr); - va_end(va_ptr); + if (grade == '+' || grade == '-' || grade == '!' || grade == '?' || grade == ' ' || TCFG.debug) { + va_start(va_ptr, format); + vsprintf(outstr, format, va_ptr); + va_end(va_ptr); - tcrc = StringCRC32(outstr); - if (tcrc == lcrc) { - lcnt++; - 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); + tcrc = StringCRC32(outstr); + if (tcrc == lcrc) { + 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; } @@ -159,117 +159,117 @@ void Syslog(int grade, const char *format, ...) */ int ulog(char *fn, char *grade, char *prname, char *prpid, char *format) { - int oldmask; - FILE *log; + int oldmask; + FILE *log; - oldmask = umask(066); - log = fopen(fn, "a"); - umask(oldmask); - if (log == NULL) { - oserr = errno; - Syslog('!', "$Cannot open user logfile %s", fn); - return -1; - } + oldmask = umask(066); + log = fopen(fn, "a"); + umask(oldmask); + if (log == NULL) { + oserr = errno; + Syslog('!', "$Cannot open user logfile %s", fn); + return -1; + } - fprintf(log, "%s %s %s[%s] ", grade, date(), prname, prpid); - fwrite(format, strlen(format), 1, log); - fprintf(log, "\n"); + fprintf(log, "%s %s %s[%s] ", grade, date(), prname, prpid); + fwrite(format, strlen(format), 1, log); + fprintf(log, "\n"); - fflush(log); - if (fclose(log) != 0) { - oserr = errno; - Syslog('!', "$Cannot close user logfile %s", fn); - return -1; - } - return 0; + fflush(log); + if (fclose(log) != 0) { + oserr = errno; + Syslog('!', "$Cannot close user logfile %s", fn); + return -1; + } + return 0; } char *xstrcpy(char *src) { - char *tmp; + char *tmp; - if (src == NULL) - return(NULL); - tmp = malloc(strlen(src)+1); - strcpy(tmp, src); - return tmp; + if (src == NULL) + return(NULL); + tmp = malloc(strlen(src)+1); + strcpy(tmp, src); + return tmp; } char *xstrcat(char *src, char *add) { - char *tmp; - size_t size = 0; + char *tmp; + size_t size = 0; - if ((add == NULL) || (strlen(add) == 0)) - return src; - if (src) - size = strlen(src); - size += strlen(add); - tmp = malloc(size + 1); - *tmp = '\0'; - if (src) { - strcpy(tmp, src); - free(src); - } - strcat(tmp, add); - return tmp; + if ((add == NULL) || (strlen(add) == 0)) + return src; + if (src) + size = strlen(src); + size += strlen(add); + tmp = malloc(size + 1); + *tmp = '\0'; + if (src) { + strcpy(tmp, src); + free(src); + } + strcat(tmp, add); + return tmp; } void CreateSema(char *sem) { - char temp[PATH_MAX]; - int fd; + char temp[PATH_MAX]; + int fd; - sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); - if (access(temp, F_OK) == 0) - return; - if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0) - close(fd); - else - Syslog('?', "Can't create semafore %s", temp); + sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); + if (access(temp, F_OK) == 0) + return; + if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0) + close(fd); + else + Syslog('?', "Can't create semafore %s", temp); } void TouchSema(char *sem) { - char temp[PATH_MAX]; - int fd; + char temp[PATH_MAX]; + int fd; - 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) { - close(fd); - } else - Syslog('?', "Can't touch semafore %s", temp); + 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) { + close(fd); + } else + Syslog('?', "Can't touch semafore %s", temp); } void RemoveSema(char *sem) { - char temp[PATH_MAX]; + char temp[PATH_MAX]; - sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); - if (access(temp, F_OK)) - return; - if (unlink(temp) == -1) - Syslog('?', "Can't remove semafore %s", temp); + sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); + if (access(temp, F_OK)) + return; + if (unlink(temp) == -1) + Syslog('?', "Can't remove semafore %s", temp); } int IsSema(char *sem) { - char temp[PATH_MAX]; + char temp[PATH_MAX]; - sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); - return (access(temp, F_OK) == 0); + sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem); + return (access(temp, F_OK) == 0); } @@ -283,10 +283,10 @@ int IsSema(char *sem) */ int file_exist(char *path, int mode) { - if (access(path, mode) != 0) - return errno; + if (access(path, mode) != 0) + return errno; - return 0; + return 0; } @@ -295,32 +295,32 @@ int file_exist(char *path, int mode) */ int mkdirs(char *name, mode_t mode) { - char buf[PATH_MAX], *p, *q; - int rc, last = 0, oldmask; + char buf[PATH_MAX], *p, *q; + int rc, last = 0, oldmask; - memset(&buf, 0, sizeof(buf)); - strncpy(buf, name, sizeof(buf)-1); - buf[sizeof(buf)-1] = '\0'; + memset(&buf, 0, sizeof(buf)); + strncpy(buf, name, sizeof(buf)-1); + buf[sizeof(buf)-1] = '\0'; - p = buf+1; + p = buf+1; - oldmask = umask(000); - while ((q = strchr(p, '/'))) { - *q = '\0'; - rc = mkdir(buf, mode); - last = errno; - *q = '/'; - p = q+1; - } + oldmask = umask(000); + while ((q = strchr(p, '/'))) { + *q = '\0'; + rc = mkdir(buf, mode); + last = errno; + *q = '/'; + p = q+1; + } - umask(oldmask); + umask(oldmask); - if ((last == 0) || (last == EEXIST)) { - return TRUE; - } else { - Syslog('?', "$mkdirs(%s)", name); - return FALSE; - } + if ((last == 0) || (last == EEXIST)) { + return TRUE; + } else { + Syslog('?', "$mkdirs(%s)", name); + return FALSE; + } } @@ -330,12 +330,12 @@ int mkdirs(char *name, mode_t mode) */ long file_size(char *path) { - static struct stat sb; + static struct stat sb; - if (stat(path, &sb) == -1) - return -1; + if (stat(path, &sb) == -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) { - static struct stat sb; + static struct stat sb; - if (stat(path, &sb) == -1) - return -1; + if (stat(path, &sb) == -1) + return -1; - return sb.st_mtime; + return sb.st_mtime; } /* - * Return ASCII string for node, the bits in 'fl' set the - * output format. + * Return ASCII string for node, the bits in 'fl' set the 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'; - 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; + 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; } +/* + * 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 buf[PATH_MAX]; diff --git a/mbtask/taskutil.h b/mbtask/taskutil.h index 5dc008ae..2986cec4 100644 --- a/mbtask/taskutil.h +++ b/mbtask/taskutil.h @@ -34,7 +34,8 @@ int file_exist(char *, int); int mkdirs(char *, mode_t); long file_size(char *); time_t file_time(char *); -char *ascfnode(fidoaddr, int); +char *ascfnode(faddr *, int); +char *fido2str(fidoaddr, int); char *Dos2Unix(char *); char *dayname(void); void InitFidonet(void);