summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/system.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/system.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp100
1 files changed, 81 insertions, 19 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp
index 2133d34..a579396 100644
--- a/noncore/settings/networksettings2/networksettings2/system.cpp
+++ b/noncore/settings/networksettings2/networksettings2/system.cpp
@@ -10,2 +10,3 @@
#include <stdlib.h>
+#include <stdio.h>
#include <fcntl.h>
@@ -19,2 +20,3 @@
#include <qtextstream.h>
+#include <qapplication.h>
@@ -37,3 +39,3 @@ static char Dig2Hex[] = {
-System::System( void ) : ProbedInterfaces() {
+System::System( void ) : QObject(), ProbedInterfaces() {
probeInterfaces();
@@ -49,3 +51,3 @@ int System::runAsRoot( const QString & S ) {
char * usr = getenv("USER");
- int rv;
+ char ch;
@@ -60,14 +62,39 @@ int System::runAsRoot( const QString & S ) {
- fprintf( stderr, "Executing %s\n", MyS.latin1() );
+ Log(("Executing %s\n", MyS.latin1() ));
- rv = system( MyS.latin1() ) ;
- switch( rv ) {
- case -1 :
+ emit lineFromCommand( tr("Command : ") + MyS );
+ emit lineFromCommand( "---------------" );
+ Log(( "Command : %s\n", MyS.latin1() ) );
+ MyS += " 2>&1 ";
+ OutputOfCmd = popen( MyS.latin1(), "r" ) ;
+ if( ! OutputOfCmd ) {
// cannot fork
return 1;
- case 127 :
- // cannot start shell
- return 2;
- default :
- if( WEXITSTATUS(rv) != 0 ) {
+ }
+
+ // read all data
+ QString Line = "";
+ while( 1 ) {
+ if( fread( &ch, 1, 1, OutputOfCmd ) < 1 )
+ // eof
+ break;
+ if( ch == '\n' || ch == '\r' ) {
+ if( ! Line.isEmpty() ) {
+ Log(( "read cmd output : **%s**\n", Line.latin1() ) );
+ emit lineFromCommand( Line );
+ Line = "";
+ qApp->processEvents();
+ }
+ } else {
+ Line += ch;
+ }
+ }
+
+ if( ! Line.isEmpty() ) {
+ emit lineFromCommand( Line );
+ Log(( "read cmd output : **%s**\n", Line.latin1() ) );
+ }
+ Log(( "End of command\n", Line.latin1() ) );
+
+ if( pclose( OutputOfCmd ) < 0 ) {
// error in command
@@ -75,3 +102,3 @@ int System::runAsRoot( const QString & S ) {
}
- }
+
// all is fine
@@ -200,3 +227,3 @@ void System::probeInterfaces( void ) {
// new nic
- fprintf( stderr, "NEWNIC %s\n", NicName.latin1());
+ Log(("NEWNIC %s\n", NicName.latin1()));
IFI = new InterfaceInfo;
@@ -227,4 +254,4 @@ void System::probeInterfaces( void ) {
if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
- fprintf( stderr, "%s = %d\n", IFI->Name.latin1(),
- ifrs.ifr_hwaddr.sa_family );
+ Log(("%s = %d\n", IFI->Name.latin1(),
+ ifrs.ifr_hwaddr.sa_family ));
@@ -295,3 +322,3 @@ void System::probeInterfaces( void ) {
} else // else already probed before -> just update
- fprintf( stderr, "OLDNIC %s\n", NicName.latin1());
+ Log(("OLDNIC %s\n", NicName.latin1()));
@@ -325,3 +352,3 @@ void System::probeInterfaces( void ) {
}
- fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp );
+ Log(("NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ));
}
@@ -334,3 +361,3 @@ void System::execAsUser( QString & Cmd, char * argv[] ) {
// if we come here, the exec was not successfull
- fprintf( stderr, "User not known \n" );
+ Log(("User not known \n" ));
return;
@@ -353,3 +380,38 @@ void System::execAsUser( QString & Cmd, char * argv[] ) {
// if we come here, the exec was not successfull
- fprintf( stderr, "Could not exec : %d\n", errno );
+ Log(("Could not exec : %d\n", errno ));
+}
+
+#include <stdarg.h>
+static FILE * logf = 0;
+
+void VLog( char * Format, ... ) {
+ va_list l;
+
+ va_start(l, Format );
+
+ if( logf == (FILE *)0 ) {
+ // logf = fopen( "/tmp/ns2log", "a" );
+ logf = stderr;
+ if( ! logf ) {
+ fprintf( stderr, "Cannot open logfile /tmp/ns2log %d\n",
+ errno );
+ logf = (FILE *)1;
+ } else {
+ fprintf( logf, "____ OPEN LOGFILE ____\n");
+ }
+ }
+
+ if( (long)logf > 1 ) {
+ vfprintf( logf, Format, l );
+ }
+ va_end( l );
+
+}
+
+void LogClose( void ) {
+ if( (long)logf > 1 ) {
+ fprintf( logf, "____ CLOSE LOGFILE ____\n");
+ fclose( logf );
+ logf = 0;
+ }
}