--- syslogd.c.old Thu Oct 25 15:53:18 2001 +++ syslogd.c Thu Oct 25 16:01:12 2001 @@ -556,7 +556,6 @@ int inetm = 0; static int debugging_on = 0; -static int nlogs = -1; static int restart = 0; #define MAXFUNIX 20 @@ -616,9 +615,7 @@ */ struct filed { -#ifndef SYSV struct filed *f_next; /* next in linked list */ -#endif short f_type; /* entry type, see below */ short f_file; /* file descriptor */ time_t f_time; /* time this was last written */ @@ -777,7 +774,6 @@ #define dprintf mydprintf #endif /* __GLIBC__ */ static void dprintf(char *, ...); -static void allocate_log(void); void sighup_handler(); #ifdef SYSLOG_UNIXAF @@ -1549,7 +1545,7 @@ int flags; { register struct filed *f; - int fac, prilev, lognum; + int fac, prilev; int msglen; char *timestamp; @@ -1599,12 +1595,7 @@ #endif return; } -#ifdef SYSV - for (lognum = 0; lognum <= nlogs; lognum++) { - f = &Files[lognum]; -#else for (f = Files; f; f = f->f_next) { -#endif /* skip messages that are incorrect priority */ if ( (f->f_pmask[fac] == TABLE_NOPRI) || \ @@ -2078,9 +2069,6 @@ void domark() { register struct filed *f; -#ifdef SYSV - int lognum; -#endif if (MarkInterval > 0) { now = time(0); @@ -2090,12 +2078,7 @@ MarkSeq = 0; } -#ifdef SYSV - for (lognum = 0; lognum <= nlogs; lognum++) { - f = &Files[lognum]; -#else for (f = Files; f; f = f->f_next) { -#endif if (f->f_prevcount && now >= REPEATTIME(f)) { dprintf("flush %s: repeated %d times, %d sec.\n", TypeNames[f->f_type], f->f_prevcount, @@ -2144,15 +2127,13 @@ { register struct filed *f; char buf[100]; - int lognum; int i; int was_initialized = Initialized; Initialized = 0; /* Don't log SIGCHLDs in case we receive one during exiting */ - for (lognum = 0; lognum <= nlogs; lognum++) { - f = &Files[lognum]; + for (f = Files; f; f = f->f_next) { /* flush any pending output */ if (f->f_prevcount) fprintlog(f, LocalHostName, 0, (char *)NULL); @@ -2200,14 +2181,11 @@ void init() { - register int i, lognum; + register int i; register FILE *cf; register struct filed *f; -#ifndef TESTING -#ifndef SYSV - register struct filed **nextp = (struct filed **) 0; -#endif -#endif + register struct filed **nextp = &Files; + register struct filed *next; register char *p; register unsigned int Forwarding = 0; #ifdef CONT_LINE @@ -2232,60 +2210,44 @@ */ dprintf("Called init.\n"); Initialized = 0; - if ( nlogs > -1 ) - { - dprintf("Initializing log structures.\n"); - for (lognum = 0; lognum <= nlogs; lognum++ ) { - f = &Files[lognum]; + dprintf("Initializing log structures.\n"); + for (f = Files; f; f = next) { - /* flush any pending output */ - if (f->f_prevcount) - fprintlog(f, LocalHostName, 0, (char *)NULL); + /* flush any pending output */ + if (f->f_prevcount) + fprintlog(f, LocalHostName, 0, (char *)NULL); - switch (f->f_type) { - case F_FILE: - case F_PIPE: - case F_TTY: - case F_CONSOLE: - (void) close(f->f_file); - break; - } + switch (f->f_type) { + case F_FILE: + case F_PIPE: + case F_TTY: + case F_CONSOLE: + (void) close(f->f_file); + break; } - /* - * This is needed especially when HUPing syslogd as the - * structure would grow infinitively. -Joey - */ - nlogs = -1; - free((void *) Files); - Files = (struct filed *) 0; + next = f->f_next; + free (f); } - -#ifdef SYSV - lognum = 0; -#else - f = NULL; -#endif + Files = NULL; /* open the configuration file */ if ((cf = fopen(ConfFile, "r")) == NULL) { dprintf("cannot open %s.\n", ConfFile); -#ifdef SYSV - allocate_log(); - f = &Files[lognum++]; -#ifndef TESTING - cfline("*.err\t" _PATH_CONSOLE, f); -#else + f = (struct filed *)calloc(1, sizeof(*f)); + *nextp = f; + nextp = &f->f_next; +#ifdef TESTING snprintf(cbuf,sizeof(cbuf), "*.*\t%s", ttyname(0)); cfline(cbuf, f); -#endif #else - *nextp = (struct filed *)calloc(1, sizeof(*f)); - cfline("*.ERR\t" _PATH_CONSOLE, *nextp); - (*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f)) /* ASP */ - cfline("*.PANIC\t*", (*nextp)->f_next); + cfline("*.err\t" _PATH_CONSOLE, f); + f = (struct filed *)calloc(1, sizeof(*f)); /* ASP */ + *nextp = f; + nextp = &f->f_next; + cfline("*.PANIC\t*", f); #endif Initialized = 1; return; @@ -2325,13 +2287,9 @@ cline = cbuf; #endif *++p = '\0'; -#ifndef SYSV f = (struct filed *)calloc(1, sizeof(*f)); *nextp = f; nextp = &f->f_next; -#endif - allocate_log(); - f = &Files[lognum++]; #if CONT_LINE cfline(cbuf, f); #else @@ -2379,15 +2337,11 @@ Initialized = 1; if ( Debug ) { -#ifdef SYSV - for (lognum = 0; lognum <= nlogs; lognum++) { - f = &Files[lognum]; + int lognum = 0; + + for (f = Files; f; f = f->f_next, ++lognum) { if (f->f_type != F_UNUSED) { printf ("%2d: ", lognum); -#else - for (f = Files; f; f = f->f_next) { - if (f->f_type != F_UNUSED) { -#endif for (i = 0; i <= LOG_NFACILITIES; i++) if (f->f_pmask[i] == TABLE_NOPRI) printf(" X "); @@ -2744,53 +2698,6 @@ fflush(stdout); return; } - - -/* - * The following function is responsible for allocating/reallocating the - * array which holds the structures which define the logging outputs. - */ -static void allocate_log() - -{ - dprintf("Called allocate_log, nlogs = %d.\n", nlogs); - - /* - * Decide whether the array needs to be initialized or needs to - * grow. - */ - if ( nlogs == -1 ) - { - Files = (struct filed *) malloc(sizeof(struct filed)); - if ( Files == (void *) 0 ) - { - dprintf("Cannot initialize log structure."); - logerror("Cannot initialize log structure."); - return; - } - } - else - { - /* Re-allocate the array. */ - Files = (struct filed *) realloc(Files, (nlogs+2) * \ - sizeof(struct filed)); - if ( Files == (struct filed *) 0 ) - { - dprintf("Cannot grow log structure."); - logerror("Cannot grow log structure."); - return; - } - } - - /* - * Initialize the array element, bump the number of elements in the - * the array and return. - */ - ++nlogs; - memset(&Files[nlogs], '\0', sizeof(struct filed)); - return; -} - /* * The following function is resposible for handling a SIGHUP signal. Since