author | erik <erik> | 2007-01-29 21:38:26 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-29 21:38:26 (UTC) |
commit | 597643805ce89c1237035e7f38ec953cfc0d080f (patch) (unidiff) | |
tree | 9ec8465a1a1c34346e7ee9c40c2d810910f66162 /core/opie-login/main.cpp | |
parent | 777cace646507cf4222f0a6d5beb2cd44ec45a0a (diff) | |
download | opie-597643805ce89c1237035e7f38ec953cfc0d080f.zip opie-597643805ce89c1237035e7f38ec953cfc0d080f.tar.gz opie-597643805ce89c1237035e7f38ec953cfc0d080f.tar.bz2 |
Reformat according to current Opie style.
-rw-r--r-- | core/opie-login/main.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 3f1077c..b76d2c7 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -69,20 +69,23 @@ int main ( int argc, char **argv ) | |||
69 | pid_t ppid = ::getpid ( ); | 69 | pid_t ppid = ::getpid ( ); |
70 | 70 | ||
71 | if ( ::geteuid ( ) != 0 ) { | 71 | if ( ::geteuid ( ) != 0 ) { |
72 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] ); | 72 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] ); |
73 | return 1; | 73 | return 1; |
74 | } | 74 | } |
75 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 75 | /*! |
76 | ::setuid ( 0 ); // messes up things like config files | 76 | * @bug |
77 | 77 | * Qte does not really like being set UID root. This is | |
78 | //struct rlimit rl; | 78 | * largely because we do almost everything on config files |
79 | //::getrlimit ( RLIMIT_NOFILE, &rl ); | 79 | * in root context. So if you even want to use opie-login |
80 | 80 | * you are in for a world of hurt unless someone at least | |
81 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | 81 | * scrubs the settings area and the PIM apps to make sure that |
82 | // ::close ( i ); | 82 | * they are covered regarding perms and users. |
83 | */ | ||
84 | if ( ::getuid ( ) != 0 ) | ||
85 | ::setuid ( 0 ); | ||
83 | 86 | ||
84 | ::setpgid ( 0, 0 ); | 87 | ::setpgid ( 0, 0 ); |
85 | ::setsid ( ); | 88 | ::setsid ( ); |
86 | 89 | ||
87 | ::signal ( SIGTERM, sigterm ); | 90 | ::signal ( SIGTERM, sigterm ); |
88 | ::signal ( SIGINT, sigterm ); | 91 | ::signal ( SIGINT, sigterm ); |
@@ -91,26 +94,28 @@ int main ( int argc, char **argv ) | |||
91 | ::atexit ( exit_closelog ); | 94 | ::atexit ( exit_closelog ); |
92 | 95 | ||
93 | const char* autolog = 0; | 96 | const char* autolog = 0; |
94 | Config c( "opie-login" ); | 97 | Config c( "opie-login" ); |
95 | c.setGroup( "autologin" ); | 98 | c.setGroup( "autologin" ); |
96 | QString entry = c.readEntry( "user", "" ); | 99 | QString entry = c.readEntry( "user", "" ); |
97 | if ( !entry.isEmpty() ) autolog = ::strdup( (const char*) entry ); | 100 | if ( !entry.isEmpty() ) |
101 | autolog = ::strdup( (const char*) entry ); | ||
98 | 102 | ||
99 | while ( true ) { | 103 | while ( true ) { |
100 | pid_t child = ::fork ( ); | 104 | pid_t child = ::fork ( ); |
101 | 105 | ||
102 | if ( child < 0 ) { | 106 | if ( child < 0 ) { |
103 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); | 107 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); |
104 | break; | 108 | break; |
105 | } | 109 | } |
106 | else if ( child > 0 ) { | 110 | else if ( child > 0 ) { |
107 | int status = 0; | 111 | int status = 0; |
108 | time_t started = ::time ( 0 ); | 112 | time_t started = ::time ( 0 ); |
109 | 113 | ||
110 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 114 | while ( ::waitpid ( child, &status, 0 ) < 0 ) |
115 | ; | ||
111 | 116 | ||
112 | LoginApplication::logout ( ); | 117 | LoginApplication::logout ( ); |
113 | 118 | ||
114 | if (( ::time ( 0 ) - started ) < 3 ) { | 119 | if (( ::time ( 0 ) - started ) < 3 ) { |
115 | if ( autolog ) { | 120 | if ( autolog ) { |
116 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 121 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
@@ -177,19 +182,17 @@ int main ( int argc, char **argv ) | |||
177 | 182 | ||
178 | if ( !user. isEmpty ( )) | 183 | if ( !user. isEmpty ( )) |
179 | autolog = ::strdup ( user. latin1 ( )); | 184 | autolog = ::strdup ( user. latin1 ( )); |
180 | } | 185 | } |
181 | 186 | ||
182 | if ( autolog && !userExited ) { | 187 | if ( autolog && !userExited ) { |
183 | |||
184 | QWSServer::setDesktopBackground( QImage() ); | 188 | QWSServer::setDesktopBackground( QImage() ); |
185 | ODevice::inst()->setDisplayStatus( true ); | 189 | ODevice::inst()->setDisplayStatus( true ); |
186 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 190 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
187 | LoginApplication::setLoginAs( autolog ); | 191 | LoginApplication::setLoginAs( autolog ); |
188 | 192 | ||
189 | |||
190 | if ( LoginApplication::changeIdentity ( )) | 193 | if ( LoginApplication::changeIdentity ( )) |
191 | ::exit ( LoginApplication::login ( )); | 194 | ::exit ( LoginApplication::login ( )); |
192 | else | 195 | else |
193 | ::exit ( 0 ); | 196 | ::exit ( 0 ); |
194 | } | 197 | } |
195 | else { | 198 | else { |
@@ -242,24 +245,23 @@ public: | |||
242 | break; | 245 | break; |
243 | case 1: | 246 | case 1: |
244 | setBacklight( 0 ); // off | 247 | setBacklight( 0 ); // off |
245 | return true; | 248 | return true; |
246 | break; | 249 | break; |
247 | case 2: | 250 | case 2: |
251 | default: | ||
248 | // We're going to suspend the whole machine | 252 | // We're going to suspend the whole machine |
249 | if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { | 253 | if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { |
250 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 254 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
251 | return true; | 255 | return true; |
252 | } | 256 | } |
253 | break; | 257 | break; |
254 | } | 258 | } |
255 | return false; | 259 | return false; |
256 | } | 260 | } |
257 | 261 | ||
258 | private: | ||
259 | public: | ||
260 | void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) | 262 | void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) |
261 | { | 263 | { |
262 | int v [4]; | 264 | int v [4]; |
263 | 265 | ||
264 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 266 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
265 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 267 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
@@ -286,12 +288,13 @@ public: | |||
286 | // Forced on | 288 | // Forced on |
287 | m_backlight_forcedoff = false; | 289 | m_backlight_forcedoff = false; |
288 | bright = -1; | 290 | bright = -1; |
289 | } | 291 | } |
290 | if ( m_backlight_forcedoff && bright != -2 ) | 292 | if ( m_backlight_forcedoff && bright != -2 ) |
291 | return ; | 293 | return ; |
294 | |||
292 | if ( bright == -2 ) { | 295 | if ( bright == -2 ) { |
293 | // Toggle between off and on | 296 | // Toggle between off and on |
294 | bright = m_backlight_bright ? 0 : -1; | 297 | bright = m_backlight_bright ? 0 : -1; |
295 | m_backlight_forcedoff = !bright; | 298 | m_backlight_forcedoff = !bright; |
296 | } | 299 | } |
297 | 300 | ||
@@ -302,13 +305,12 @@ public: | |||
302 | 305 | ||
303 | m_backlight_bright = bright; | 306 | m_backlight_bright = bright; |
304 | } | 307 | } |
305 | 308 | ||
306 | private: | 309 | private: |
307 | bool m_lcd_status; | 310 | bool m_lcd_status; |
308 | |||
309 | int m_backlight_bright; | 311 | int m_backlight_bright; |
310 | bool m_backlight_forcedoff; | 312 | bool m_backlight_forcedoff; |
311 | }; | 313 | }; |
312 | 314 | ||
313 | 315 | ||
314 | int login_main ( int argc, char **argv, pid_t ppid ) | 316 | int login_main ( int argc, char **argv, pid_t ppid ) |
@@ -317,13 +319,14 @@ int login_main ( int argc, char **argv, pid_t ppid ) | |||
317 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 319 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
318 | 320 | ||
319 | app-> setFont ( QFont ( "Helvetica", 10 )); | 321 | app-> setFont ( QFont ( "Helvetica", 10 )); |
320 | app-> setStyle ( new QPEStyle ( )); | 322 | app-> setStyle ( new QPEStyle ( )); |
321 | 323 | ||
322 | if ( QWSServer::mouseHandler() && | 324 | if ( QWSServer::mouseHandler() && |
323 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | 325 | QWSServer::mouseHandler()-> inherits("QCalibratedMouseHandler") ) |
326 | { | ||
324 | if ( !QFile::exists ( "/etc/pointercal" )) { | 327 | if ( !QFile::exists ( "/etc/pointercal" )) { |
325 | // Make sure calibration widget starts on top. | 328 | // Make sure calibration widget starts on top. |
326 | Calibrate *cal = new Calibrate; | 329 | Calibrate *cal = new Calibrate; |
327 | cal-> exec ( ); | 330 | cal-> exec ( ); |
328 | delete cal; | 331 | delete cal; |
329 | } | 332 | } |
@@ -332,32 +335,31 @@ int login_main ( int argc, char **argv, pid_t ppid ) | |||
332 | LoginScreenSaver *saver = new LoginScreenSaver; | 335 | LoginScreenSaver *saver = new LoginScreenSaver; |
333 | 336 | ||
334 | saver-> setIntervals ( ); | 337 | saver-> setIntervals ( ); |
335 | QWSServer::setScreenSaver ( saver ); | 338 | QWSServer::setScreenSaver ( saver ); |
336 | saver-> restore ( ); | 339 | saver-> restore ( ); |
337 | 340 | ||
338 | |||
339 | LoginWindowImpl *lw = new LoginWindowImpl ( ); | 341 | LoginWindowImpl *lw = new LoginWindowImpl ( ); |
340 | app-> setMainWidget ( lw ); | 342 | app-> setMainWidget ( lw ); |
341 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 343 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), |
344 | app-> desktop ( )-> height ( )); | ||
342 | lw-> show ( ); | 345 | lw-> show ( ); |
343 | 346 | ||
344 | int rc = app-> exec ( ); | 347 | int rc = app-> exec ( ); |
345 | 348 | ||
346 | if ( app-> loginAs ( )) { | 349 | if ( app-> loginAs ( )) { |
347 | if ( app-> changeIdentity ( )) { | 350 | if ( app-> changeIdentity ( )) { |
348 | app-> login ( ); | 351 | app-> login ( ); |
349 | |||
350 | // if login succeeds, it never comes back | 352 | // if login succeeds, it never comes back |
351 | 353 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), | |
352 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); | 354 | LoginWindowImpl::tr( "Could not start Opie." )); |
353 | rc = 1; | 355 | rc = 1; |
354 | } | 356 | } |
355 | else { | 357 | else { |
356 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); | 358 | QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), |
359 | LoginWindowImpl::tr( "Could not switch to new user identity" )); | ||
357 | rc = 2; | 360 | rc = 2; |
358 | } | 361 | } |
359 | |||
360 | } | 362 | } |
361 | return rc; | 363 | return rc; |
362 | } | 364 | } |
363 | 365 | ||