} if (launch_gui && (query_cmd || remote_cmd)) { launch_gui = 0; gui_str = NULL;
int main(int argc, char* argv[]) {	int i, len, tmpi;	int ev, er, maj, min;	char *arg;	int remote_sync = 0;	char *remote_cmd = NULL;	char *query_cmd  = NULL;	char *gui_str = NULL;	int pw_loc = -1, got_passwd = 0, got_rfbauth = 0, nopw = NOPW;	int got_viewpasswd = 0, got_localhost = 0, got_passwdfile = 0;	int running_without_passwd = 0;	int vpw_loc = -1;	int dt = 0, bg = 0;	int got_rfbwait = 0;	int got_httpdir = 0, try_http = 0;	/* used to pass args we do not know about to rfbGetScreen(): */	int argc_vnc = 1; char *argv_vnc[128];	dtime0(&x11vnc_start);	if (!getuid() || !geteuid()) {		started_as_root = 1;		/* check for '-users =bob' */		immediate_switch_user(argc, argv);	}	argv_vnc[0] = strdup(argv[0]);	program_name = strdup(argv[0]);	program_pid = (int) getpid();	solid_default = strdup(solid_default);	/* for freeing with -R */	len = 0;	for (i=1; i < argc; i++) {		len += strlen(argv[i]) + 4 + 1;	}	program_cmdline = (char *) malloc(len+1);	program_cmdline[0] = '\0';	for (i=1; i < argc; i++) {		char *s = argv[i];		if (program_cmdline[0]) {			strcat(program_cmdline, " ");		}		if (*s == '-') {			strcat(program_cmdline, s);		} else {			strcat(program_cmdline, "{{");			strcat(program_cmdline, s);			strcat(program_cmdline, "}}");		}	}	for (i=0; i<ICON_MODE_SOCKS; i++) {		icon_mode_socks[i] = -1;	}	check_rcfile(argc, argv);	/* kludge for the new array argv2 set in check_rcfile() */#	define argc argc2#	define argv argv2#	define CHECK_ARGC if (i >= argc-1) { \		fprintf(stderr, "not enough arguments for: %s\n", arg); \		exit(1); \	}	for (i=1; i < argc; i++) {		/* quick-n-dirty --option handling. */		arg = argv[i];		if (strstr(arg, "--") == arg) {			arg++;		}		if (!strcmp(arg, "-display")) {			CHECK_ARGC			use_dpy = strdup(argv[++i]);		} else if (!strcmp(arg, "-auth") || !strcmp(arg, "-xauth")) {			CHECK_ARGC			auth_file = strdup(argv[++i]);		} else if (!strcmp(arg, "-id") || !strcmp(arg, "-sid")) {			CHECK_ARGC			if (!strcmp(arg, "-sid")) {				rootshift = 1;			} else {				rootshift = 0;			}			i++;			if (!strcmp("pick", argv[i])) {				if (started_as_root) {					fprintf(stderr, "unsafe: %s pick\n",					    arg);					exit(1);				} else if (! pick_windowid(&subwin)) {					fprintf(stderr, "invalid %s pick\n",					    arg);					exit(1);				}			} else if (! scan_hexdec(argv[i], &subwin)) {				fprintf(stderr, "invalid %s arg: %s\n", arg,				    argv[i]);				exit(1);			}		} else if (!strcmp(arg, "-waitmapped")) {			subwin_wait_mapped = 1;		} else if (!strcmp(arg, "-clip")) {			CHECK_ARGC			clip_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-flashcmap")) {			flash_cmap = 1;		} else if (!strcmp(arg, "-shiftcmap")) {			CHECK_ARGC			shift_cmap = atoi(argv[++i]);		} else if (!strcmp(arg, "-notruecolor")) {			force_indexed_color = 1;		} else if (!strcmp(arg, "-overlay")) {			overlay = 1;		} else if (!strcmp(arg, "-overlay_nocursor")) {			overlay = 1;			overlay_cursor = 0;		} else if (!strcmp(arg, "-overlay_yescursor")) {			overlay = 1;			overlay_cursor = 2;		} else if (!strcmp(arg, "-visual")) {			CHECK_ARGC			visual_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scale")) {			CHECK_ARGC			scale_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scale_cursor")) {			CHECK_ARGC			scale_cursor_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-viewonly")) {			view_only = 1;		} else if (!strcmp(arg, "-noviewonly")) {			view_only = 0;			got_noviewonly = 1;		} else if (!strcmp(arg, "-shared")) {			shared = 1;		} else if (!strcmp(arg, "-once")) {			connect_once = 1;			got_connect_once = 1;		} else if (!strcmp(arg, "-many") || !strcmp(arg, "-forever")) {			connect_once = 0;		} else if (!strcmp(arg, "-timeout")) {			CHECK_ARGC			first_conn_timeout = atoi(argv[++i]);		} else if (!strcmp(arg, "-users")) {			CHECK_ARGC			users_list = strdup(argv[++i]);		} else if (!strcmp(arg, "-inetd")) {			inetd = 1;		} else if (!strcmp(arg, "-http")) {			try_http = 1;		} else if (!strcmp(arg, "-connect")) {			CHECK_ARGC			if (strchr(argv[++i], '/')) {				client_connect_file = strdup(argv[i]);			} else {				client_connect = strdup(argv[i]);			}		} else if (!strcmp(arg, "-vncconnect")) {			vnc_connect = 1;		} else if (!strcmp(arg, "-novncconnect")) {			vnc_connect = 0;		} else if (!strcmp(arg, "-allow")) {			CHECK_ARGC			allow_list = strdup(argv[++i]);		} else if (!strcmp(arg, "-localhost")) {			allow_list = strdup("127.0.0.1");			got_localhost = 1;		} else if (!strcmp(arg, "-nolookup")) {			host_lookup = 0;		} else if (!strcmp(arg, "-input")) {			CHECK_ARGC			allowed_input_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-viewpasswd")) {			vpw_loc = i;			CHECK_ARGC			viewonly_passwd = strdup(argv[++i]);			got_viewpasswd = 1;		} else if (!strcmp(arg, "-passwdfile")) {			CHECK_ARGC			passwdfile = strdup(argv[++i]);			got_passwdfile = 1;		} else if (!strcmp(arg, "-nopw")) {			nopw = 1;		} else if (!strcmp(arg, "-storepasswd")) {			if (i+2 >= argc || rfbEncryptAndStorePasswd(argv[i+1],			    argv[i+2]) != 0) {				fprintf(stderr, "-storepasswd failed\n");				exit(1);			} else {				fprintf(stderr, "stored passwd in file %s\n",				    argv[i+2]);				exit(0);			}		} else if (!strcmp(arg, "-accept")) {			CHECK_ARGC			accept_cmd = strdup(argv[++i]);		} else if (!strcmp(arg, "-gone")) {			CHECK_ARGC			gone_cmd = strdup(argv[++i]);		} else if (!strcmp(arg, "-noshm")) {			using_shm = 0;		} else if (!strcmp(arg, "-flipbyteorder")) {			flip_byte_order = 1;		} else if (!strcmp(arg, "-onetile")) {			single_copytile = 1;		} else if (!strcmp(arg, "-solid")) {			use_solid_bg = 1;			if (i < argc-1) {				char *s = argv[i+1];				if (s[0] != '-') {					solid_str = strdup(s);					i++;				}			}			if (! solid_str) {				solid_str = strdup(solid_default);			}		} else if (!strcmp(arg, "-blackout")) {			CHECK_ARGC			blackout_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-xinerama")) {			xinerama = 1;		} else if (!strcmp(arg, "-xtrap")) {			xtrap_input = 1;		} else if (!strcmp(arg, "-xrandr")) {			xrandr = 1;			if (i < argc-1) {				char *s = argv[i+1];				if (known_xrandr_mode(s)) {					xrandr_mode = strdup(s);					i++;				}			}		} else if (!strcmp(arg, "-padgeom")		    || !strcmp(arg, "-padgeometry")) {			CHECK_ARGC			pad_geometry = strdup(argv[++i]);		} else if (!strcmp(arg, "-o") || !strcmp(arg, "-logfile")) {			CHECK_ARGC			logfile_append = 0;			logfile = strdup(argv[++i]);		} else if (!strcmp(arg, "-oa") || !strcmp(arg, "-logappend")) {			CHECK_ARGC			logfile_append = 1;			logfile = strdup(argv[++i]);		} else if (!strcmp(arg, "-flag")) {			CHECK_ARGC			flagfile = strdup(argv[++i]);		} else if (!strcmp(arg, "-rc")) {			i++;	/* done above */		} else if (!strcmp(arg, "-norc")) {			;	/* done above */		} else if (!strcmp(arg, "-h") || !strcmp(arg, "-help")) {			print_help(0);		} else if (!strcmp(arg, "-?") || !strcmp(arg, "-opts")) {			print_help(1);		} else if (!strcmp(arg, "-V") || !strcmp(arg, "-version")) {			fprintf(stdout, "x11vnc: %s\n", lastmod);			exit(0);		} else if (!strcmp(arg, "-dbg")) {			crash_debug = 1;		} else if (!strcmp(arg, "-nodbg")) {			crash_debug = 0;		} else if (!strcmp(arg, "-q") || !strcmp(arg, "-quiet")) {			quiet = 1;		} else if (!strcmp(arg, "-bg") || !strcmp(arg, "-background")) {#if LIBVNCSERVER_HAVE_SETSID			bg = 1;			opts_bg = bg;#else			fprintf(stderr, "warning: -bg mode not supported.\n");#endif		} else if (!strcmp(arg, "-modtweak")) {			use_modifier_tweak = 1;		} else if (!strcmp(arg, "-nomodtweak")) {			use_modifier_tweak = 0;			got_nomodtweak = 1;		} else if (!strcmp(arg, "-isolevel3")) {			use_iso_level3 = 1;		} else if (!strcmp(arg, "-xkb")) {			use_modifier_tweak = 1;			use_xkb_modtweak = 1;		} else if (!strcmp(arg, "-noxkb")) {			use_xkb_modtweak = 0;			got_noxkb = 1;		} else if (!strcmp(arg, "-xkbcompat")) {			xkbcompat = 1;		} else if (!strcmp(arg, "-skip_keycodes")) {			CHECK_ARGC			skip_keycodes = strdup(argv[++i]);		} else if (!strcmp(arg, "-sloppy_keys")) {			sloppy_keys++;		} else if (!strcmp(arg, "-skip_dups")) {			skip_duplicate_key_events = 1;		} else if (!strcmp(arg, "-noskip_dups")) {			skip_duplicate_key_events = 0;		} else if (!strcmp(arg, "-add_keysyms")) {			add_keysyms++;		} else if (!strcmp(arg, "-noadd_keysyms")) {			add_keysyms = 0;		} else if (!strcmp(arg, "-clear_mods")) {			clear_mods = 1;		} else if (!strcmp(arg, "-clear_keys")) {			clear_mods = 2;		} else if (!strcmp(arg, "-remap")) {			CHECK_ARGC			remap_file = strdup(argv[++i]);		} else if (!strcmp(arg, "-norepeat")) {			no_autorepeat = 1;			if (i < argc-1) {				char *s = argv[i+1];				if (*s == '-') {					s++;				}				if (isdigit(*s)) {					no_repeat_countdown = atoi(argv[++i]);				}			}		} else if (!strcmp(arg, "-repeat")) {			no_autorepeat = 0;		} else if (!strcmp(arg, "-nofb")) {			nofb = 1;		} else if (!strcmp(arg, "-nobell")) {			watch_bell = 0;			sound_bell = 0;		} else if (!strcmp(arg, "-nosel")) {			watch_selection = 0;			watch_primary = 0;		} else if (!strcmp(arg, "-noprimary")) {			watch_primary = 0;		} else if (!strcmp(arg, "-seldir")) {			CHECK_ARGC			sel_direction = strdup(argv[++i]);		} else if (!strcmp(arg, "-cursor")) {			show_cursor = 1;			if (i < argc-1) {				char *s = argv[i+1];				if (known_cursors_mode(s)) {					multiple_cursors_mode = strdup(s);					i++;					if (!strcmp(s, "none")) {						show_cursor = 0;					}				} 			}		} else if (!strcmp(arg, "-nocursor")) { 			multiple_cursors_mode = strdup("none");			show_cursor = 0;		} else if (!strcmp(arg, "-arrow")) {			CHECK_ARGC			alt_arrow = atoi(argv[++i]);		} else if (!strcmp(arg, "-xfixes")) { 			use_xfixes = 1;		} else if (!strcmp(arg, "-noxfixes")) { 			use_xfixes = 0;		} else if (!strcmp(arg, "-alphacut")) {			CHECK_ARGC			alpha_threshold = atoi(argv[++i]);		} else if (!strcmp(arg, "-alphafrac")) {			CHECK_ARGC			alpha_frac = atof(argv[++i]);		} else if (!strcmp(arg, "-alpharemove")) {			alpha_remove = 1;		} else if (!strcmp(arg, "-noalphablend")) {			alpha_blend = 0;		} else if (!strcmp(arg, "-nocursorshape")) {			cursor_shape_updates = 0;		} else if (!strcmp(arg, "-cursorpos")) {			cursor_pos_updates = 1;			got_cursorpos = 1;		} else if (!strcmp(arg, "-nocursorpos")) {			cursor_pos_updates = 0;		} else if (!strcmp(arg, "-xwarppointer")) {			use_xwarppointer = 1;		} else if (!strcmp(arg, "-buttonmap")) {			CHECK_ARGC			pointer_remap = strdup(argv[++i]);		} else if (!strcmp(arg, "-nodragging")) {			show_dragging = 0;		} else if (!strcmp(arg, "-wireframe")		    || !strcmp(arg, "-wf")) {			wireframe = 1;			if (i < argc-1) {				char *s = argv[i+1];				if (*s != '-') {					wireframe_str = strdup(argv[++i]);				}			}		} else if (!strcmp(arg, "-nowireframe")		    || !strcmp(arg, "-nowf")) {			wireframe = 0;		} else if (!strcmp(arg, "-wirecopyrect")		    || !strcmp(arg, "-wcr")) {			CHECK_ARGC			set_wirecopyrect_mode(argv[++i]);			got_wirecopyrect = 1;		} else if (!strcmp(arg, "-nowirecopyrect")		    || !strcmp(arg, "-nowf")) {			set_wirecopyrect_mode("never");		} else if (!strcmp(arg, "-debug_wireframe")		    || !strcmp(arg, "-dwf")) {			debug_wireframe++;		} else if (!strcmp(arg, "-scrollcopyrect")		    || !strcmp(arg, "-scr")) {			CHECK_ARGC			set_scrollcopyrect_mode(argv[++i]);			got_scrollcopyrect = 1;		} else if (!strcmp(arg, "-noscrollcopyrect")		    || !strcmp(arg, "-noscr")) {			set_scrollcopyrect_mode("never");		} else if (!strcmp(arg, "-scr_area")) {			int tn;			CHECK_ARGC			tn = atoi(argv[++i]);			if (tn >= 0) {				scrollcopyrect_min_area = tn;			}		} else if (!strcmp(arg, "-scr_skip")) {			CHECK_ARGC			scroll_skip_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scr_inc")) {			CHECK_ARGC			scroll_good_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scr_keys")) {			CHECK_ARGC			scroll_key_list_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scr_term")) {			CHECK_ARGC			scroll_term_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scr_keyrepeat")) {			CHECK_ARGC			max_keyrepeat_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-scr_parms")) {			CHECK_ARGC			scroll_copyrect_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-fixscreen")) {			CHECK_ARGC			screen_fixup_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-debug_scroll")		    || !strcmp(arg, "-ds")) {			debug_scroll++;		} else if (!strcmp(arg, "-noxrecord")) {			noxrecord = 1;		} else if (!strcmp(arg, "-pointer_mode")		    || !strcmp(arg, "-pm")) {			char *p, *s;			CHECK_ARGC			s = argv[++i];			if ((p = strchr(s, ':')) != NULL) {				ui_skip = atoi(p+1);				if (! ui_skip) ui_skip = 1;				*p = '\0';			}			if (atoi(s) < 1 || atoi(s) > pointer_mode_max) {				rfbLog("pointer_mode out of range 1-%d: %d\n",				    pointer_mode_max, atoi(s));			} else {				pointer_mode = atoi(s);				got_pointer_mode = pointer_mode;			}		} else if (!strcmp(arg, "-input_skip")) {			CHECK_ARGC			ui_skip = atoi(argv[++i]);			if (! ui_skip) ui_skip = 1;		} else if (!strcmp(arg, "-speeds")) {			CHECK_ARGC			speeds_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-wmdt")) {			CHECK_ARGC			wmdt_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-debug_pointer")		    || !strcmp(arg, "-dp")) {			debug_pointer++;		} else if (!strcmp(arg, "-debug_keyboard")		    || !strcmp(arg, "-dk")) {			debug_keyboard++;		} else if (!strcmp(arg, "-defer")) {			CHECK_ARGC			defer_update = atoi(argv[++i]);			got_defer = 1;		} else if (!strcmp(arg, "-wait")) {			CHECK_ARGC			waitms = atoi(argv[++i]);		} else if (!strcmp(arg, "-wait_ui")) {			CHECK_ARGC			wait_ui = atof(argv[++i]);		} else if (!strcmp(arg, "-nowait_bog")) {			wait_bog = 0;		} else if (!strcmp(arg, "-readtimeout")) {			CHECK_ARGC			rfbMaxClientWait = atoi(argv[++i]) * 1000;		} else if (!strcmp(arg, "-nap")) {			take_naps = 1;		} else if (!strcmp(arg, "-nonap")) {			take_naps = 0;		} else if (!strcmp(arg, "-sb")) {			CHECK_ARGC			screen_blank = atoi(argv[++i]);		} else if (!strcmp(arg, "-xdamage")) {			use_xdamage = 1;		} else if (!strcmp(arg, "-noxdamage")) {			use_xdamage = 0;		} else if (!strcmp(arg, "-xd_area")) {			int tn;			CHECK_ARGC			tn = atoi(argv[++i]);			if (tn >= 0) {				xdamage_max_area = tn;			}		} else if (!strcmp(arg, "-xd_mem")) {			double f;			CHECK_ARGC			f = atof(argv[++i]);			if (f >= 0.0) {				xdamage_memory = f;			}		} else if (!strcmp(arg, "-sigpipe")) {			CHECK_ARGC			if (known_sigpipe_mode(argv[++i])) {				sigpipe = strdup(argv[i]);			} else {				fprintf(stderr, "invalid -sigpipe arg: %s, must"				    " be \"ignore\" or \"exit\"\n", argv[i]);				exit(1);			}#if LIBVNCSERVER_HAVE_LIBPTHREAD		} else if (!strcmp(arg, "-threads")) {			use_threads = 1;		} else if (!strcmp(arg, "-nothreads")) {			use_threads = 0;#endif		} else if (!strcmp(arg, "-fs")) {			CHECK_ARGC			fs_frac = atof(argv[++i]);		} else if (!strcmp(arg, "-gaps")) {			CHECK_ARGC			gaps_fill = atoi(argv[++i]);		} else if (!strcmp(arg, "-grow")) {			CHECK_ARGC			grow_fill = atoi(argv[++i]);		} else if (!strcmp(arg, "-fuzz")) {			CHECK_ARGC			tile_fuzz = atoi(argv[++i]);		} else if (!strcmp(arg, "-debug_tiles")		    || !strcmp(arg, "-dbt")) {			debug_tiles++;		} else if (!strcmp(arg, "-debug_grabs")) {			debug_grabs++;		} else if (!strcmp(arg, "-grab_buster")) {			grab_buster++;		} else if (!strcmp(arg, "-nograb_buster")) {			grab_buster = 0;		} else if (!strcmp(arg, "-snapfb")) {			use_snapfb = 1;		} else if (!strcmp(arg, "-rawfb")) {			CHECK_ARGC			raw_fb_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-pipeinput")) {			CHECK_ARGC			pipeinput_str = strdup(argv[++i]);		} else if (!strcmp(arg, "-gui")) {			launch_gui = 1;			if (i < argc-1) {				char *s = argv[i+1];				if (*s != '-') {					gui_str = strdup(s);					i++;				} 			}		} else if (!strcmp(arg, "-remote") || !strcmp(arg, "-R")		    || !strcmp(arg, "-r") || !strcmp(arg, "-remote-control")) {			char *str;			CHECK_ARGC			i++;			str = argv[i];			if (*str == '-') {				/* accidental leading '-' */				str++;			}			if (!strcmp(str, "ping")) {				query_cmd = strdup(str);			} else {				remote_cmd = strdup(str);			}			if (remote_cmd && strchr(remote_cmd, ':') == NULL) {			    /* interpret -R -scale 3/4 at least */		 	    if (i < argc-1 && *(argv[i+1]) != '-') {				int n;				/* it must be the parameter value */				i++;				n = strlen(remote_cmd) + strlen(argv[i]) + 2;				str = (char *) malloc(n);				sprintf(str, "%s:%s", remote_cmd, argv[i]);				free(remote_cmd);				remote_cmd = str;			    }			}			quiet = 1;			xkbcompat = 0;		} else if (!strcmp(arg, "-query") || !strcmp(arg, "-Q")) {			CHECK_ARGC			query_cmd = strdup(argv[++i]);			quiet = 1;			xkbcompat = 0;		} else if (!strcmp(arg, "-QD")) {			CHECK_ARGC			query_cmd = strdup(argv[++i]);			query_default = 1;		} else if (!strcmp(arg, "-sync")) {			remote_sync = 1;		} else if (!strcmp(arg, "-nosync")) {			remote_sync = 0;		} else if (!strcmp(arg, "-noremote")) {			accept_remote_cmds = 0;		} else if (!strcmp(arg, "-yesremote")) {			accept_remote_cmds = 1;		} else if (!strcmp(arg, "-unsafe")) {			safe_remote_only = 0;		} else if (!strcmp(arg, "-privremote")) {			priv_remote = 1;		} else if (!strcmp(arg, "-safer")) {			more_safe = 1;		} else if (!strcmp(arg, "-nocmds")) {			no_external_cmds = 1;		} else if (!strcmp(arg, "-deny_all")) {			deny_all = 1;		} else if (!strcmp(arg, "-httpdir")) {			CHECK_ARGC			http_dir = strdup(argv[++i]);			got_httpdir = 1;		} else {			if (!strcmp(arg, "-desktop") && i < argc-1) {				dt = 1;				rfb_desktop_name = strdup(argv[i+1]);			}			if (!strcmp(arg, "-passwd")) {				pw_loc = i;				got_passwd = 1;			}			if (!strcmp(arg, "-rfbauth")) {				got_rfbauth = 1;			}			if (!strcmp(arg, "-rfbwait")) {				got_rfbwait = 1;			}			if (!strcmp(arg, "-deferupdate")) {				got_deferupdate = 1;			}			if (!strcmp(arg, "-rfbport")) {				got_rfbport = 1;			}			if (!strcmp(arg, "-alwaysshared ")) {				got_alwaysshared = 1;			}			if (!strcmp(arg, "-nevershared")) {				got_nevershared = 1;			}			if (!strcmp(arg, "-listen") && i < argc-1) {				listen_str = strdup(argv[i+1]);			}			/* otherwise copy it for libvncserver use below. */			if (argc_vnc < 100) {				argv_vnc[argc_vnc++] = strdup(arg);			}		}	}	if (!got_passwd && !got_rfbauth && !got_passwdfile && !nopw)  {		running_without_passwd = 1;	}	if (launch_gui) {		int sleep = 0;		if (running_without_passwd && !quiet) {			sleep = 3;		}		do_gui(gui_str, sleep);	}	if (logfile) {		int n;		if (logfile_append) {			n = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0666);		} else {			n = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0666);		}		if (n < 0) {			fprintf(stderr, "error opening logfile: %s\n", logfile);			perror("open");			exit(1);		}		if (dup2(n, 2) < 0) {			fprintf(stderr, "dup2 failed\n");			perror("dup2");			exit(1);		}		if (n > 2) {			close(n);		}	}	if (inetd && quiet && !logfile) {		int n;		/*		 * Redir stderr to /dev/null under -inetd and -quiet		 * but no -o logfile.  Typical problem:		 *   Xlib:  extension "RECORD" missing on display ":1.0".		 * If they want this info, they should use -o logfile,		 * or no -q and 2>logfile.		 */		n = open("/dev/null", O_WRONLY);		if (n >= 0) {			if (dup2(n, 2) >= 0) {				if (n > 2) {					close(n);				}			}		}	}	if (! quiet && ! inetd) {		int i;		for (i=1; i < argc_vnc; i++) {			rfbLog("passing arg to libvncserver: %s\n", argv_vnc[i]);			if (!strcmp(argv_vnc[i], "-passwd")) {				i++;			}		}	}	if (remote_cmd || query_cmd) {		/*		 * no need to open DISPLAY, just write it to the file now		 * similar for query_default.		 */		if (client_connect_file || query_default) {			int rc = do_remote_query(remote_cmd, query_cmd,			     remote_sync, query_default);			fflush(stderr);			fflush(stdout);			exit(rc);		}	}	/*	 * If -passwd was used, clear it out of argv.  This does not	 * work on all UNIX, have to use execvp() in general...	 */	if (pw_loc > 0) {		int i;		for (i=pw_loc; i <= pw_loc+1; i++) {			if (i < argc) {				char *p = argv[i];						while (*p != '\0') {					*p++ = '\0';				}			}		}	} else if (passwdfile) {		/* read passwd from file */		char line[1024];		FILE *in;		in = fopen(passwdfile, "r");		if (in == NULL) {			rfbLog("cannot open passwdfile: %s\n", passwdfile);			rfbLogPerror("fopen");			exit(1);		}		if (fgets(line, 1024, in) != NULL) {			char *q;			int len = strlen(line); 			if (len > 0 && line[len-1] == '\n') {				line[len-1] = '\0';			}			argv_vnc[argc_vnc++] = strdup("-passwd");			got_passwd = 1;			if (!strcmp(line, "__EMPTY__")) {				argv_vnc[argc_vnc++] = strdup("");			} else if ((q = strstr(line, "__ENDPASSWD__")) !=NULL) {				*q = '\0';				argv_vnc[argc_vnc++] = strdup(line);			} else {				argv_vnc[argc_vnc++] = strdup(line);			}			pw_loc = 100;	/* just for pw_loc check below */			if (fgets(line, 1024, in) != NULL) {				/* try to read viewonly passwd from file */				int ok = 0;				len = strlen(line); 				if (len > 0 && line[len-1] == '\n') {					line[len-1] = '\0';				}				if (strlen(line) > 0) {					char *p = line;					/* check for non-blank line */					while (*p != '\0') {						if (! isspace(*p)) {							ok = 1;						}						p++;					}				}				if (ok) {					if (!strcmp(line, "__EMPTY__")) {						viewonly_passwd = strdup("");					} else if ((q = strstr(line,					    "__ENDPASSWD__")) != NULL) {						*q = '\0';						viewonly_passwd = strdup(line);					} else {						viewonly_passwd = strdup(line);					}				} else {					rfbLog("*** not setting"					    " viewonly password to the 2nd"					    " line of %s. (blank or other"					    " problem)\n", passwdfile);				}			}		} else {			rfbLog("cannot read a line from passwdfile: %s\n",			    passwdfile);			exit(1);		}		fclose(in);	}	if (vpw_loc > 0) {		int i;		for (i=vpw_loc; i <= vpw_loc+1; i++) {			if (i < argc) {				char *p = argv[i];						while (*p != '\0') {					*p++ = '\0';				}			}		}	} #ifdef HARDWIRE_PASSWD	if (! got_rfbauth && ! got_passwd) {		argv_vnc[argc_vnc++] = strdup("-passwd");		argv_vnc[argc_vnc++] = strdup(HARDWIRE_PASSWD);		got_passwd = 1;		pw_loc = 100;	}#endif#ifdef HARDWIRE_VIEWPASSWD	if (! got_rfbauth && got_passwd && ! viewonly_passwd) {		viewonly_passwd = strdup(HARDWIRE_VIEWPASSWD);	}#endif	if (viewonly_passwd && pw_loc < 0) {		rfbLog("-passwd must be supplied when using -viewpasswd\n");		exit(1);	}	if (!got_passwd && !got_rfbauth && !got_passwdfile && !nopw) {		nopassword_warning_msg(got_localhost);	}	if (more_safe) {		if (! quiet) {			rfbLog("-safer mode:\n");			rfbLog("   vnc_connect=0\n");			rfbLog("   accept_remote_cmds=0\n");			rfbLog("   safe_remote_only=1\n");			rfbLog("   launch_gui=0\n");		}		vnc_connect = 0;		accept_remote_cmds = 0;		safe_remote_only = 1;		launch_gui = 0;	}	/* fixup settings that do not make sense */			if (use_threads && nofb && cursor_pos_updates) {		if (! quiet) {			rfbLog("disabling -threads under -nofb -cursorpos\n");		}		use_threads = 0;	}	if (tile_fuzz < 1) {		tile_fuzz = 1;	}	if (waitms < 0) {		waitms = 0;	}	if (alpha_threshold < 0) {		alpha_threshold = 0;	}	if (alpha_threshold > 256) {		alpha_threshold = 256;	}	if (alpha_frac < 0.0) {		alpha_frac = 0.0;	}	if (alpha_frac > 1.0) {		alpha_frac = 1.0;	}	if (alpha_blend) {		alpha_remove = 0;	}	if (inetd) {		shared = 0;		connect_once = 1;		bg = 0;		/* others? */	}	if (flip_byte_order && using_shm && ! quiet) {		rfbLog("warning: -flipbyte order only works with -noshm\n");	}	if (! wireframe_copyrect) {		set_wirecopyrect_mode(NULL);	}	if (! scroll_copyrect) {		set_scrollcopyrect_mode(NULL);	}	if (screen_fixup_str) {		parse_fixscreen();	}	initialize_scroll_matches();	initialize_scroll_term();	initialize_max_keyrepeat();	/* increase rfbwait if threaded */	if (use_threads && ! got_rfbwait) {		rfbMaxClientWait = 604800000;	}	/* no framebuffer (Win2VNC) mode */	if (nofb) {		/* disable things that do not make sense with no fb */		set_nofb_params();		if (! got_deferupdate && ! got_defer) {			/* reduce defer time under -nofb */			defer_update = defer_update_nofb;		}		if (got_pointer_mode < 0) {			pointer_mode = POINTER_MODE_NOFB;		}	}	if (raw_fb_str) {		set_raw_fb_params(0);	}	if (! got_deferupdate) {		char tmp[40];		sprintf(tmp, "%d", defer_update);		argv_vnc[argc_vnc++] = strdup("-deferupdate");		argv_vnc[argc_vnc++] = strdup(tmp);	}	if (debug_pointer || debug_keyboard) {		if (bg || quiet) {			rfbLog("disabling -bg/-q under -debug_pointer"			    "/-debug_keyboard\n");			bg = 0;			quiet = 0;		}	}	/* initialize added_keysyms[] array to zeros */	add_keysym(NoSymbol);	/* tie together cases of -localhost vs. -listen localhost */	if (! listen_str) {		if (allow_list && !strcmp(allow_list, "127.0.0.1")) {			listen_str = strdup("localhost");			argv_vnc[argc_vnc++] = strdup("-listen");			argv_vnc[argc_vnc++] = strdup(listen_str);		}	} else if (!strcmp(listen_str, "localhost") ||	    !strcmp(listen_str, "127.0.0.1")) {		allow_list = strdup("127.0.0.1");	}	/* set OS struct UT */	uname(&UT);	initialize_crash_handler();	if (! quiet) {		fprintf(stderr, "\n");		fprintf(stderr, "Settings:\n");		fprintf(stderr, " display:    %s\n", use_dpy ? use_dpy                    : "null");		fprintf(stderr, " authfile:   %s\n", auth_file ? auth_file                    : "null");		fprintf(stderr, " subwin:     0x%lx\n", subwin);		fprintf(stderr, " -sid mode:  %d\n", rootshift);		fprintf(stderr, " clip:       %s\n", clip_str ? clip_str                    : "null");		fprintf(stderr, " flashcmap:  %d\n", flash_cmap);		fprintf(stderr, " shiftcmap:  %d\n", shift_cmap);		fprintf(stderr, " force_idx:  %d\n", force_indexed_color);		fprintf(stderr, " visual:     %s\n", visual_str ? visual_str                    : "null");		fprintf(stderr, " overlay:    %d\n", overlay);		fprintf(stderr, " ovl_cursor: %d\n", overlay_cursor);		fprintf(stderr, " scaling:    %d %.5f\n", scaling, scale_fac);		fprintf(stderr, " viewonly:   %d\n", view_only);		fprintf(stderr, " shared:     %d\n", shared);		fprintf(stderr, " conn_once:  %d\n", connect_once);		fprintf(stderr, " timeout:    %d\n", first_conn_timeout);		fprintf(stderr, " inetd:      %d\n", inetd);		fprintf(stderr, " http:       %d\n", try_http);		fprintf(stderr, " connect:    %s\n", client_connect		    ? client_connect : "null");		fprintf(stderr, " connectfile %s\n", client_connect_file		    ? client_connect_file : "null");		fprintf(stderr, " vnc_conn:   %d\n", vnc_connect);		fprintf(stderr, " allow:      %s\n", allow_list ? allow_list                    : "null");		fprintf(stderr, " input:      %s\n", allowed_input_str		    ? allowed_input_str : "null");		fprintf(stderr, " passfile:   %s\n", passwdfile ? passwdfile                    : "null");		fprintf(stderr, " accept:     %s\n", accept_cmd ? accept_cmd                    : "null");		fprintf(stderr, " gone:       %s\n", gone_cmd ? gone_cmd                    : "null");		fprintf(stderr, " users:      %s\n", users_list ? users_list                    : "null");		fprintf(stderr, " using_shm:  %d\n", using_shm);		fprintf(stderr, " flipbytes:  %d\n", flip_byte_order);		fprintf(stderr, " onetile:    %d\n", single_copytile);		fprintf(stderr, " solid:      %s\n", solid_str		    ? solid_str : "null");		fprintf(stderr, " blackout:   %s\n", blackout_str		    ? blackout_str : "null");		fprintf(stderr, " xinerama:   %d\n", xinerama);		fprintf(stderr, " xtrap:      %d\n", xtrap_input);		fprintf(stderr, " xrandr:     %d\n", xrandr);		fprintf(stderr, " xrandrmode: %s\n", xrandr_mode ? xrandr_mode		    : "null");		fprintf(stderr, " padgeom:    %s\n", pad_geometry		    ? pad_geometry : "null");		fprintf(stderr, " logfile:    %s\n", logfile ? logfile                    : "null");		fprintf(stderr, " logappend:  %d\n", logfile_append);		fprintf(stderr, " flag:       %s\n", flagfile ? flagfile                    : "null");		fprintf(stderr, " rc_file:    \"%s\"\n", rc_rcfile ? rc_rcfile                    : "null");		fprintf(stderr, " norc:       %d\n", rc_norc);		fprintf(stderr, " dbg:        %d\n", crash_debug);		fprintf(stderr, " bg:         %d\n", bg);		fprintf(stderr, " mod_tweak:  %d\n", use_modifier_tweak);		fprintf(stderr, " isolevel3:  %d\n", use_iso_level3);		fprintf(stderr, " xkb:        %d\n", use_xkb_modtweak);		fprintf(stderr, " skipkeys:   %s\n",		    skip_keycodes ? skip_keycodes : "null");		fprintf(stderr, " sloppykeys: %d\n", sloppy_keys);		fprintf(stderr, " skip_dups:  %d\n", skip_duplicate_key_events);		fprintf(stderr, " addkeysyms: %d\n", add_keysyms);		fprintf(stderr, " xkbcompat:  %d\n", xkbcompat);		fprintf(stderr, " clearmods:  %d\n", clear_mods);		fprintf(stderr, " remap:      %s\n", remap_file ? remap_file                    : "null");		fprintf(stderr, " norepeat:   %d\n", no_autorepeat);		fprintf(stderr, " norepeatcnt:%d\n", no_repeat_countdown);		fprintf(stderr, " nofb:       %d\n", nofb);		fprintf(stderr, " watchbell:  %d\n", watch_bell);		fprintf(stderr, " watchsel:   %d\n", watch_selection);		fprintf(stderr, " watchprim:  %d\n", watch_primary);		fprintf(stderr, " seldir:     %s\n", sel_direction ?		    sel_direction : "null");		fprintf(stderr, " cursor:     %d\n", show_cursor);		fprintf(stderr, " multicurs:  %d\n", show_multiple_cursors);		fprintf(stderr, " curs_mode:  %s\n", multiple_cursors_mode		    ? multiple_cursors_mode : "null");		fprintf(stderr, " arrow:      %d\n", alt_arrow);		fprintf(stderr, " xfixes:     %d\n", use_xfixes);		fprintf(stderr, " alphacut:   %d\n", alpha_threshold);		fprintf(stderr, " alphafrac:  %.2f\n", alpha_frac);		fprintf(stderr, " alpharemove:%d\n", alpha_remove);		fprintf(stderr, " alphablend: %d\n", alpha_blend);		fprintf(stderr, " cursorshape:%d\n", cursor_shape_updates);		fprintf(stderr, " cursorpos:  %d\n", cursor_pos_updates);		fprintf(stderr, " xwarpptr:   %d\n", use_xwarppointer);		fprintf(stderr, " buttonmap:  %s\n", pointer_remap		    ? pointer_remap : "null");		fprintf(stderr, " dragging:   %d\n", show_dragging);		fprintf(stderr, " wireframe:  %s\n", wireframe_str ?		    wireframe_str : WIREFRAME_PARMS);		fprintf(stderr, " wirecopy:   %s\n", wireframe_copyrect ?		    wireframe_copyrect : wireframe_copyrect_default);		fprintf(stderr, " scrollcopy: %s\n", scroll_copyrect ?		    scroll_copyrect : scroll_copyrect_default);		fprintf(stderr, "  scr_area:  %d\n", scrollcopyrect_min_area);		fprintf(stderr, "  scr_skip:  %s\n", scroll_skip_str ?		    scroll_skip_str : scroll_skip_str0);		fprintf(stderr, "  scr_inc:   %s\n", scroll_good_str ?		    scroll_good_str : scroll_good_str0);		fprintf(stderr, "  scr_keys:  %s\n", scroll_key_list_str ?		    scroll_key_list_str : "null");		fprintf(stderr, "  scr_term:  %s\n", scroll_term_str ?		    scroll_term_str : "null");		fprintf(stderr, "  scr_keyrep: %s\n", max_keyrepeat_str ?		    max_keyrepeat_str : "null");		fprintf(stderr, "  scr_parms: %s\n", scroll_copyrect_str ?		    scroll_copyrect_str : SCROLL_COPYRECT_PARMS);		fprintf(stderr, " fixscreen:  %s\n", screen_fixup_str ?		    screen_fixup_str : "null");		fprintf(stderr, " noxrecord:  %d\n", noxrecord);		fprintf(stderr, " grabbuster: %d\n", grab_buster);		fprintf(stderr, " ptr_mode:   %d\n", pointer_mode);		fprintf(stderr, " inputskip:  %d\n", ui_skip);		fprintf(stderr, " speeds:     %s\n", speeds_str		    ? speeds_str : "null");		fprintf(stderr, " wmdt:       %s\n", wmdt_str		    ? wmdt_str : "null");		fprintf(stderr, " debug_ptr:  %d\n", debug_pointer);		fprintf(stderr, " debug_key:  %d\n", debug_keyboard);		fprintf(stderr, " defer:      %d\n", defer_update);		fprintf(stderr, " waitms:     %d\n", waitms);		fprintf(stderr, " wait_ui:    %.2f\n", wait_ui);		fprintf(stderr, " nowait_bog: %d\n", !wait_bog);		fprintf(stderr, " readtimeout: %d\n", rfbMaxClientWait/1000);		fprintf(stderr, " take_naps:  %d\n", take_naps);		fprintf(stderr, " sb:         %d\n", screen_blank);		fprintf(stderr, " xdamage:    %d\n", use_xdamage);		fprintf(stderr, "  xd_area:   %d\n", xdamage_max_area);		fprintf(stderr, "  xd_mem:    %.3f\n", xdamage_memory);		fprintf(stderr, " sigpipe:    %s\n", sigpipe		    ? sigpipe : "null");		fprintf(stderr, " threads:    %d\n", use_threads);		fprintf(stderr, " fs_frac:    %.2f\n", fs_frac);		fprintf(stderr, " gaps_fill:  %d\n", gaps_fill);		fprintf(stderr, " grow_fill:  %d\n", grow_fill);		fprintf(stderr, " tile_fuzz:  %d\n", tile_fuzz);		fprintf(stderr, " snapfb:     %d\n", use_snapfb);		fprintf(stderr, " rawfb:      %s\n", raw_fb_str		    ? raw_fb_str : "null");		fprintf(stderr, " pipeinput:  %s\n", pipeinput_str		    ? pipeinput_str : "null");		fprintf(stderr, " gui:        %d\n", launch_gui);		fprintf(stderr, " gui_mode:   %s\n", gui_str		    ? gui_str : "null");		fprintf(stderr, " noremote:   %d\n", !accept_remote_cmds);		fprintf(stderr, " unsafe:     %d\n", !safe_remote_only);		fprintf(stderr, " privremote: %d\n", priv_remote);		fprintf(stderr, " safer:      %d\n", more_safe);		fprintf(stderr, " nocmds:     %d\n", no_external_cmds);		fprintf(stderr, " deny_all:   %d\n", deny_all);		fprintf(stderr, "\n");		rfbLog("x11vnc version: %s\n", lastmod);	} else {		rfbLogEnable(0);	}	X_INIT;	SCR_INIT;		/* open the X display: */	if (auth_file) {		set_env("XAUTHORITY", auth_file);	}#if LIBVNCSERVER_HAVE_XKEYBOARD	/*	 * Disable XKEYBOARD before calling XOpenDisplay()	 * this should be used if there is ambiguity in the keymapping. 	 */	if (xkbcompat) {		Bool rc = XkbIgnoreExtension(True);		if (! quiet) {			rfbLog("Disabling xkb XKEYBOARD extension. rc=%d\n",			    rc);		}		if (watch_bell) {			watch_bell = 0;			if (! quiet) rfbLog("Disabling bell.\n");		}	}#else	watch_bell = 0;	use_xkb_modtweak = 0;#endif	if (users_list && strstr(users_list, "lurk=")) {		if (use_dpy) {			rfbLog("warning: -display does not make sense in "			    "\"lurk=\" mode...\n");		}		lurk_loop(users_list);	}	if (use_dpy) {		dpy = XOpenDisplay(use_dpy);	} else if ( (use_dpy = getenv("DISPLAY")) ) {		dpy = XOpenDisplay(use_dpy);	} else {		dpy = XOpenDisplay("");	}	if (! dpy && raw_fb_str) {		rfbLog("continuing without X display in -rawfb mode, "		    "hold on tight..\n");		goto raw_fb_pass_go_and_collect_200_dollars;	}	if (! dpy && ! use_dpy && ! getenv("DISPLAY")) {		int i, s = 4;		rfbLogEnable(1);		rfbLog("\a\n");		rfbLog("*** XOpenDisplay failed. No -display or DISPLAY.\n");		rfbLog("*** Trying \":0\" in %d seconds.  Press Ctrl-C to"		    " abort.\n", s);		rfbLog("*** ");		for (i=1; i<=s; i++)  {			fprintf(stderr, "%d ", i);			sleep(1);		}		fprintf(stderr, "\n");		use_dpy = ":0";		dpy = XOpenDisplay(use_dpy);		if (dpy) {			rfbLog("*** XOpenDisplay of \":0\" successful.\n");		}		rfbLog("\n");		if (quiet) rfbLogEnable(0);	}	if (! dpy) {		char *d = use_dpy;		if (!d) d = getenv("DISPLAY");		if (!d) d = "null";		rfbLogEnable(1);		fprintf(stderr, "\n");		rfbLog("***************************************\n", d);		rfbLog("*** XOpenDisplay failed (%s)\n", d);		xopen_display_fail_message(d);		exit(1);	} else if (use_dpy) {		if (! quiet) rfbLog("Using X display %s\n", use_dpy);	} else {		if (! quiet) rfbLog("Using default X display.\n");	}	scr = DefaultScreen(dpy);	rootwin = RootWindow(dpy, scr);	if (! quiet) {		rfbLog("\n");		rfbLog("------------------ USEFUL INFORMATION ------------------\n");	}	if (remote_cmd || query_cmd) {		int rc = do_remote_query(remote_cmd, query_cmd, remote_sync,		    query_default);		XFlush(dpy);		fflush(stderr);		fflush(stdout);		usleep(30 * 1000);	/* still needed? */		XCloseDisplay(dpy);		exit(rc);	}	if (priv_remote) {		if (! remote_control_access_ok()) {			rfbLog("** Disabling remote commands in -privremote "			    "mode.\n");			accept_remote_cmds = 0;		}	}	sync_tod_with_servertime();	if (grab_buster) {		spawn_grab_buster();	}#if LIBVNCSERVER_HAVE_LIBXFIXES	if (! XFixesQueryExtension(dpy, &xfixes_base_event_type, &er)) {		if (! quiet) {			rfbLog("Disabling XFIXES mode: display does not "			    "support it.\n");		}		xfixes_base_event_type = 0;		xfixes_present = 0;	} else {		xfixes_present = 1;	}#endif	if (! xfixes_present) {		use_xfixes = 0;	}#if LIBVNCSERVER_HAVE_LIBXDAMAGE	if (! XDamageQueryExtension(dpy, &xdamage_base_event_type, &er)) {		if (! quiet) {			rfbLog("Disabling X DAMAGE mode: display does not "			    "support it.\n");		}		xdamage_base_event_type = 0;		xdamage_present = 0;	} else {		xdamage_present = 1;	}#endif	if (! xdamage_present) {		use_xdamage = 0;	}	if (! quiet && xdamage_present && use_xdamage) {		rfbLog("X DAMAGE available on display, using it for"		    " polling hints.\n");		rfbLog("  To disable this behavior use: "		    "'-noxdamage'\n");	}	if (! quiet && wireframe) {		rfbLog("Wireframing: -wireframe mode is in effect for window "		    "moves.\n");		rfbLog("  If this yields undesired behavior (poor response, "		    "painting\n");		rfbLog("  errors, etc) it may be disabled:\n");		rfbLog("   - use '-nowf' to disable wireframing completely.\n");		rfbLog("   - use '-nowcr' to disable the Copy Rectangle after "		    "the\n");		rfbLog("     moved window is released in the new position.\n");		rfbLog("  Also see the -help entry for tuning parameters.\n");		rfbLog("  You can press 3 Alt_L's (Left \"Alt\" key) in a row"		    " to \n");		rfbLog("  repaint the screen, also see the -fixscreen option"		    " for\n");		rfbLog("  periodic repaints.\n");		if (scale_str && !strstr(scale_str, "nocr")) {			rfbLog("  Note: '-scale' is on and this can cause "			    "more problems.\n");		}	}	overlay_present = 0;#ifdef SOLARIS_OVERLAY	if (! XQueryExtension(dpy, "SUN_OVL", &maj, &ev, &er)) {		if (! quiet && overlay) {			rfbLog("Disabling -overlay: SUN_OVL "			    "extension not available.\n");		}	} else {		overlay_present = 1;	}#endif#ifdef IRIX_OVERLAY	if (! XReadDisplayQueryExtension(dpy, &ev, &er)) {		if (! quiet && overlay) {			rfbLog("Disabling -overlay: IRIX ReadDisplay "			    "extension not available.\n");		}	} else {		overlay_present = 1;	}#endif	if (overlay && !overlay_present) {		overlay = 0;		overlay_cursor = 0;	}	/* cursor shapes setup */	if (! multiple_cursors_mode) {		multiple_cursors_mode = strdup("default");	}	if (show_cursor) {		if(!strcmp(multiple_cursors_mode, "default")		    && xfixes_present && use_xfixes) {			free(multiple_cursors_mode);			multiple_cursors_mode = strdup("most");			if (! quiet) {				rfbLog("XFIXES available on display, resetting"				    " cursor mode\n");				rfbLog("  to: '-cursor most'.\n");				rfbLog("  to disable this behavior use: "				    "'-cursor arrow'\n");				rfbLog("  or '-noxfixes'.\n");			}		}		if(!strcmp(multiple_cursors_mode, "most")) {			if (xfixes_present && use_xfixes &&			    overlay_cursor == 1) {				if (! quiet) {					rfbLog("using XFIXES for cursor "					    "drawing.\n");				}				overlay_cursor = 0;			}		}	}	if (overlay) {		using_shm = 0;		if (flash_cmap && ! quiet) {			rfbLog("warning: -flashcmap may be "			    "incompatible with -overlay\n");		}		if (show_cursor && overlay_cursor) {			char *s = multiple_cursors_mode;			if (*s == 'X' || !strcmp(s, "some") ||			    !strcmp(s, "arrow")) {				/*				 * user wants these modes, so disable fb cursor				 */				overlay_cursor = 0;			} else {				/*				 * "default" and "most", we turn off				 * show_cursor since it will automatically				 * be in the framebuffer.				 */				show_cursor = 0;			}		}	}	initialize_cursors_mode();	/* check for XTEST */	if (! XTestQueryExtension_wr(dpy, &ev, &er, &maj, &min)) {		if (! quiet) {			rfbLog("WARNING: XTEST extension not available "			    "(either missing from\n");			rfbLog("  display or client library libXtst "			    "missing at build time).\n");			rfbLog("  MOST user input (pointer and keyboard) "			    "will be DISCARDED.\n");			rfbLog("  If display does have XTEST, be sure to "			    "build x11vnc with\n");			rfbLog("  a working libXtst build environment "			    "(e.g. libxtst-dev,\n");			rfbLog("  or other packages).\n");			rfbLog("No XTEST extension, switching to "			    "-xwarppointer mode for\n");			rfbLog("  pointer motion input.\n");		}		xtest_present = 0;		use_xwarppointer = 1;	} else {		xtest_present = 1;		xtest_base_event_type = ev;		if (maj <= 1 || (maj == 2 && min <= 2)) {			/* no events defined as of 2.2 */			xtest_base_event_type = 0;		}	}	if (! XETrapQueryExtension_wr(dpy, &ev, &er, &maj)) {		xtrap_present = 0;	} else {		xtrap_present = 1;		xtrap_base_event_type = ev;	}	/*	 * Window managers will often grab the display during resize,	 * etc, using XGrabServer().  To avoid deadlock (our user resize	 * input is not processed) we tell the server to process our	 * requests during all grabs:	 */	disable_grabserver(dpy, 0);	/* check for RECORD */	if (! XRecordQueryVersion_wr(dpy, &maj, &min)) {		xrecord_present = 0;	} else {		xrecord_present = 1;	}	initialize_xrecord();	tmpi = 1;	if (scroll_copyrect) {		if (strstr(scroll_copyrect, "never")) {			tmpi = 0;		}	} else if (scroll_copyrect_default) {		if (strstr(scroll_copyrect_default, "never")) {			tmpi = 0;		}	}	if (! xrecord_present) {		tmpi = 0;	}#if !LIBVNCSERVER_HAVE_RECORD	tmpi = 0;#endif	if (! quiet && tmpi) {		rfbLog("Scroll Detection: -scrollcopyrect mode is in effect "		    "to\n");		rfbLog("  use RECORD extension to try to detect scrolling "		    "windows\n");		rfbLog("  (induced by either user keystroke or mouse input).\n");		rfbLog("  If this yields undesired behavior (poor response, "		    "painting\n");		rfbLog("  errors, etc) it may be disabled via: '-noscr'\n");		rfbLog("  Also see the -help entry for tuning parameters.\n");		rfbLog("  You can press 3 Alt_L's (Left \"Alt\" key) in a row"		    " to \n");		rfbLog("  repaint the screen, also see the -fixscreen option"		    " for\n");		rfbLog("  periodic repaints.\n");		if (scale_str && !strstr(scale_str, "nocr")) {			rfbLog("  Note: '-scale' is on and this can cause "			    "more problems.\n");		}	}	/* check for OS with small shm limits */	if (using_shm && ! single_copytile) {		if (limit_shm()) {			single_copytile = 1;		}	}	single_copytile_orig = single_copytile;	/* check for MIT-SHM */	if (! XShmQueryExtension_wr(dpy)) {		xshm_present = 0;		if (! using_shm) {			if (! quiet) {				rfbLog("info: display does not support"				    " XShm.\n");			}		} else {		    if (! quiet) {			rfbLog("warning: XShm extension is not available.\n");			rfbLog("For best performance the X Display should be"			    " local. (i.e.\n");			rfbLog("the x11vnc and X server processes should be"			    " running on\n");			rfbLog("the same machine.)\n");#if LIBVNCSERVER_HAVE_XSHM			rfbLog("Restart with -noshm to override this.\n");		    }		    exit(1);#else			rfbLog("Switching to -noshm mode.\n");		    }		    using_shm = 0;#endif		}	}#if LIBVNCSERVER_HAVE_XKEYBOARD	/* check for XKEYBOARD */	initialize_xkb();	initialize_watch_bell();	if (!xkb_present && use_xkb_modtweak) {		if (! quiet) {			rfbLog("warning: disabling xkb modtweak."			    " XKEYBOARD ext. not present.\n");		}		use_xkb_modtweak = 0;	}#endif	if (xkb_present && !use_xkb_modtweak && !got_noxkb) {		if (use_modifier_tweak) {			switch_to_xkb_if_better();		}	}#if LIBVNCSERVER_HAVE_LIBXRANDR	if (! XRRQueryExtension(dpy, &xrandr_base_event_type, &er)) {		if (xrandr && ! quiet) {			rfbLog("Disabling -xrandr mode: display does not"			    " support X RANDR.\n");		}		xrandr_base_event_type = 0;		xrandr = 0;		xrandr_present = 0;	} else {		xrandr_present = 1;	}#endif	if (! quiet) {		rfbLog("--------------------------------------------------------\n");		rfbLog("\n");	}	raw_fb_pass_go_and_collect_200_dollars:	if (! dt) {		static char str[] = "-desktop";		argv_vnc[argc_vnc++] = str;		argv_vnc[argc_vnc++] = choose_title(use_dpy);		rfb_desktop_name = strdup(argv_vnc[argc_vnc-1]);	}		initialize_pipeinput();	/*	 * Create the XImage corresponding to the display framebuffer.	 */	fb0 = initialize_xdisplay_fb();	/*	 * n.b. we do not have to X_LOCK any X11 calls until watch_loop()	 * is called since we are single-threaded until then.	 */	initialize_screen(&argc_vnc, argv_vnc, fb0);	if (try_http && ! got_httpdir && check_httpdir()) {		http_connections(1);	}	initialize_tiles();	/* rectangular blackout regions */	initialize_blackouts_and_xinerama();	/* created shm or XImages when using_shm = 0 */	initialize_polling_images();	initialize_signals();	initialize_speeds();	initialize_keyboard_and_pointer();	initialize_allowed_input();	if (! inetd) {		if (! screen->port || screen->listenSock < 0) {			rfbLogEnable(1);			rfbLog("Error: could not obtain listening port.\n");			clean_up_exit(1);		}	}	if (! quiet) {		rfbLog("screen setup finished.\n");		if (!got_passwd && !got_rfbauth && !got_passwdfile && !nopw) {			rfbLog("\n");			rfbLog("WARNING: You are running x11vnc WITHOUT"			    " a password.  See\n");			rfbLog("WARNING: the warning message printed above"			    " for more info.\n");		}	}	set_vnc_desktop_name();#if LIBVNCSERVER_HAVE_FORK && LIBVNCSERVER_HAVE_SETSID	if (bg) {		/* fork into the background now */		int p, n;		if ((p = fork()) > 0)  {			exit(0);		} else if (p == -1) {			rfbLogEnable(1);			fprintf(stderr, "could not fork\n");			perror("fork");			clean_up_exit(1);		}		if (setsid() == -1) {			rfbLogEnable(1);			fprintf(stderr, "setsid failed\n");			perror("setsid");			clean_up_exit(1);		}		/* adjust our stdio */		n = open("/dev/null", O_RDONLY);		dup2(n, 0);		dup2(n, 1);		if (! logfile) {			dup2(n, 2);		}		if (n > 2) {			close(n);		}	}#endif	watch_loop();	return(0);#undef argc#undef argv}