rfbLogEnable(1);
static int run_user_command(char *cmd, rfbClientPtr client, char *mode) {	char *old_display = NULL;	char *addr = client->host;	char str[100];	int rc;	ClientData *cd = (ClientData *) client->clientData;	if (addr == NULL || addr[0] == '\0') {		addr = "unknown-host";	}	/* set RFB_CLIENT_ID to semi unique id for command to use */	if (cd && cd->uid) {		sprintf(str, "0x%x", cd->uid);	} else {		/* not accepted yet: */		sprintf(str, "0x%x", clients_served);	}	set_env("RFB_CLIENT_ID", str);	/* set RFB_CLIENT_IP to IP addr for command to use */	set_env("RFB_CLIENT_IP", addr);	/* set RFB_X11VNC_PID to our pid for command to use */	sprintf(str, "%d", (int) getpid());	set_env("RFB_X11VNC_PID", str);	/* set RFB_CLIENT_PORT to peer port for command to use */	if (cd && cd->client_port > 0) {		sprintf(str, "%d", cd->client_port);	} else {		sprintf(str, "%d", get_remote_port(client->sock));	}	set_env("RFB_CLIENT_PORT", str);	set_env("RFB_MODE", mode);	/* 	 * now do RFB_SERVER_IP and RFB_SERVER_PORT (i.e. us!)	 * This will establish a 5-tuple (including tcp) the external	 * program can potentially use to work out the virtual circuit	 * for this connection.	 */	if (cd && cd->server_ip) {		set_env("RFB_SERVER_IP", cd->server_ip);	} else {		char *sip = get_local_host(client->sock);		set_env("RFB_SERVER_IP", sip);		free(sip);	}	if (cd && cd->server_port > 0) {		sprintf(str, "%d", cd->server_port);	} else {		sprintf(str, "%d", get_local_port(client->sock));	}	set_env("RFB_SERVER_PORT", str);	/* 	 * Better set DISPLAY to the one we are polling, if they	 * want something trickier, they can handle on their own	 * via environment, etc. 	 */	if (getenv("DISPLAY")) {		old_display = strdup(getenv("DISPLAY"));	}	if (raw_fb && ! dpy) {	/* raw_fb hack */		set_env("DISPLAY", "rawfb");	} else {		set_env("DISPLAY", DisplayString(dpy));	}	/*	 * work out the number of clients (have to use client_count	 * since there is deadlock in rfbGetClientIterator) 	 */	sprintf(str, "%d", client_count);	set_env("RFB_CLIENT_COUNT", str);	if (no_external_cmds) {		rfbLog("cannot run external commands in -nocmds mode:\n");		rfbLog("   \"%s\"\n", cmd);		rfbLog("   exiting.\n");		clean_up_exit(1);	}	rfbLog("running command:\n");	rfbLog("  %s\n", cmd);	/* XXX need to close port 5900, etc.. */	rc = system(cmd);	if (rc >= 256) {		rc = rc/256;	}	rfbLog("command returned: %d\n", rc);	if (old_display) {		set_env("DISPLAY", old_display);		free(old_display);	}	return rc;}