author | dwmw2 <dwmw2> | 2002-09-23 08:37:16 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2002-09-23 08:37:16 (UTC) |
commit | 8b06ea9e4407628ebae54d63592e8b8c940a62ad (patch) (unidiff) | |
tree | 344af00df0e403c5b5d5475e641489213ace46f7 | |
parent | d7098ef25f7f4ebe5678061aa3a3c0bd1f077f7f (diff) | |
download | opie-8b06ea9e4407628ebae54d63592e8b8c940a62ad.zip opie-8b06ea9e4407628ebae54d63592e8b8c940a62ad.tar.gz opie-8b06ea9e4407628ebae54d63592e8b8c940a62ad.tar.bz2 |
Log stderr more sanely, fix buffer abuse. It is really sane to use '+=' on
a QString? Do I care? It's C++, let it do what it does best -- hide
implementation details like the fact that some stuff _really_ sucks and
encourage the programmer to do those things :)
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.cpp | 58 | ||||
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.h | 5 |
2 files changed, 54 insertions, 9 deletions
diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp index c5e1170..43e02af 100644 --- a/noncore/settings/sshkeys/sshkeys.cpp +++ b/noncore/settings/sshkeys/sshkeys.cpp | |||
@@ -50,5 +50,5 @@ SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) | |||
50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 50 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); |
51 | connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), | 51 | connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), |
52 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 52 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); |
53 | connect(&addprocess, SIGNAL(processExited(OProcess*)), | 53 | connect(&addprocess, SIGNAL(processExited(OProcess*)), |
54 | this, SLOT(ssh_add_exited(OProcess*))); | 54 | this, SLOT(ssh_add_exited(OProcess*))); |
@@ -91,5 +91,5 @@ void SSHKeysApp::doRefreshListButton() | |||
91 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); | 91 | this, SLOT(get_list_keys_output(OProcess*,char*,int))); |
92 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), | 92 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), |
93 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 93 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); |
94 | 94 | ||
95 | keystate = KeySize; | 95 | keystate = KeySize; |
@@ -105,4 +105,5 @@ void SSHKeysApp::doRefreshListButton() | |||
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | flush_sshadd_output(); | ||
107 | if (sshadd_process.exitStatus() == 2) { | 108 | if (sshadd_process.exitStatus() == 2) { |
108 | setEnabled(FALSE); | 109 | setEnabled(FALSE); |
@@ -178,10 +179,47 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) | |||
178 | } | 179 | } |
179 | 180 | ||
181 | void SSHKeysApp::flush_sshadd_output(void) | ||
182 | { | ||
183 | if (pending_stdout.length()) { | ||
184 | log_text(pending_stdout.ascii()); | ||
185 | } | ||
186 | pending_stdout = ""; | ||
187 | |||
188 | if (pending_stderr.length()) { | ||
189 | log_text(pending_stderr.ascii()); | ||
190 | } | ||
191 | pending_stderr = ""; | ||
192 | } | ||
193 | |||
180 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) | 194 | void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) |
181 | { | 195 | { |
182 | (void)proc; | 196 | (void) proc; |
183 | (void)buflen; | ||
184 | 197 | ||
185 | log_text(buffer); | 198 | while (buflen) { |
199 | if (*buffer == '\n') { | ||
200 | log_text(pending_stdout); | ||
201 | pending_stdout = ""; | ||
202 | } else { | ||
203 | pending_stdout += *buffer; | ||
204 | } | ||
205 | buffer++; | ||
206 | buflen--; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen) | ||
211 | { | ||
212 | (void) proc; | ||
213 | |||
214 | while (buflen) { | ||
215 | if (*buffer == '\n') { | ||
216 | log_text(pending_stderr); | ||
217 | pending_stderr = ""; | ||
218 | } else { | ||
219 | pending_stderr += *buffer; | ||
220 | } | ||
221 | buffer++; | ||
222 | buflen--; | ||
223 | } | ||
186 | } | 224 | } |
187 | 225 | ||
@@ -217,8 +255,8 @@ void SSHKeysApp::doAddButton() | |||
217 | if (KeyFileName->currentText().length()) { | 255 | if (KeyFileName->currentText().length()) { |
218 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); | 256 | addprocess << "ssh-add" << "--" << KeyFileName->currentText(); |
219 | log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); | 257 | // log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); |
220 | } else { | 258 | } else { |
221 | addprocess << "ssh-add"; | 259 | addprocess << "ssh-add"; |
222 | log_text(tr("Running ssh-add")); | 260 | // log_text(tr("Running ssh-add")); |
223 | } | 261 | } |
224 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); | 262 | bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); |
@@ -228,4 +266,5 @@ void SSHKeysApp::doAddButton() | |||
228 | setEnabled(TRUE); | 266 | setEnabled(TRUE); |
229 | } | 267 | } |
268 | flush_sshadd_output(); | ||
230 | } | 269 | } |
231 | 270 | ||
@@ -243,7 +282,7 @@ void SSHKeysApp::doRemoveAllButton() | |||
243 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 282 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); |
244 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), | 283 | connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), |
245 | this, SLOT(log_sshadd_output(OProcess*,char*,int))); | 284 | this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); |
246 | 285 | ||
247 | log_text(tr("Running ssh-add -D")); | 286 | //log_text(tr("Running ssh-add -D")); |
248 | sshadd_process << "ssh-add" << "-D"; | 287 | sshadd_process << "ssh-add" << "-D"; |
249 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); | 288 | bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); |
@@ -251,4 +290,5 @@ void SSHKeysApp::doRemoveAllButton() | |||
251 | log_text(tr("Error running ssh-add")); | 290 | log_text(tr("Error running ssh-add")); |
252 | } | 291 | } |
292 | flush_sshadd_output(); | ||
253 | doRefreshListButton(); | 293 | doRefreshListButton(); |
254 | } | 294 | } |
diff --git a/noncore/settings/sshkeys/sshkeys.h b/noncore/settings/sshkeys/sshkeys.h index 5e306d1..bbc6993 100644 --- a/noncore/settings/sshkeys/sshkeys.h +++ b/noncore/settings/sshkeys/sshkeys.h | |||
@@ -36,4 +36,6 @@ class SSHKeysApp : public SSHKeysBase | |||
36 | private: | 36 | private: |
37 | void log_text(const char *text); | 37 | void log_text(const char *text); |
38 | void flush_sshadd_output(void); | ||
39 | |||
38 | enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; | 40 | enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; |
39 | QString incoming_keyname; | 41 | QString incoming_keyname; |
@@ -42,4 +44,6 @@ class SSHKeysApp : public SSHKeysBase | |||
42 | QString incoming_noise; | 44 | QString incoming_noise; |
43 | OProcess addprocess; | 45 | OProcess addprocess; |
46 | QString pending_stdout; | ||
47 | QString pending_stderr; | ||
44 | 48 | ||
45 | private slots: | 49 | private slots: |
@@ -49,4 +53,5 @@ class SSHKeysApp : public SSHKeysBase | |||
49 | void get_list_keys_output(OProcess *proc, char *buffer, int buflen); | 53 | void get_list_keys_output(OProcess *proc, char *buffer, int buflen); |
50 | void log_sshadd_output(OProcess *proc, char *buffer, int buflen); | 54 | void log_sshadd_output(OProcess *proc, char *buffer, int buflen); |
55 | void log_sshadd_stderr(OProcess *proc, char *buffer, int buflen); | ||
51 | void ssh_add_exited(OProcess *proc); | 56 | void ssh_add_exited(OProcess *proc); |
52 | void add_text_changed(const QString &text); | 57 | void add_text_changed(const QString &text); |