author | dwmw2 <dwmw2> | 2002-09-23 08:37:16 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2002-09-23 08:37:16 (UTC) |
commit | 8b06ea9e4407628ebae54d63592e8b8c940a62ad (patch) (side-by-side diff) | |
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 | 56 | ||||
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.h | 5 |
2 files changed, 53 insertions, 8 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 ) this, SLOT(log_sshadd_output(OProcess*,char*,int))); connect(&addprocess, SIGNAL(receivedStderr(OProcess*,char*,int)), - this, SLOT(log_sshadd_output(OProcess*,char*,int))); + this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); connect(&addprocess, SIGNAL(processExited(OProcess*)), this, SLOT(ssh_add_exited(OProcess*))); @@ -91,5 +91,5 @@ void SSHKeysApp::doRefreshListButton() this, SLOT(get_list_keys_output(OProcess*,char*,int))); connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), - this, SLOT(log_sshadd_output(OProcess*,char*,int))); + this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); keystate = KeySize; @@ -105,4 +105,5 @@ void SSHKeysApp::doRefreshListButton() return; } + flush_sshadd_output(); if (sshadd_process.exitStatus() == 2) { setEnabled(FALSE); @@ -178,10 +179,47 @@ void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) } +void SSHKeysApp::flush_sshadd_output(void) +{ + if (pending_stdout.length()) { + log_text(pending_stdout.ascii()); + } + pending_stdout = ""; + + if (pending_stderr.length()) { + log_text(pending_stderr.ascii()); + } + pending_stderr = ""; +} + void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) { (void)proc; - (void)buflen; - log_text(buffer); + while (buflen) { + if (*buffer == '\n') { + log_text(pending_stdout); + pending_stdout = ""; + } else { + pending_stdout += *buffer; + } + buffer++; + buflen--; + } +} + +void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen) +{ + (void) proc; + + while (buflen) { + if (*buffer == '\n') { + log_text(pending_stderr); + pending_stderr = ""; + } else { + pending_stderr += *buffer; + } + buffer++; + buflen--; + } } @@ -217,8 +255,8 @@ void SSHKeysApp::doAddButton() if (KeyFileName->currentText().length()) { addprocess << "ssh-add" << "--" << KeyFileName->currentText(); - log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); +// log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); } else { addprocess << "ssh-add"; - log_text(tr("Running ssh-add")); +// log_text(tr("Running ssh-add")); } bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); @@ -228,4 +266,5 @@ void SSHKeysApp::doAddButton() setEnabled(TRUE); } + flush_sshadd_output(); } @@ -243,7 +282,7 @@ void SSHKeysApp::doRemoveAllButton() this, SLOT(log_sshadd_output(OProcess*,char*,int))); connect(&sshadd_process, SIGNAL(receivedStderr(OProcess*,char*,int)), - this, SLOT(log_sshadd_output(OProcess*,char*,int))); + this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); - log_text(tr("Running ssh-add -D")); +// log_text(tr("Running ssh-add -D")); sshadd_process << "ssh-add" << "-D"; bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); @@ -251,4 +290,5 @@ void SSHKeysApp::doRemoveAllButton() log_text(tr("Error running ssh-add")); } + flush_sshadd_output(); doRefreshListButton(); } 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 private: void log_text(const char *text); + void flush_sshadd_output(void); + enum { Noise, KeyName, KeySize, KeyFingerprint } keystate; QString incoming_keyname; @@ -42,4 +44,6 @@ class SSHKeysApp : public SSHKeysBase QString incoming_noise; OProcess addprocess; + QString pending_stdout; + QString pending_stderr; private slots: @@ -49,4 +53,5 @@ class SSHKeysApp : public SSHKeysBase void get_list_keys_output(OProcess *proc, char *buffer, int buflen); void log_sshadd_output(OProcess *proc, char *buffer, int buflen); + void log_sshadd_stderr(OProcess *proc, char *buffer, int buflen); void ssh_add_exited(OProcess *proc); void add_text_changed(const QString &text); |