author | mickeyl <mickeyl> | 2004-11-12 13:51:35 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-12 13:51:35 (UTC) |
commit | de558d6f0bc31f58ffaa894a0236f0d9cb5d73e0 (patch) (unidiff) | |
tree | 55f7c2ec8c1e93983d41c962e557f3651db39b03 | |
parent | ee67d61c20b6840f3fb353e314d16a90c0438e7c (diff) | |
download | opie-de558d6f0bc31f58ffaa894a0236f0d9cb5d73e0.zip opie-de558d6f0bc31f58ffaa894a0236f0d9cb5d73e0.tar.gz opie-de558d6f0bc31f58ffaa894a0236f0d9cb5d73e0.tar.bz2 |
handle more signals and don't kill the process @ end
-rw-r--r-- | core/launcher/main.cpp | 92 |
1 files changed, 37 insertions, 55 deletions
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp index b119399..aa0dfdf 100644 --- a/core/launcher/main.cpp +++ b/core/launcher/main.cpp | |||
@@ -1,292 +1,274 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef QTOPIA_INTERNAL_FILEOPERATIONS | 21 | #ifndef QTOPIA_INTERNAL_FILEOPERATIONS |
22 | #define QTOPIA_INTERNAL_FILEOPERATIONS | 22 | #define QTOPIA_INTERNAL_FILEOPERATIONS |
23 | #endif | 23 | #endif |
24 | #ifdef QT_QWS_LOGIN | 24 | #ifdef QT_QWS_LOGIN |
25 | #include "../login/qdmdialogimpl.h" | 25 | #include "../login/qdmdialogimpl.h" |
26 | #endif | 26 | #endif |
27 | #include "calibrate.h" | 27 | #include "calibrate.h" |
28 | #include "server.h" | 28 | #include "server.h" |
29 | #include "serverapp.h" | 29 | #include "serverapp.h" |
30 | #include "stabmon.h" | 30 | #include "stabmon.h" |
31 | #include "firstuse.h" | 31 | #include "firstuse.h" |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #include <opie2/odevice.h> | 35 | #include <opie2/odevice.h> |
36 | #include <opie2/oglobal.h> | 36 | #include <opie2/oglobal.h> |
37 | #include <qtopia/network.h> | 37 | #include <qtopia/network.h> |
38 | #include <qtopia/alarmserver.h> | 38 | #include <qtopia/alarmserver.h> |
39 | using namespace Opie::Core; | 39 | using namespace Opie::Core; |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | #include <qdir.h> | 42 | #include <qdir.h> |
43 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
44 | #ifdef QWS | 44 | #ifdef QWS |
45 | #include <qwindowsystem_qws.h> | 45 | #include <qwindowsystem_qws.h> |
46 | #include <qtopia/qcopenvelope_qws.h> | 46 | #include <qtopia/qcopenvelope_qws.h> |
47 | #endif | 47 | #endif |
48 | #ifdef Q_WS_QWS | 48 | #ifdef Q_WS_QWS |
49 | #include <qkeyboard_qws.h> | 49 | #include <qkeyboard_qws.h> |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | /* STD */ | 52 | /* STD */ |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> |
54 | #include <stdio.h> | 54 | #include <stdio.h> |
55 | #include <signal.h> | 55 | #include <signal.h> |
56 | #ifndef Q_OS_WIN32 | 56 | #ifndef Q_OS_WIN32 |
57 | #include <unistd.h> | 57 | #include <unistd.h> |
58 | #else | 58 | #else |
59 | #include <process.h> | 59 | #include <process.h> |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | static void cleanup() | 62 | static void cleanup() |
63 | { | 63 | { |
64 | QDir dir( "/tmp", "qcop-msg-*" ); | 64 | QDir dir( "/tmp", "qcop-msg-*" ); |
65 | 65 | ||
66 | QStringList stale = dir.entryList(); | 66 | QStringList stale = dir.entryList(); |
67 | QStringList::Iterator it; | 67 | QStringList::Iterator it; |
68 | for ( it = stale.begin(); it != stale.end(); ++it ) { | 68 | for ( it = stale.begin(); it != stale.end(); ++it ) { |
69 | dir.remove( *it ); | 69 | dir.remove( *it ); |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | static void refreshTimeZoneConfig() | 73 | static void refreshTimeZoneConfig() |
74 | { | 74 | { |
75 | /* ### FIXME timezone handling for qtopia */ | 75 | /* ### FIXME timezone handling for qtopia */ |
76 | } | 76 | } |
77 | 77 | ||
78 | void initEnvironment() | 78 | void initEnvironment() |
79 | { | 79 | { |
80 | #ifdef Q_OS_WIN32 | 80 | #ifdef Q_OS_WIN32 |
81 | // Config file requires HOME dir which uses QDir which needs the winver | 81 | // Config file requires HOME dir which uses QDir which needs the winver |
82 | qt_init_winver(); | 82 | qt_init_winver(); |
83 | #endif | 83 | #endif |
84 | Config config("locale"); | 84 | Config config("locale"); |
85 | config.setGroup( "Location" ); | 85 | config.setGroup( "Location" ); |
86 | QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); | 86 | QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); |
87 | 87 | ||
88 | // if not timezone set, pick New York | 88 | // if not timezone set, pick New York |
89 | if (tz.isNull() || tz.isEmpty()) | 89 | if (tz.isNull() || tz.isEmpty()) |
90 | tz = "America/New_York"; | 90 | tz = "America/New_York"; |
91 | 91 | ||
92 | setenv( "TZ", tz, 1 ); | 92 | setenv( "TZ", tz, 1 ); |
93 | config.writeEntry( "Timezone", tz); | 93 | config.writeEntry( "Timezone", tz); |
94 | 94 | ||
95 | config.setGroup( "Language" ); | 95 | config.setGroup( "Language" ); |
96 | QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); | 96 | QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); |
97 | if( lang.isNull() || lang.isEmpty()) | 97 | if( lang.isNull() || lang.isEmpty()) |
98 | lang = "en_US"; | 98 | lang = "en_US"; |
99 | 99 | ||
100 | setenv( "LANG", lang, 1 ); | 100 | setenv( "LANG", lang, 1 ); |
101 | config.writeEntry("Language", lang); | 101 | config.writeEntry("Language", lang); |
102 | config.write(); | 102 | config.write(); |
103 | 103 | ||
104 | 104 | ||
105 | QString env(getenv("QWS_DISPLAY")); | 105 | QString env(getenv("QWS_DISPLAY")); |
106 | if (env.contains("Transformed")) { | 106 | if (env.contains("Transformed")) { |
107 | int rot; | 107 | int rot; |
108 | // transformed driver default rotation is controlled by the hardware. | 108 | // transformed driver default rotation is controlled by the hardware. |
109 | Config config("qpe"); | 109 | Config config("qpe"); |
110 | config.setGroup( "Rotation" ); | 110 | config.setGroup( "Rotation" ); |
111 | if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) | 111 | if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) |
112 | rot = ODevice::inst ( )-> rotation ( ) * 90; | 112 | rot = ODevice::inst ( )-> rotation ( ) * 90; |
113 | 113 | ||
114 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 114 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
115 | QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ | 115 | QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | static void initKeyboard() | 119 | static void initKeyboard() |
120 | { | 120 | { |
121 | Config config("qpe"); | 121 | Config config("qpe"); |
122 | 122 | ||
123 | config.setGroup( "Keyboard" ); | 123 | config.setGroup( "Keyboard" ); |
124 | 124 | ||
125 | int ard = config.readNumEntry( "RepeatDelay" ); | 125 | int ard = config.readNumEntry( "RepeatDelay" ); |
126 | int arp = config.readNumEntry( "RepeatPeriod" ); | 126 | int arp = config.readNumEntry( "RepeatPeriod" ); |
127 | if ( ard > 0 && arp > 0 ) | 127 | if ( ard > 0 && arp > 0 ) |
128 | qwsSetKeyboardAutoRepeat( ard, arp ); | 128 | qwsSetKeyboardAutoRepeat( ard, arp ); |
129 | 129 | ||
130 | QString layout = config.readEntry( "Layout", "us101" ); | 130 | QString layout = config.readEntry( "Layout", "us101" ); |
131 | Server::setKeyboardLayout( layout ); | 131 | Server::setKeyboardLayout( layout ); |
132 | } | 132 | } |
133 | 133 | ||
134 | static bool firstUse() | 134 | static bool firstUse() |
135 | { | 135 | { |
136 | bool needFirstUse = FALSE; | 136 | bool needFirstUse = FALSE; |
137 | if ( QWSServer::mouseHandler() && | 137 | if ( QWSServer::mouseHandler() && |
138 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | 138 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { |
139 | if ( !QFile::exists( "/etc/pointercal" ) ) | 139 | if ( !QFile::exists( "/etc/pointercal" ) ) |
140 | needFirstUse = TRUE; | 140 | needFirstUse = TRUE; |
141 | } | 141 | } |
142 | 142 | ||
143 | { | 143 | { |
144 | Config config( "qpe" ); | 144 | Config config( "qpe" ); |
145 | config.setGroup( "Startup" ); | 145 | config.setGroup( "Startup" ); |
146 | needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); | 146 | needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); |
147 | } | 147 | } |
148 | 148 | ||
149 | if ( !needFirstUse ) | 149 | if ( !needFirstUse ) |
150 | return FALSE; | 150 | return FALSE; |
151 | 151 | ||
152 | FirstUse *fu = new FirstUse(); | 152 | FirstUse *fu = new FirstUse(); |
153 | fu->exec(); | 153 | fu->exec(); |
154 | bool rs = fu->restartNeeded(); | 154 | bool rs = fu->restartNeeded(); |
155 | delete fu; | 155 | delete fu; |
156 | return rs; | 156 | return rs; |
157 | } | 157 | } |
158 | 158 | ||
159 | int initApplication( int argc, char ** argv ) | 159 | int initApplication( int argc, char ** argv ) |
160 | { | 160 | { |
161 | cleanup(); | 161 | cleanup(); |
162 | 162 | ||
163 | 163 | ||
164 | initEnvironment(); | 164 | initEnvironment(); |
165 | 165 | ||
166 | //Don't flicker at startup: | 166 | //Don't flicker at startup: |
167 | #ifdef QWS | 167 | #ifdef QWS |
168 | QWSServer::setDesktopBackground( QImage() ); | 168 | QWSServer::setDesktopBackground( QImage() ); |
169 | #endif | 169 | #endif |
170 | ServerApplication a( argc, argv, QApplication::GuiServer ); | 170 | ServerApplication a( argc, argv, QApplication::GuiServer ); |
171 | 171 | ||
172 | refreshTimeZoneConfig(); | 172 | refreshTimeZoneConfig(); |
173 | 173 | ||
174 | initKeyboard(); | 174 | initKeyboard(); |
175 | 175 | ||
176 | // Don't use first use under Windows | 176 | // Don't use first use under Windows |
177 | if ( firstUse() ) { | 177 | if ( firstUse() ) { |
178 | a.restart(); | 178 | a.restart(); |
179 | return 0; | 179 | return 0; |
180 | } | 180 | } |
181 | 181 | ||
182 | ODevice::inst ( )-> setSoftSuspend ( true ); | 182 | ODevice::inst ( )-> setSoftSuspend ( true ); |
183 | 183 | ||
184 | { | 184 | { |
185 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | 185 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); |
186 | e << -3; // Forced on | 186 | e << -3; // Forced on |
187 | } | 187 | } |
188 | 188 | ||
189 | AlarmServer::initialize(); | 189 | AlarmServer::initialize(); |
190 | 190 | ||
191 | 191 | ||
192 | 192 | ||
193 | Server *s = new Server(); | 193 | Server *s = new Server(); |
194 | 194 | ||
195 | (void)new SysFileMonitor(s); | 195 | (void)new SysFileMonitor(s); |
196 | #ifdef QWS | 196 | #ifdef QWS |
197 | Network::createServer(s); | 197 | Network::createServer(s); |
198 | #endif | 198 | #endif |
199 | 199 | ||
200 | s->show(); | 200 | s->show(); |
201 | 201 | ||
202 | /* THE ARM rtc has problem holdings the time on reset */ | 202 | /* THE ARM rtc has problem holdings the time on reset */ |
203 | if ( QDate::currentDate ( ). year ( ) < 2000 ) { | 203 | if ( QDate::currentDate ( ). year ( ) < 2000 ) { |
204 | if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ), ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" ). arg( TimeString::dateString ( QDate::currentDate ( ))), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 204 | if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ), ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" ). arg( TimeString::dateString ( QDate::currentDate ( ))), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
205 | QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); | 205 | QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); |
206 | e << QString ( ); | 206 | e << QString ( ); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | int rv = a.exec(); | 210 | int rv = a.exec(); |
211 | 211 | ||
212 | odebug << "exiting..." << oendl; | 212 | odebug << "exiting..." << oendl; |
213 | delete s; | 213 | delete s; |
214 | 214 | ||
215 | #ifndef Q_OS_MACX | 215 | #ifndef Q_OS_MACX |
216 | ODevice::inst()->setSoftSuspend( false ); | 216 | ODevice::inst()->setSoftSuspend( false ); |
217 | #endif | 217 | #endif |
218 | 218 | ||
219 | return rv; | 219 | return rv; |
220 | } | 220 | } |
221 | 221 | ||
222 | static const char *pidfile_path = "/var/run/opie.pid"; | 222 | static const char *pidfile_path = "/var/run/opie.pid"; |
223 | 223 | ||
224 | void create_pidfile ( ) | 224 | void create_pidfile ( ) |
225 | { | 225 | { |
226 | FILE *f; | 226 | FILE *f; |
227 | 227 | ||
228 | if (( f = ::fopen ( pidfile_path, "w" ))) { | 228 | if (( f = ::fopen ( pidfile_path, "w" ))) { |
229 | ::fprintf ( f, "%d", getpid ( )); | 229 | ::fprintf ( f, "%d", getpid ( )); |
230 | ::fclose ( f ); | 230 | ::fclose ( f ); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | 233 | ||
234 | void remove_pidfile ( ) | 234 | void remove_pidfile ( ) |
235 | { | 235 | { |
236 | ::unlink ( pidfile_path ); | 236 | ::unlink ( pidfile_path ); |
237 | } | 237 | } |
238 | 238 | ||
239 | void handle_sigterm ( int /* sig */ ) | 239 | void handle_sigterm ( int /* sig */ ) |
240 | { | 240 | { |
241 | if ( qApp ) | 241 | ::signal( SIGCHLD, SIG_IGN ); |
242 | qApp-> quit ( ); | 242 | ::signal( SIGSEGV, SIG_IGN ); |
243 | ::signal( SIGBUS, SIG_IGN ); | ||
244 | ::signal( SIGILL, SIG_IGN ); | ||
245 | ::signal( SIGTERM, SIG_IGN ); | ||
246 | ::signal ( SIGINT, SIG_IGN ); | ||
247 | if ( qApp ) qApp->quit(); | ||
243 | } | 248 | } |
244 | 249 | ||
245 | #ifndef Q_OS_WIN32 | ||
246 | int main( int argc, char ** argv ) | 250 | int main( int argc, char ** argv ) |
247 | { | 251 | { |
248 | 252 | ::signal( SIGCHLD, SIG_IGN ); | |
249 | ::signal ( SIGCHLD, SIG_IGN ); | 253 | ::signal( SIGSEGV, handle_sigterm ); |
250 | 254 | ::signal( SIGBUS, handle_sigterm ); | |
251 | ::signal ( SIGTERM, handle_sigterm ); | 255 | ::signal( SIGILL, handle_sigterm ); |
256 | ::signal( SIGTERM, handle_sigterm ); | ||
252 | ::signal ( SIGINT, handle_sigterm ); | 257 | ::signal ( SIGINT, handle_sigterm ); |
258 | ::setsid(); | ||
259 | ::setpgid( 0, 0 ); | ||
253 | 260 | ||
254 | ::setsid ( ); | 261 | ::atexit( remove_pidfile ); |
255 | ::setpgid ( 0, 0 ); | 262 | create_pidfile(); |
256 | |||
257 | ::atexit ( remove_pidfile ); | ||
258 | create_pidfile ( ); | ||
259 | 263 | ||
260 | int retVal = initApplication( argc, argv ); | 264 | int retVal = initApplication( argc, argv ); |
261 | 265 | ||
262 | // Have we been asked to restart? | 266 | // Have we been asked to restart? |
263 | if ( ServerApplication::doRestart ) { | 267 | if ( ServerApplication::doRestart ) |
264 | for ( int fd = 3; fd < 100; fd++ ) | 268 | { |
265 | close( fd ); | 269 | for ( int fd = 3; fd < 100; fd++ ) close( fd ); |
266 | 270 | execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 ); | |
267 | execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 ); | ||
268 | } | ||
269 | |||
270 | // Kill them. Kill them all. | ||
271 | ::kill ( 0, SIGTERM ); | ||
272 | ::sleep ( 1 ); | ||
273 | ::kill ( 0, SIGKILL ); | ||
274 | |||
275 | return retVal; | ||
276 | } | ||
277 | #else | ||
278 | |||
279 | int main( int argc, char ** argv ) | ||
280 | { | ||
281 | int retVal = initApplication( argc, argv ); | ||
282 | |||
283 | if ( DesktopApplication::doRestart ) { | ||
284 | odebug << "Trying to restart" << oendl; | ||
285 | execl( (QPEApplication::qpeDir()+"bin\\qpe").latin1(), "qpe", 0 ); | ||
286 | } | 271 | } |
287 | 272 | ||
288 | return retVal; | 273 | return retVal; |
289 | } | 274 | } |
290 | |||
291 | #endif | ||
292 | |||