summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/main.cpp92
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
@@ -57,54 +57,54 @@ using namespace Opie::Core;
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
62static void cleanup() 62static 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
73static void refreshTimeZoneConfig() 73static void refreshTimeZoneConfig()
74{ 74{
75 /* ### FIXME timezone handling for qtopia */ 75 /* ### FIXME timezone handling for qtopia */
76} 76}
77 77
78void initEnvironment() 78void 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" );
@@ -116,47 +116,47 @@ void initEnvironment()
116 } 116 }
117} 117}
118 118
119static void initKeyboard() 119static 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
134static bool firstUse() 134static 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
159int initApplication( int argc, char ** argv ) 159int initApplication( int argc, char ** argv )
160{ 160{
161 cleanup(); 161 cleanup();
162 162
@@ -166,33 +166,33 @@ int initApplication( int argc, char ** argv )
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
@@ -214,79 +214,61 @@ int initApplication( int argc, char ** argv )
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
222static const char *pidfile_path = "/var/run/opie.pid"; 222static const char *pidfile_path = "/var/run/opie.pid";
223 223
224void create_pidfile ( ) 224void 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
234void remove_pidfile ( ) 234void remove_pidfile ( )
235{ 235{
236 ::unlink ( pidfile_path ); 236 ::unlink ( pidfile_path );
237} 237}
238 238
239void handle_sigterm ( int /* sig */ ) 239void 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
246int main( int argc, char ** argv ) 250int 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
279int 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