summaryrefslogtreecommitdiff
path: root/core/opie-login/main.cpp
authorsandman <sandman>2002-10-14 00:59:28 (UTC)
committer sandman <sandman>2002-10-14 00:59:28 (UTC)
commit62c946c5a92ab11b5ad9495ff0bab158d38bce48 (patch) (unidiff)
tree01375a50aace755e808eef3103d3c4395530b4f1 /core/opie-login/main.cpp
parent72c07a1db3bad19fa227fc6fb482afe517d18095 (diff)
downloadopie-62c946c5a92ab11b5ad9495ff0bab158d38bce48.zip
opie-62c946c5a92ab11b5ad9495ff0bab158d38bce48.tar.gz
opie-62c946c5a92ab11b5ad9495ff0bab158d38bce48.tar.bz2
- last login name is saved
- wait image should be displayed right now - the qApp object is destroyed before the launcher is started -- this should prevent some semaphore permission problems - added a (very basic) crash handler - added a simple "respawned too fast" detection in case of qt/e fb problems - if opie-login is started with -a <user> or --autologin <user> it doesn't prompt for a username/password - instead it loads qpe directly using the specified user account So even if you are not running multiuser, you should now start qpe with: opie-login --autologin=root
Diffstat (limited to 'core/opie-login/main.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp126
1 files changed, 112 insertions, 14 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index df9451d..91610af 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,11 +1,16 @@
1#define _GNU_SOURCE
2
3#include <sys/types.h>
4#include <time.h>
1#include <sys/time.h> 5#include <sys/time.h>
2#include <sys/resource.h> 6#include <sys/resource.h>
3#include <unistd.h> 7#include <unistd.h>
4#include <syslog.h> 8#include <syslog.h>
5#include <sys/types.h>
6#include <sys/wait.h> 9#include <sys/wait.h>
7#include <stdio.h> 10#include <stdio.h>
8#include <stdlib.h> 11#include <stdlib.h>
9#include <signal.h> 12#include <signal.h>
13#include <getopt.h>
14#include <string.h>
10 15
11#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
@@ -17,6 +22,9 @@
17 22
18#include <qwindowsystem_qws.h> 23#include <qwindowsystem_qws.h>
19#include <qfile.h> 24#include <qmessagebox.h>
25#include <qlabel.h>
26#include <qtimer.h>
20 27
28#include "loginapplication.h"
21#include "loginwindowimpl.h" 29#include "loginwindowimpl.h"
22#include "calibrate.h" 30#include "calibrate.h"
@@ -25,7 +33,11 @@ using namespace Opie;
25 33
26int login_main ( int argc, char **argv ); 34int login_main ( int argc, char **argv );
27void sigusr1 ( int sig ); 35void sigterm ( int sig );
28void exit_closelog ( ); 36void exit_closelog ( );
29 37
38static struct option long_options [] = {
39 { "autologin", 1, 0, 'a' },
40 { 0, 0, 0, 0 }
41};
30 42
31 43
@@ -36,4 +48,19 @@ int main ( int argc, char **argv )
36 return 1; 48 return 1;
37 } 49 }
50 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and
51 ::setuid ( 0 ); // messes up things like config files
52
53 char *autolog = 0;
54 int c;
55 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) {
56 switch ( c ) {
57 case 'a':
58 autolog = optarg;
59 break;
60 default:
61 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] );
62 return 2;
63 }
64 }
38 65
39 //struct rlimit rl; 66 //struct rlimit rl;
@@ -46,5 +73,5 @@ int main ( int argc, char **argv )
46 ::setsid ( ); 73 ::setsid ( );
47 74
48 ::signal ( SIGUSR1, sigusr1 ); 75 ::signal ( SIGTERM, sigterm );
49 76
50 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 77 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
@@ -55,15 +82,69 @@ int main ( int argc, char **argv )
55 82
56 if ( child < 0 ) { 83 if ( child < 0 ) {
57 ::syslog ( LOG_ERR, "Could not fork process" ); 84 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
58 break; 85 break;
59
60 } 86 }
61 else if ( child > 0 ) { 87 else if ( child > 0 ) {
62 int status = 0; 88 int status = 0;
89 time_t started = ::time ( 0 );
63 90
64 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 91 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
92
93 if (( ::time ( 0 ) - started ) < 3 ) {
94 if ( autolog ) {
95 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
96 autolog = 0;
97 }
98 else {
99 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
100 break;
101 }
102 }
103 int killedbysig = 0;
104
105 if ( WIFSIGNALED( status )) {
106 switch ( WTERMSIG( status )) {
107 case SIGINT :
108 case SIGTERM:
109 case SIGKILL:
110 break;
111
112 default :
113 killedbysig = WTERMSIG( status );
114 break;
115 }
116 }
117 if ( killedbysig ) { // qpe was killed by an uncaught signal
118 qApp = 0;
119
120 QWSServer::setDesktopBackground ( QImage ( ));
121 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
122 app-> setFont ( QFont ( "Helvetica", 10 ));
123 app-> setStyle ( new QPEStyle ( ));
124
125 const char *sig = ::strsignal ( killedbysig );
126 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool );
127 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig ));
128 l-> setAlignment ( Qt::AlignCenter );
129 l-> move ( 0, 0 );
130 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
131 l-> show ( );
132 QTimer::singleShot ( 3000, app, SLOT( quit ( )));
133 app-> exec ( );
134 delete app;
135 qApp = 0;
136 }
65 } 137 }
66 else { 138 else {
67 ::exit ( login_main ( argc, argv )); 139 if ( autolog ) {
140 LoginApplication::setLoginAs ( autolog );
141
142 if ( LoginApplication::changeIdentity ( ))
143 ::exit ( LoginApplication::login ( ));
144 else
145 ::exit ( 0 );
146 }
147 else
148 ::exit ( login_main ( argc, argv ));
68 } 149 }
69 } 150 }
@@ -71,9 +152,10 @@ int main ( int argc, char **argv )
71} 152}
72 153
73void sigusr1 ( int /*sig*/ ) 154void sigterm ( int /*sig*/ )
74{ 155{
75 ::exit ( 0 ); 156 ::exit ( 0 );
76} 157}
77 158
159
78void exit_closelog ( ) 160void exit_closelog ( )
79{ 161{
@@ -182,11 +264,12 @@ private:
182 264
183 265
266
184int login_main ( int argc, char **argv ) 267int login_main ( int argc, char **argv )
185{ 268{
186 QWSServer::setDesktopBackground( QImage() ); 269 QWSServer::setDesktopBackground( QImage() );
187 QPEApplication app ( argc, argv, QApplication::GuiServer ); 270 LoginApplication *app = new LoginApplication ( argc, argv );
188 271
189 app. setFont ( QFont ( "Helvetica", 10 )); 272 app-> setFont ( QFont ( "Helvetica", 10 ));
190 app. setStyle ( new QPEStyle ( )); 273 app-> setStyle ( new QPEStyle ( ));
191 274
192 ODevice::inst ( )-> setSoftSuspend ( true ); 275 ODevice::inst ( )-> setSoftSuspend ( true );
@@ -209,12 +292,27 @@ int login_main ( int argc, char **argv )
209 292
210 LoginWindowImpl *lw = new LoginWindowImpl ( ); 293 LoginWindowImpl *lw = new LoginWindowImpl ( );
211 app. setMainWidget ( lw ); 294 app-> setMainWidget ( lw );
212 lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( )); 295 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
213 lw-> show ( ); 296 lw-> show ( );
214 297
215 int rc = app. exec ( ); 298 int rc = app-> exec ( );
216 299
217 ODevice::inst ( )-> setSoftSuspend ( false ); 300 ODevice::inst ( )-> setSoftSuspend ( false );
218 301
302 if ( app-> loginAs ( )) {
303 if ( app-> changeIdentity ( )) {
304 app-> login ( );
305
306 // if login succeeds, it never comes back
307
308 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start OPIE." ));
309 rc = 1;
310 }
311 else {
312 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" ));
313 rc = 2;
314 }
315
316 }
219 return rc; 317 return rc;
220} 318}