summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-14 23:33:00 (UTC)
committer sandman <sandman>2002-10-14 23:33:00 (UTC)
commitb3ad9188f40cf6e3c170cc48be3ed180d509036f (patch) (unidiff)
tree04978e0fb1bd258244a6578a27ab09e3c6843d75
parentc7aed90e02d06502dff04043103c5db0883cc011 (diff)
downloadopie-b3ad9188f40cf6e3c170cc48be3ed180d509036f.zip
opie-b3ad9188f40cf6e3c170cc48be3ed180d509036f.tar.gz
opie-b3ad9188f40cf6e3c170cc48be3ed180d509036f.tar.bz2
autologin feature can now (also) be configured by:
~/Settings/opie-login.conf: [General] AutoLogin=<user> command line options override config file settings !
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index 8f795e3..579a93a 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,271 +1,281 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can 5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that 12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details. 17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .: 18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU 19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file; 20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the 21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc., 22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, 23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. 24 Boston, MA 02111-1307, USA.
25 25
26*/ 26*/
27 27
28#define _GNU_SOURCE 28#define _GNU_SOURCE
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31#include <time.h> 31#include <time.h>
32#include <sys/time.h> 32#include <sys/time.h>
33#include <sys/resource.h> 33#include <sys/resource.h>
34#include <unistd.h> 34#include <unistd.h>
35#include <syslog.h> 35#include <syslog.h>
36#include <sys/wait.h> 36#include <sys/wait.h>
37#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <signal.h> 39#include <signal.h>
40#include <getopt.h> 40#include <getopt.h>
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 48
48#include <opie/odevice.h> 49#include <opie/odevice.h>
49 50
50#include <qwindowsystem_qws.h> 51#include <qwindowsystem_qws.h>
51#include <qmessagebox.h> 52#include <qmessagebox.h>
52#include <qlabel.h> 53#include <qlabel.h>
53#include <qtimer.h> 54#include <qtimer.h>
54#include <qfile.h> 55#include <qfile.h>
55 56
56#include "loginapplication.h" 57#include "loginapplication.h"
57#include "loginwindowimpl.h" 58#include "loginwindowimpl.h"
58#include "calibrate.h" 59#include "calibrate.h"
59 60
60using namespace Opie; 61using namespace Opie;
61 62
62int login_main ( int argc, char **argv ); 63int login_main ( int argc, char **argv );
63void sigterm ( int sig ); 64void sigterm ( int sig );
64void exit_closelog ( ); 65void exit_closelog ( );
65 66
66static struct option long_options [] = { 67static struct option long_options [] = {
67 { "autologin", 1, 0, 'a' }, 68 { "autologin", 1, 0, 'a' },
68 { 0, 0, 0, 0 } 69 { 0, 0, 0, 0 }
69}; 70};
70 71
71 72
72int main ( int argc, char **argv ) 73int main ( int argc, char **argv )
73{ 74{
74 if ( ::geteuid ( ) != 0 ) { 75 if ( ::geteuid ( ) != 0 ) {
75 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); 76 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
76 return 1; 77 return 1;
77 } 78 }
78 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and 79 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and
79 ::setuid ( 0 ); // messes up things like config files 80 ::setuid ( 0 ); // messes up things like config files
80 81
81 char *autolog = 0; 82 char *autolog = 0;
82 int c; 83 int c;
83 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { 84 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) {
84 switch ( c ) { 85 switch ( c ) {
85 case 'a': 86 case 'a':
86 autolog = optarg; 87 autolog = optarg;
87 break; 88 break;
88 default: 89 default:
89 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); 90 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] );
90 return 2; 91 return 2;
91 } 92 }
92 } 93 }
93 94
94 //struct rlimit rl; 95 //struct rlimit rl;
95 //::getrlimit ( RLIMIT_NOFILE, &rl ); 96 //::getrlimit ( RLIMIT_NOFILE, &rl );
96 97
97 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 98 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
98 // ::close ( i ); 99 // ::close ( i );
99 100
100 ::setpgid ( 0, 0 ); 101 ::setpgid ( 0, 0 );
101 ::setsid ( ); 102 ::setsid ( );
102 103
103 ::signal ( SIGTERM, sigterm ); 104 ::signal ( SIGTERM, sigterm );
104 105
105 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 106 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
106 ::atexit ( exit_closelog ); 107 ::atexit ( exit_closelog );
107 108
108 while ( true ) { 109 while ( true ) {
109 pid_t child = ::fork ( ); 110 pid_t child = ::fork ( );
110 111
111 if ( child < 0 ) { 112 if ( child < 0 ) {
112 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 113 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
113 break; 114 break;
114 } 115 }
115 else if ( child > 0 ) { 116 else if ( child > 0 ) {
116 int status = 0; 117 int status = 0;
117 time_t started = ::time ( 0 ); 118 time_t started = ::time ( 0 );
118 119
119 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 120 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
120 121
121 if (( ::time ( 0 ) - started ) < 3 ) { 122 if (( ::time ( 0 ) - started ) < 3 ) {
122 if ( autolog ) { 123 if ( autolog ) {
123 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); 124 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
124 autolog = 0; 125 autolog = 0;
125 } 126 }
126 else { 127 else {
127 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); 128 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
128 break; 129 break;
129 } 130 }
130 } 131 }
131 int killedbysig = 0; 132 int killedbysig = 0;
132 133
133 if ( WIFSIGNALED( status )) { 134 if ( WIFSIGNALED( status )) {
134 switch ( WTERMSIG( status )) { 135 switch ( WTERMSIG( status )) {
135 case SIGINT : 136 case SIGINT :
136 case SIGTERM: 137 case SIGTERM:
137 case SIGKILL: 138 case SIGKILL:
138 break; 139 break;
139 140
140 default : 141 default :
141 killedbysig = WTERMSIG( status ); 142 killedbysig = WTERMSIG( status );
142 break; 143 break;
143 } 144 }
144 } 145 }
145 if ( killedbysig ) { // qpe was killed by an uncaught signal 146 if ( killedbysig ) { // qpe was killed by an uncaught signal
146 qApp = 0; 147 qApp = 0;
147 148
148 QWSServer::setDesktopBackground ( QImage ( )); 149 QWSServer::setDesktopBackground ( QImage ( ));
149 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); 150 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
150 app-> setFont ( QFont ( "Helvetica", 10 )); 151 app-> setFont ( QFont ( "Helvetica", 10 ));
151 app-> setStyle ( new QPEStyle ( )); 152 app-> setStyle ( new QPEStyle ( ));
152 153
153 const char *sig = ::strsignal ( killedbysig ); 154 const char *sig = ::strsignal ( killedbysig );
154 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); 155 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool );
155 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); 156 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig ));
156 l-> setAlignment ( Qt::AlignCenter ); 157 l-> setAlignment ( Qt::AlignCenter );
157 l-> move ( 0, 0 ); 158 l-> move ( 0, 0 );
158 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 159 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
159 l-> show ( ); 160 l-> show ( );
160 QTimer::singleShot ( 3000, app, SLOT( quit ( ))); 161 QTimer::singleShot ( 3000, app, SLOT( quit ( )));
161 app-> exec ( ); 162 app-> exec ( );
162 delete app; 163 delete app;
163 qApp = 0; 164 qApp = 0;
164 } 165 }
165 } 166 }
166 else { 167 else {
168 if ( !autolog ) {
169 Config cfg ( "opie-login" );
170 cfg. setGroup ( "General" );
171 QString user = cfg. readEntry ( "AutoLogin" );
172
173 if ( !user. isEmpty ( ))
174 autolog = ::strdup ( user. latin1 ( ));
175 }
176
167 if ( autolog ) { 177 if ( autolog ) {
168 LoginApplication::setLoginAs ( autolog ); 178 LoginApplication::setLoginAs ( autolog );
169 179
170 if ( LoginApplication::changeIdentity ( )) 180 if ( LoginApplication::changeIdentity ( ))
171 ::exit ( LoginApplication::login ( )); 181 ::exit ( LoginApplication::login ( ));
172 else 182 else
173 ::exit ( 0 ); 183 ::exit ( 0 );
174 } 184 }
175 else 185 else
176 ::exit ( login_main ( argc, argv )); 186 ::exit ( login_main ( argc, argv ));
177 } 187 }
178 } 188 }
179 return 0; 189 return 0;
180} 190}
181 191
182void sigterm ( int /*sig*/ ) 192void sigterm ( int /*sig*/ )
183{ 193{
184 ::exit ( 0 ); 194 ::exit ( 0 );
185} 195}
186 196
187 197
188void exit_closelog ( ) 198void exit_closelog ( )
189{ 199{
190 ::closelog ( ); 200 ::closelog ( );
191} 201}
192 202
193 203
194class LoginScreenSaver : public QWSScreenSaver 204class LoginScreenSaver : public QWSScreenSaver
195{ 205{
196public: 206public:
197 LoginScreenSaver ( ) 207 LoginScreenSaver ( )
198 { 208 {
199 m_lcd_status = true; 209 m_lcd_status = true;
200 210
201 m_backlight_bright = -1; 211 m_backlight_bright = -1;
202 m_backlight_forcedoff = false; 212 m_backlight_forcedoff = false;
203 213
204 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 214 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
205 ODevice::inst ( )-> setDisplayStatus ( true ); 215 ODevice::inst ( )-> setDisplayStatus ( true );
206 } 216 }
207 void restore() 217 void restore()
208 { 218 {
209 if ( !m_lcd_status ) // We must have turned it off 219 if ( !m_lcd_status ) // We must have turned it off
210 ODevice::inst ( ) -> setDisplayStatus ( true ); 220 ODevice::inst ( ) -> setDisplayStatus ( true );
211 221
212 setBacklight ( -3 ); 222 setBacklight ( -3 );
213 } 223 }
214 bool save( int level ) 224 bool save( int level )
215 { 225 {
216 switch ( level ) { 226 switch ( level ) {
217 case 0: 227 case 0:
218 if ( backlight() > 1 ) 228 if ( backlight() > 1 )
219 setBacklight( 1 ); // lowest non-off 229 setBacklight( 1 ); // lowest non-off
220 return true; 230 return true;
221 break; 231 break;
222 case 1: 232 case 1:
223 setBacklight( 0 ); // off 233 setBacklight( 0 ); // off
224 return true; 234 return true;
225 break; 235 break;
226 case 2: 236 case 2:
227 // We're going to suspend the whole machine 237 // We're going to suspend the whole machine
228 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 238 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
229 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 239 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
230 return true; 240 return true;
231 } 241 }
232 break; 242 break;
233 } 243 }
234 return false; 244 return false;
235 } 245 }
236 246
237private: 247private:
238public: 248public:
239 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) 249 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
240 { 250 {
241 int v [4]; 251 int v [4];
242 252
243 v [ 0 ] = QMAX( 1000 * i1, 100 ); 253 v [ 0 ] = QMAX( 1000 * i1, 100 );
244 v [ 1 ] = QMAX( 1000 * i2, 100 ); 254 v [ 1 ] = QMAX( 1000 * i2, 100 );
245 v [ 2 ] = QMAX( 1000 * i3, 100 ); 255 v [ 2 ] = QMAX( 1000 * i3, 100 );
246 v [ 3 ] = 0; 256 v [ 3 ] = 0;
247 257
248 if ( !i1 && !i2 && !i3 ) 258 if ( !i1 && !i2 && !i3 )
249 QWSServer::setScreenSaverInterval ( 0 ); 259 QWSServer::setScreenSaverInterval ( 0 );
250 else 260 else
251 QWSServer::setScreenSaverIntervals ( v ); 261 QWSServer::setScreenSaverIntervals ( v );
252 } 262 }
253 263
254 int backlight ( ) 264 int backlight ( )
255 { 265 {
256 if ( m_backlight_bright == -1 ) 266 if ( m_backlight_bright == -1 )
257 m_backlight_bright = 255; 267 m_backlight_bright = 255;
258 268
259 return m_backlight_bright; 269 return m_backlight_bright;
260 } 270 }
261 271
262 void setBacklight ( int bright ) 272 void setBacklight ( int bright )
263 { 273 {
264 if ( bright == -3 ) { 274 if ( bright == -3 ) {
265 // Forced on 275 // Forced on
266 m_backlight_forcedoff = false; 276 m_backlight_forcedoff = false;
267 bright = -1; 277 bright = -1;
268 } 278 }
269 if ( m_backlight_forcedoff && bright != -2 ) 279 if ( m_backlight_forcedoff && bright != -2 )
270 return ; 280 return ;
271 if ( bright == -2 ) { 281 if ( bright == -2 ) {