Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/system.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/system.cpp | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 141484c..9512579 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp | |||
@@ -35,75 +35,88 @@ static char Dig2Hex[] = { | |||
35 | '0', '1', '2', '3', | 35 | '0', '1', '2', '3', |
36 | '4', '5', '6', '7', | 36 | '4', '5', '6', '7', |
37 | '8', '9', 'A', 'B', | 37 | '8', '9', 'A', 'B', |
38 | 'C', 'D', 'E', 'F' | 38 | 'C', 'D', 'E', 'F' |
39 | }; | 39 | }; |
40 | 40 | ||
41 | // get HIGH nibble of byte | 41 | // get HIGH nibble of byte |
42 | #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] | 42 | #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] |
43 | // get LOW nibble of byte | 43 | // get LOW nibble of byte |
44 | #define LN(x) Dig2Hex[((x)&0x0f)] | 44 | #define LN(x) Dig2Hex[((x)&0x0f)] |
45 | 45 | ||
46 | System::System( void ) : QObject(), ProbedInterfaces() { | 46 | System::System( void ) : QObject(), ProbedInterfaces() { |
47 | probeInterfaces(); | ||
48 | } | 47 | } |
49 | 48 | ||
50 | System::~System( void ) { | 49 | System::~System( void ) { |
51 | if( ProcDevNet ) | 50 | if( ProcDevNet ) |
52 | delete ProcDevNet; | 51 | delete ProcDevNet; |
53 | } | 52 | } |
54 | 53 | ||
55 | int System::runAsRoot( QStringList & S ) { | 54 | QDict<InterfaceInfo> & System::interfaces( void ) { |
55 | if( ProbedInterfaces.count() == 0 ) { | ||
56 | probeInterfaces(); | ||
57 | } | ||
58 | return ProbedInterfaces; | ||
59 | } | ||
60 | |||
61 | int System::runAsRoot( QStringList & S, MyProcess * Prc ) { | ||
56 | char * usr = getenv("USER"); | 62 | char * usr = getenv("USER"); |
57 | 63 | ||
58 | if( S.count() == 0 ) { | 64 | if( S.count() == 0 ) { |
59 | // loophole to start shell | 65 | // loophole to start shell |
60 | return 8888; | 66 | return 8888; |
61 | } | 67 | } |
62 | if( usr == 0 || strcmp( usr, "root" ) ) { | 68 | if( usr == 0 || strcmp( usr, "root" ) ) { |
63 | // unknown or non-root user -> use SUDO | 69 | // unknown or non-root user -> use SUDO |
64 | S.prepend( "sudo" ); | 70 | S.prepend( "sudo" ); |
65 | } | 71 | } |
66 | 72 | ||
67 | if( getenv( "NS2TESTMODE" ) ) { | 73 | if( getenv( "NS2TESTMODE" ) ) { |
68 | owarn << "TESTMODE !!! execute " | 74 | owarn << "TESTMODE !!! execute " |
69 | << S.join( " ") | 75 | << S.join( " ") |
70 | << oendl; | 76 | << oendl; |
71 | } else { | 77 | } else { |
72 | MyProcess * P = new MyProcess(); | 78 | MyProcess * P; |
73 | emit processEvent( tr("Command : ") + S.join( " " ) ); | ||
74 | 79 | ||
75 | P->process() << S; | 80 | if( Prc ) { |
76 | 81 | P = Prc; | |
77 | connect( P, | 82 | } else { |
78 | SIGNAL( stdoutLine( const QString & ) ), | 83 | P = new MyProcess(); |
79 | this, | 84 | emit processEvent( tr("Command : ") + S.join( " " ) ); |
80 | SIGNAL( stdoutLine( const QString & ) ) ); | 85 | |
81 | 86 | connect( P, | |
82 | connect( P, | 87 | SIGNAL( stdoutLine( const QString & ) ), |
83 | SIGNAL( stderrLine( const QString & ) ), | 88 | this, |
84 | this, | 89 | SIGNAL( stdoutLine( const QString & ) ) ); |
85 | SIGNAL( stderrLine( const QString & ) ) ); | 90 | |
91 | connect( P, | ||
92 | SIGNAL( stderrLine( const QString & ) ), | ||
93 | this, | ||
94 | SIGNAL( stderrLine( const QString & ) ) ); | ||
95 | |||
96 | connect( P, | ||
97 | SIGNAL(processExited(MyProcess*) ), | ||
98 | this, SLOT | ||
99 | (SLOT_ProcessExited(MyProcess*) ) ); | ||
100 | } | ||
86 | 101 | ||
87 | connect( P, | 102 | P->process() << S; |
88 | SIGNAL(processExited(MyProcess*) ), | ||
89 | this, SLOT | ||
90 | (SLOT_ProcessExited(MyProcess*) ) ); | ||
91 | 103 | ||
92 | Log(("Executing %s\n", S.join( " " ).latin1() )); | 104 | Log(("Executing %s\n", S.join( " " ).latin1() )); |
93 | 105 | ||
94 | if( ! P->process().start( OProcess::DontCare, | 106 | if( ! P->process().start( OProcess::DontCare, |
95 | OProcess::AllOutput ) ) { | 107 | OProcess::AllOutput ) ) { |
96 | owarn << "Error starting " << S << oendl; | 108 | owarn << "Error starting " << S << oendl; |
97 | delete P; | 109 | if( ! Prc ) |
110 | delete P; | ||
98 | // error starting app | 111 | // error starting app |
99 | return 1; | 112 | return 1; |
100 | } | 113 | } |
101 | owarn << "Started " << S << oendl; | 114 | owarn << "Started " << S << oendl; |
102 | } | 115 | } |
103 | 116 | ||
104 | // all is fine | 117 | // all is fine |
105 | return 0; | 118 | return 0; |
106 | } | 119 | } |
107 | 120 | ||
108 | int System::execAsUser( QStringList & SL ) { | 121 | int System::execAsUser( QStringList & SL ) { |
109 | MyProcess * P = new MyProcess(); | 122 | MyProcess * P = new MyProcess(); |