Index: trunk/app.h =================================================================== --- trunk/app.h (revision 151) +++ trunk/app.h (working copy) @@ -34,6 +34,7 @@ ~App(); void Run(); int GetServerPID(); + void RestartServer(); void StopServer(); // Lock functions @@ -48,7 +49,6 @@ void Console(); void Exit(); void KillAllClients(Bool top); - void RestartServer(); void ReadConfig(); void OpenLog(); void CloseLog(); Index: trunk/app.cpp =================================================================== --- trunk/app.cpp (revision 151) +++ trunk/app.cpp (working copy) @@ -100,6 +100,11 @@ extern App* LoginApp; +int xioerror(Display *disp) { + LoginApp->RestartServer(); + return 0; +} + void CatchSignal(int sig) { cerr << APPNAME << ": unexpected signal " << sig << endl; LoginApp->StopServer(); @@ -107,19 +112,6 @@ exit(ERR_EXIT); } - -void AlarmSignal(int sig) { - int pid = LoginApp->GetServerPID(); - if(waitpid(pid, NULL, WNOHANG) == pid) { - LoginApp->StopServer(); - LoginApp->RemoveLock(); - exit(OK_EXIT); - } - signal(sig, AlarmSignal); - alarm(2); -} - - void User1Signal(int sig) { signal(sig, User1Signal); } @@ -257,7 +249,6 @@ signal(SIGHUP, CatchSignal); signal(SIGPIPE, CatchSignal); signal(SIGUSR1, User1Signal); - signal(SIGALRM, AlarmSignal); #ifndef XNEST_DEBUG OpenLog(); @@ -277,7 +268,6 @@ CreateServerAuth(); StartServer(); - alarm(2); #endif } @@ -575,6 +565,8 @@ int status; while (wpid != pid) { wpid = wait(&status); + if (wpid == ServerPID) + xioerror(Dpy); // Server died, simulate IO error } if (WIFEXITED(status) && WEXITSTATUS(status)) { LoginPanel->Message("Failed to execute login command"); @@ -620,9 +612,6 @@ void App::Reboot() { - // Stop alarm clock - alarm(0); - #ifdef USE_PAM try{ pam.end(); @@ -645,9 +634,6 @@ void App::Halt() { - // Stop alarm clock - alarm(0); - #ifdef USE_PAM try{ pam.end(); @@ -733,6 +719,7 @@ StopServer(); RemoveLock(); + while (waitpid(-1, NULL, WNOHANG) > 0); // Collects all dead childrens Run(); } @@ -803,6 +790,7 @@ for(cycles = 0; cycles < ncycles; cycles++) { if((Dpy = XOpenDisplay(DisplayName))) { + XSetIOErrorHandler(xioerror); return 1; } else { if(!ServerTimeout(1, "X server to begin accepting connections")) @@ -885,9 +873,6 @@ ServerPID = -1; break; } - alarm(15); - pause(); - alarm(0); // Wait for server to start up if(WaitForServer() == 0) { @@ -920,15 +905,12 @@ void App::StopServer() { - // Stop alars clock and ignore signals - alarm(0); signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGTERM, SIG_DFL); signal(SIGKILL, SIG_DFL); - signal(SIGALRM, SIG_DFL); // Catch X error XSetIOErrorHandler(IgnoreXIO);