Display *dpy2 = 0;
Display *dpy2 = NULL;
int try_user_and_display(uid_t uid, char *dpystr) {	/* NO strtoks */#if LIBVNCSERVER_HAVE_FORK && LIBVNCSERVER_HAVE_SYS_WAIT_H && LIBVNCSERVER_HAVE_PWD_H	pid_t pid, pidw;	char *home, *name;	int st;	struct passwd *pw;		pw = getpwuid(uid);	if (pw) {		name = pw->pw_name;		home = pw->pw_dir;	} else {		return 0;	}	/* 	 * We fork here and try to open the display again as the	 * new user.  Unreadable XAUTHORITY could be a problem...	 * This is not really needed since we have DISPLAY open but:	 * 1) is a good indicator this user owns the session and  2)	 * some activities do spawn new X apps, e.g.  xmessage(1), etc.	 */	if ((pid = fork()) > 0) {		;	} else if (pid == -1) {		fprintf(stderr, "could not fork\n");		rfbLogPerror("fork");		return 0;	} else {		/* child */		Display *dpy2 = 0;		int rc;		rc = switch_user_env(uid, name, home, 0); 		if (! rc) {			exit(1);		}		fclose(stderr);		dpy2 = XOpenDisplay(dpystr);		if (dpy2) {			XCloseDisplay(dpy2);			exit(0);	/* success */		} else {			exit(2);	/* fail */		}	}	/* see what the child says: */	pidw = waitpid(pid, &st, 0);	if (pidw == pid && WIFEXITED(st) && WEXITSTATUS(st) == 0) {		return 1;	}#endif	/* LIBVNCSERVER_HAVE_FORK ... */	return 0;}