sprintf(pid, "%d", (int) getpid()); set_env("X11VNC_PID", pid); if (program_name) {  set_env("X11VNC_PROG", program_name); } if (program_cmdline) { set_env("X11VNC_CMDLINE", program_cmdline); } if (raw_fb_str) { set_env("X11VNC_RAWFB_STR", raw_fb_str); }
set_child_info();
void initialize_pipeinput(void) {	char *p;	char pid[16];	if (pipeinput_fh != NULL) {		rfbLog("closing pipeinput stream: %p\n", pipeinput_fh);		pclose(pipeinput_fh);		pipeinput_fh = NULL;	}	pipeinput_tee = 0;	if (pipeinput_opts) {		free(pipeinput_opts);		pipeinput_opts = NULL;	}	if (! pipeinput_str) {		return;	}	/* look for options:  tee, reopen, ... */	p = strchr(pipeinput_str, ':');	if (p != NULL) {		char *str, *opt, *q;		int got = 0;		*p = '\0';		str = strdup(pipeinput_str);		opt = strdup(pipeinput_str);		*p = ':';		q = strtok(str, ",");		while (q) {			if (!strcmp(q, "key") || !strcmp(q, "keycodes")) {				got = 1;			}			if (!strcmp(q, "reopen")) {				got = 1;			}			if (!strcmp(q, "tee")) {				pipeinput_tee = 1;				got = 1;			}			q = strtok(NULL, ",");		}		if (got) {			pipeinput_opts = opt;		} else {			free(opt);		}		free(str);		p++;	} else {		p = pipeinput_str;	}	/* set up useful environment for child process */	sprintf(pid, "%d", (int) getpid());	set_env("X11VNC_PID", pid);	if (program_name) {		/* e.g. for remote control -R */		set_env("X11VNC_PROG", program_name);	}	if (program_cmdline) {		set_env("X11VNC_CMDLINE", program_cmdline);	}	if (raw_fb_str) {		set_env("X11VNC_RAWFB_STR", raw_fb_str);	}	rfbLog("pipeinput: starting: \"%s\"...\n", p);	pipeinput_fh = popen(p, "w");	if (! pipeinput_fh) {		rfbLog("popen(\"%s\", \"w\") failed.\n", p);		rfbLogPerror("popen");		rfbLog("Disabling -pipeinput mode.\n");		return;	}	fprintf(pipeinput_fh, "%s","# \n""# Format of the -pipeinput stream:\n""# --------------------------------\n""#\n""# Lines like these beginning with '#' are to be ignored.\n""#\n""# Pointer events (mouse motion and button clicks) come in the form:\n""#\n""#\n""# Pointer <client#> <x> <y> <mask> <hint>\n""#\n""#\n""# The <client#> is a decimal integer uniquely identifying the client\n""# that generated the event.  If it is negative that means this event\n""# would have been discarded since the client was viewonly.\n""#\n""# <x> and <y> are decimal integers reflecting the position on the screen\n""# the event took place at.\n""#\n""# <mask> is the button mask indicating the button press state, as normal\n""# 0 means no buttons pressed, 1 means button 1 is down 3 (11) means buttons\n""# 1 and 2 are down, etc.\n""#\n""# <hint> is a string containing no spaces and may be ignored.\n""# It contains some interpretation about what has happened.\n""# It can be:\n""#\n""#	None		(nothing to report)\n""#	ButtonPress-N	(this event will cause button-1 to be pressed) \n""#	ButtonRelease-N	(this event will cause button-1 to be released) \n""#\n""# if two more more buttons change state in one event they are listed\n""# separated by commas.\n""#\n""# One might parse a Pointer like with:\n""#\n""# int client, x, y, mask; char *hint;\n""# sscanf(line, \"Pointer %d %d %d %s\", &client, &x, &y, &mask, &hint);\n""#\n""#\n""# Keysym events (keyboard presses and releases) come in the form:\n""#\n""#\n""# Keysym <client#> <down> <keysym#> <keysym-name> <hint>\n""#\n""#\n""# The <client#> is as with Pointer.\n""#\n""# <down> is a decimal either 1 or 0 indicating KeyPress or KeyRelease,\n""# respectively.\n""#\n""# <keysym#> is a decimal integer incidating the Keysym of the event.\n""#\n""# <keysym-name> is the corresponding Keysym name.\n""#\n""# See the file /usr/include/X11/keysymdef.h for the mappings.\n""# You basically remove the leading 'XK_' prefix from the macro name in\n""# that file to get the Keysym name.\n""#\n""# One might parse a Pointer like with:\n""#\n""# int client, down, keysym; char *name, *hint;\n""# sscanf(line, \"Keysym %d %d %s %s\", &client, &down, &keysym, &name, &hint);\n""#\n""# The <hint> value is currently just None, KeyPress, or KeyRelease.\n""#\n""# In the future <hint> will provide a hint for the sequence of KeyCodes\n""# (i.e. keyboard scancodes) that x11vnc would inject to an X display to\n""# simulate the Keysym.\n""#\n""# You see, some Keysyms will require more than one injected Keycode to\n""# generate the symbol.  E.g. the Keysym \"ampersand\" going down usually\n""# requires a Shift key going down, then the key with the \"&\" on it going\n""# down, and, perhaps, the Shift key going up (that is how x11vnc does it).\n""#\n""# The Keysym => Keycode(s) stuff gets pretty messy.  Hopefully the Keysym\n""# info will be enough for most purposes (having identical keyboards on\n""# both sides helps).\n""#\n""# Here comes yours stream:\n""# END_OF_TOP\n");	fflush(pipeinput_fh);	if (raw_fb_str) {		/* the pipe program may actually create the fb */		sleep(1);	}}