示例#1
0
/*
 * Normal exiting
 */
void clean_up_exit (int ret) {
	static int depth = 0;
	exit_flag = 1;

	if (depth++ > 2) {
		exit(ret);
	}

	if (icon_mode) {
		clean_icon_mode();
	}

	/* remove the shm areas: */
	clean_shm(0);

	stop_stunnel();
	if (use_openssl) {
		ssl_helper_pid(0, 0);	/* killall */
	}

	if (! dpy) exit(ret);	/* raw_rb hack */

	/* X keyboard cleanups */
	delete_added_keycodes(0);

	if (clear_mods == 1) {
		clear_modifiers(0);
	} else if (clear_mods == 2) {
		clear_keys();
	}

	if (no_autorepeat) {
		autorepeat(1, 0);
	}
	if (use_solid_bg) {
		solid_bg(1);
	}
	X_LOCK;
	XTestDiscard_wr(dpy);
#if LIBVNCSERVER_HAVE_LIBXDAMAGE
	if (xdamage) {
		XDamageDestroy(dpy, xdamage);
	}
#endif
#if LIBVNCSERVER_HAVE_LIBXTRAP
	if (trap_ctx) {
		XEFreeTC(trap_ctx);
	}
#endif
	/* XXX rdpy_ctrl, etc. cannot close w/o blocking */
	XCloseDisplay_wr(dpy);
	X_UNLOCK;

	fflush(stderr);
	exit(ret);
}
示例#2
0
文件: xtrapproto.c 项目: aosm/X11
int
main(int argc, char *argv[])
{
    static Widget appW;
    XtAppContext app;
    char *tmp = NULL;
    XETrapGetAvailRep     ret_avail;
    XETrapGetCurRep       ret_cur;
    XETrapGetStatsRep     ret_stats;
    XETrapGetVersRep      ret_vers;
    XETrapGetLastInpTimeRep ret_time;
    XETC    *tc;
    Display *dpy;

    /* Connect to Server */
    appW = XtAppInitialize(&app,"XTrap",NULL,(Cardinal)0L,
        (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
        (Cardinal)NULL);
    dpy = XtDisplay(appW);
    printf("Display:  %s \n", DisplayString(dpy));
    if ((tc = XECreateTC(dpy,0L, NULL)) == False)
    {
        fprintf(stderr,"%s: could not initialize extension\n",argv[0]);
        exit(1L);
    }
    XSynchronize(dpy, True);
    XEResetRequest(tc);
    XEGetAvailableRequest(tc,&ret_avail);
    XEPrintAvail(stdout,&ret_avail);
    XEGetCurrentRequest(tc,&ret_cur);
    XEPrintCurrent(stderr,&ret_cur);
    XETrapSetStatistics(tc, True);  /* trigger config and def stats */
    XEFlushConfig(tc);
    XEGetStatisticsRequest(tc, &ret_stats);
    XEPrintStatistics(stdout, &ret_stats,tc);
    XEStartTrapRequest(tc);
    XESimulateXEventRequest(tc, MotionNotify, 0, 10L, 20L, 0L);
    XEStopTrapRequest(tc);
    if (tc->protocol == 31)
    {   /* didn't work in V3.1 */
        printf("XEGetVersionRequest() & XEGetLastInpTimeRequest() are\n");
        printf("broken using the V3.1 protocol!\n");
    }
    else
    {
        XEGetVersionRequest(tc,&ret_vers);
        XEGetLastInpTimeRequest(tc, &ret_time);
    }
    XEFreeTC(tc);
    (void)XCloseDisplay(dpy);
    exit(0L);
}
示例#3
0
/*
 * Normal exiting
 */
void clean_up_exit(int ret) {
	static int depth = 0;
	exit_flag = 1;

	if (depth++ > 2) {
		exit(ret);
	}

	if (icon_mode) {
		clean_icon_mode();
	}

	/* remove the shm areas: */
	clean_shm(0);

	stop_stunnel();
	if (use_openssl) {
		ssl_helper_pid(0, 0);	/* killall */
	}

	if (ssh_pid > 0) {
		kill(ssh_pid, SIGTERM);
		ssh_pid = 0;
	}

#ifdef MACOSX
	if (client_connect_file) {
		if (strstr(client_connect_file, "/tmp/x11vnc-macosx-remote")
		    == client_connect_file) {
			unlink(client_connect_file);
		}
	}
	if (macosx_console) {
		macosxCG_fini();
	}
#endif

	if (pipeinput_fh != NULL) {
		pclose(pipeinput_fh);
		pipeinput_fh = NULL;
	}


	shutdown_uinput();

	if (unix_sock) {
		if (unix_sock_fd >= 0) {
			rfbLog("deleting unix sock: %s\n", unix_sock);
			close(unix_sock_fd);
			unix_sock_fd = -1;
			unlink(unix_sock);
		}
	}

	if (! dpy) {	/* raw_rb hack */
		if (rm_flagfile) {
			unlink(rm_flagfile);
			rm_flagfile = NULL;
		}
		exit(ret);
	}

	/* X keyboard cleanups */
	delete_added_keycodes(0);

	if (clear_mods == 1) {
		clear_modifiers(0);
	} else if (clear_mods == 2) {
		clear_keys();
	} else if (clear_mods == 3) {
		clear_keys();
		clear_locks();
	}

	if (no_autorepeat) {
		autorepeat(1, 0);
	}
	if (use_solid_bg) {
		solid_bg(1);
	}
	if (ncache || ncache0) {
		kde_no_animate(1);
	}
	X_LOCK;
	XTestDiscard_wr(dpy);
#if LIBVNCSERVER_HAVE_LIBXDAMAGE
	if (xdamage) {
		XDamageDestroy(dpy, xdamage);
	}
#endif
#if LIBVNCSERVER_HAVE_LIBXTRAP
	if (trap_ctx) {
		XEFreeTC(trap_ctx);
	}
#endif
	/* XXX rdpy_ctrl, etc. cannot close w/o blocking */
	XCloseDisplay_wr(dpy);
	X_UNLOCK;

	fflush(stderr);

	if (rm_flagfile) {
		unlink(rm_flagfile);
		rm_flagfile = NULL;
	}

	if (avahi) {
		avahi_cleanup();
		fflush(stderr);
	}

	exit(ret);
}
示例#4
0
文件: xtrapout.c 项目: aosm/X11
int
main(int argc, char *argv[])
{
    XETrapGetAvailRep ret_avail;
    XETrapGetCurRep   ret_cur;
    XETC    *tc;
    ReqFlags     requests;
    EventFlags   events;
    XtAppContext app;
    char *tmp = NULL;
    INT16 ch;
    int *popterr;
    char **poptarg;
#ifndef vms
    popterr = &opterr;
    poptarg = &optarg;
#else
    popterr = XEgetopterr();
    poptarg = XEgetoptarg();
#endif

    eventFlag = False;
    ofp = NULL;
    *popterr = 0; /* don't complain about -d (display) */
    while ((ch = getopt(argc, argv, "d:evf:")) != EOF)
    {
        switch(ch)
        {
            case 'e':
                eventFlag = True;
                break;
            case 'v':
                verboseFlag = True;
                break;
            case 'f':
                if ((ofp = fopen(*poptarg,"wb")) == NULL)
                {   /* can't open it */
                    fprintf(stderr,"%s: could not open output file '%s'!\n",
                        ProgName, *poptarg);
                }
                break;
            case 'd':   /* -display, let's let the toolkit parse it */
                break;
            default:
                break;
        }
    }
    ofp = (ofp ? ofp : stdout);

    appW = XtAppInitialize(&app,"XTrap",optionTable,(Cardinal)2L,
        (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
        (Cardinal)NULL);

    dpy = XtDisplay(appW);
#ifdef DEBUG
    XSynchronize(dpy, True);
#endif
    fprintf(stderr,"Display:  %s \n", DisplayString(dpy));
    if ((tc = XECreateTC(dpy,0L, NULL)) == False)
    {
        fprintf(stderr,"%s: could not initialize XTrap extension\n",ProgName);
        exit (1L);
    }
    XETrapSetTimestamps(tc,True, False);
    (void)XEGetAvailableRequest(tc,&ret_avail);
    XEPrintAvail(stderr,&ret_avail);
    XEPrintTkFlags(stderr,tc);

    /* Need to prime events/requests initially turning all off  */
    (void)memset(requests,0L,sizeof(requests));
    (void)memset(events,0L,sizeof(events));
    /* Now turn on the ones you really want */
    (void)memset(events,0xFFL,XETrapMaxEvent);
    if (eventFlag == False)
    {   /* doesn't want just events */
        (void)memset(requests,0xFFL,XETrapMaxRequest);
        /* Turn off XTrap Requests for multi-client regression tests & XLib */
        BitFalse(requests, XETrapGetExtOpcode(tc));
        /* Turn off noisy events */
        BitFalse(events, MotionNotify);
    }
    if (verboseFlag == True)
    {   /* want's *all* requests/events */
        (void)memset(requests,0xFFL,XETrapMaxRequest);
        (void)memset(events,0xFFL,XETrapMaxEvent);
    }
    /* Tell the TC about it */
    XETrapSetRequests(tc, True, requests);
    XETrapSetEvents(tc, True, events);
    XETrapSetMaxPacket(tc, True, XETrapMinPktSize); /* just get the minimum */
    
    /* Set up callbacks for data */
    XEAddRequestCBs(tc, requests, print_req_callback, NULL);
    XEAddEventCBs(tc, events, print_evt_callback, NULL);

    (void)XEStartTrapRequest(tc);
    (void)XEGetCurrentRequest(tc,&ret_cur);
    XEPrintCurrent(stderr,&ret_cur);

    /* Add signal handlers so that we clean up properly */
    _InitExceptionHandling((void_function)SetGlobalDone);
    (void)XEEnableCtrlKeys((void_function)SetGlobalDone);
             
    XETrapAppWhileLoop(app,tc,&GlobalDone);

    /* Make sure <CTRL> key is released */
    XESimulateXEventRequest(tc, KeyRelease, 
        XKeysymToKeycode(dpy, XK_Control_L), 0L, 0L, 0L);

    /* close down everything nicely */
    XEFreeTC(tc);
    (void)XCloseDisplay(dpy);
    (void)XEClearCtrlKeys();
    _ClearExceptionHandling();
    exit(0L);
}
示例#5
0
文件: xtrapstats.c 项目: aosm/X11
int
main(int argc, char *argv[])
{
    XETrapGetAvailRep     ret_avail;
    XETrapGetStatsRep     ret_stats;
    Widget  appW;
    XtAppContext app;
    char *tmp = NULL;
    XETC    *tc;
    Display *dpy;
    Bool done;
    char    buffer[10];
    ReqFlags   requests;
    EventFlags events;
    int i;

    /* Connect to Server */
    appW = XtAppInitialize(&app,"XTrap",NULL,(Cardinal)0L,
        (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
        (Cardinal)NULL);
    dpy = XtDisplay(appW);
#ifdef DEBUG
    XSynchronize(dpy, True);
#endif
    printf("Display:  %s \n", DisplayString(dpy));
    if ((tc = XECreateTC(dpy,0L, NULL)) == False)
    {
        fprintf(stderr,"%s: could not initialize extension\n",argv[0]);
        exit(1L);
    }

    (void)XEGetAvailableRequest(tc,&ret_avail);
    if (BitIsFalse(ret_avail.valid, XETrapStatistics))
    {
        printf("\nStatistics not available from '%s'.\n",
            DisplayString(dpy));
        exit(1L);
    }
    XETrapSetStatistics(tc, True);
    for (i=0; i<256L; i++)
    {
        BitTrue(requests, i);
    }
    XETrapSetRequests(tc, True, requests);
    for (i=KeyPress; i<=MotionNotify; i++)
    {
        BitTrue(events, i);
    }
    XETrapSetEvents(tc, True, events);
    done = False;
    while(done == False)
    {
        fprintf(stderr,"Stats Command (Zero, Quit, [Show])? ");
        fgets(buffer, sizeof(buffer), stdin);
        switch(toupper(buffer[0]))
        {
            case '\n':  /* Default command */
            case 'S':   /* Request fresh counters & display */
                (void)XEGetStatisticsRequest(tc,&ret_stats);
                (void)XEPrintStatistics(stdout,&ret_stats,tc);
                break;
            case 'Z':  /* Zero out counters */
                XETrapSetStatistics(tc, False);
                break;
            case 'Q':
                done = True;
                break;
            default:
                printf("Invalid command, reenter!\n");
                break;
        }
    }
    (void)XEFreeTC(tc);
    (void)XCloseDisplay(dpy);
    exit(0L);
}