summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index 9c40fc4..d95a59b 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,368 +1,369 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can 5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that 12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details. 17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .: 18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU 19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file; 20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the 21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc., 22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, 23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. 24 Boston, MA 02111-1307, USA.
25 25
26*/ 26*/
27 27
28#define _GNU_SOURCE 28#define _GNU_SOURCE
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31#include <time.h> 31#include <time.h>
32#include <sys/time.h> 32#include <sys/time.h>
33#include <sys/resource.h> 33#include <sys/resource.h>
34#include <unistd.h> 34#include <unistd.h>
35#include <syslog.h> 35#include <syslog.h>
36#include <sys/wait.h> 36#include <sys/wait.h>
37#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <signal.h> 39#include <signal.h>
40#include <getopt.h> 40#include <getopt.h>
41#include <string.h> 41#include <string.h>
42 42
43#include <qpe/qpeapplication.h> 43#include <qpe/qpeapplication.h>
44#include <qpe/qcopenvelope_qws.h> 44#include <qpe/qcopenvelope_qws.h>
45#include <qpe/qpestyle.h> 45#include <qpe/qpestyle.h>
46#include <qpe/power.h> 46#include <qpe/power.h>
47#include <qpe/config.h> 47#include <qpe/config.h>
48 48
49#include <opie/odevice.h> 49#include <opie/odevice.h>
50 50
51#include <qwindowsystem_qws.h> 51#include <qwindowsystem_qws.h>
52#include <qwsmouse_qws.h>
52#include <qmessagebox.h> 53#include <qmessagebox.h>
53#include <qlabel.h> 54#include <qlabel.h>
54#include <qtimer.h> 55#include <qtimer.h>
55#include <qfile.h> 56#include <qfile.h>
56 57
57#include "loginapplication.h" 58#include "loginapplication.h"
58#include "loginwindowimpl.h" 59#include "loginwindowimpl.h"
59#include "calibrate.h" 60#include "calibrate.h"
60 61
61using namespace Opie; 62using namespace Opie;
62 63
63int login_main ( int argc, char **argv, pid_t ppid ); 64int login_main ( int argc, char **argv, pid_t ppid );
64void sigterm ( int sig ); 65void sigterm ( int sig );
65void sigint ( int sig ); 66void sigint ( int sig );
66void exit_closelog ( ); 67void exit_closelog ( );
67 68
68static struct option long_options [] = { 69static struct option long_options [] = {
69 { "autologin", 1, 0, 'a' }, 70 { "autologin", 1, 0, 'a' },
70 { 0, 0, 0, 0 } 71 { 0, 0, 0, 0 }
71}; 72};
72 73
73 74
74int main ( int argc, char **argv ) 75int main ( int argc, char **argv )
75{ 76{
76 pid_t ppid = ::getpid ( ); 77 pid_t ppid = ::getpid ( );
77 78
78 if ( ::geteuid ( ) != 0 ) { 79 if ( ::geteuid ( ) != 0 ) {
79 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); 80 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
80 return 1; 81 return 1;
81 } 82 }
82 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and 83 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and
83 ::setuid ( 0 ); // messes up things like config files 84 ::setuid ( 0 ); // messes up things like config files
84 85
85 char *autolog = 0; 86 char *autolog = 0;
86 int c; 87 int c;
87 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { 88 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) {
88 switch ( c ) { 89 switch ( c ) {
89 case 'a': 90 case 'a':
90 autolog = optarg; 91 autolog = optarg;
91 break; 92 break;
92 default: 93 default:
93 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); 94 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] );
94 return 2; 95 return 2;
95 } 96 }
96 } 97 }
97 98
98 //struct rlimit rl; 99 //struct rlimit rl;
99 //::getrlimit ( RLIMIT_NOFILE, &rl ); 100 //::getrlimit ( RLIMIT_NOFILE, &rl );
100 101
101 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 102 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
102 // ::close ( i ); 103 // ::close ( i );
103 104
104 ::setpgid ( 0, 0 ); 105 ::setpgid ( 0, 0 );
105 ::setsid ( ); 106 ::setsid ( );
106 107
107 ::signal ( SIGTERM, sigterm ); 108 ::signal ( SIGTERM, sigterm );
108 ::signal ( SIGINT, sigterm ); 109 ::signal ( SIGINT, sigterm );
109 110
110 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 111 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
111 ::atexit ( exit_closelog ); 112 ::atexit ( exit_closelog );
112 113
113 while ( true ) { 114 while ( true ) {
114 pid_t child = ::fork ( ); 115 pid_t child = ::fork ( );
115 116
116 if ( child < 0 ) { 117 if ( child < 0 ) {
117 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 118 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
118 break; 119 break;
119 } 120 }
120 else if ( child > 0 ) { 121 else if ( child > 0 ) {
121 int status = 0; 122 int status = 0;
122 time_t started = ::time ( 0 ); 123 time_t started = ::time ( 0 );
123 124
124 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 125 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
125 126
126 LoginApplication::logout ( ); 127 LoginApplication::logout ( );
127 128
128 if (( ::time ( 0 ) - started ) < 3 ) { 129 if (( ::time ( 0 ) - started ) < 3 ) {
129 if ( autolog ) { 130 if ( autolog ) {
130 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); 131 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
131 autolog = 0; 132 autolog = 0;
132 } 133 }
133 else { 134 else {
134 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); 135 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
135 break; 136 break;
136 } 137 }
137 } 138 }
138 int killedbysig = 0; 139 int killedbysig = 0;
139 140
140 if ( WIFSIGNALED( status )) { 141 if ( WIFSIGNALED( status )) {
141 switch ( WTERMSIG( status )) { 142 switch ( WTERMSIG( status )) {
142 case SIGINT : 143 case SIGINT :
143 case SIGTERM: 144 case SIGTERM:
144 case SIGKILL: 145 case SIGKILL:
145 break; 146 break;
146 147
147 default : 148 default :
148 killedbysig = WTERMSIG( status ); 149 killedbysig = WTERMSIG( status );
149 break; 150 break;
150 } 151 }
151 } 152 }
152 if ( killedbysig ) { // qpe was killed by an uncaught signal 153 if ( killedbysig ) { // qpe was killed by an uncaught signal
153 qApp = 0; 154 qApp = 0;
154 155
155 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); 156 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig );
156 157
157 QWSServer::setDesktopBackground ( QImage ( )); 158 QWSServer::setDesktopBackground ( QImage ( ));
158 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); 159 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
159 app-> setFont ( QFont ( "Helvetica", 10 )); 160 app-> setFont ( QFont ( "Helvetica", 10 ));
160 app-> setStyle ( new QPEStyle ( )); 161 app-> setStyle ( new QPEStyle ( ));
161 162
162 const char *sig = ::strsignal ( killedbysig ); 163 const char *sig = ::strsignal ( killedbysig );
163 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); 164 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool );
164 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); 165 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig ));
165 l-> setAlignment ( Qt::AlignCenter ); 166 l-> setAlignment ( Qt::AlignCenter );
166 l-> move ( 0, 0 ); 167 l-> move ( 0, 0 );
167 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 168 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
168 l-> show ( ); 169 l-> show ( );
169 QTimer::singleShot ( 3000, app, SLOT( quit ( ))); 170 QTimer::singleShot ( 3000, app, SLOT( quit ( )));
170 app-> exec ( ); 171 app-> exec ( );
171 delete app; 172 delete app;
172 qApp = 0; 173 qApp = 0;
173 } 174 }
174 } 175 }
175 else { 176 else {
176 if ( !autolog ) { 177 if ( !autolog ) {
177 Config cfg ( "opie-login" ); 178 Config cfg ( "opie-login" );
178 cfg. setGroup ( "General" ); 179 cfg. setGroup ( "General" );
179 QString user = cfg. readEntry ( "AutoLogin" ); 180 QString user = cfg. readEntry ( "AutoLogin" );
180 181
181 if ( !user. isEmpty ( )) 182 if ( !user. isEmpty ( ))
182 autolog = ::strdup ( user. latin1 ( )); 183 autolog = ::strdup ( user. latin1 ( ));
183 } 184 }
184 185
185 if ( autolog ) { 186 if ( autolog ) {
186 LoginApplication::setLoginAs ( autolog ); 187 LoginApplication::setLoginAs ( autolog );
187 188
188 if ( LoginApplication::changeIdentity ( )) 189 if ( LoginApplication::changeIdentity ( ))
189 ::exit ( LoginApplication::login ( )); 190 ::exit ( LoginApplication::login ( ));
190 else 191 else
191 ::exit ( 0 ); 192 ::exit ( 0 );
192 } 193 }
193 else 194 else
194 ::exit ( login_main ( argc, argv, ppid )); 195 ::exit ( login_main ( argc, argv, ppid ));
195 } 196 }
196 } 197 }
197 return 0; 198 return 0;
198} 199}
199 200
200void sigterm ( int /*sig*/ ) 201void sigterm ( int /*sig*/ )
201{ 202{
202 ::exit ( 0 ); 203 ::exit ( 0 );
203} 204}
204 205
205 206
206void exit_closelog ( ) 207void exit_closelog ( )
207{ 208{
208 ::closelog ( ); 209 ::closelog ( );
209} 210}
210 211
211 212
212class LoginScreenSaver : public QWSScreenSaver 213class LoginScreenSaver : public QWSScreenSaver
213{ 214{
214public: 215public:
215 LoginScreenSaver ( ) 216 LoginScreenSaver ( )
216 { 217 {
217 m_lcd_status = true; 218 m_lcd_status = true;
218 219
219 m_backlight_bright = -1; 220 m_backlight_bright = -1;
220 m_backlight_forcedoff = false; 221 m_backlight_forcedoff = false;
221 222
222 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 223 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
223 ODevice::inst ( )-> setDisplayStatus ( true ); 224 ODevice::inst ( )-> setDisplayStatus ( true );
224 } 225 }
225 void restore() 226 void restore()
226 { 227 {
227 if ( !m_lcd_status ) // We must have turned it off 228 if ( !m_lcd_status ) // We must have turned it off
228 ODevice::inst ( ) -> setDisplayStatus ( true ); 229 ODevice::inst ( ) -> setDisplayStatus ( true );
229 230
230 setBacklight ( -3 ); 231 setBacklight ( -3 );
231 } 232 }
232 bool save( int level ) 233 bool save( int level )
233 { 234 {
234 switch ( level ) { 235 switch ( level ) {
235 case 0: 236 case 0:
236 if ( backlight() > 1 ) 237 if ( backlight() > 1 )
237 setBacklight( 1 ); // lowest non-off 238 setBacklight( 1 ); // lowest non-off
238 return true; 239 return true;
239 break; 240 break;
240 case 1: 241 case 1:
241 setBacklight( 0 ); // off 242 setBacklight( 0 ); // off
242 return true; 243 return true;
243 break; 244 break;
244 case 2: 245 case 2:
245 // We're going to suspend the whole machine 246 // We're going to suspend the whole machine
246 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 247 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
247 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 248 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
248 return true; 249 return true;
249 } 250 }
250 break; 251 break;
251 } 252 }
252 return false; 253 return false;
253 } 254 }
254 255
255private: 256private:
256public: 257public:
257 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) 258 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
258 { 259 {
259 int v [4]; 260 int v [4];
260 261
261 v [ 0 ] = QMAX( 1000 * i1, 100 ); 262 v [ 0 ] = QMAX( 1000 * i1, 100 );
262 v [ 1 ] = QMAX( 1000 * i2, 100 ); 263 v [ 1 ] = QMAX( 1000 * i2, 100 );
263 v [ 2 ] = QMAX( 1000 * i3, 100 ); 264 v [ 2 ] = QMAX( 1000 * i3, 100 );
264 v [ 3 ] = 0; 265 v [ 3 ] = 0;
265 266
266 if ( !i1 && !i2 && !i3 ) 267 if ( !i1 && !i2 && !i3 )
267 QWSServer::setScreenSaverInterval ( 0 ); 268 QWSServer::setScreenSaverInterval ( 0 );
268 else 269 else
269 QWSServer::setScreenSaverIntervals ( v ); 270 QWSServer::setScreenSaverIntervals ( v );
270 } 271 }
271 272
272 int backlight ( ) 273 int backlight ( )
273 { 274 {
274 if ( m_backlight_bright == -1 ) 275 if ( m_backlight_bright == -1 )
275 m_backlight_bright = 255; 276 m_backlight_bright = 255;
276 277
277 return m_backlight_bright; 278 return m_backlight_bright;
278 } 279 }
279 280
280 void setBacklight ( int bright ) 281 void setBacklight ( int bright )
281 { 282 {
282 if ( bright == -3 ) { 283 if ( bright == -3 ) {
283 // Forced on 284 // Forced on
284 m_backlight_forcedoff = false; 285 m_backlight_forcedoff = false;
285 bright = -1; 286 bright = -1;
286 } 287 }
287 if ( m_backlight_forcedoff && bright != -2 ) 288 if ( m_backlight_forcedoff && bright != -2 )
288 return ; 289 return ;
289 if ( bright == -2 ) { 290 if ( bright == -2 ) {
290 // Toggle between off and on 291 // Toggle between off and on
291 bright = m_backlight_bright ? 0 : -1; 292 bright = m_backlight_bright ? 0 : -1;
292 m_backlight_forcedoff = !bright; 293 m_backlight_forcedoff = !bright;
293 } 294 }
294 295
295 m_backlight_bright = bright; 296 m_backlight_bright = bright;
296 297
297 bright = backlight ( ); 298 bright = backlight ( );
298 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 299 ODevice::inst ( ) -> setDisplayBrightness ( bright );
299 300
300 m_backlight_bright = bright; 301 m_backlight_bright = bright;
301 } 302 }
302 303
303private: 304private:
304 bool m_lcd_status; 305 bool m_lcd_status;
305 306
306 int m_backlight_bright; 307 int m_backlight_bright;
307 bool m_backlight_forcedoff; 308 bool m_backlight_forcedoff;
308}; 309};
309 310
310 311
311namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting 312namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting
312 313
313 314
314int login_main ( int argc, char **argv, pid_t ppid ) 315int login_main ( int argc, char **argv, pid_t ppid )
315{ 316{
316 QWSServer::setDesktopBackground( QImage() ); 317 QWSServer::setDesktopBackground( QImage() );
317 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 318 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
318 319
319 Opie::force_appearance = 0; 320 Opie::force_appearance = 0;
320 321
321 app-> setFont ( QFont ( "Helvetica", 10 )); 322 app-> setFont ( QFont ( "Helvetica", 10 ));
322 app-> setStyle ( new QPEStyle ( )); 323 app-> setStyle ( new QPEStyle ( ));
323 324
324 ODevice::inst ( )-> setSoftSuspend ( true ); 325 ODevice::inst ( )-> setSoftSuspend ( true );
325 326
326 if ( QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 327 if ( QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
327 if ( !QFile::exists ( "/etc/pointercal" )) { 328 if ( !QFile::exists ( "/etc/pointercal" )) {
328 // Make sure calibration widget starts on top. 329 // Make sure calibration widget starts on top.
329 Calibrate *cal = new Calibrate; 330 Calibrate *cal = new Calibrate;
330 cal-> exec ( ); 331 cal-> exec ( );
331 delete cal; 332 delete cal;
332 } 333 }
333 } 334 }
334 335
335 LoginScreenSaver *saver = new LoginScreenSaver; 336 LoginScreenSaver *saver = new LoginScreenSaver;
336 337
337 saver-> setIntervals ( ); 338 saver-> setIntervals ( );
338 QWSServer::setScreenSaver ( saver ); 339 QWSServer::setScreenSaver ( saver );
339 saver-> restore ( ); 340 saver-> restore ( );
340 341
341 342
342 LoginWindowImpl *lw = new LoginWindowImpl ( ); 343 LoginWindowImpl *lw = new LoginWindowImpl ( );
343 app-> setMainWidget ( lw ); 344 app-> setMainWidget ( lw );
344 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 345 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
345 lw-> show ( ); 346 lw-> show ( );
346 347
347 int rc = app-> exec ( ); 348 int rc = app-> exec ( );
348 349
349 ODevice::inst ( )-> setSoftSuspend ( false ); 350 ODevice::inst ( )-> setSoftSuspend ( false );
350 351
351 if ( app-> loginAs ( )) { 352 if ( app-> loginAs ( )) {
352 if ( app-> changeIdentity ( )) { 353 if ( app-> changeIdentity ( )) {
353 app-> login ( ); 354 app-> login ( );
354 355
355 // if login succeeds, it never comes back 356 // if login succeeds, it never comes back
356 357
357 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start OPIE." )); 358 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start OPIE." ));
358 rc = 1; 359 rc = 1;
359 } 360 }
360 else { 361 else {
361 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); 362 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" ));
362 rc = 2; 363 rc = 2;
363 } 364 }
364 365
365 } 366 }
366 return rc; 367 return rc;
367} 368}
368 369