/* * derived from sample code on the net from here: http://groups.google.co.in/group/comp.os.linux.x/browse_thread/thread/2166307a9473ffbe/6bd3c21d87c2d5f6?lnk=st&q=pid+and+window+id&rnum=12&hl=en#6bd3c21d87c2d5f6 * also found at: http://cvsweb.netbsd.org/bsdweb.cgi/xsrc/xc/test/appgroup/Attic/embedtest.c?rev=1.1.1 * * compile with: * cc -o xorgcrash xorgcrash.c -L/usr/X11R6/lib -lXau -lXext -lXt -lX11 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include XtAppContext xLac; XtIntervalId tout = 0; Widget shell; pid_t pid[4]; static void EH(Widget w, XtPointer clientdata, XEvent * event, Boolean * cont) { switch (event->type) { case MapRequest: XMapWindow(XtDisplay(w), event->xmaprequest.window); printf("0x%x\n", event->xmaprequest.window); fflush(stdout); XSelectInput(XtDisplay(w), event->xmaprequest.window, PropertyChangeMask|StructureNotifyMask); break; case ConfigureRequest: XResizeWindow(XtDisplay(w), event->xconfigurerequest.window, event->xconfigurerequest.width, event->xconfigurerequest.height); XtResizeWidget(w, event->xconfigurerequest.width, event->xconfigurerequest.height, 0); break; case DestroyNotify: default: break; } } void lastAction(void *x1, XtIntervalId *val) { int i; sleep(4); if (0 == fork()) for (i = 0; i < 4; i++) { sleep(1); kill(pid[i], 2); } exit(0); } void nextAction(void *x1, XtIntervalId *val) { XtDestroyWidget(shell); tout = XtAppAddTimeOut(xLac, 5000, lastAction, None); } void firstAction(void *x1, XtIntervalId *val) { kill(pid[0], 2); /* Tout = XtAppAddTimeOut(xLac, 5000, lastAction, None); */ lastAction(x1, val); } int main(int argc, char **argv) { Display * dpy; int i, major, minor; XAppGroup appgrp; Xauth * auth1; Xauth * auth2; struct utsname uts; FILE * file; XSecurityAuthorizationAttributes secattr; XSecurityAuthorization secid; char tmpfile[80], *c_argv[4]; pid_t ppid; shell = XtVaOpenApplication(&xLac, "Test", 0, 0, &argc, argv, 0, applicationShellWidgetClass, XtNgeometry, "100x100+100+100", XtNinput, True, 0); XtRealizeWidget(shell); XtAddRawEventHandler(shell, SubstructureRedirectMask, False, EH, 0); dpy = XtDisplay(shell); XagQueryVersion(dpy, &major, &minor); XSecurityQueryExtension(dpy, &major, &minor); XagCreateEmbeddedApplicationGroup(dpy, None, None, 0, 0, &appgrp); XtRegisterDrawable(dpy, appgrp, shell); auth1 = XSecurityAllocXauth(); auth1->family = FamilyWild; auth1->name = strdup("MIT-MAGIC-COOKIE-1"); auth1->name_length = strlen(auth1->name); auth1->data = 0; auth1->data_length = 0; secattr.timeout = 0; secattr.trust_level = XSecurityClientTrusted; secattr.group = appgrp; uname(&uts); auth2 = XSecurityGenerateAuthorization(dpy, auth1, XSecurityTimeout|XSecurityTrustLevel|XSecurityGroup, &secattr, &secid); auth2->family = FamilyLocal; auth2->address = strdup(uts.nodename); auth2->address_length = strlen(auth2->address); auth2->number = "0"; auth2->number_length = strlen(auth2->number); sprintf(tmpfile, "/tmp/secfile.%d", ppid = getpid()); if (NULL == (file = fopen(tmpfile, "w"))) { fprintf(stderr, "cannot open auth file '%s'\n", tmpfile); exit(1); } XauWriteAuth(file, auth2); fclose(file); XSecurityFreeXauth(auth1); XSecurityFreeXauth(auth2); c_argv[0] = "xterm"; c_argv[1] = "-e"; c_argv[2] = "xterm"; c_argv[3] = NULL; for (i = 0; i < 4; i++) { if (0 == (pid[i] = fork())) { sprintf(tmpfile, "XAUTHORITY=/tmp/secfile.%d", ppid); putenv(tmpfile); execvp(c_argv[0], c_argv); exit(ENOENT); } } /* wait 5 secs to stabilize */ tout = XtAppAddTimeOut(xLac, 5000, firstAction, None); for ( ; FALSE == XtAppGetExitFlag(xLac); ) { XEvent event; XtAppNextEvent(xLac, &event); if (MapNotify == event.type || DestroyNotify == event.type) EH(shell, None, &event, None); XtDispatchEvent(&event); } return 0; }