author | wimpie <wimpie> | 2004-08-19 21:48:46 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-08-19 21:48:46 (UTC) |
commit | 45616f57d3871827a247c1962e7c88699d111002 (patch) (side-by-side diff) | |
tree | 7ad9cbe10eb624cb08a7a41944e59f0371547517 /noncore/settings/networksettings2/networksettings2 | |
parent | f58fb0a08321b6d8a9ce1bac2ce4b7eb67c27347 (diff) | |
download | opie-45616f57d3871827a247c1962e7c88699d111002.zip opie-45616f57d3871827a247c1962e7c88699d111002.tar.gz opie-45616f57d3871827a247c1962e7c88699d111002.tar.bz2 |
Network_NN.cpp : had to generate full path to networksettings since
ifup (when run from hotplug) does not know about QPEDIR ...
main.cpp : a bit more logging
nsdata.cpp resources : optimized user detection code, report error
when user could not be detected (instead of gracefull crash)
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/resources.cpp | 109 | ||||
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/resources.h | 5 |
2 files changed, 58 insertions, 56 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 7ece817..2f17693 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -294,14 +294,14 @@ typedef struct EnvVars { #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { - // AnEV( "HOME=" ), -> SPECIAL - // AnEV( "LOGNAME=" ), -> SPECIAL - AnEV( "USER=" ), - AnEV( "LD_LIBRARY_PATH=" ), - AnEV( "PATH=" ), - AnEV( "QTDIR=" ), - AnEV( "OPIEDIR=" ), - AnEV( "SHELL=" ), + AnEV( "HOME" ), + AnEV( "LOGNAME" ), + AnEV( "USER" ), + AnEV( "LD_LIBRARY_PATH" ), + AnEV( "PATH" ), + AnEV( "QTDIR" ), + AnEV( "OPIEDIR" ), + AnEV( "SHELL" ), { NULL, 0 } }; @@ -309,6 +309,9 @@ void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; + CurrentUser.UserName = ""; + CurrentUser.HomeDir = ""; + if( getenv( "OPIEDIR" ) == 0 ) { // nothing known { // open proc dir and find all dirs in it @@ -367,32 +370,27 @@ void TheNSResources::detectCurrentUser( void ) { // get env items out of list while( Data < DataEnd ) { - if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { - CurrentUser.UserName = Data+8; - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { - CurrentUser.HomeDir = Data+5; - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - } else { - EnvVar_t * Run = EV; - while( Run->Name ) { - if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( Data ); - // put OPIEDIR in env - if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) { - putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); - } - break; + EnvVar_t * Run = EV; + while( Run->Name ) { + if( strncmp( Data, Run->Name, Run->Len ) == 0 && + Data[Run->Len] == '=' + ) { + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( Data ); + + if( strcmp( Run->Name, "OPIEDIR" ) == 0 ) { + // put OPIEDIR in env + putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] ); + } else if( strcmp( Run->Name, "HOME" ) == 0 ) { + CurrentUser.HomeDir = Data+5; + } else if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { + CurrentUser.UserName = Data+8; } - Run ++; + break; } + Run ++; } Data += strlen( Data )+1; @@ -421,31 +419,30 @@ void TheNSResources::detectCurrentUser( void ) { } } else { - CurrentUser.UserName = getenv( "LOGNAME" ); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( CurrentUser.UserName ); - - CurrentUser.HomeDir = getenv( "HOME" ); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = - strdup( CurrentUser.HomeDir ); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER"); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH"); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH"); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR"); - - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR"); - CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); - CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL"); + char * X; + QString S; + + EnvVar_t * Run = EV; + while( Run->Name ) { + + if( ( X = getenv( Run->Name ) ) ) { + Log(( "Env : %s = %s\n", Run->Name, X )); + + S.sprintf( "%s=%s", Run->Name, X ); + CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); + CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = + strdup( S.latin1() ); + + if( strcmp( Run->Name, "LOGNAME" ) == 0 ) { + CurrentUser.UserName = X; + } else if( strcmp( Run->Name, "HOME" ) == 0 ) { + CurrentUser.HomeDir = X; + } // regulare env var + } else { + Log(("Could not determine %s\n", Run->Name )); + } + Run ++; + } CurrentUser.Uid = getuid(); CurrentUser.Gid = getgid(); diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 16355ba..23b120e 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -27,6 +27,9 @@ class CurrentQPEUser { public : CurrentQPEUser() : UserName(), HomeDir(), EnvList() {} + inline bool known( void ) + { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); } + QString UserName; QString HomeDir; int Uid; @@ -99,6 +102,8 @@ public : Name2Connection_t & connections( void ) { return ConnectionsMap; } + inline bool userKnown( void ) + { return CurrentUser.known(); } CurrentQPEUser & currentUser( void ) { return CurrentUser; } |