diff -ur sysklogd-1.4.1~/syslogd.c sysklogd-1.4.1/syslogd.c --- sysklogd-1.4.1~/syslogd.c Sun Apr 14 23:38:09 2002 +++ sysklogd-1.4.1/syslogd.c Mon Apr 15 01:05:25 2002 @@ -492,6 +492,8 @@ #include #include +#include +#include #include #include @@ -567,7 +569,7 @@ #define MAXFUNIX 20 int nfunix = 1; -char *funixn[MAXFUNIX] = { _PATH_LOG }; +const char *funixn[MAXFUNIX] = { _PATH_LOG }; int funix[MAXFUNIX] = { -1, }; #ifdef UT_NAMESIZE @@ -804,6 +806,76 @@ return 0; } +char * +xstrdup (const char *s) +{ + char *r = strdup (s); + + if (!r) + error (1, errno, "strdup"); + return r; +} + +static void +add_funix_name (const char *fname) +{ + unsigned i; + + for (i = 0; i < MAXFUNIX; ++i) + if (!strcmp (fname, funixn[i])) + return; + + if (nfunix < MAXFUNIX) + funixn[nfunix++] = fname; + else + error (0, 0, "out of descriptors, ignoring %s\n", fname); +} + +static void +add_funix_dir (const char *dname) +{ + DIR *dir; + struct dirent *entry; + + if (chdir (dname)) + { + error (0, errno, "chdir: %s", dname); + return; + } + + if (!(dir = opendir ("."))) + { + error (0, errno, "opendir: %s", dname); + chdir ("/"); + return; + } + + while ((entry = readdir (dir))) + { + struct stat st; + + if (strchr (entry->d_name, '.')) + continue; + + if (lstat (entry->d_name, &st)) + continue; + + if (S_ISLNK(st.st_mode)) + { + char buf[MAXPATHLEN]; + int n = readlink (entry->d_name, buf, sizeof(buf)); + if ((n <= 0) || (n >= sizeof(buf)) || (buf[0] != '/')) + continue; + buf[n] = '\0'; + add_funix_name (xstrdup (buf)); + } + } + + if (closedir (dir)) + error (0, errno, "closedir: %s", dname); + chdir ("/"); +} + int main(argc, argv) int argc; char **argv; @@ -848,6 +920,7 @@ extern int optind; extern char *optarg; int maxfds; + const char *funix_dir = "/etc/syslog.d"; #ifndef TESTING chdir ("/"); @@ -857,13 +930,13 @@ funix[i] = -1; } - while ((ch = getopt(argc, argv, "a:dhf:i:j:l:m:np:rs:u:v")) != EOF) + while ((ch = getopt(argc, argv, "a:A:dhf:i:j:l:m:np:rs:u:v")) != EOF) switch((char)ch) { case 'a': - if (nfunix < MAXFUNIX) - funixn[nfunix++] = optarg; - else - fprintf(stderr, "Out of descriptors, ignoring %s\n", optarg); + add_funix_name (optarg); + break; + case 'A': + funix_dir = optarg; break; case 'd': /* debug */ Debug = 1; @@ -930,6 +1003,8 @@ fputs("'-j' is only valid with '-u'", stderr); exit(1); } + if (funix_dir && *funix_dir) + add_funix_dir (funix_dir); #ifndef TESTING if ( !(Debug || NoFork) ) {