void CRecognizerViewImpl::HandleForegroundEventL(TBool aForeground) { CALLSTACKITEM_N(_CL("CRecognizerViewImpl"), _CL("HandleForegroundEventL")); Reporting().DebugLog(_L("CRecognizerViewImpl::HandleForegroundEventL")); if (aForeground) { StartDisplay(); } else { StopDisplay(); } }
static void CheckDisplayStatus (struct display *d) { switch (d->state) { case MissingEntry: StopDisplay (d); break; case NewEntry: d->state = OldEntry; case OldEntry: if (d->status == notRunning) StartDisplay (d); break; } }
void WaitForChild(void) { int pid; struct display *d; waitType status; sigset_t mask, omask; sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGHUP); sigprocmask(SIG_BLOCK, &mask, &omask); WDMDebug("signals blocked\n"); if (!ChildReady && !Rescan) sigsuspend(&omask); ChildReady = 0; sigprocmask(SIG_SETMASK, &omask, (sigset_t *) NULL); while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { WDMDebug("Manager wait returns pid: %d sig %d core %d code %d\n", pid, waitSig(status), waitCore(status), waitCode(status)); if (autoRescan.i) RescanIfMod(); /* SUPPRESS 560 */ if ((d = FindDisplayByPid(pid))) { d->pid = -1; switch (waitVal(status)) { case UNMANAGE_DISPLAY: WDMDebug("Display exited with UNMANAGE_DISPLAY\n"); StopDisplay(d); break; case OBEYSESS_DISPLAY: d->startTries = 0; WDMDebug("Display exited with OBEYSESS_DISPLAY\n"); if (d->displayType.lifetime != Permanent || d->status == zombie) StopDisplay(d); else RestartDisplay(d, FALSE); break; default: WDMDebug("Display exited with unknown status %d\n", waitVal(status)); WDMError("Unknown session exit code %d from process %d\n", waitVal(status), pid); StopDisplay(d); break; case OPENFAILED_DISPLAY: WDMDebug("Display exited with OPENFAILED_DISPLAY, try %d of %d\n", d->startTries, d->startAttempts); WDMError("Display %s cannot be opened\n", d->name); /* * no display connection was ever made, tell the * terminal that the open attempt failed */ #ifdef XDMCP if (d->displayType.origin == FromXDMCP) SendFailed(d, "Cannot open display"); #endif if (d->displayType.origin == FromXDMCP || d->status == zombie || ++d->startTries >= d->startAttempts) { WDMError("Display %s is being disabled\n", d->name); StopDisplay(d); } else { RestartDisplay(d, TRUE); } break; case RESERVER_DISPLAY: d->startTries = 0; WDMDebug("Display exited with RESERVER_DISPLAY\n"); if (d->displayType.origin == FromXDMCP || d->status == zombie) StopDisplay(d); else RestartDisplay(d, TRUE); { Time_t Time; time(&Time); WDMDebug("time %i %i\n", (int)Time, (int)d->lastCrash); if (d->lastCrash && ((Time - d->lastCrash) < XDM_BROKEN_INTERVAL)) { WDMDebug("Server crash frequency too high:" " removing display %s\n", d->name); WDMError("Server crash rate too high:" " removing display %s\n", d->name); RemoveDisplay(d); } else d->lastCrash = Time; } break; case waitCompose(SIGTERM, 0, 0): WDMDebug("Display exited on SIGTERM, try %d of %d\n", d->startTries, d->startAttempts); if (d->displayType.origin == FromXDMCP || d->status == zombie || ++d->startTries >= d->startAttempts) { WDMError("Display %s is being disabled\n", d->name); StopDisplay(d); } else RestartDisplay(d, TRUE); break; case REMANAGE_DISPLAY: d->startTries = 0; WDMDebug("Display exited with REMANAGE_DISPLAY\n"); /* * XDMCP will restart the session if the display * requests it */ if (d->displayType.origin == FromXDMCP || d->status == zombie) StopDisplay(d); else RestartDisplay(d, FALSE); break; } } /* SUPPRESS 560 */ else if ((d = FindDisplayByServerPid(pid))) { d->serverPid = -1; switch (d->status) { case zombie: WDMDebug("Zombie server reaped, removing display %s\n", d->name); RemoveDisplay(d); break; case phoenix: WDMDebug("Phoenix server arises, restarting display %s\n", d->name); d->status = notRunning; break; case running: WDMDebug("Server for display %s terminated unexpectedly, status %d %d\n", d->name, waitVal(status), status); WDMError("Server for display %s terminated unexpectedly: %d\n", d->name, waitVal(status)); d->status = notRunning; if (d->pid != -1) { WDMDebug("Terminating session pid %d\n", d->pid); TerminateProcess(d->pid, SIGTERM); } break; case notRunning: WDMDebug("Server exited for notRunning session on display %s\n", d->name); break; } } else { WDMDebug("Unknown child termination, status %d\n", waitVal(status)); } } StartDisplays(); }
static void processDPipe( struct display *d ) { char *user, *pass, *args; int cmd; GTalk dpytalk; #ifdef XDMCP int ct, len; ARRAY8 ca, ha; #endif dpytalk.pipe = &d->pipe; if (Setjmp( dpytalk.errjmp )) { StopDisplay( d ); return; } GSet( &dpytalk ); if (!GRecvCmd( &cmd )) { /* process already exited */ UnregisterInput( d->pipe.rfd ); return; } switch (cmd) { case D_User: d->userSess = GRecvInt(); d->userName = GRecvStr(); d->sessName = GRecvStr(); break; case D_ReLogin: user = GRecvStr(); pass = GRecvStr(); args = GRecvStr(); setNLogin( d, user, pass, args, 1 ); free( args ); free( pass ); free( user ); break; #ifdef XDMCP case D_ChooseHost: ca.data = (unsigned char *)GRecvArr( &len ); ca.length = (CARD16)len; ct = GRecvInt(); ha.data = (unsigned char *)GRecvArr( &len ); ha.length = (CARD16)len; RegisterIndirectChoice( &ca, ct, &ha ); XdmcpDisposeARRAY8( &ha ); XdmcpDisposeARRAY8( &ca ); break; case D_RemoteHost: if (d->remoteHost) free( d->remoteHost ); d->remoteHost = GRecvStr(); break; #endif case D_XConnOk: startingServer = 0; break; default: LogError( "Internal error: unknown D_* command %d\n", cmd ); StopDisplay( d ); break; } }
static void StopInactiveDisplay( struct display *d ) { if (d->status != remoteLogin && d->userSess < 0) StopDisplay( d ); }
void WaitForChild (void) { pid_t pid; struct display *d; waitType status; sigset_t mask, omask; sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGHUP); sigprocmask(SIG_BLOCK, &mask, &omask); Debug ("signals blocked\n"); if (!ChildReady && !Rescan) sigsuspend(&omask); ChildReady = 0; sigprocmask(SIG_SETMASK, &omask, (sigset_t *)NULL); while ((pid = waitpid (-1, &status, WNOHANG)) > 0) { Debug ("Manager wait returns pid: %d sig %d core %d code %d\n", pid, waitSig(status), waitCore(status), waitCode(status)); if (autoRescan) RescanIfMod (); /* SUPPRESS 560 */ if ((d = FindDisplayByPid (pid))) { d->pid = -1; switch (waitVal (status)) { case UNMANAGE_DISPLAY: Debug ("Display exited with UNMANAGE_DISPLAY\n"); StopDisplay (d); break; case OBEYSESS_DISPLAY: d->startTries = 0; d->reservTries = 0; Debug ("Display exited with OBEYSESS_DISPLAY\n"); if (d->status == zombie) StopDisplay (d); else RestartDisplay (d, FALSE); break; case OPENFAILED_DISPLAY: Debug ("Display exited with OPENFAILED_DISPLAY, try %d of %d\n", d->startTries, d->startAttempts); LogError ("Display %s cannot be opened\n", d->name); /* * no display connection was ever made, tell the * terminal that the open attempt failed */ if (d->status == zombie || ++d->startTries >= d->startAttempts) { LogError ("Display %s is being disabled\n", d->name); StopDisplay (d); } else { RestartDisplay (d, TRUE); } break; case RESERVER_DISPLAY: d->startTries = 0; Debug ("Display exited with RESERVER_DISPLAY\n"); if (d->status == zombie) StopDisplay(d); else { Time_t now; int crash; time(&now); crash = d->lastReserv && ((now - d->lastReserv) < XDM_BROKEN_INTERVAL); Debug("time %lli %lli try %i of %i%s\n", (long long)now, (long long)d->lastReserv, d->reservTries, d->reservAttempts, crash ? " crash" : ""); if (!crash) d->reservTries = 0; if (crash && ++d->reservTries >= d->reservAttempts) { const char *msg = "Server crash frequency too high: stopping display"; Debug("%s %s\n", msg, d->name); LogError("%s %s\n", msg, d->name); /* For a local X server either: * 1. The server exit was returned by waitpid(). So * serverPid==-1 => StopDisplay() calls RemoveDisplay() * * 2. The server is in zombie state or still running. So * serverPid>1 => StopDisplay() * a. sets status=zombie, * b. kills the server. * The next waitpid() returns this zombie server pid * and the 'case zombie:' below then calls * RemoveDisplay(). */ StopDisplay(d); } else { RestartDisplay(d, TRUE); } d->lastReserv = now; } break; case waitCompose (SIGTERM,0,0): Debug ("Display exited on SIGTERM, try %d of %d\n", d->startTries, d->startAttempts); if (d->status == zombie || ++d->startTries >= d->startAttempts) { /* * During normal xdm shutdown, killed local X servers * can be zombies; this is not an error. */ if (d->status == zombie && (d->startTries < d->startAttempts)) LogInfo ("display %s is being disabled\n", d->name); else LogError ("display %s is being disabled\n", d->name); StopDisplay(d); } else RestartDisplay (d, TRUE); break; case REMANAGE_DISPLAY: d->startTries = 0; Debug ("Display exited with REMANAGE_DISPLAY\n"); /* * XDMCP will restart the session if the display * requests it */ if (d->status == zombie) StopDisplay(d); else RestartDisplay (d, FALSE); break; default: Debug ("Display exited with unknown status %d\n", waitVal(status)); LogError ("Unknown session exit code %d from process %d\n", waitVal (status), pid); StopDisplay (d); break; } } /* SUPPRESS 560 */ else if ((d = FindDisplayByServerPid (pid))) { d->serverPid = -1; switch (d->status) { case zombie: Debug ("Zombie server reaped, removing display %s\n", d->name); RemoveDisplay (d); break; case phoenix: Debug ("Phoenix server arises, restarting display %s\n", d->name); d->status = notRunning; break; case running: Debug ("Server for display %s terminated unexpectedly, status %d %d\n", d->name, waitVal (status), status); LogError ("Server for display %s terminated unexpectedly: %d\n", d->name, waitVal (status)); if (d->pid != -1) { Debug ("Terminating session pid %d\n", d->pid); kill (d->pid, SIGTERM); } break; case notRunning: Debug ("Server exited for notRunning session on display %s\n", d->name); break; } } else { Debug ("Unknown child termination, status %d\n", waitVal (status)); } } StartDisplays (); }
static void manage(struct sockaddr *from, int fromlen, int length, int fd) { CARD32 sessionID; CARD16 displayNumber; ARRAY8 displayClass; int expectlen; struct protoDisplay *pdpy; struct display *d; char *name = NULL; char *class2 = NULL; XdmcpNetaddr from_save; ARRAY8 clientAddress, clientPort; CARD16 connectionType; Debug("<manage> %d\n", length); displayClass.data = 0; displayClass.length = 0; if(XdmcpReadCARD32(&buffer, &sessionID) && XdmcpReadCARD16(&buffer, &displayNumber) && XdmcpReadARRAY8(&buffer, &displayClass)) { expectlen = 4 + /* session ID */ 2 + /* displayNumber */ 2 + displayClass.length; /* displayClass */ if(expectlen != length) { Debug("<manage> length error got %d expect %d\n", length, expectlen); goto abort; } pdpy = FindProtoDisplay((XdmcpNetaddr)from, fromlen, displayNumber); Debug("<manage> session ID %ld, pdpy %p\n", (long)sessionID, pdpy); if(!pdpy || pdpy->sessionID != sessionID) { /* * We may have already started a session for this display * but it hasn't seen the response in the form of an * XOpenDisplay() yet. So check if it is in the list of active * displays, and if so check that the session id's match. * If all this is true, then we have a duplicate request that * can be ignored. */ if(!pdpy && (d = FindDisplayByAddress((XdmcpNetaddr)from, fromlen, displayNumber)) && d->sessionID == sessionID) { Debug("manage: got duplicate pkt, ignoring\n"); goto abort; } Debug("session ID %ld refused\n", (long)sessionID); if(pdpy) Debug("existing session ID %ld\n", (long)pdpy->sessionID); send_refuse(from, fromlen, sessionID, fd); } else { name = NetworkAddressToName(pdpy->connectionType, &pdpy->connectionAddress, from, pdpy->displayNumber); if(!name) { Debug("could not compute display name\n"); send_failed(from, fromlen, "(no name)", sessionID, "out of memory", fd); goto abort; } Debug("computed display name: %s\n", name); if((d = FindDisplayByName(name))) { Debug("terminating active session for %s\n", d->name); StopDisplay(d); } if(displayClass.length) { if(!StrNDup(&class2, (char *)displayClass.data, displayClass.length)) { send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } } if(!(from_save = (XdmcpNetaddr)Malloc(fromlen))) { send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } memmove(from_save, from, fromlen); if(!(d = NewDisplay(name))) { free((char *)from_save); send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } d->class2 = class2; class2 = 0; d->displayType = dForeign | dTransient | dFromXDMCP; d->sessionID = pdpy->sessionID; d->from.data = (unsigned char *)from_save; d->from.length = fromlen; d->displayNumber = pdpy->displayNumber; ClientAddress(from, &clientAddress, &clientPort, &connectionType); d->useChooser = 0; d->xdmcpFd = fd; if(IsIndirectClient(&clientAddress, connectionType)) { Debug("IsIndirectClient\n"); ForgetIndirectClient(&clientAddress, connectionType); if(UseChooser(&clientAddress, connectionType)) { d->useChooser = 1; Debug("use chooser for %s\n", d->name); } } d->clientAddr = clientAddress; d->connectionType = connectionType; d->remoteHost = NetworkAddressToHostname(pdpy->connectionType, &pdpy->connectionAddress); XdmcpDisposeARRAY8(&clientPort); if(pdpy->fileAuthorization) { d->authorizations = (Xauth **)Malloc(sizeof(Xauth *)); if(!d->authorizations) { free((char *)from_save); free((char *)d); send_failed(from, fromlen, name, sessionID, "out of memory", fd); goto abort; } d->authorizations[0] = pdpy->fileAuthorization; d->authNum = 1; pdpy->fileAuthorization = 0; } DisposeProtoDisplay(pdpy); Debug("starting display %s,%s\n", d->name, d->class2); if(LoadDisplayResources(d) < 0) { LogError( "Unable to read configuration for display %s; " "stopping it.\n", d->name); StopDisplay(d); } else StartDisplay(d); CloseGetter(); } } abort: XdmcpDisposeARRAY8(&displayClass); if(name) free((char *)name); if(class2) free((char *)class2); }