if (cur_state == STATE_RESTART) {
if (restart) {
priv_init(char *conf, int numeric, int lockfd, int nullfd, char *argv[]){	int i, fd, socks[2], cmd, addr_len, addr_af, result;	size_t path_len, hostname_len;	char path[MAXPATHLEN], hostname[MAXHOSTNAMELEN];	struct stat cf_stat;	struct hostent *hp;	struct passwd *pw;	/* Create sockets */	if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, socks) == -1)		err(1, "socketpair() failed");	pw = getpwnam("_syslogd");	if (pw == NULL)		errx(1, "unknown user _syslogd");	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");		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;	}	close(lockfd);	if (!Debug) {		dup2(nullfd, STDIN_FILENO);		dup2(nullfd, STDOUT_FILENO);		dup2(nullfd, STDERR_FILENO);	}	if (nullfd > 2)		close(nullfd);	/* Father */	for (i = 1; i <= _NSIG; i++)		signal(i, SIG_DFL);	/* Pass TERM/HUP through to child, and accept CHLD */	signal(SIGTERM, sig_pass_to_chld);	signal(SIGHUP, sig_pass_to_chld);	signal(SIGCHLD, sig_got_chld);	setproctitle("[priv]");	close(socks[1]);	/* Close descriptors that only the unpriv child needs */	for (i = 0; i < nfunix; i++)		if (funix[i] != -1)			close(funix[i]);	if (finet != -1)		close(finet);	if (fklog != -1)		close(fklog);	/* Save the config file specified by the child process */	if (strlcpy(config_file, conf, sizeof config_file) >= sizeof(config_file))		errx(1, "config_file truncation");	if (stat(config_file, &cf_info) < 0)		err(1, "stat config file failed");	/* Save whether or not the child can have access to gethostbyaddr(3) */	if (numeric > 0)		allow_gethostbyaddr = 0;	else		allow_gethostbyaddr = 1;	TAILQ_INIT(&lognames);	increase_state(STATE_CONFIG);	while (cur_state < STATE_QUIT) {		must_read(socks[0], &cmd, sizeof(int));		switch (cmd) {		case PRIV_OPEN_TTY:			dprintf("[priv]: msg PRIV_OPEN_TTY received\n");			/* Expecting: length, path */			must_read(socks[0], &path_len, sizeof(size_t));			if (path_len == 0 || path_len > sizeof(path))				_exit(0);			must_read(socks[0], &path, path_len);			path[path_len - 1] = '\0';			check_tty_name(path, path_len);			fd = open(path, O_WRONLY|O_NONBLOCK, 0);			if (fd < 0)				warnx("priv_open_tty failed");			send_fd(socks[0], fd);			close(fd);			break;		case PRIV_OPEN_LOG:			dprintf("[priv]: msg PRIV_OPEN_LOG received: %s\n", path);			/* Expecting: length, path */			must_read(socks[0], &path_len, sizeof(size_t));			if (path_len == 0 || path_len > sizeof(path))				_exit(0);			must_read(socks[0], &path, path_len);			path[path_len - 1] = '\0';			check_log_name(path, path_len);			fd = open(path, O_WRONLY|O_APPEND|O_NONBLOCK, 0);			if (fd < 0)				warnx("priv_open_log failed");			send_fd(socks[0], fd);			close(fd);			break;		case PRIV_OPEN_UTMP:			dprintf("[priv]: msg PRIV_OPEN_UTMP received\n");			fd = open(_PATH_UTMP, O_RDONLY|O_NONBLOCK, 0);			if (fd < 0)				warnx("priv_open_utmp failed");			send_fd(socks[0], fd);			close(fd);			break;		case PRIV_OPEN_CONFIG:			dprintf("[priv]: msg PRIV_OPEN_CONFIG received\n");			stat(config_file, &cf_info);			fd = open(config_file, O_RDONLY|O_NONBLOCK, 0);			if (fd < 0)				warnx("priv_open_config failed");			send_fd(socks[0], fd);			close(fd);			break;		case PRIV_CONFIG_MODIFIED:			dprintf("[priv]: msg PRIV_CONFIG_MODIFIED received\n");			if (stat(config_file, &cf_stat) < 0 ||			    timespeccmp(&cf_info.st_mtimespec,			    &cf_stat.st_mtimespec, <) ||			    cf_info.st_size != cf_stat.st_size) {				dprintf("config file modified: restarting\n");				result = 1;				must_write(socks[0], &result, sizeof(int));				increase_state(STATE_RESTART);			} else {				result = 0;				must_write(socks[0], &result, sizeof(int));			}			break;		case PRIV_DONE_CONFIG_PARSE:			dprintf("[priv]: msg PRIV_DONE_CONFIG_PARSE received\n");			increase_state(STATE_RUNNING);			break;		case PRIV_GETHOSTBYNAME:			dprintf("[priv]: msg PRIV_GETHOSTBYNAME received\n");			/* Expecting: length, hostname */			must_read(socks[0], &hostname_len, sizeof(size_t));			if (hostname_len == 0 || hostname_len > sizeof(hostname))				_exit(0);			must_read(socks[0], &hostname, hostname_len);			hostname[hostname_len - 1] = '\0';			hp = gethostbyname(hostname);			if (hp == NULL) {				addr_len = 0;				must_write(socks[0], &addr_len, sizeof(int));			} else {				must_write(socks[0], &hp->h_length, sizeof(int));				must_write(socks[0], hp->h_addr, hp->h_length);			}			break;		case PRIV_GETHOSTBYADDR:			dprintf("[priv]: msg PRIV_GETHOSTBYADDR received\n");			if (!allow_gethostbyaddr)				errx(1, "rejected attempt to gethostbyaddr");			/* Expecting: length, address, address family */			must_read(socks[0], &addr_len, sizeof(int));			if (addr_len <= 0 || addr_len > sizeof(hostname))				_exit(0);			must_read(socks[0], hostname, addr_len);			must_read(socks[0], &addr_af, sizeof(int));			hp = gethostbyaddr(hostname, addr_len, addr_af);			if (hp == NULL) {				addr_len = 0;				must_write(socks[0], &addr_len, sizeof(int));			} else {				addr_len = strlen(hp->h_name) + 1;				must_write(socks[0], &addr_len, sizeof(int));				must_write(socks[0], hp->h_name, addr_len);			}			break;		default:			errx(1, "unknown command %d", cmd);			break;		}	}	/* Unlink any domain sockets that have been opened */	for (i = 0; i < nfunix; i++)		if (funixn[i] && funix[i] != -1)			(void)unlink(funixn[i]);	if (cur_state == STATE_RESTART) {		int r;		wait(&r);		execvp(argv[0], argv);	}	_exit(1);}