diff --git a/FileUtils.h b/FileUtils.h index a707b822..e203b720 100644 --- a/FileUtils.h +++ b/FileUtils.h @@ -292,14 +292,12 @@ public: m_iPid = -1; } - CExecSock(const CString& sExec) : Csock() { - Execute(sExec); - } - int Execute(const CString & sExec) { int iReadFD, iWriteFD; m_iPid = popen2(iReadFD, iWriteFD, sExec); - ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0"); + if (m_iPid != -1) { + ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0"); + } return(m_iPid); } void Kill(int iSignal) diff --git a/modules/shell.cpp b/modules/shell.cpp index b64842d7..f16c9567 100644 --- a/modules/shell.cpp +++ b/modules/shell.cpp @@ -14,11 +14,18 @@ class CShellMod; class CShellSock : public CExecSock { public: - CShellSock(CShellMod* pShellMod, CClient* pClient, const CString& sExec) : CExecSock(sExec) { + CShellSock(CShellMod* pShellMod, CClient* pClient, const CString& sExec) : CExecSock() { EnableReadLine(); m_pParent = pShellMod; m_pClient = pClient; + if (Execute(sExec) == -1) { + CString s = "Failed to execute: "; + s += strerror(errno); + ReadLine(s); + return; + } + // Get rid of that write fd, we aren't going to use it // (And clients expecting input will fail this way). close(GetWSock());