summaryrefslogtreecommitdiff
authorerik <erik>2007-01-29 21:38:26 (UTC)
committer erik <erik>2007-01-29 21:38:26 (UTC)
commit597643805ce89c1237035e7f38ec953cfc0d080f (patch) (unidiff)
tree9ec8465a1a1c34346e7ee9c40c2d810910f66162
parent777cace646507cf4222f0a6d5beb2cd44ec45a0a (diff)
downloadopie-597643805ce89c1237035e7f38ec953cfc0d080f.zip
opie-597643805ce89c1237035e7f38ec953cfc0d080f.tar.gz
opie-597643805ce89c1237035e7f38ec953cfc0d080f.tar.bz2
Reformat according to current Opie style.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp466
1 files changed, 234 insertions, 232 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
@@ -68,58 +68,63 @@ int main ( int argc, char **argv )
68 int userExited = 0; 68 int userExited = 0;
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 );
86
87 ::setpgid ( 0, 0 );
88 ::setsid ( );
89
90 ::signal ( SIGTERM, sigterm );
91 ::signal ( SIGINT, sigterm );
92
93 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
94 ::atexit ( exit_closelog );
95
96 const char* autolog = 0;
97 Config c( "opie-login" );
98 c.setGroup( "autologin" );
99 QString entry = c.readEntry( "user", "" );
100 if ( !entry.isEmpty() )
101 autolog = ::strdup( (const char*) entry );
102
103 while ( true ) {
104 pid_t child = ::fork ( );
83 105
84 ::setpgid ( 0, 0 ); 106 if ( child < 0 ) {
85 ::setsid ( ); 107 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
108 break;
109 }
110 else if ( child > 0 ) {
111 int status = 0;
112 time_t started = ::time ( 0 );
86 113
87 ::signal ( SIGTERM, sigterm ); 114 while ( ::waitpid ( child, &status, 0 ) < 0 )
88 ::signal ( SIGINT, sigterm ); 115 ;
89 116
90 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 117 LoginApplication::logout ( );
91 ::atexit ( exit_closelog );
92 118
93 const char* autolog = 0; 119 if (( ::time ( 0 ) - started ) < 3 ) {
94 Config c( "opie-login" ); 120 if ( autolog ) {
95 c.setGroup( "autologin" ); 121 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
96 QString entry = c.readEntry( "user", "" ); 122 autolog = 0;
97 if ( !entry.isEmpty() ) autolog = ::strdup( (const char*) entry ); 123 }
98 124 else {
99 while ( true ) { 125 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
100 pid_t child = ::fork ( ); 126 break;
101 127 }
102 if ( child < 0 ) { 128 }
103 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 129 int killedbysig = 0;
104 break;
105 }
106 else if ( child > 0 ) {
107 int status = 0;
108 time_t started = ::time ( 0 );
109
110 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
111
112 LoginApplication::logout ( );
113
114 if (( ::time ( 0 ) - started ) < 3 ) {
115 if ( autolog ) {
116 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
117 autolog = 0;
118 }
119 else {
120 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
121 break;
122 }
123 }
124 int killedbysig = 0;
125 userExited=0; 130 userExited=0;
@@ -131,54 +136,53 @@ int main ( int argc, char **argv )
131 136
132 if ( WIFSIGNALED( status )) { 137 if ( WIFSIGNALED( status )) {
133 switch ( WTERMSIG( status )) { 138 switch ( WTERMSIG( status )) {
134 case SIGTERM: 139 case SIGTERM:
135 case SIGINT : 140 case SIGINT :
136 case SIGKILL: 141 case SIGKILL:
137 break; 142 break;
138 143
139 default : 144 default :
140 killedbysig = WTERMSIG( status ); 145 killedbysig = WTERMSIG( status );
141 break; 146 break;
142 } 147 }
143 } 148 }
144 if ( killedbysig ) { // qpe was killed by an uncaught signal 149 if ( killedbysig ) { // qpe was killed by an uncaught signal
145 qApp = 0; 150 qApp = 0;
146 151
147 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); 152 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig );
148 153
149 QWSServer::setDesktopBackground ( QImage ( )); 154 QWSServer::setDesktopBackground ( QImage ( ));
150 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); 155 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
151 app-> setFont ( QFont ( "Helvetica", 10 )); 156 app-> setFont ( QFont ( "Helvetica", 10 ));
152 app-> setStyle ( new QPEStyle ( )); 157 app-> setStyle ( new QPEStyle ( ));
153 158
154#ifndef __UCLIBC__ 159#ifndef __UCLIBC__
155 const char *sig = ::sys_siglist[killedbysig]; 160 const char *sig = ::sys_siglist[killedbysig];
156#else 161#else
157 const char *sig = ::strsignal ( killedbysig ); 162 const char *sig = ::strsignal ( killedbysig );
158#endif 163#endif
159 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 );
160 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 ));
161 l-> setAlignment ( Qt::AlignCenter ); 166 l-> setAlignment ( Qt::AlignCenter );
162 l-> move ( 0, 0 ); 167 l-> move ( 0, 0 );
163 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 168 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
164 l-> show ( ); 169 l-> show ( );
165 QTimer::singleShot ( 3000, app, SLOT( quit())); 170 QTimer::singleShot ( 3000, app, SLOT( quit()));
166 app-> exec ( ); 171 app-> exec ( );
167 delete app; 172 delete app;
168 qApp = 0; 173 qApp = 0;
169 } 174 }
170 } 175 }
171 else { 176 else {
172 if ( !autolog ) { 177 if ( !autolog ) {
173 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf"; 178 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf";
174 Config cfg ( confFile, Config::File ); 179 Config cfg ( confFile, Config::File );
175 cfg. setGroup ( "General" ); 180 cfg. setGroup ( "General" );
176 QString user = cfg. readEntry ( "AutoLogin" ); 181 QString user = cfg. readEntry ( "AutoLogin" );
177
178 if ( !user. isEmpty ( ))
179 autolog = ::strdup ( user. latin1 ( ));
180 }
181 182
182 if ( autolog && !userExited ) { 183 if ( !user. isEmpty ( ))
184 autolog = ::strdup ( user. latin1 ( ));
185 }
183 186
187 if ( autolog && !userExited ) {
184 QWSServer::setDesktopBackground( QImage() ); 188 QWSServer::setDesktopBackground( QImage() );
@@ -188,14 +192,13 @@ int main ( int argc, char **argv )
188 192
189 193 if ( LoginApplication::changeIdentity ( ))
190 if ( LoginApplication::changeIdentity ( )) 194 ::exit ( LoginApplication::login ( ));
191 ::exit ( LoginApplication::login ( )); 195 else
192 else 196 ::exit ( 0 );
193 ::exit ( 0 ); 197 }
194 } 198 else {
195 else { 199 ::exit ( login_main ( argc, argv, ppid ));
196 ::exit ( login_main ( argc, argv, ppid ));
197 } 200 }
198 } 201 }
199 } 202 }
200 return 0; 203 return 0;
201} 204}
@@ -204,3 +207,3 @@ void sigterm ( int /*sig*/ )
204{ 207{
205 ::exit ( 0 ); 208 ::exit ( 0 );
206} 209}
@@ -210,3 +213,3 @@ void exit_closelog ( )
210{ 213{
211 ::closelog ( ); 214 ::closelog ( );
212} 215}
@@ -216,147 +219,146 @@ class LoginScreenSaver : public QWSScreenSaver
216{ 219{
217public: 220 public:
218 LoginScreenSaver ( ) 221 LoginScreenSaver ( )
219 { 222 {
220 m_lcd_status = true; 223 m_lcd_status = true;
221 224
222 m_backlight_bright = -1; 225 m_backlight_bright = -1;
223 m_backlight_forcedoff = false; 226 m_backlight_forcedoff = false;
224 227
225 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 228 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
226 ODevice::inst ( )-> setDisplayStatus ( true ); 229 ODevice::inst ( )-> setDisplayStatus ( true );
227 }
228 void restore()
229 {
230 if ( !m_lcd_status ) // We must have turned it off
231 ODevice::inst ( ) -> setDisplayStatus ( true );
232
233 setBacklight ( -3 );
234 }
235 bool save( int level )
236 {
237 switch ( level ) {
238 case 0:
239 if ( backlight() > 1 )
240 setBacklight( 1 ); // lowest non-off
241 return true;
242 break;
243 case 1:
244 setBacklight( 0 ); // off
245 return true;
246 break;
247 case 2:
248 // We're going to suspend the whole machine
249 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
250 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
251 return true;
252 } 230 }
253 break; 231 void restore()
254 } 232 {
255 return false; 233 if ( !m_lcd_status ) // We must have turned it off
256 } 234 ODevice::inst ( ) -> setDisplayStatus ( true );
257
258private:
259public:
260 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
261 {
262 int v [4];
263
264 v [ 0 ] = QMAX( 1000 * i1, 100 );
265 v [ 1 ] = QMAX( 1000 * i2, 100 );
266 v [ 2 ] = QMAX( 1000 * i3, 100 );
267 v [ 3 ] = 0;
268
269 if ( !i1 && !i2 && !i3 )
270 QWSServer::setScreenSaverInterval ( 0 );
271 else
272 QWSServer::setScreenSaverIntervals ( v );
273 }
274
275 int backlight ( )
276 {
277 if ( m_backlight_bright == -1 )
278 m_backlight_bright = 255;
279
280 return m_backlight_bright;
281 }
282
283 void setBacklight ( int bright )
284 {
285 if ( bright == -3 ) {
286 // Forced on
287 m_backlight_forcedoff = false;
288 bright = -1;
289 }
290 if ( m_backlight_forcedoff && bright != -2 )
291 return ;
292 if ( bright == -2 ) {
293 // Toggle between off and on
294 bright = m_backlight_bright ? 0 : -1;
295 m_backlight_forcedoff = !bright;
296 }
297 235
298 m_backlight_bright = bright; 236 setBacklight ( -3 );
237 }
238 bool save( int level )
239 {
240 switch ( level ) {
241 case 0:
242 if ( backlight() > 1 )
243 setBacklight( 1 ); // lowest non-off
244 return true;
245 break;
246 case 1:
247 setBacklight( 0 ); // off
248 return true;
249 break;
250 case 2:
251 default:
252 // We're going to suspend the whole machine
253 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
254 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
255 return true;
256 }
257 break;
258 }
259 return false;
260 }
299 261
300 bright = backlight ( ); 262 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
301 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 263 {
264 int v [4];
302 265
303 m_backlight_bright = bright; 266 v [ 0 ] = QMAX( 1000 * i1, 100 );
304 } 267 v [ 1 ] = QMAX( 1000 * i2, 100 );
268 v [ 2 ] = QMAX( 1000 * i3, 100 );
269 v [ 3 ] = 0;
305 270
306private: 271 if ( !i1 && !i2 && !i3 )
307 bool m_lcd_status; 272 QWSServer::setScreenSaverInterval ( 0 );
273 else
274 QWSServer::setScreenSaverIntervals ( v );
275 }
308 276
309 int m_backlight_bright; 277 int backlight ( )
310 bool m_backlight_forcedoff; 278 {
311}; 279 if ( m_backlight_bright == -1 )
280 m_backlight_bright = 255;
312 281
282 return m_backlight_bright;
283 }
313 284
314int login_main ( int argc, char **argv, pid_t ppid ) 285 void setBacklight ( int bright )
315{ 286 {
316 QWSServer::setDesktopBackground( QImage() ); 287 if ( bright == -3 ) {
317 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 288 // Forced on
289 m_backlight_forcedoff = false;
290 bright = -1;
291 }
292 if ( m_backlight_forcedoff && bright != -2 )
293 return;
318 294
319 app-> setFont ( QFont ( "Helvetica", 10 )); 295 if ( bright == -2 ) {
320 app-> setStyle ( new QPEStyle ( )); 296 // Toggle between off and on
297 bright = m_backlight_bright ? 0 : -1;
298 m_backlight_forcedoff = !bright;
299 }
321 300
322 if ( QWSServer::mouseHandler() && 301 m_backlight_bright = bright;
323 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
324 if ( !QFile::exists ( "/etc/pointercal" )) {
325 // Make sure calibration widget starts on top.
326 Calibrate *cal = new Calibrate;
327 cal-> exec ( );
328 delete cal;
329 }
330 }
331 302
332 LoginScreenSaver *saver = new LoginScreenSaver; 303 bright = backlight ( );
304 ODevice::inst ( ) -> setDisplayBrightness ( bright );
333 305
334 saver-> setIntervals ( ); 306 m_backlight_bright = bright;
335 QWSServer::setScreenSaver ( saver ); 307 }
336 saver-> restore ( );
337 308
309 private:
310 bool m_lcd_status;
311 int m_backlight_bright;
312 bool m_backlight_forcedoff;
313};
338 314
339 LoginWindowImpl *lw = new LoginWindowImpl ( );
340 app-> setMainWidget ( lw );
341 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
342 lw-> show ( );
343 315
344 int rc = app-> exec ( ); 316int login_main ( int argc, char **argv, pid_t ppid )
317{
318 QWSServer::setDesktopBackground( QImage() );
319 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
320
321 app-> setFont ( QFont ( "Helvetica", 10 ));
322 app-> setStyle ( new QPEStyle ( ));
323
324 if ( QWSServer::mouseHandler() &&
325 QWSServer::mouseHandler()-> inherits("QCalibratedMouseHandler") )
326 {
327 if ( !QFile::exists ( "/etc/pointercal" )) {
328 // Make sure calibration widget starts on top.
329 Calibrate *cal = new Calibrate;
330 cal-> exec ( );
331 delete cal;
332 }
333 }
334
335 LoginScreenSaver *saver = new LoginScreenSaver;
345 336
346 if ( app-> loginAs ( )) { 337 saver-> setIntervals ( );
347 if ( app-> changeIdentity ( )) { 338 QWSServer::setScreenSaver ( saver );
348 app-> login ( ); 339 saver-> restore ( );
349 340
350 // if login succeeds, it never comes back 341 LoginWindowImpl *lw = new LoginWindowImpl ( );
342 app-> setMainWidget ( lw );
343 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ),
344 app-> desktop ( )-> height ( ));
345 lw-> show ( );
351 346
352 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); 347 int rc = app-> exec ( );
353 rc = 1;
354 }
355 else {
356 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" ));
357 rc = 2;
358 }
359 348
360 } 349 if ( app-> loginAs ( )) {
361 return rc; 350 if ( app-> changeIdentity ( )) {
351 app-> login ( );
352 // if login succeeds, it never comes back
353 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ),
354 LoginWindowImpl::tr( "Could not start Opie." ));
355 rc = 1;
356 }
357 else {
358 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ),
359 LoginWindowImpl::tr( "Could not switch to new user identity" ));
360 rc = 2;
361 }
362 }
363 return rc;
362} 364}