[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: sftp ioslave patch
From: Lucas Fisher <ljfisher () iastate ! edu>
Date: 2002-03-11 21:00:01
[Download RAW message or body]
This is an important patch for ksshprocess that is part of my sftp ioslave.
It checks that a ssh process has actually been started and that the pid is valid
before trying to kill it, otherwise bad things may happen.
Please review.
Index: ksshprocess.h
===================================================================
RCS file: /home/kde/kdebase/kioslave/sftp/ksshprocess.h,v
retrieving revision 1.7
diff -u -3 -p -r1.7 ksshprocess.h
--- ksshprocess.h 2001/08/30 02:36:55 1.7
+++ ksshprocess.h 2002/03/12 02:07:13
@@ -258,6 +258,7 @@ private:
QString mUsername;
QString mHost;
bool mConnected;
+ bool mRunning;
int mPort;
int mError;
QString mErrorMsg;
Index: ksshprocess.cpp
===================================================================
RCS file: /home/kde/kdebase/kioslave/sftp/ksshprocess.cpp,v
retrieving revision 1.12
diff -u -3 -p -r1.12 ksshprocess.cpp
--- ksshprocess.cpp 2002/02/28 04:36:22 1.12
+++ ksshprocess.cpp 2002/03/12 02:07:13
@@ -111,6 +111,7 @@ KSshProcess::~KSshProcess(){
void KSshProcess::init() {
mVersion = -1;
mConnected = false;
+ mRunning = false;
}
bool KSshProcess::setSshPath(QString pathToSsh) {
@@ -340,10 +341,23 @@ int KSshProcess::error(QString& msg) {
}
void KSshProcess::kill(int signal) {
- // expects the signal to kill the process. we should change this later
- ::kill(ssh.pid(), signal);
- ::waitpid(ssh.pid(), NULL, 0);
- mConnected = false;
+ kdDebug(KSSHPROC) << "KSshProcess::kill(): ssh pid is " << ssh.pid() << endl;
+ kdDebug(KSSHPROC) << "KSshPRocess::kill(): we are " << (mConnected ? "" : "not ") <<
+ "connected" << endl;
+ kdDebug(KSSHPROC) << "KSshProcess::kill(): we are " << (mRunning ? "" : "not ") <<
+ "running a ssh process" << endl;
+
+ if( mRunning && ssh.pid() > 1 ) { // make sure there is a running ssh process
+ if( ::kill(ssh.pid(), signal) == 0 ) {
+ ::waitpid(ssh.pid(), NULL, 0);
+ mConnected = false;
+ mRunning = false;
+ }
+ else
+ kdDebug(KSSHPROC) << "KSshProcess::kill(): kill failed" << endl;
+ }
+ else
+ kdDebug(KSSHPROC) << "KSshProcess::kill(): Refusing to kill ssh process" << endl;
}
bool KSshProcess::connect(bool acceptHostKey) {
@@ -366,7 +380,9 @@ bool KSshProcess::connect(bool acceptHos
mError = ERR_CANNOT_LAUNCH;
return false;
}
-
+
+ mRunning = true;
+
int ptyfd = ssh.fd();
int errfd = ssh.stderrFd();
int stdiofd = ssh.stdioFd();
@@ -488,6 +504,7 @@ bool KSshProcess::connect(bool acceptHos
else if( errLine.contains(authSuccessMsg[mVersion]) ) {
// Authentication has succeeded!
kdDebug(KSSHPROC) << "KSshProcess::connect(): Authentication succeeded." << endl;
+ mConnected = true;
return true;
}
else {
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic