Date: Mon, 12 Dec 2016 19:24:52 +0000 (UTC) From: Hiroki Sato <hrs@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309931 - head/usr.sbin/syslogd Message-ID: <201612121924.uBCJOqwv089767@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hrs Date: Mon Dec 12 19:24:52 2016 New Revision: 309931 URL: https://svnweb.freebsd.org/changeset/base/309931 Log: Temporarily backout the previous commit because it was totally broken due to unresolved merge conflicts. Pointy hat to: hrs Modified: head/usr.sbin/syslogd/Makefile head/usr.sbin/syslogd/syslogd.c Modified: head/usr.sbin/syslogd/Makefile ============================================================================== --- head/usr.sbin/syslogd/Makefile Mon Dec 12 19:24:32 2016 (r309930) +++ head/usr.sbin/syslogd/Makefile Mon Dec 12 19:24:52 2016 (r309931) @@ -13,9 +13,6 @@ LIBADD= util WARNS?= 3 -.if ${MK_INET_SUPPORT} != "no" -CFLAGS+= -DINET -.endif .if ${MK_INET6_SUPPORT} != "no" CFLAGS+= -DINET6 .endif Modified: head/usr.sbin/syslogd/syslogd.c ============================================================================== --- head/usr.sbin/syslogd/syslogd.c Mon Dec 12 19:24:32 2016 (r309930) +++ head/usr.sbin/syslogd/syslogd.c Mon Dec 12 19:24:52 2016 (r309931) @@ -88,6 +88,7 @@ __FBSDID("$FreeBSD$"); #include <sys/time.h> #include <sys/resource.h> #include <sys/syslimits.h> +#include <sys/types.h> #include <netinet/in.h> #include <netdb.h> @@ -115,60 +116,43 @@ __FBSDID("$FreeBSD$"); #define SYSLOG_NAMES #include <sys/syslog.h> -static const char *ConfFile = _PATH_LOGCONF; -static const char *PidFile = _PATH_LOGPID; -static const char ctty[] = _PATH_CONSOLE; -static const char include_str[] = "include"; -static const char include_ext[] = ".conf"; +const char *ConfFile = _PATH_LOGCONF; +const char *PidFile = _PATH_LOGPID; +const char ctty[] = _PATH_CONSOLE; +static const char include_str[] = "include"; +static const char include_ext[] = ".conf"; #define dprintf if (Debug) printf #define MAXUNAMES 20 /* maximum number of user names */ -#define sstosa(ss) ((struct sockaddr *)(ss)) -#ifdef INET -#define satosin(sa) ((struct sockaddr_in *)(void *)(sa)) -#endif -#ifdef INET6 -#define satosin6(sa) ((struct sockaddr_in6 *)(void *)(sa)) -#define s6_addr32 __u6_addr.__u6_addr32 -#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \ - (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \ - (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \ - (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \ - (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 ) -#endif /* - * List of peers and sockets for binding. + * List of hosts for binding. */ -struct peer { - const char *pe_name; - const char *pe_serv; - mode_t pe_mode; - STAILQ_ENTRY(peer) next; -}; -struct socklist { - struct sockaddr_storage sl_ss; - int sl_socket; - struct peer *sl_peer; - STAILQ_ENTRY(socklist) next; +static STAILQ_HEAD(, host) hqueue; +struct host { + char *name; + STAILQ_ENTRY(host) next; }; -static STAILQ_HEAD(, socklist) shead = STAILQ_HEAD_INITIALIZER(shead); -static struct peer funix_secure = { - .pe_name = _PATH_LOG_PRIV, - .pe_mode = S_IRUSR | S_IWUSR, - .next = {NULL}, -}; -static struct peer funix_default = { - .pe_name = _PATH_LOG, - .pe_mode = DEFFILEMODE, - .next = {&funix_secure}, -}; -static STAILQ_HEAD(, peer) pqueue = { - &funix_default, - &funix_secure.next.stqe_next, +/* + * Unix sockets. + * We have two default sockets, one with 666 permissions, + * and one for privileged programs. + */ +struct funix { + int s; + const char *name; + mode_t mode; + STAILQ_ENTRY(funix) next; }; +struct funix funix_secure = { -1, _PATH_LOG_PRIV, S_IRUSR | S_IWUSR, + { NULL } }; +struct funix funix_default = { -1, _PATH_LOG, DEFFILEMODE, + { &funix_secure } }; + +STAILQ_HEAD(, funix) funixes = { &funix_default, + &(funix_secure.next.stqe_next) }; /* * Flags to logmsg(). @@ -188,7 +172,7 @@ static STAILQ_HEAD(, peer) pqueue = { */ struct filed { - STAILQ_ENTRY(filed) next; /* next in linked list */ + struct filed *f_next; /* next in linked list */ short f_type; /* entry type, see below */ short f_file; /* file descriptor */ time_t f_time; /* time this was last written */ @@ -212,12 +196,6 @@ struct filed { pid_t f_pid; } f_pipe; } f_un; -#define fu_uname f_un.f_uname -#define fu_forw_hname f_un.f_forw.f_hname -#define fu_forw_addr f_un.f_forw.f_addr -#define fu_fname f_un.f_fname -#define fu_pipe_pname f_un.f_pipe.f_pname -#define fu_pipe_pid f_un.f_pipe.f_pid char f_prevline[MAXSVLINE]; /* last message logged */ char f_lasttime[16]; /* time of last occurrence */ char f_prevhost[MAXHOSTNAMELEN]; /* host from which recd. */ @@ -233,12 +211,15 @@ struct filed { /* * Queue of about-to-be dead processes we should watch out for. */ + +TAILQ_HEAD(stailhead, deadq_entry) deadq_head; +struct stailhead *deadq_headp; + struct deadq_entry { pid_t dq_pid; int dq_timeout; TAILQ_ENTRY(deadq_entry) dq_entries; }; -static TAILQ_HEAD(, deadq_entry) deadq_head; /* * The timeout to apply to processes waiting on the dead queue. Unit @@ -268,9 +249,7 @@ struct allowedpeer { #define a_addr u.numeric.addr #define a_mask u.numeric.mask #define a_name u.name - STAILQ_ENTRY(allowedpeer) next; }; -static STAILQ_HEAD(, allowedpeer) aphead = STAILQ_HEAD_INITIALIZER(aphead); /* @@ -278,7 +257,7 @@ static STAILQ_HEAD(, allowedpeer) aphead * in seconds after previous message is logged. After each flush, * we move to the next interval until we reach the largest. */ -static int repeatinterval[] = { 30, 120, 600 }; /* # of secs before flush */ +int repeatinterval[] = { 30, 120, 600 }; /* # of secs before flush */ #define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) #define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) #define BACKOFF(f) { if (++(f)->f_repeatcount > MAXREPEAT) \ @@ -295,13 +274,12 @@ static int repeatinterval[] = { 30, 120, #define F_WALL 6 /* everyone logged on */ #define F_PIPE 7 /* pipe to program */ -static const char *TypeNames[8] = { +const char *TypeNames[8] = { "UNUSED", "FILE", "TTY", "CONSOLE", "FORW", "USERS", "WALL", "PIPE" }; -static STAILQ_HEAD(, filed) fhead = - STAILQ_HEAD_INITIALIZER(fhead); /* Log files that we write to */ +static struct filed *Files; /* Log files that we write to */ static struct filed consfile; /* Console */ static int Debug; /* debug flag */ @@ -309,6 +287,7 @@ static int Foreground = 0; /* Run in for static int resolve = 1; /* resolve hostname */ static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ static const char *LocalDomain; /* our local domain name */ +static int *finet; /* Internet datagram sockets */ static int fklog = -1; /* /dev/klog */ static int Initialized; /* set when we have initialized ourselves */ static int MarkInterval = 20 * 60; /* interval between marks in seconds */ @@ -328,6 +307,8 @@ static int logflags = O_WRONLY|O_APPEND; static char bootfile[MAXLINE+1]; /* booted kernel file */ +struct allowedpeer *AllowedPeers; /* List of allowed peers */ +static int NumAllowed; /* Number of entries in AllowedPeers */ static int RemoteAddDate; /* Always set the date on remote messages */ static int UniquePriority; /* Only log specified priority? */ @@ -337,7 +318,7 @@ static int KeepKernFac; /* Keep remotely static int needdofsync = 0; /* Are any file(s) waiting to be fsynced? */ static struct pidfh *pfh; -static volatile sig_atomic_t MarkSet, WantDie; +volatile sig_atomic_t MarkSet, WantDie; static int allowaddr(char *); static void cfline(const char *, struct filed *, @@ -351,7 +332,7 @@ static void dodie(int); static void dofsync(void); static void domark(int); static void fprintlog(struct filed *, int, const char *); -static int socksetup(struct peer *); +static int *socksetup(int, char *); static void init(int); static void logerror(const char *); static void logmsg(int, const char *, const char *, int); @@ -387,30 +368,31 @@ close_filed(struct filed *f) int main(int argc, char *argv[]) { - int ch, i, fdsrmax = 0; - struct sockaddr_storage ss; + int ch, i, fdsrmax = 0, l; + struct sockaddr_un sunx, fromunix; + struct sockaddr_storage frominet; fd_set *fdsr = NULL; char line[MAXLINE + 1]; const char *hname; struct timeval tv, *tvp; struct sigaction sact; - struct peer *pe; - struct socklist *sl; + struct host *host; + struct funix *fx, *fx1; sigset_t mask; pid_t ppid = 1, spid; - socklen_t sslen; + socklen_t len; if (madvise(NULL, 0, MADV_PROTECT) != 0) dprintf("madvise() failed: %s\n", strerror(errno)); + STAILQ_INIT(&hqueue); + while ((ch = getopt(argc, argv, "468Aa:b:cCdf:Fkl:m:nNop:P:sS:Tuv")) != -1) switch (ch) { -#ifdef INET case '4': family = PF_INET; break; -#endif #ifdef INET6 case '6': family = PF_INET6; @@ -427,12 +409,13 @@ main(int argc, char *argv[]) usage(); break; case 'b': - if ((pe = calloc(1, sizeof(*pe))) == NULL) + { + if ((host = malloc(sizeof(struct host))) == NULL) err(1, "malloc failed"); - pe->pe_name = optarg; - pe->pe_serv = NULL; - STAILQ_INSERT_TAIL(&pqueue, pe, next); + host->name = optarg; + STAILQ_INSERT_TAIL(&hqueue, host, next); break; + } case 'c': no_compress++; break; @@ -475,12 +458,17 @@ main(int argc, char *argv[]) } else errx(1, "invalid mode %s, exiting", optarg); - } - if ((pe = calloc(1, sizeof(*pe))) == NULL) + } else /* doesn't begin with '/', and no ':' */ + errx(1, "can't parse path %s", optarg); + + if (strlen(name) >= sizeof(sunx.sun_path)) + errx(1, "%s path too long, exiting", name); + if ((fx = malloc(sizeof(struct funix))) == NULL) err(1, "malloc failed"); - pe->pe_name = name; - pe->pe_mode = mode; - STAILQ_INSERT_TAIL(&pqueue, pe, next); + fx->s = -1; + fx->name = name; + fx->mode = mode; + STAILQ_INSERT_TAIL(&funixes, fx, next); break; } case 'm': /* mark interval */ @@ -497,7 +485,9 @@ main(int argc, char *argv[]) use_bootfile = 1; break; case 'p': /* path */ - funix_default.pe_name = optarg; + if (strlen(optarg) >= sizeof(sunx.sun_path)) + errx(1, "%s path too long, exiting", optarg); + funix_default.name = optarg; break; case 'P': /* path for alt. PID */ PidFile = optarg; @@ -506,7 +496,9 @@ main(int argc, char *argv[]) SecureMode++; break; case 'S': /* path for privileged originator */ - funix_secure.pe_name = optarg; + if (strlen(optarg) >= sizeof(sunx.sun_path)) + errx(1, "%s path too long, exiting", optarg); + funix_secure.name = optarg; break; case 'T': RemoteAddDate = 1; @@ -522,8 +514,6 @@ main(int argc, char *argv[]) } if ((argc -= optind) != 0) usage(); - STAILQ_FOREACH(pe, &pqueue, next) - socksetup(pe); pfh = pidfile_open(PidFile, 0600, &spid); if (pfh == NULL) { @@ -539,12 +529,16 @@ main(int argc, char *argv[]) pidfile_remove(pfh); exit(1); } - } else if (Debug) + } else if (Debug) { setlinebuf(stdout); + } + + if (NumAllowed) + endservent(); consfile.f_type = F_CONSOLE; - (void)strlcpy(consfile.fu_fname, ctty + sizeof _PATH_DEV - 1, - sizeof(consfile.fu_fname)); + (void)strlcpy(consfile.f_un.f_fname, ctty + sizeof _PATH_DEV - 1, + sizeof(consfile.f_un.f_fname)); (void)strlcpy(bootfile, getbootfile(), sizeof(bootfile)); (void)signal(SIGTERM, dodie); (void)signal(SIGINT, Debug ? dodie : SIG_IGN); @@ -567,6 +561,69 @@ main(int argc, char *argv[]) TAILQ_INIT(&deadq_head); +#ifndef SUN_LEN +#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2) +#endif + STAILQ_FOREACH_SAFE(fx, &funixes, next, fx1) { + (void)unlink(fx->name); + memset(&sunx, 0, sizeof(sunx)); + sunx.sun_family = AF_LOCAL; + (void)strlcpy(sunx.sun_path, fx->name, sizeof(sunx.sun_path)); + fx->s = socket(PF_LOCAL, SOCK_DGRAM, 0); + if (fx->s < 0 || + bind(fx->s, (struct sockaddr *)&sunx, SUN_LEN(&sunx)) < 0 || + chmod(fx->name, fx->mode) < 0) { + (void)snprintf(line, sizeof line, + "cannot create %s", fx->name); + logerror(line); + dprintf("cannot create %s (%d)\n", fx->name, errno); + if (fx == &funix_default || fx == &funix_secure) + die(0); + else { + STAILQ_REMOVE(&funixes, fx, funix, next); + continue; + } + } + increase_rcvbuf(fx->s); + } + if (SecureMode <= 1) { + if (STAILQ_EMPTY(&hqueue)) + finet = socksetup(family, NULL); + STAILQ_FOREACH(host, &hqueue, next) { + int *finet0, total; + finet0 = socksetup(family, host->name); + if (finet0 && !finet) { + finet = finet0; + } else if (finet0 && finet) { + total = *finet0 + *finet + 1; + finet = realloc(finet, total * sizeof(int)); + if (finet == NULL) + err(1, "realloc failed"); + for (i = 1; i <= *finet0; i++) { + finet[(*finet)+i] = finet0[i]; + } + *finet = total - 1; + free(finet0); + } + } + } + + if (finet) { + if (SecureMode) { + for (i = 0; i < *finet; i++) { + if (shutdown(finet[i+1], SHUT_RD) < 0 && + errno != ENOTCONN) { + logerror("shutdown"); + if (!Debug) + die(0); + } + } + } else { + dprintf("listening on inet and/or inet6 socket\n"); + } + dprintf("sending on inet and/or inet6 socket\n"); + } + if ((fklog = open(_PATH_KLOG, O_RDONLY|O_NONBLOCK, 0)) < 0) dprintf("can't open %s (%d)\n", _PATH_KLOG, errno); @@ -589,10 +646,15 @@ main(int argc, char *argv[]) if (fklog != -1 && fklog > fdsrmax) fdsrmax = fklog; - STAILQ_FOREACH(sl, &shead, next) { - if (sl->sl_socket > fdsrmax) - fdsrmax = sl->sl_socket; + if (finet && !SecureMode) { + for (i = 0; i < *finet; i++) { + if (finet[i+1] != -1 && finet[i+1] > fdsrmax) + fdsrmax = finet[i+1]; + } } + STAILQ_FOREACH(fx, &funixes, next) + if (fx->s > fdsrmax) + fdsrmax = fx->s; fdsr = (fd_set *)calloc(howmany(fdsrmax+1, NFDBITS), sizeof(fd_mask)); @@ -610,11 +672,16 @@ main(int argc, char *argv[]) if (fklog != -1) FD_SET(fklog, fdsr); - STAILQ_FOREACH(sl, &shead, next) { - if (sl->sl_socket != -1) - FD_SET(sl->sl_socket, fdsr); + if (finet && !SecureMode) { + for (i = 0; i < *finet; i++) { + if (finet[i+1] != -1) + FD_SET(finet[i+1], fdsr); + } } - i = select(fdsrmax + 1, fdsr, NULL, NULL, + STAILQ_FOREACH(fx, &funixes, next) + FD_SET(fx->s, fdsr); + + i = select(fdsrmax+1, fdsr, NULL, NULL, needdofsync ? &tv : tvp); switch (i) { case 0: @@ -633,40 +700,34 @@ main(int argc, char *argv[]) } if (fklog != -1 && FD_ISSET(fklog, fdsr)) readklog(); - STAILQ_FOREACH(sl, &shead, next) { - int date, len; - - if (FD_ISSET(sl->sl_socket, fdsr)) { - sslen = sizeof(ss); - dprintf("sslen(1) = %d\n", sslen); - len = recvfrom(sl->sl_socket, line, - sizeof(line) - 1, 0, - sstosa(&ss), &sslen); - dprintf("sslen(2) = %d\n", sslen); - if (len == 0) - continue; - if (len < 0) { - if (errno != EINTR) - logerror("recvfrom"); - continue; - } - /* Received valid data. */ - line[len] = '\0'; - if (sl->sl_ss.ss_family == AF_LOCAL) { - hname = LocalHostName; - date = 0; - } else { - hname = cvthname(sstosa(&ss)); - unmapped(sstosa(&ss)); - if (validate(sstosa(&ss), hname) == 0) - hname = NULL; - date = RemoteAddDate ? ADDDATE : 0; + if (finet && !SecureMode) { + for (i = 0; i < *finet; i++) { + if (FD_ISSET(finet[i+1], fdsr)) { + len = sizeof(frominet); + l = recvfrom(finet[i+1], line, MAXLINE, + 0, (struct sockaddr *)&frominet, + &len); + if (l > 0) { + line[l] = '\0'; + hname = cvthname((struct sockaddr *)&frominet); + unmapped((struct sockaddr *)&frominet); + if (validate((struct sockaddr *)&frominet, hname)) + printline(hname, line, RemoteAddDate ? ADDDATE : 0); + } else if (l < 0 && errno != EINTR) + logerror("recvfrom inet"); } - if (hname != NULL) - printline(hname, line, date); - else - dprintf("Invalid msg from " - "%s was ignored.", hname); + } + } + STAILQ_FOREACH(fx, &funixes, next) { + if (FD_ISSET(fx->s, fdsr)) { + len = sizeof(fromunix); + l = recvfrom(fx->s, line, MAXLINE, 0, + (struct sockaddr *)&fromunix, &len); + if (l > 0) { + line[l] = '\0'; + printline(LocalHostName, line, 0); + } else if (l < 0 && errno != EINTR) + logerror("recvfrom unix"); } } } @@ -674,36 +735,30 @@ main(int argc, char *argv[]) free(fdsr); } -#ifdef INET6 static void unmapped(struct sockaddr *sa) { struct sockaddr_in6 *sin6; struct sockaddr_in sin4; - if (sa == NULL || - sa->sa_family != AF_INET6 || - sa->sa_len != sizeof(*sin6)) + if (sa->sa_family != AF_INET6) return; - sin6 = satosin6(sa); + if (sa->sa_len != sizeof(struct sockaddr_in6) || + sizeof(sin4) > sa->sa_len) + return; + sin6 = (struct sockaddr_in6 *)sa; if (!IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) return; memset(&sin4, 0, sizeof(sin4)); sin4.sin_family = AF_INET; - sin4.sin_len = sizeof(sin4); + sin4.sin_len = sizeof(struct sockaddr_in); memcpy(&sin4.sin_addr, &sin6->sin6_addr.s6_addr[12], sizeof(sin4.sin_addr)); sin4.sin_port = sin6->sin6_port; memcpy(sa, &sin4, sin4.sin_len); } -#else -static void -unmapped(struct sockaddr *sa __unused) -{ -} -#endif static void usage(void) @@ -988,7 +1043,7 @@ logmsg(int pri, const char *msg, const c (void)sigsetmask(omask); return; } - STAILQ_FOREACH(f, &fhead, next) { + for (f = Files; f; f = f->f_next) { /* skip messages that are incorrect priority */ if (!(((f->f_pcmp[fac] & PRI_EQ) && (f->f_pmask[fac] == prilev)) ||((f->f_pcmp[fac] & PRI_LT) && (f->f_pmask[fac] < prilev)) @@ -1065,7 +1120,7 @@ dofsync(void) { struct filed *f; - STAILQ_FOREACH(f, &fhead, next) { + for (f = Files; f; f = f->f_next) { if ((f->f_type == F_FILE) && (f->f_flags & FFLAG_NEEDSYNC)) { f->f_flags &= ~FFLAG_NEEDSYNC; @@ -1081,7 +1136,7 @@ fprintlog(struct filed *f, int flags, co struct iovec iov[IOV_SIZE]; struct iovec *v; struct addrinfo *r; - int l, lsent = 0; + int i, l, lsent = 0; char line[MAXLINE + 1], repbuf[80], greetings[200], *wmsg = NULL; char nul[] = "", space[] = " ", lf[] = "\n", crlf[] = "\r\n"; const char *msgret; @@ -1189,11 +1244,12 @@ fprintlog(struct filed *f, int flags, co break; case F_FORW: - port = ntohs(satosin(f->fu_forw_addr->ai_addr)->sin_port); + port = (int)ntohs(((struct sockaddr_in *) + (f->f_un.f_forw.f_addr->ai_addr))->sin_port); if (port != 514) { - dprintf(" %s:%d\n", f->fu_forw_hname, port); + dprintf(" %s:%d\n", f->f_un.f_forw.f_hname, port); } else { - dprintf(" %s\n", f->fu_forw_hname); + dprintf(" %s\n", f->f_un.f_forw.f_hname); } /* check for local vs remote messages */ if (strcasecmp(f->f_prevhost, LocalHostName)) @@ -1210,51 +1266,57 @@ fprintlog(struct filed *f, int flags, co else if (l > MAXLINE) l = MAXLINE; - for (r = f->fu_forw_addr; r; r = r->ai_next) { - struct socklist *sl; - - STAILQ_FOREACH(sl, &shead, next) { - if (sl->sl_ss.ss_family == AF_LOCAL) - continue; - lsent = sendto(sl->sl_socket, line, l, 0, - r->ai_addr, r->ai_addrlen); - if (lsent == l) + if (finet) { + for (r = f->f_un.f_forw.f_addr; r; r = r->ai_next) { + for (i = 0; i < *finet; i++) { +#if 0 + /* + * should we check AF first, or just + * trial and error? FWD + */ + if (r->ai_family == + address_family_of(finet[i+1])) +#endif + lsent = sendto(finet[i+1], line, l, 0, + r->ai_addr, r->ai_addrlen); + if (lsent == l) + break; + } + if (lsent == l && !send_to_all) break; } - if (lsent == l && !send_to_all) - break; - } - dprintf("lsent/l: %d/%d\n", lsent, l); - if (lsent != l) { - int e = errno; - logerror("sendto"); - errno = e; - switch (errno) { - case ENOBUFS: - case ENETDOWN: - case ENETUNREACH: - case EHOSTUNREACH: - case EHOSTDOWN: - case EADDRNOTAVAIL: - break; - /* case EBADF: */ - /* case EACCES: */ - /* case ENOTSOCK: */ - /* case EFAULT: */ - /* case EMSGSIZE: */ - /* case EAGAIN: */ - /* case ENOBUFS: */ - /* case ECONNREFUSED: */ - default: - dprintf("removing entry: errno=%d\n", e); - f->f_type = F_UNUSED; - break; + dprintf("lsent/l: %d/%d\n", lsent, l); + if (lsent != l) { + int e = errno; + logerror("sendto"); + errno = e; + switch (errno) { + case ENOBUFS: + case ENETDOWN: + case ENETUNREACH: + case EHOSTUNREACH: + case EHOSTDOWN: + case EADDRNOTAVAIL: + break; + /* case EBADF: */ + /* case EACCES: */ + /* case ENOTSOCK: */ + /* case EFAULT: */ + /* case EMSGSIZE: */ + /* case EAGAIN: */ + /* case ENOBUFS: */ + /* case ECONNREFUSED: */ + default: + dprintf("removing entry: errno=%d\n", e); + f->f_type = F_UNUSED; + break; + } } } break; case F_FILE: - dprintf(" %s\n", f->fu_fname); + dprintf(" %s\n", f->f_un.f_fname); v->iov_base = lf; v->iov_len = 1; if (writev(f->f_file, iov, IOV_SIZE) < 0) { @@ -1267,7 +1329,7 @@ fprintlog(struct filed *f, int flags, co int e = errno; close_filed(f); errno = e; - logerror(f->fu_fname); + logerror(f->f_un.f_fname); } } else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC)) { f->f_flags |= FFLAG_NEEDSYNC; @@ -1276,26 +1338,26 @@ fprintlog(struct filed *f, int flags, co break; case F_PIPE: - dprintf(" %s\n", f->fu_pipe_pname); + dprintf(" %s\n", f->f_un.f_pipe.f_pname); v->iov_base = lf; v->iov_len = 1; - if (f->fu_pipe_pid == 0) { - if ((f->f_file = p_open(f->fu_pipe_pname, - &f->fu_pipe_pid)) < 0) { + if (f->f_un.f_pipe.f_pid == 0) { + if ((f->f_file = p_open(f->f_un.f_pipe.f_pname, + &f->f_un.f_pipe.f_pid)) < 0) { f->f_type = F_UNUSED; - logerror(f->fu_pipe_pname); + logerror(f->f_un.f_pipe.f_pname); break; } } if (writev(f->f_file, iov, IOV_SIZE) < 0) { int e = errno; close_filed(f); - if (f->fu_pipe_pid > 0) - deadq_enter(f->fu_pipe_pid, - f->fu_pipe_pname); - f->fu_pipe_pid = 0; + if (f->f_un.f_pipe.f_pid > 0) + deadq_enter(f->f_un.f_pipe.f_pid, + f->f_un.f_pipe.f_pname); + f->f_un.f_pipe.f_pid = 0; errno = e; - logerror(f->fu_pipe_pname); + logerror(f->f_un.f_pipe.f_pname); } break; @@ -1307,12 +1369,12 @@ fprintlog(struct filed *f, int flags, co /* FALLTHROUGH */ case F_TTY: - dprintf(" %s%s\n", _PATH_DEV, f->fu_fname); + dprintf(" %s%s\n", _PATH_DEV, f->f_un.f_fname); v->iov_base = crlf; v->iov_len = 2; errno = 0; /* ttymsg() only sometimes returns an errno */ - if ((msgret = ttymsg(iov, IOV_SIZE, f->fu_fname, 10))) { + if ((msgret = ttymsg(iov, IOV_SIZE, f->f_un.f_fname, 10))) { f->f_type = F_UNUSED; logerror(msgret); } @@ -1361,9 +1423,9 @@ wallmsg(struct filed *f, struct iovec *i } /* should we send the message to this user? */ for (i = 0; i < MAXUNAMES; i++) { - if (!f->fu_uname[i][0]) + if (!f->f_un.f_uname[i][0]) break; - if (!strcmp(f->fu_uname[i], ut->ut_user)) { + if (!strcmp(f->f_un.f_uname[i], ut->ut_user)) { if ((p = ttymsg_check(iov, iovlen, ut->ut_line, TTYMSGTIME)) != NULL) { errno = 0; /* already in msg */ @@ -1414,18 +1476,20 @@ reapchild(int signo __unused) /* First, look if it's a process from the dead queue. */ if (deadq_remove(pid)) - continue; + goto oncemore; /* Now, look in list of active processes. */ - STAILQ_FOREACH(f, &fhead, next) { + for (f = Files; f; f = f->f_next) if (f->f_type == F_PIPE && - f->fu_pipe_pid == pid) { + f->f_un.f_pipe.f_pid == pid) { close_filed(f); - f->fu_pipe_pid = 0; - log_deadchild(pid, status, f->fu_pipe_pname); + f->f_un.f_pipe.f_pid = 0; + log_deadchild(pid, status, + f->f_un.f_pipe.f_pname); break; } - } + oncemore: + continue; } } @@ -1439,9 +1503,9 @@ cvthname(struct sockaddr *f) sigset_t omask, nmask; static char hname[NI_MAXHOST], ip[NI_MAXHOST]; - dprintf("cvthname(%d) len = %d, %zu\n", f->sa_family, f->sa_len, sizeof(struct sockaddr_in6)); - error = getnameinfo(f, f->sa_len, ip, sizeof(ip), NULL, 0, - NI_NUMERICHOST); + error = getnameinfo((struct sockaddr *)f, + ((struct sockaddr *)f)->sa_len, + ip, sizeof ip, NULL, 0, NI_NUMERICHOST); dprintf("cvthname(%s)\n", ip); if (error) { @@ -1511,19 +1575,19 @@ static void die(int signo) { struct filed *f; - struct socklist *sl; + struct funix *fx; int was_initialized; char buf[100]; was_initialized = Initialized; Initialized = 0; /* Don't log SIGCHLDs. */ - STAILQ_FOREACH(f, &fhead, next) { + for (f = Files; f != NULL; f = f->f_next) { /* flush any pending output */ if (f->f_prevcount) fprintlog(f, 0, (char *)NULL); - if (f->f_type == F_PIPE && f->fu_pipe_pid > 0) { + if (f->f_type == F_PIPE && f->f_un.f_pipe.f_pid > 0) { close_filed(f); - f->fu_pipe_pid = 0; + f->f_un.f_pipe.f_pid = 0; } } Initialized = was_initialized; @@ -1533,10 +1597,8 @@ die(int signo) errno = 0; logerror(buf); } - STAILQ_FOREACH(sl, &shead, next) { - if (sl->sl_ss.ss_family == AF_LOCAL) - unlink(sl->sl_peer->pe_name); - } + STAILQ_FOREACH(fx, &funixes, next) + (void)unlink(fx->name); pidfile_remove(pfh); exit(1); @@ -1564,7 +1626,7 @@ configfiles(const struct dirent *dp) } static void -readconfigfile(FILE *cf, int allow_includes) +readconfigfile(FILE *cf, struct filed **nextp, int allow_includes) { FILE *cf2; struct filed *f; @@ -1624,7 +1686,7 @@ readconfigfile(FILE *cf, int allow_inclu if (cf2 == NULL) continue; dprintf("reading %s\n", file); - readconfigfile(cf2, 0); + readconfigfile(cf2, nextp, 0); fclose(cf2); } free(ent); @@ -1687,7 +1749,8 @@ readconfigfile(FILE *cf, int allow_inclu logerror("calloc"); exit(1); } - STAILQ_INSERT_TAIL(&fhead, f, next); + *nextp = f; + nextp = &f->f_next; cfline(cline, f, prog, host); } } @@ -1700,7 +1763,7 @@ init(int signo) { int i; FILE *cf; - struct filed *f; + struct filed *f, *next, **nextp; char *p; char oldLocalHostName[MAXHOSTNAMELEN]; char hostMsg[2*MAXHOSTNAMELEN+40]; @@ -1745,7 +1808,7 @@ init(int signo) * Close all open log files. */ Initialized = 0; - STAILQ_FOREACH(f, &fhead, next) { + for (f = Files; f != NULL; f = next) { /* flush any pending output */ if (f->f_prevcount) fprintlog(f, 0, (char *)NULL); @@ -1758,48 +1821,42 @@ init(int signo) close_filed(f); break; case F_PIPE: - if (f->fu_pipe_pid > 0) { + if (f->f_un.f_pipe.f_pid > 0) { close_filed(f); - deadq_enter(f->fu_pipe_pid, - f->fu_pipe_pname); + deadq_enter(f->f_un.f_pipe.f_pid, + f->f_un.f_pipe.f_pname); } - f->fu_pipe_pid = 0; + f->f_un.f_pipe.f_pid = 0; break; } + next = f->f_next; + if (f->f_program) free(f->f_program); + if (f->f_host) free(f->f_host); + free((char *)f); } - while(!STAILQ_EMPTY(&fhead)) { - f = STAILQ_FIRST(&fhead); - STAILQ_REMOVE_HEAD(&fhead, next); - free(f->f_program); - free(f->f_host); - free(f); - } + Files = NULL; nextp = &Files; /* open the configuration file */ if ((cf = fopen(ConfFile, "r")) == NULL) { dprintf("cannot open %s\n", ConfFile); - f = calloc(1, sizeof(*f)); - if (f == NULL) { + *nextp = (struct filed *)calloc(1, sizeof(*f)); + if (*nextp == NULL) { logerror("calloc"); exit(1); } - cfline("*.ERR\t/dev/console", f, "*", "*"); - STAILQ_INSERT_TAIL(&fhead, f, next); - - f = calloc(1, sizeof(*f)); - if (f == NULL) { + cfline("*.ERR\t/dev/console", *nextp, "*", "*"); + (*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f)); + if ((*nextp)->f_next == NULL) { logerror("calloc"); exit(1); } - cfline("*.PANIC\t*", f, "*", "*"); - STAILQ_INSERT_TAIL(&fhead, f, next); - + cfline("*.PANIC\t*", (*nextp)->f_next, "*", "*"); Initialized = 1; return; } - readconfigfile(cf, 1); + readconfigfile(cf, &Files, 1); /* close the configuration file */ (void)fclose(cf); @@ -1808,7 +1865,7 @@ init(int signo) if (Debug) { int port; - STAILQ_FOREACH(f, &fhead, next) { + for (f = Files; f; f = f->f_next) { for (i = 0; i <= LOG_NFACILITIES; i++) if (f->f_pmask[i] == INTERNAL_NOPRI) printf("X "); @@ -1817,31 +1874,32 @@ init(int signo) printf("%s: ", TypeNames[f->f_type]); switch (f->f_type) { case F_FILE: - printf("%s", f->fu_fname); + printf("%s", f->f_un.f_fname); break; case F_CONSOLE: case F_TTY: - printf("%s%s", _PATH_DEV, f->fu_fname); + printf("%s%s", _PATH_DEV, f->f_un.f_fname); break; case F_FORW: - port = ntohs(satosin(f->fu_forw_addr->ai_addr)->sin_port); + port = (int)ntohs(((struct sockaddr_in *) + (f->f_un.f_forw.f_addr->ai_addr))->sin_port); if (port != 514) { printf("%s:%d", *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201612121924.uBCJOqwv089767>