-rw-r--r-- | core/opie-login/main.cpp | 124 |
1 files changed, 111 insertions, 13 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 +1,5 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | |||
3 | #include <sys/types.h> | ||
4 | #include <time.h> | ||
1 | #include <sys/time.h> | 5 | #include <sys/time.h> |
@@ -4,3 +8,2 @@ | |||
4 | #include <syslog.h> | 8 | #include <syslog.h> |
5 | #include <sys/types.h> | ||
6 | #include <sys/wait.h> | 9 | #include <sys/wait.h> |
@@ -9,2 +12,4 @@ | |||
9 | #include <signal.h> | 12 | #include <signal.h> |
13 | #include <getopt.h> | ||
14 | #include <string.h> | ||
10 | 15 | ||
@@ -18,4 +23,7 @@ | |||
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" |
@@ -26,5 +34,9 @@ using namespace Opie; | |||
26 | int login_main ( int argc, char **argv ); | 34 | int login_main ( int argc, char **argv ); |
27 | void sigusr1 ( int sig ); | 35 | void sigterm ( int sig ); |
28 | void exit_closelog ( ); | 36 | void exit_closelog ( ); |
29 | 37 | ||
38 | static struct option long_options [] = { | ||
39 | { "autologin", 1, 0, 'a' }, | ||
40 | { 0, 0, 0, 0 } | ||
41 | }; | ||
30 | 42 | ||
@@ -37,2 +49,17 @@ int main ( int argc, char **argv ) | |||
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 | ||
@@ -47,3 +74,3 @@ int main ( int argc, char **argv ) | |||
47 | 74 | ||
48 | ::signal ( SIGUSR1, sigusr1 ); | 75 | ::signal ( SIGTERM, sigterm ); |
49 | 76 | ||
@@ -56,5 +83,4 @@ int main ( int argc, char **argv ) | |||
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 | } |
@@ -62,6 +88,61 @@ int main ( int argc, char **argv ) | |||
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; | ||
65 | } | 97 | } |
66 | else { | 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 | } | ||
137 | } | ||
138 | else { | ||
139 | if ( autolog ) { | ||
140 | LoginApplication::setLoginAs ( autolog ); | ||
141 | |||
142 | if ( LoginApplication::changeIdentity ( )) | ||
143 | ::exit ( LoginApplication::login ( )); | ||
144 | else | ||
145 | ::exit ( 0 ); | ||
146 | } | ||
147 | else | ||
67 | ::exit ( login_main ( argc, argv )); | 148 | ::exit ( login_main ( argc, argv )); |
@@ -72,3 +153,3 @@ int main ( int argc, char **argv ) | |||
72 | 153 | ||
73 | void sigusr1 ( int /*sig*/ ) | 154 | void sigterm ( int /*sig*/ ) |
74 | { | 155 | { |
@@ -77,2 +158,3 @@ void sigusr1 ( int /*sig*/ ) | |||
77 | 158 | ||
159 | |||
78 | void exit_closelog ( ) | 160 | void exit_closelog ( ) |
@@ -183,2 +265,3 @@ private: | |||
183 | 265 | ||
266 | |||
184 | int login_main ( int argc, char **argv ) | 267 | int login_main ( int argc, char **argv ) |
@@ -186,6 +269,6 @@ int login_main ( int argc, char **argv ) | |||
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 | ||
@@ -210,7 +293,7 @@ int login_main ( int argc, char **argv ) | |||
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 | ||
@@ -218,2 +301,17 @@ int login_main ( int argc, char **argv ) | |||
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; |