"syslogd: path to long, ignoring %s\n",
"syslogd: path too long, ignoring %s\n",
main(argc, argv)	int argc;	char *argv[];{	int ch, i, fklog, len, linesize, fdsrmax = 0;	struct sockaddr_un sunx, fromunix;	struct sockaddr_in sin, frominet;	fd_set *fdsr = NULL;	char *p, *line;	FILE *fp;	while ((ch = getopt(argc, argv, "duf:m:p:a:")) != -1)		switch (ch) {		case 'd':		/* debug */			Debug++;			break;		case 'f':		/* configuration file */			ConfFile = optarg;			break;		case 'm':		/* mark interval */			MarkInterval = atoi(optarg) * 60;			break;		case 'p':		/* path */			funixn[0] = optarg;			break;		case 'u':		/* allow udp input port */			SecureMode = 0;			break;		case 'a':			if (nfunix >= MAXFUNIX)				fprintf(stderr,				    "syslogd: out of descriptors, ignoring %s\n",				    optarg);			else if (strlen(optarg) >= sizeof(sunx.sun_path))				fprintf(stderr,				    "syslogd: path to long, ignoring %s\n",				    optarg);			else				funixn[nfunix++] = optarg;			break;		case '?':		default:			usage();		}	if ((argc -= optind) != 0)		usage();	if (!Debug)		(void)daemon(0, 0);	else		setlinebuf(stdout);	consfile.f_type = F_CONSOLE;	(void)strlcpy(consfile.f_un.f_fname, ctty,	    sizeof(consfile.f_un.f_fname));	(void)gethostname(LocalHostName, sizeof(LocalHostName));	if ((p = strchr(LocalHostName, '.')) != NULL) {		*p++ = '\0';		LocalDomain = p;	} else		LocalDomain = "";	linesize = getmsgbufsize();	if (linesize < MAXLINE)		linesize = MAXLINE;	linesize++;	line = malloc(linesize);	(void)signal(SIGTERM, dodie);	(void)signal(SIGINT, Debug ? dodie : SIG_IGN);	(void)signal(SIGQUIT, Debug ? dodie : SIG_IGN);	(void)signal(SIGCHLD, reapchild);	(void)signal(SIGALRM, domark);	(void)alarm(TIMERINTVL);#ifndef SUN_LEN#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)#endif	for (i = 0; i < nfunix; i++) {		(void)unlink(funixn[i]);		memset(&sunx, 0, sizeof(sunx));		sunx.sun_family = AF_UNIX;		(void)strlcpy(sunx.sun_path, funixn[i], sizeof(sunx.sun_path));		funix[i] = socket(AF_UNIX, SOCK_DGRAM, 0);		if (funix[i] < 0 ||		    bind(funix[i], (struct sockaddr *)&sunx,		    SUN_LEN(&sunx)) < 0 ||		    chmod(funixn[i], 0666) < 0) {			(void) snprintf(line, sizeof line, "cannot create %s",			    funixn[i]);			logerror(line);			dprintf("cannot create %s (%d)\n", funixn[i], errno);			if (i == 0)				die(0);		}	}	finet = socket(AF_INET, SOCK_DGRAM, 0);	if (finet >= 0) {		struct servent *sp;		sp = getservbyname("syslog", "udp");		if (sp == NULL) {			errno = 0;			logerror("syslog/udp: unknown service");			die(0);		}		memset(&sin, 0, sizeof(sin));		sin.sin_len = sizeof(sin);		sin.sin_family = AF_INET;		sin.sin_port = LogPort = sp->s_port;		if (bind(finet, (struct sockaddr *)&sin, sizeof(sin)) < 0) {			logerror("bind");			if (!Debug)				die(0);		} else {			InetInuse = 1;		}	}	if ((fklog = open(_PATH_KLOG, O_RDONLY, 0)) < 0)		dprintf("can't open %s (%d)\n", _PATH_KLOG, errno);	/* tuck my process id away */	if (!Debug) {		fp = fopen(PidFile, "w");		if (fp != NULL) {			fprintf(fp, "%d\n", getpid());			(void) fclose(fp);		}	}	dprintf("off & running....\n");	init(0);	(void)signal(SIGHUP, init);	if (fklog != -1 && fklog > fdsrmax)		fdsrmax = fklog;	if (finet != -1 && finet > fdsrmax)		fdsrmax = finet;	for (i = 0; i < nfunix; i++) {		if (funix[i] != -1 && funix[i] > fdsrmax)			fdsrmax = funix[i];	}	fdsr = (fd_set *)calloc(howmany(fdsrmax+1, NFDBITS),	    sizeof(fd_mask));	if (fdsr == NULL)		errx(1, "calloc fd_set");	for (;;) {		if (MarkSet)			markit();		if (WantDie)			die(WantDie);		bzero(fdsr, howmany(fdsrmax+1, NFDBITS) *		    sizeof(fd_mask));		if (fklog != -1)			FD_SET(fklog, fdsr);		if (finet != -1)			FD_SET(finet, fdsr);		for (i = 0; i < nfunix; i++) {			if (funix[i] != -1)				FD_SET(funix[i], fdsr);		}		switch (select(fdsrmax+1, fdsr, NULL, NULL, NULL)) {		case 0:			continue;		case -1:			if (errno != EINTR)				logerror("select");			continue;		}		if (fklog != -1 && FD_ISSET(fklog, fdsr)) {			i = read(fklog, line, linesize - 1);			if (i > 0) {				line[i] = '\0';				printsys(line);			} else if (i < 0 && errno != EINTR) {				logerror("klog");				fklog = -1;			}		}		if (finet != -1 && FD_ISSET(finet, fdsr)) {			len = sizeof(frominet);			i = recvfrom(finet, line, MAXLINE, 0,			    (struct sockaddr *)&frominet, &len);			if (SecureMode) {				/* silently drop it */			} else {				if (i > 0) {					line[i] = '\0';					printline(cvthname(&frominet), line);				} else if (i < 0 && errno != EINTR)					logerror("recvfrom inet");			}		} 		for (i = 0; i < nfunix; i++) {			if (funix[i] != -1 && FD_ISSET(funix[i], fdsr)) {				len = sizeof(fromunix);				len = recvfrom(funix[i], line, MAXLINE, 0,				    (struct sockaddr *)&fromunix, &len);				if (len > 0) {					line[len] = '\0';					printline(LocalHostName, line);				} else if (len < 0 && errno != EINTR)					logerror("recvfrom unix");			}		}	}	if (fdsr)		free(fdsr);}