summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/main.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index 2c10f77..8f795e3 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,181 +1,182 @@
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 47
48#include <opie/odevice.h> 48#include <opie/odevice.h>
49 49
50#include <qwindowsystem_qws.h> 50#include <qwindowsystem_qws.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qlabel.h> 52#include <qlabel.h>
53#include <qtimer.h> 53#include <qtimer.h>
54#include <qfile.h>
54 55
55#include "loginapplication.h" 56#include "loginapplication.h"
56#include "loginwindowimpl.h" 57#include "loginwindowimpl.h"
57#include "calibrate.h" 58#include "calibrate.h"
58 59
59using namespace Opie; 60using namespace Opie;
60 61
61int login_main ( int argc, char **argv ); 62int login_main ( int argc, char **argv );
62void sigterm ( int sig ); 63void sigterm ( int sig );
63void exit_closelog ( ); 64void exit_closelog ( );
64 65
65static struct option long_options [] = { 66static struct option long_options [] = {
66 { "autologin", 1, 0, 'a' }, 67 { "autologin", 1, 0, 'a' },
67 { 0, 0, 0, 0 } 68 { 0, 0, 0, 0 }
68}; 69};
69 70
70 71
71int main ( int argc, char **argv ) 72int main ( int argc, char **argv )
72{ 73{
73 if ( ::geteuid ( ) != 0 ) { 74 if ( ::geteuid ( ) != 0 ) {
74 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); 75 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
75 return 1; 76 return 1;
76 } 77 }
77 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and 78 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and
78 ::setuid ( 0 ); // messes up things like config files 79 ::setuid ( 0 ); // messes up things like config files
79 80
80 char *autolog = 0; 81 char *autolog = 0;
81 int c; 82 int c;
82 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { 83 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) {
83 switch ( c ) { 84 switch ( c ) {
84 case 'a': 85 case 'a':
85 autolog = optarg; 86 autolog = optarg;
86 break; 87 break;
87 default: 88 default:
88 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); 89 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] );
89 return 2; 90 return 2;
90 } 91 }
91 } 92 }
92 93
93 //struct rlimit rl; 94 //struct rlimit rl;
94 //::getrlimit ( RLIMIT_NOFILE, &rl ); 95 //::getrlimit ( RLIMIT_NOFILE, &rl );
95 96
96 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 97 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
97 // ::close ( i ); 98 // ::close ( i );
98 99
99 ::setpgid ( 0, 0 ); 100 ::setpgid ( 0, 0 );
100 ::setsid ( ); 101 ::setsid ( );
101 102
102 ::signal ( SIGTERM, sigterm ); 103 ::signal ( SIGTERM, sigterm );
103 104
104 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 105 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
105 ::atexit ( exit_closelog ); 106 ::atexit ( exit_closelog );
106 107
107 while ( true ) { 108 while ( true ) {
108 pid_t child = ::fork ( ); 109 pid_t child = ::fork ( );
109 110
110 if ( child < 0 ) { 111 if ( child < 0 ) {
111 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 112 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
112 break; 113 break;
113 } 114 }
114 else if ( child > 0 ) { 115 else if ( child > 0 ) {
115 int status = 0; 116 int status = 0;
116 time_t started = ::time ( 0 ); 117 time_t started = ::time ( 0 );
117 118
118 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 119 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
119 120
120 if (( ::time ( 0 ) - started ) < 3 ) { 121 if (( ::time ( 0 ) - started ) < 3 ) {
121 if ( autolog ) { 122 if ( autolog ) {
122 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); 123 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
123 autolog = 0; 124 autolog = 0;
124 } 125 }
125 else { 126 else {
126 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); 127 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
127 break; 128 break;
128 } 129 }
129 } 130 }
130 int killedbysig = 0; 131 int killedbysig = 0;
131 132
132 if ( WIFSIGNALED( status )) { 133 if ( WIFSIGNALED( status )) {
133 switch ( WTERMSIG( status )) { 134 switch ( WTERMSIG( status )) {
134 case SIGINT : 135 case SIGINT :
135 case SIGTERM: 136 case SIGTERM:
136 case SIGKILL: 137 case SIGKILL:
137 break; 138 break;
138 139
139 default : 140 default :
140 killedbysig = WTERMSIG( status ); 141 killedbysig = WTERMSIG( status );
141 break; 142 break;
142 } 143 }
143 } 144 }
144 if ( killedbysig ) { // qpe was killed by an uncaught signal 145 if ( killedbysig ) { // qpe was killed by an uncaught signal
145 qApp = 0; 146 qApp = 0;
146 147
147 QWSServer::setDesktopBackground ( QImage ( )); 148 QWSServer::setDesktopBackground ( QImage ( ));
148 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); 149 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
149 app-> setFont ( QFont ( "Helvetica", 10 )); 150 app-> setFont ( QFont ( "Helvetica", 10 ));
150 app-> setStyle ( new QPEStyle ( )); 151 app-> setStyle ( new QPEStyle ( ));
151 152
152 const char *sig = ::strsignal ( killedbysig ); 153 const char *sig = ::strsignal ( killedbysig );
153 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); 154 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool );
154 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); 155 l-> setText ( LoginWindowImpl::tr( "OPIE was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig ));
155 l-> setAlignment ( Qt::AlignCenter ); 156 l-> setAlignment ( Qt::AlignCenter );
156 l-> move ( 0, 0 ); 157 l-> move ( 0, 0 );
157 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 158 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
158 l-> show ( ); 159 l-> show ( );
159 QTimer::singleShot ( 3000, app, SLOT( quit ( ))); 160 QTimer::singleShot ( 3000, app, SLOT( quit ( )));
160 app-> exec ( ); 161 app-> exec ( );
161 delete app; 162 delete app;
162 qApp = 0; 163 qApp = 0;
163 } 164 }
164 } 165 }
165 else { 166 else {
166 if ( autolog ) { 167 if ( autolog ) {
167 LoginApplication::setLoginAs ( autolog ); 168 LoginApplication::setLoginAs ( autolog );
168 169
169 if ( LoginApplication::changeIdentity ( )) 170 if ( LoginApplication::changeIdentity ( ))
170 ::exit ( LoginApplication::login ( )); 171 ::exit ( LoginApplication::login ( ));
171 else 172 else
172 ::exit ( 0 ); 173 ::exit ( 0 );
173 } 174 }
174 else 175 else
175 ::exit ( login_main ( argc, argv )); 176 ::exit ( login_main ( argc, argv ));
176 } 177 }
177 } 178 }
178 return 0; 179 return 0;
179} 180}
180 181
181void sigterm ( int /*sig*/ ) 182void sigterm ( int /*sig*/ )