-rw-r--r-- | core/opie-login/main.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 674829d..81f4d1e 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -41,134 +41,139 @@ | |||
41 | #include <string.h> | 41 | #include <string.h> |
42 | 42 | ||
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/qcopenvelope_qws.h> | 44 | #include <qpe/qcopenvelope_qws.h> |
45 | #include <qpe/qpestyle.h> | 45 | #include <qpe/qpestyle.h> |
46 | #include <qpe/power.h> | 46 | #include <qpe/power.h> |
47 | #include <qpe/config.h> | 47 | #include <qpe/config.h> |
48 | 48 | ||
49 | #include <opie/odevice.h> | 49 | #include <opie/odevice.h> |
50 | 50 | ||
51 | #include <qwindowsystem_qws.h> | 51 | #include <qwindowsystem_qws.h> |
52 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
53 | #include <qlabel.h> | 53 | #include <qlabel.h> |
54 | #include <qtimer.h> | 54 | #include <qtimer.h> |
55 | #include <qfile.h> | 55 | #include <qfile.h> |
56 | 56 | ||
57 | #include "loginapplication.h" | 57 | #include "loginapplication.h" |
58 | #include "loginwindowimpl.h" | 58 | #include "loginwindowimpl.h" |
59 | #include "calibrate.h" | 59 | #include "calibrate.h" |
60 | 60 | ||
61 | using namespace Opie; | 61 | using namespace Opie; |
62 | 62 | ||
63 | int login_main ( int argc, char **argv, pid_t ppid ); | 63 | int login_main ( int argc, char **argv, pid_t ppid ); |
64 | void sigterm ( int sig ); | 64 | void sigterm ( int sig ); |
65 | void sigint ( int sig ); | ||
65 | void exit_closelog ( ); | 66 | void exit_closelog ( ); |
66 | 67 | ||
67 | static struct option long_options [] = { | 68 | static struct option long_options [] = { |
68 | { "autologin", 1, 0, 'a' }, | 69 | { "autologin", 1, 0, 'a' }, |
69 | { 0, 0, 0, 0 } | 70 | { 0, 0, 0, 0 } |
70 | }; | 71 | }; |
71 | 72 | ||
72 | 73 | ||
73 | int main ( int argc, char **argv ) | 74 | int main ( int argc, char **argv ) |
74 | { | 75 | { |
75 | pid_t ppid = ::getpid ( ); | 76 | pid_t ppid = ::getpid ( ); |
76 | 77 | ||
77 | |||
78 | if ( ::geteuid ( ) != 0 ) { | 78 | if ( ::geteuid ( ) != 0 ) { |
79 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 79 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); |
80 | return 1; | 80 | return 1; |
81 | } | 81 | } |
82 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 82 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and |
83 | ::setuid ( 0 ); // messes up things like config files | 83 | ::setuid ( 0 ); // messes up things like config files |
84 | 84 | ||
85 | char *autolog = 0; | 85 | char *autolog = 0; |
86 | int c; | 86 | int c; |
87 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { | 87 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { |
88 | switch ( c ) { | 88 | switch ( c ) { |
89 | case 'a': | 89 | case 'a': |
90 | autolog = optarg; | 90 | autolog = optarg; |
91 | break; | 91 | break; |
92 | default: | 92 | default: |
93 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); | 93 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); |
94 | return 2; | 94 | return 2; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | //struct rlimit rl; | 98 | //struct rlimit rl; |
99 | //::getrlimit ( RLIMIT_NOFILE, &rl ); | 99 | //::getrlimit ( RLIMIT_NOFILE, &rl ); |
100 | 100 | ||
101 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | 101 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) |
102 | // ::close ( i ); | 102 | // ::close ( i ); |
103 | 103 | ||
104 | ::setpgid ( 0, 0 ); | 104 | ::setpgid ( 0, 0 ); |
105 | ::setsid ( ); | 105 | ::setsid ( ); |
106 | 106 | ||
107 | ::signal ( SIGTERM, sigterm ); | 107 | ::signal ( SIGTERM, sigterm ); |
108 | ::signal ( SIGINT, sigterm ); | ||
108 | 109 | ||
109 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); | 110 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); |
110 | ::atexit ( exit_closelog ); | 111 | ::atexit ( exit_closelog ); |
111 | 112 | ||
112 | while ( true ) { | 113 | while ( true ) { |
113 | pid_t child = ::fork ( ); | 114 | pid_t child = ::fork ( ); |
114 | 115 | ||
115 | if ( child < 0 ) { | 116 | if ( child < 0 ) { |
116 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); | 117 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); |
117 | break; | 118 | break; |
118 | } | 119 | } |
119 | else if ( child > 0 ) { | 120 | else if ( child > 0 ) { |
120 | int status = 0; | 121 | int status = 0; |
121 | time_t started = ::time ( 0 ); | 122 | time_t started = ::time ( 0 ); |
122 | 123 | ||
123 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 124 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } |
124 | 125 | ||
126 | LoginApplication::logout ( ); | ||
127 | |||
125 | if (( ::time ( 0 ) - started ) < 3 ) { | 128 | if (( ::time ( 0 ) - started ) < 3 ) { |
126 | if ( autolog ) { | 129 | if ( autolog ) { |
127 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 130 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
128 | autolog = 0; | 131 | autolog = 0; |
129 | } | 132 | } |
130 | else { | 133 | else { |
131 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); | 134 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); |
132 | break; | 135 | break; |
133 | } | 136 | } |
134 | } | 137 | } |
135 | int killedbysig = 0; | 138 | int killedbysig = 0; |
136 | 139 | ||
137 | if ( WIFSIGNALED( status )) { | 140 | if ( WIFSIGNALED( status )) { |
138 | switch ( WTERMSIG( status )) { | 141 | switch ( WTERMSIG( status )) { |
139 | case SIGINT : | 142 | case SIGINT : |
140 | case SIGTERM: | 143 | case SIGTERM: |
141 | case SIGKILL: | 144 | case SIGKILL: |
142 | break; | 145 | break; |
143 | 146 | ||
144 | default : | 147 | default : |
145 | killedbysig = WTERMSIG( status ); | 148 | killedbysig = WTERMSIG( status ); |
146 | break; | 149 | break; |
147 | } | 150 | } |
148 | } | 151 | } |
149 | if ( killedbysig ) { // qpe was killed by an uncaught signal | 152 | if ( killedbysig ) { // qpe was killed by an uncaught signal |
150 | qApp = 0; | 153 | qApp = 0; |
154 | |||
155 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); | ||
151 | 156 | ||
152 | QWSServer::setDesktopBackground ( QImage ( )); | 157 | QWSServer::setDesktopBackground ( QImage ( )); |
153 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); | 158 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); |
154 | app-> setFont ( QFont ( "Helvetica", 10 )); | 159 | app-> setFont ( QFont ( "Helvetica", 10 )); |
155 | app-> setStyle ( new QPEStyle ( )); | 160 | app-> setStyle ( new QPEStyle ( )); |
156 | 161 | ||
157 | const char *sig = ::strsignal ( killedbysig ); | 162 | const char *sig = ::strsignal ( killedbysig ); |
158 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); | 163 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); |
159 | l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); | 164 | l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); |
160 | l-> setAlignment ( Qt::AlignCenter ); | 165 | l-> setAlignment ( Qt::AlignCenter ); |
161 | l-> move ( 0, 0 ); | 166 | l-> move ( 0, 0 ); |
162 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 167 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
163 | l-> show ( ); | 168 | l-> show ( ); |
164 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); | 169 | QTimer::singleShot ( 3000, app, SLOT( quit ( ))); |
165 | app-> exec ( ); | 170 | app-> exec ( ); |
166 | delete app; | 171 | delete app; |
167 | qApp = 0; | 172 | qApp = 0; |
168 | } | 173 | } |
169 | } | 174 | } |
170 | else { | 175 | else { |
171 | if ( !autolog ) { | 176 | if ( !autolog ) { |
172 | Config cfg ( "opie-login" ); | 177 | Config cfg ( "opie-login" ); |
173 | cfg. setGroup ( "General" ); | 178 | cfg. setGroup ( "General" ); |
174 | QString user = cfg. readEntry ( "AutoLogin" ); | 179 | QString user = cfg. readEntry ( "AutoLogin" ); |
@@ -282,55 +287,58 @@ public: | |||
282 | if ( m_backlight_forcedoff && bright != -2 ) | 287 | if ( m_backlight_forcedoff && bright != -2 ) |
283 | return ; | 288 | return ; |
284 | if ( bright == -2 ) { | 289 | if ( bright == -2 ) { |
285 | // Toggle between off and on | 290 | // Toggle between off and on |
286 | bright = m_backlight_bright ? 0 : -1; | 291 | bright = m_backlight_bright ? 0 : -1; |
287 | m_backlight_forcedoff = !bright; | 292 | m_backlight_forcedoff = !bright; |
288 | } | 293 | } |
289 | 294 | ||
290 | m_backlight_bright = bright; | 295 | m_backlight_bright = bright; |
291 | 296 | ||
292 | bright = backlight ( ); | 297 | bright = backlight ( ); |
293 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); | 298 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); |
294 | 299 | ||
295 | m_backlight_bright = bright; | 300 | m_backlight_bright = bright; |
296 | } | 301 | } |
297 | 302 | ||
298 | private: | 303 | private: |
299 | bool m_lcd_status; | 304 | bool m_lcd_status; |
300 | 305 | ||
301 | int m_backlight_bright; | 306 | int m_backlight_bright; |
302 | bool m_backlight_forcedoff; | 307 | bool m_backlight_forcedoff; |
303 | }; | 308 | }; |
304 | 309 | ||
305 | 310 | ||
311 | namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting | ||
306 | 312 | ||
307 | 313 | ||
308 | int login_main ( int argc, char **argv, pid_t ppid ) | 314 | int login_main ( int argc, char **argv, pid_t ppid ) |
309 | { | 315 | { |
310 | QWSServer::setDesktopBackground( QImage() ); | 316 | QWSServer::setDesktopBackground( QImage() ); |
311 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 317 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
312 | 318 | ||
319 | Opie::force_appearance = 0; | ||
320 | |||
313 | app-> setFont ( QFont ( "Helvetica", 10 )); | 321 | app-> setFont ( QFont ( "Helvetica", 10 )); |
314 | app-> setStyle ( new QPEStyle ( )); | 322 | app-> setStyle ( new QPEStyle ( )); |
315 | 323 | ||
316 | ODevice::inst ( )-> setSoftSuspend ( true ); | 324 | ODevice::inst ( )-> setSoftSuspend ( true ); |
317 | 325 | ||
318 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 326 | #if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
319 | if ( !QFile::exists ( "/etc/pointercal" )) { | 327 | if ( !QFile::exists ( "/etc/pointercal" )) { |
320 | // Make sure calibration widget starts on top. | 328 | // Make sure calibration widget starts on top. |
321 | Calibrate *cal = new Calibrate; | 329 | Calibrate *cal = new Calibrate; |
322 | cal-> exec ( ); | 330 | cal-> exec ( ); |
323 | delete cal; | 331 | delete cal; |
324 | } | 332 | } |
325 | #endif | 333 | #endif |
326 | 334 | ||
327 | LoginScreenSaver *saver = new LoginScreenSaver; | 335 | LoginScreenSaver *saver = new LoginScreenSaver; |
328 | 336 | ||
329 | saver-> setIntervals ( ); | 337 | saver-> setIntervals ( ); |
330 | QWSServer::setScreenSaver ( saver ); | 338 | QWSServer::setScreenSaver ( saver ); |
331 | saver-> restore ( ); | 339 | saver-> restore ( ); |
332 | 340 | ||
333 | 341 | ||
334 | LoginWindowImpl *lw = new LoginWindowImpl ( ); | 342 | LoginWindowImpl *lw = new LoginWindowImpl ( ); |
335 | app-> setMainWidget ( lw ); | 343 | app-> setMainWidget ( lw ); |
336 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 344 | lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |