author | sandman <sandman> | 2002-10-14 00:59:28 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-14 00:59:28 (UTC) |
commit | 62c946c5a92ab11b5ad9495ff0bab158d38bce48 (patch) (unidiff) | |
tree | 01375a50aace755e808eef3103d3c4395530b4f1 /core/opie-login/main.cpp | |
parent | 72c07a1db3bad19fa227fc6fb482afe517d18095 (diff) | |
download | opie-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
-rw-r--r-- | core/opie-login/main.cpp | 126 |
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,109 +1,191 @@ | |||
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> |
12 | #include <qpe/qcopenvelope_qws.h> | 17 | #include <qpe/qcopenvelope_qws.h> |
13 | #include <qpe/qpestyle.h> | 18 | #include <qpe/qpestyle.h> |
14 | #include <qpe/power.h> | 19 | #include <qpe/power.h> |
15 | 20 | ||
16 | #include <opie/odevice.h> | 21 | #include <opie/odevice.h> |
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" |
23 | 31 | ||
24 | using namespace Opie; | 32 | using namespace Opie; |
25 | 33 | ||
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 | ||
31 | 43 | ||
32 | int main ( int argc, char **argv ) | 44 | int main ( int argc, char **argv ) |
33 | { | 45 | { |
34 | if ( ::geteuid ( ) != 0 ) { | 46 | if ( ::geteuid ( ) != 0 ) { |
35 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 47 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); |
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; |
40 | //::getrlimit ( RLIMIT_NOFILE, &rl ); | 67 | //::getrlimit ( RLIMIT_NOFILE, &rl ); |
41 | 68 | ||
42 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | 69 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) |
43 | // ::close ( i ); | 70 | // ::close ( i ); |
44 | 71 | ||
45 | ::setpgid ( 0, 0 ); | 72 | ::setpgid ( 0, 0 ); |
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 ); |
51 | ::atexit ( exit_closelog ); | 78 | ::atexit ( exit_closelog ); |
52 | 79 | ||
53 | while ( true ) { | 80 | while ( true ) { |
54 | pid_t child = ::fork ( ); | 81 | pid_t child = ::fork ( ); |
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 | } |
70 | return 0; | 151 | return 0; |
71 | } | 152 | } |
72 | 153 | ||
73 | void sigusr1 ( int /*sig*/ ) | 154 | void sigterm ( int /*sig*/ ) |
74 | { | 155 | { |
75 | ::exit ( 0 ); | 156 | ::exit ( 0 ); |
76 | } | 157 | } |
77 | 158 | ||
159 | |||
78 | void exit_closelog ( ) | 160 | void exit_closelog ( ) |
79 | { | 161 | { |
80 | ::closelog ( ); | 162 | ::closelog ( ); |
81 | } | 163 | } |
82 | 164 | ||
83 | 165 | ||
84 | class LoginScreenSaver : public QWSScreenSaver | 166 | class LoginScreenSaver : public QWSScreenSaver |
85 | { | 167 | { |
86 | public: | 168 | public: |
87 | LoginScreenSaver ( ) | 169 | LoginScreenSaver ( ) |
88 | { | 170 | { |
89 | m_lcd_status = true; | 171 | m_lcd_status = true; |
90 | 172 | ||
91 | m_backlight_bright = -1; | 173 | m_backlight_bright = -1; |
92 | m_backlight_forcedoff = false; | 174 | m_backlight_forcedoff = false; |
93 | 175 | ||
94 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 176 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
95 | ODevice::inst ( )-> setDisplayStatus ( true ); | 177 | ODevice::inst ( )-> setDisplayStatus ( true ); |
96 | } | 178 | } |
97 | void restore() | 179 | void restore() |
98 | { | 180 | { |
99 | if ( !m_lcd_status ) // We must have turned it off | 181 | if ( !m_lcd_status ) // We must have turned it off |
100 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 182 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
101 | 183 | ||
102 | setBacklight ( -3 ); | 184 | setBacklight ( -3 ); |
103 | } | 185 | } |
104 | bool save( int level ) | 186 | bool save( int level ) |
105 | { | 187 | { |
106 | switch ( level ) { | 188 | switch ( level ) { |
107 | case 0: | 189 | case 0: |
108 | if ( backlight() > 1 ) | 190 | if ( backlight() > 1 ) |
109 | setBacklight( 1 ); // lowest non-off | 191 | setBacklight( 1 ); // lowest non-off |
@@ -152,70 +234,86 @@ public: | |||
152 | void setBacklight ( int bright ) | 234 | void setBacklight ( int bright ) |
153 | { | 235 | { |
154 | if ( bright == -3 ) { | 236 | if ( bright == -3 ) { |
155 | // Forced on | 237 | // Forced on |
156 | m_backlight_forcedoff = false; | 238 | m_backlight_forcedoff = false; |
157 | bright = -1; | 239 | bright = -1; |
158 | } | 240 | } |
159 | if ( m_backlight_forcedoff && bright != -2 ) | 241 | if ( m_backlight_forcedoff && bright != -2 ) |
160 | return ; | 242 | return ; |
161 | if ( bright == -2 ) { | 243 | if ( bright == -2 ) { |
162 | // Toggle between off and on | 244 | // Toggle between off and on |
163 | bright = m_backlight_bright ? 0 : -1; | 245 | bright = m_backlight_bright ? 0 : -1; |
164 | m_backlight_forcedoff = !bright; | 246 | m_backlight_forcedoff = !bright; |
165 | } | 247 | } |
166 | 248 | ||
167 | m_backlight_bright = bright; | 249 | m_backlight_bright = bright; |
168 | 250 | ||
169 | bright = backlight ( ); | 251 | bright = backlight ( ); |
170 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); | 252 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); |
171 | 253 | ||
172 | m_backlight_bright = bright; | 254 | m_backlight_bright = bright; |
173 | } | 255 | } |
174 | 256 | ||
175 | private: | 257 | private: |
176 | bool m_lcd_status; | 258 | bool m_lcd_status; |
177 | 259 | ||
178 | int m_backlight_bright; | 260 | int m_backlight_bright; |
179 | bool m_backlight_forcedoff; | 261 | bool m_backlight_forcedoff; |
180 | }; | 262 | }; |
181 | 263 | ||
182 | 264 | ||
183 | 265 | ||
266 | |||
184 | int login_main ( int argc, char **argv ) | 267 | int 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 ); |
193 | 276 | ||
194 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 277 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
195 | if ( !QFile::exists ( "/etc/pointercal" )) { | 278 | if ( !QFile::exists ( "/etc/pointercal" )) { |
196 | // Make sure calibration widget starts on top. | 279 | // Make sure calibration widget starts on top. |
197 | Calibrate *cal = new Calibrate; | 280 | Calibrate *cal = new Calibrate; |
198 | cal-> exec ( ); | 281 | cal-> exec ( ); |
199 | delete cal; | 282 | delete cal; |
200 | } | 283 | } |
201 | #endif | 284 | #endif |
202 | 285 | ||
203 | LoginScreenSaver *saver = new LoginScreenSaver; | 286 | LoginScreenSaver *saver = new LoginScreenSaver; |
204 | 287 | ||
205 | saver-> setIntervals ( ); | 288 | saver-> setIntervals ( ); |
206 | QWSServer::setScreenSaver ( saver ); | 289 | QWSServer::setScreenSaver ( saver ); |
207 | saver-> restore ( ); | 290 | saver-> restore ( ); |
208 | 291 | ||
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 | } |
221 | 319 | ||