int snaplen, ret;
int snaplen, ret, olderrno;
priv_init(void){	int i, fd, socks[2], cmd;	int snaplen, ret;	struct passwd *pw;	for (i = 1; i < _NSIG; i++)		signal(i, SIG_DFL);	/* Create sockets */	if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, socks) == -1)		err(1, "socketpair() failed");	pw = getpwnam("_pflogd");	if (pw == NULL)		errx(1, "unknown user _pflogd");	endpwent();	child_pid = fork();	if (child_pid < 0)		err(1, "fork() failed");	if (!child_pid) {		gid_t gidset[1];		/* Child - drop privileges and return */		if (chroot(pw->pw_dir) != 0)			err(1, "unable to chroot");		if (chdir("/") != 0)			err(1, "unable to chdir");		gidset[0] = pw->pw_gid;		if (setgroups(1, gidset) == -1)			err(1, "setgroups() failed");		if (setegid(pw->pw_gid) == -1)			err(1, "setegid() failed");		if (setgid(pw->pw_gid) == -1)			err(1, "setgid() failed");		if (seteuid(pw->pw_uid) == -1)			err(1, "seteuid() failed");		if (setuid(pw->pw_uid) == -1)			err(1, "setuid() failed");		close(socks[0]);		priv_fd = socks[1];		return 0;	}	/* Father */	/* Pass ALRM/TERM/HUP through to child, and accept CHLD */	signal(SIGALRM, sig_pass_to_chld);	signal(SIGTERM, sig_pass_to_chld);	signal(SIGHUP,  sig_pass_to_chld);	signal(SIGCHLD, sig_chld);	setproctitle("[priv]");	close(socks[1]);	while (!gotsig_chld) {		if (may_read(socks[0], &cmd, sizeof(int)))			break;		switch (cmd) {		case PRIV_SET_SNAPLEN:			logmsg(LOG_DEBUG,			    "[priv]: msg PRIV_SET_SNAPLENGTH received");			must_read(socks[0], &snaplen, sizeof(int));			ret = set_snaplen(snaplen);			if (ret) {				logmsg(LOG_NOTICE,				   "[priv]: set_snaplen failed for snaplen %d",				   snaplen);			}			must_write(socks[0], &ret, sizeof(int));			break;		case PRIV_OPEN_LOG:			logmsg(LOG_DEBUG,			    "[priv]: msg PRIV_OPEN_LOG received");			/* create or append logs but do not follow symlinks */			fd = open(filename,			    O_RDWR|O_CREAT|O_APPEND|O_NONBLOCK|O_NOFOLLOW,			    0600);			if (fd < 0)				logmsg(LOG_NOTICE,				    "[priv]: failed to open %s: %s",				    filename, strerror(errno));			else				close(fd);			send_fd(socks[0], fd);			break;		default:			logmsg(LOG_ERR, "[priv]: unknown command %d", cmd);			_exit(1);			/* NOTREACHED */		}	}	_exit(1);}