summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/system.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/system.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp108
1 files changed, 85 insertions, 23 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 @@
10#include <stdlib.h> 10#include <stdlib.h>
11#include <stdio.h>
11#include <fcntl.h> 12#include <fcntl.h>
@@ -19,2 +20,3 @@
19#include <qtextstream.h> 20#include <qtextstream.h>
21#include <qapplication.h>
20 22
@@ -37,3 +39,3 @@ static char Dig2Hex[] = {
37 39
38System::System( void ) : ProbedInterfaces() { 40System::System( void ) : QObject(), ProbedInterfaces() {
39 probeInterfaces(); 41 probeInterfaces();
@@ -49,3 +51,3 @@ int System::runAsRoot( const QString & S ) {
49 char * usr = getenv("USER"); 51 char * usr = getenv("USER");
50 int rv; 52 char ch;
51 53
@@ -60,18 +62,43 @@ int System::runAsRoot( const QString & S ) {
60 62
61 fprintf( stderr, "Executing %s\n", MyS.latin1() ); 63 Log(("Executing %s\n", MyS.latin1() ));
62 64
63 rv = system( MyS.latin1() ) ; 65 emit lineFromCommand( tr("Command : ") + MyS );
64 switch( rv ) { 66 emit lineFromCommand( "---------------" );
65 case -1 : 67 Log(( "Command : %s\n", MyS.latin1() ) );
66 // cannot fork 68 MyS += " 2>&1 ";
67 return 1; 69 OutputOfCmd = popen( MyS.latin1(), "r" ) ;
68 case 127 : 70 if( ! OutputOfCmd ) {
69 // cannot start shell 71 // cannot fork
70 return 2; 72 return 1;
71 default : 73 }
72 if( WEXITSTATUS(rv) != 0 ) { 74
73 // error in command 75 // read all data
74 return 3; 76 QString Line = "";
77 while( 1 ) {
78 if( fread( &ch, 1, 1, OutputOfCmd ) < 1 )
79 // eof
80 break;
81 if( ch == '\n' || ch == '\r' ) {
82 if( ! Line.isEmpty() ) {
83 Log(( "read cmd output : **%s**\n", Line.latin1() ) );
84 emit lineFromCommand( Line );
85 Line = "";
86 qApp->processEvents();
75 } 87 }
88 } else {
89 Line += ch;
90 }
91 }
92
93 if( ! Line.isEmpty() ) {
94 emit lineFromCommand( Line );
95 Log(( "read cmd output : **%s**\n", Line.latin1() ) );
96 }
97 Log(( "End of command\n", Line.latin1() ) );
98
99 if( pclose( OutputOfCmd ) < 0 ) {
100 // error in command
101 return 3;
76 } 102 }
103
77 // all is fine 104 // all is fine
@@ -200,3 +227,3 @@ void System::probeInterfaces( void ) {
200 // new nic 227 // new nic
201 fprintf( stderr, "NEWNIC %s\n", NicName.latin1()); 228 Log(("NEWNIC %s\n", NicName.latin1()));
202 IFI = new InterfaceInfo; 229 IFI = new InterfaceInfo;
@@ -227,4 +254,4 @@ void System::probeInterfaces( void ) {
227 if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) { 254 if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
228 fprintf( stderr, "%s = %d\n", IFI->Name.latin1(), 255 Log(("%s = %d\n", IFI->Name.latin1(),
229 ifrs.ifr_hwaddr.sa_family ); 256 ifrs.ifr_hwaddr.sa_family ));
230 257
@@ -295,3 +322,3 @@ void System::probeInterfaces( void ) {
295 } else // else already probed before -> just update 322 } else // else already probed before -> just update
296 fprintf( stderr, "OLDNIC %s\n", NicName.latin1()); 323 Log(("OLDNIC %s\n", NicName.latin1()));
297 324
@@ -325,3 +352,3 @@ void System::probeInterfaces( void ) {
325 } 352 }
326 fprintf( stderr, "NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ); 353 Log(("NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ));
327 } 354 }
@@ -334,3 +361,3 @@ void System::execAsUser( QString & Cmd, char * argv[] ) {
334 // if we come here, the exec was not successfull 361 // if we come here, the exec was not successfull
335 fprintf( stderr, "User not known \n" ); 362 Log(("User not known \n" ));
336 return; 363 return;
@@ -353,3 +380,38 @@ void System::execAsUser( QString & Cmd, char * argv[] ) {
353 // if we come here, the exec was not successfull 380 // if we come here, the exec was not successfull
354 fprintf( stderr, "Could not exec : %d\n", errno ); 381 Log(("Could not exec : %d\n", errno ));
382}
383
384#include <stdarg.h>
385static FILE * logf = 0;
386
387void VLog( char * Format, ... ) {
388 va_list l;
389
390 va_start(l, Format );
391
392 if( logf == (FILE *)0 ) {
393 // logf = fopen( "/tmp/ns2log", "a" );
394 logf = stderr;
395 if( ! logf ) {
396 fprintf( stderr, "Cannot open logfile /tmp/ns2log %d\n",
397 errno );
398 logf = (FILE *)1;
399 } else {
400 fprintf( logf, "____ OPEN LOGFILE ____\n");
401 }
402 }
403
404 if( (long)logf > 1 ) {
405 vfprintf( logf, Format, l );
406 }
407 va_end( l );
408
409}
410
411void LogClose( void ) {
412 if( (long)logf > 1 ) {
413 fprintf( logf, "____ CLOSE LOGFILE ____\n");
414 fclose( logf );
415 logf = 0;
416 }
355} 417}