aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-graphics/slim/slim/0008-restart-Xserver-if-killed.patch
blob: 0c5cfb742f1e05381b5565b822f18cab6208821b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
From ee77a3d154443d2823ecbf2141daa1b5924f629f Mon Sep 17 00:00:00 2001
From: iwamatsu <iwamatsu@7c53e7cc-98ea-0310-8f1f-a0b24da60408>
Date: Fri, 17 Jun 2011 20:38:34 +0000
Subject: [PATCH 8/8] restart Xserver if killed

Patch from http://developer.berlios.de/patch/?func=detailpatch&patch_id=2378&group_id=2663.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

git-svn-id: svn://svn.berlios.de/slim/trunk@182 7c53e7cc-98ea-0310-8f1f-a0b24da60408
---
 app.cpp |   36 +++++++++---------------------------
 app.h   |    2 +-
 2 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/app.cpp b/app.cpp
index 44ab099..358a98f 100644
--- a/app.cpp
+++ b/app.cpp
@@ -104,6 +104,11 @@ int conv(int num_msg, const struct pam_message **msg,
 
 extern App* LoginApp;
 
+int xioerror(Display *disp) {
+	LoginApp->RestartServer();
+    return 0;
+}
+
 void CatchSignal(int sig) {
     cerr << APPNAME << ": unexpected signal " << sig << endl;
 
@@ -114,19 +119,6 @@ void CatchSignal(int sig) {
     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);
 }
@@ -275,7 +267,6 @@ void App::Run() {
         signal(SIGHUP, CatchSignal);
         signal(SIGPIPE, CatchSignal);
         signal(SIGUSR1, User1Signal);
-        signal(SIGALRM, AlarmSignal);
 
 #ifndef XNEST_DEBUG
         if (!force_nodaemon && cfg->getOption("daemon") == "yes") {
@@ -297,7 +288,6 @@ void App::Run() {
 
         CreateServerAuth();
         StartServer();
-        alarm(2);
 #endif
 
     }
@@ -613,6 +603,8 @@ void App::Login() {
     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");
@@ -658,9 +650,6 @@ void App::Login() {
 
 
 void App::Reboot() {
-    // Stop alarm clock
-    alarm(0);
-
 #ifdef USE_PAM
     try{
         pam.end();
@@ -683,9 +672,6 @@ void App::Reboot() {
 
 
 void App::Halt() {
-    // Stop alarm clock
-    alarm(0);
-
 #ifdef USE_PAM
     try{
         pam.end();
@@ -771,6 +757,7 @@ void App::RestartServer() {
 
     StopServer(); 
     RemoveLock();
+	while (waitpid(-1, NULL, WNOHANG) > 0); // Collects all dead childrens
     Run();
 } 
 
@@ -841,6 +828,7 @@ int App::WaitForServer() {
 
     for(cycles = 0; cycles < ncycles; cycles++) {
         if((Dpy = XOpenDisplay(DisplayName))) {
+            XSetIOErrorHandler(xioerror);
             return 1;
         } else {
             if(!ServerTimeout(1, (char *) "X server to begin accepting connections"))
@@ -925,9 +913,6 @@ int App::StartServer() {
             ServerPID = -1;
             break;
         }
-        alarm(15);
-        pause();
-        alarm(0);
 
         // Wait for server to start up
         if(WaitForServer() == 0) {
@@ -962,15 +947,12 @@ int IgnoreXIO(Display *d) {
 
 
 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);
diff --git a/app.h b/app.h
index dd7c281..2db1038 100644
--- a/app.h
+++ b/app.h
@@ -34,6 +34,7 @@ public:
     ~App();
     void Run();
     int GetServerPID();
+    void RestartServer();
     void StopServer();
 
 	bool serverStarted;
@@ -49,7 +50,6 @@ private:
     void Console();
     void Exit();
     void KillAllClients(Bool top);
-    void RestartServer();
     void ReadConfig();
     void OpenLog();
     void CloseLog();
-- 
1.6.6.1