-rw-r--r-- | core/opie-login/main.cpp | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp index 711bedc..554efd3 100644 --- a/core/opie-login/main.cpp +++ b/core/opie-login/main.cpp | |||
@@ -18,228 +18,215 @@ | |||
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 | #include "loginapplication.h" | 28 | #include "loginapplication.h" |
29 | #include "loginwindowimpl.h" | 29 | #include "loginwindowimpl.h" |
30 | #include "calibrate.h" | 30 | #include "calibrate.h" |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/odevice.h> | 33 | #include <opie2/odevice.h> |
34 | #include <qpe/qpestyle.h> | 34 | #include <qpe/qpestyle.h> |
35 | #include <qpe/power.h> | 35 | #include <qpe/power.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qwindowsystem_qws.h> | 39 | #include <qwindowsystem_qws.h> |
40 | #include <qmessagebox.h> | 40 | #include <qmessagebox.h> |
41 | #include <qlabel.h> | 41 | #include <qlabel.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qfile.h> | 43 | #include <qfile.h> |
44 | 44 | ||
45 | /* STD */ | 45 | /* STD */ |
46 | #include <sys/types.h> | 46 | #include <sys/types.h> |
47 | #include <time.h> | 47 | #include <time.h> |
48 | #include <sys/time.h> | 48 | #include <sys/time.h> |
49 | #include <sys/resource.h> | 49 | #include <sys/resource.h> |
50 | #include <unistd.h> | 50 | #include <unistd.h> |
51 | #include <syslog.h> | 51 | #include <syslog.h> |
52 | #include <sys/wait.h> | 52 | #include <sys/wait.h> |
53 | #include <stdio.h> | 53 | #include <stdio.h> |
54 | #include <stdlib.h> | 54 | #include <stdlib.h> |
55 | #include <signal.h> | 55 | #include <signal.h> |
56 | #include <getopt.h> | 56 | #include <getopt.h> |
57 | #include <string.h> | 57 | #include <string.h> |
58 | 58 | ||
59 | using namespace Opie::Core; | 59 | using namespace Opie::Core; |
60 | 60 | ||
61 | int login_main ( int argc, char **argv, pid_t ppid ); | 61 | int login_main ( int argc, char **argv, pid_t ppid ); |
62 | void sigterm ( int sig ); | 62 | void sigterm ( int sig ); |
63 | void sigint ( int sig ); | 63 | void sigint ( int sig ); |
64 | void exit_closelog ( ); | 64 | void exit_closelog ( ); |
65 | 65 | ||
66 | static struct option long_options [] = { | ||
67 | { "autologin", 1, 0, 'a' }, | ||
68 | { 0, 0, 0, 0 } | ||
69 | }; | ||
70 | |||
71 | |||
72 | int main ( int argc, char **argv ) | 66 | int main ( int argc, char **argv ) |
73 | { | 67 | { |
74 | int userExited = 0; | 68 | int userExited = 0; |
75 | pid_t ppid = ::getpid ( ); | 69 | pid_t ppid = ::getpid ( ); |
76 | 70 | ||
77 | if ( ::geteuid ( ) != 0 ) { | 71 | if ( ::geteuid ( ) != 0 ) { |
78 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); | 72 | ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)\n", argv [0] ); |
79 | return 1; | 73 | return 1; |
80 | } | 74 | } |
81 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and | 75 | if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and |
82 | ::setuid ( 0 ); // messes up things like config files | 76 | ::setuid ( 0 ); // messes up things like config files |
83 | 77 | ||
84 | char *autolog = 0; | ||
85 | int c; | ||
86 | while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { | ||
87 | switch ( c ) { | ||
88 | case 'a': | ||
89 | autolog = optarg; | ||
90 | break; | ||
91 | default: | ||
92 | ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); | ||
93 | return 2; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | //struct rlimit rl; | 78 | //struct rlimit rl; |
98 | //::getrlimit ( RLIMIT_NOFILE, &rl ); | 79 | //::getrlimit ( RLIMIT_NOFILE, &rl ); |
99 | 80 | ||
100 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) | 81 | //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) |
101 | // ::close ( i ); | 82 | // ::close ( i ); |
102 | 83 | ||
103 | ::setpgid ( 0, 0 ); | 84 | ::setpgid ( 0, 0 ); |
104 | ::setsid ( ); | 85 | ::setsid ( ); |
105 | 86 | ||
106 | ::signal ( SIGTERM, sigterm ); | 87 | ::signal ( SIGTERM, sigterm ); |
107 | ::signal ( SIGINT, sigterm ); | 88 | ::signal ( SIGINT, sigterm ); |
108 | 89 | ||
109 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); | 90 | ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); |
110 | ::atexit ( exit_closelog ); | 91 | ::atexit ( exit_closelog ); |
111 | 92 | ||
93 | const char* autolog = 0; | ||
94 | Config c( "opie-login" ); | ||
95 | c.setGroup( "autologin" ); | ||
96 | QString entry = c.readEntry( "user", "" ); | ||
97 | if ( !entry.isEmpty() ) autolog = ::strdup( (const char*) entry ); | ||
98 | |||
112 | while ( true ) { | 99 | while ( true ) { |
113 | pid_t child = ::fork ( ); | 100 | pid_t child = ::fork ( ); |
114 | 101 | ||
115 | if ( child < 0 ) { | 102 | if ( child < 0 ) { |
116 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); | 103 | ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); |
117 | break; | 104 | break; |
118 | } | 105 | } |
119 | else if ( child > 0 ) { | 106 | else if ( child > 0 ) { |
120 | int status = 0; | 107 | int status = 0; |
121 | time_t started = ::time ( 0 ); | 108 | time_t started = ::time ( 0 ); |
122 | 109 | ||
123 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } | 110 | while ( ::waitpid ( child, &status, 0 ) < 0 ) { } |
124 | 111 | ||
125 | LoginApplication::logout ( ); | 112 | LoginApplication::logout ( ); |
126 | 113 | ||
127 | if (( ::time ( 0 ) - started ) < 3 ) { | 114 | if (( ::time ( 0 ) - started ) < 3 ) { |
128 | if ( autolog ) { | 115 | if ( autolog ) { |
129 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); | 116 | ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); |
130 | autolog = 0; | 117 | autolog = 0; |
131 | } | 118 | } |
132 | else { | 119 | else { |
133 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); | 120 | ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); |
134 | break; | 121 | break; |
135 | } | 122 | } |
136 | } | 123 | } |
137 | int killedbysig = 0; | 124 | int killedbysig = 0; |
138 | userExited=0; | 125 | userExited=0; |
139 | if (WIFEXITED(status)!=0 ) { | 126 | if (WIFEXITED(status)!=0 ) { |
140 | if (WEXITSTATUS(status)==137) { | 127 | if (WEXITSTATUS(status)==137) { |
141 | userExited=1; | 128 | userExited=1; |
142 | } | 129 | } |
143 | } | 130 | } |
144 | 131 | ||
145 | if ( WIFSIGNALED( status )) { | 132 | if ( WIFSIGNALED( status )) { |
146 | switch ( WTERMSIG( status )) { | 133 | switch ( WTERMSIG( status )) { |
147 | case SIGTERM: | 134 | case SIGTERM: |
148 | case SIGINT : | 135 | case SIGINT : |
149 | case SIGKILL: | 136 | case SIGKILL: |
150 | break; | 137 | break; |
151 | 138 | ||
152 | default : | 139 | default : |
153 | killedbysig = WTERMSIG( status ); | 140 | killedbysig = WTERMSIG( status ); |
154 | break; | 141 | break; |
155 | } | 142 | } |
156 | } | 143 | } |
157 | if ( killedbysig ) { // qpe was killed by an uncaught signal | 144 | if ( killedbysig ) { // qpe was killed by an uncaught signal |
158 | qApp = 0; | 145 | qApp = 0; |
159 | 146 | ||
160 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); | 147 | ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); |
161 | 148 | ||
162 | QWSServer::setDesktopBackground ( QImage ( )); | 149 | QWSServer::setDesktopBackground ( QImage ( )); |
163 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); | 150 | QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); |
164 | app-> setFont ( QFont ( "Helvetica", 10 )); | 151 | app-> setFont ( QFont ( "Helvetica", 10 )); |
165 | app-> setStyle ( new QPEStyle ( )); | 152 | app-> setStyle ( new QPEStyle ( )); |
166 | 153 | ||
167 | // const char *sig = ::strsignal ( killedbysig ); | 154 | // const char *sig = ::strsignal ( killedbysig ); |
168 | const char *sig = ::sys_siglist[killedbysig]; | 155 | const char *sig = ::sys_siglist[killedbysig]; |
169 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); | 156 | QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); |
170 | l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); | 157 | l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); |
171 | l-> setAlignment ( Qt::AlignCenter ); | 158 | l-> setAlignment ( Qt::AlignCenter ); |
172 | l-> move ( 0, 0 ); | 159 | l-> move ( 0, 0 ); |
173 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); | 160 | l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); |
174 | l-> show ( ); | 161 | l-> show ( ); |
175 | QTimer::singleShot ( 3000, app, SLOT( quit())); | 162 | QTimer::singleShot ( 3000, app, SLOT( quit())); |
176 | app-> exec ( ); | 163 | app-> exec ( ); |
177 | delete app; | 164 | delete app; |
178 | qApp = 0; | 165 | qApp = 0; |
179 | } | 166 | } |
180 | } | 167 | } |
181 | else { | 168 | else { |
182 | if ( !autolog ) { | 169 | if ( !autolog ) { |
183 | QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf"; | 170 | QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf"; |
184 | Config cfg ( confFile, Config::File ); | 171 | Config cfg ( confFile, Config::File ); |
185 | cfg. setGroup ( "General" ); | 172 | cfg. setGroup ( "General" ); |
186 | QString user = cfg. readEntry ( "AutoLogin" ); | 173 | QString user = cfg. readEntry ( "AutoLogin" ); |
187 | 174 | ||
188 | if ( !user. isEmpty ( )) | 175 | if ( !user. isEmpty ( )) |
189 | autolog = ::strdup ( user. latin1 ( )); | 176 | autolog = ::strdup ( user. latin1 ( )); |
190 | } | 177 | } |
191 | 178 | ||
192 | if ( autolog && !userExited ) { | 179 | if ( autolog && !userExited ) { |
193 | 180 | ||
194 | QWSServer::setDesktopBackground( QImage() ); | 181 | QWSServer::setDesktopBackground( QImage() ); |
195 | ODevice::inst()->setDisplayStatus( true ); | 182 | ODevice::inst()->setDisplayStatus( true ); |
196 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); | 183 | LoginApplication *app = new LoginApplication ( argc, argv, ppid ); |
197 | LoginApplication::setLoginAs ( autolog ); | 184 | LoginApplication::setLoginAs( autolog ); |
198 | 185 | ||
199 | 186 | ||
200 | if ( LoginApplication::changeIdentity ( )) | 187 | if ( LoginApplication::changeIdentity ( )) |
201 | ::exit ( LoginApplication::login ( )); | 188 | ::exit ( LoginApplication::login ( )); |
202 | else | 189 | else |
203 | ::exit ( 0 ); | 190 | ::exit ( 0 ); |
204 | } | 191 | } |
205 | else { | 192 | else { |
206 | ::exit ( login_main ( argc, argv, ppid )); | 193 | ::exit ( login_main ( argc, argv, ppid )); |
207 | } | 194 | } |
208 | } | 195 | } |
209 | } | 196 | } |
210 | return 0; | 197 | return 0; |
211 | } | 198 | } |
212 | 199 | ||
213 | void sigterm ( int /*sig*/ ) | 200 | void sigterm ( int /*sig*/ ) |
214 | { | 201 | { |
215 | ::exit ( 0 ); | 202 | ::exit ( 0 ); |
216 | } | 203 | } |
217 | 204 | ||
218 | 205 | ||
219 | void exit_closelog ( ) | 206 | void exit_closelog ( ) |
220 | { | 207 | { |
221 | ::closelog ( ); | 208 | ::closelog ( ); |
222 | } | 209 | } |
223 | 210 | ||
224 | 211 | ||
225 | class LoginScreenSaver : public QWSScreenSaver | 212 | class LoginScreenSaver : public QWSScreenSaver |
226 | { | 213 | { |
227 | public: | 214 | public: |
228 | LoginScreenSaver ( ) | 215 | LoginScreenSaver ( ) |
229 | { | 216 | { |
230 | m_lcd_status = true; | 217 | m_lcd_status = true; |
231 | 218 | ||
232 | m_backlight_bright = -1; | 219 | m_backlight_bright = -1; |
233 | m_backlight_forcedoff = false; | 220 | m_backlight_forcedoff = false; |
234 | 221 | ||
235 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 222 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
236 | ODevice::inst ( )-> setDisplayStatus ( true ); | 223 | ODevice::inst ( )-> setDisplayStatus ( true ); |
237 | } | 224 | } |
238 | void restore() | 225 | void restore() |
239 | { | 226 | { |
240 | if ( !m_lcd_status ) // We must have turned it off | 227 | if ( !m_lcd_status ) // We must have turned it off |
241 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 228 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
242 | 229 | ||
243 | setBacklight ( -3 ); | 230 | setBacklight ( -3 ); |
244 | } | 231 | } |
245 | bool save( int level ) | 232 | bool save( int level ) |