mirror of
https://github.com/znc/znc.git
synced 2026-08-07 17:33:34 +02:00
Move CExecSock to ExecSock.h
As a result, Utils.h no longer has to include Socket.h and lots of stuff breaks. Due to a severe case of lazyness, some of the code for CExecSock is still in Utils.cpp. Feel free to fix if you really have to. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "zncconfig.h"
|
||||
#include "FileUtils.h"
|
||||
#include "Socket.h"
|
||||
|
||||
// Forward Declarations
|
||||
class CUser;
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2011 See the AUTHORS file for details.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef EXEC_SOCK_H
|
||||
#define EXEC_SOCK_H
|
||||
|
||||
#include "Socket.h"
|
||||
#include <signal.h>
|
||||
|
||||
//! @author imaginos@imaginos.net
|
||||
class CExecSock : public CZNCSock {
|
||||
public:
|
||||
CExecSock() : CZNCSock() {
|
||||
m_iPid = -1;
|
||||
}
|
||||
|
||||
int Execute(const CString & sExec) {
|
||||
int iReadFD, iWriteFD;
|
||||
m_iPid = popen2(iReadFD, iWriteFD, sExec);
|
||||
if (m_iPid != -1) {
|
||||
ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0");
|
||||
}
|
||||
return(m_iPid);
|
||||
}
|
||||
void Kill(int iSignal)
|
||||
{
|
||||
kill(m_iPid, iSignal);
|
||||
Close();
|
||||
}
|
||||
virtual ~CExecSock() {
|
||||
close2(m_iPid, GetRSock(), GetWSock());
|
||||
SetRSock(-1);
|
||||
SetWSock(-1);
|
||||
}
|
||||
|
||||
int popen2(int & iReadFD, int & iWriteFD, const CString & sCommand);
|
||||
void close2(int iPid, int iReadFD, int iWriteFD);
|
||||
|
||||
private:
|
||||
int m_iPid;
|
||||
};
|
||||
|
||||
#endif // !EXEC_SOCK_H
|
||||
+5
-2
@@ -7,12 +7,15 @@
|
||||
*/
|
||||
|
||||
#include "FileUtils.h"
|
||||
#include "ExecSock.h"
|
||||
#include "Utils.h"
|
||||
#include "ZNCDebug.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#ifndef HAVE_LSTAT
|
||||
# define lstat(a, b) stat(a, b)
|
||||
|
||||
+3
-35
@@ -10,11 +10,12 @@
|
||||
#define _FILEUTILS_H
|
||||
|
||||
#include "zncconfig.h"
|
||||
#include "Socket.h"
|
||||
#include "ZNCString.h"
|
||||
#include <dirent.h>
|
||||
#include <map>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
@@ -256,37 +257,4 @@ protected:
|
||||
CFile::EFileAttr m_eSortAttr;
|
||||
bool m_bDesc;
|
||||
};
|
||||
|
||||
//! @author imaginos@imaginos.net
|
||||
class CExecSock : public CZNCSock {
|
||||
public:
|
||||
CExecSock() : CZNCSock() {
|
||||
m_iPid = -1;
|
||||
}
|
||||
|
||||
int Execute(const CString & sExec) {
|
||||
int iReadFD, iWriteFD;
|
||||
m_iPid = popen2(iReadFD, iWriteFD, sExec);
|
||||
if (m_iPid != -1) {
|
||||
ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0");
|
||||
}
|
||||
return(m_iPid);
|
||||
}
|
||||
void Kill(int iSignal)
|
||||
{
|
||||
kill(m_iPid, iSignal);
|
||||
Close();
|
||||
}
|
||||
virtual ~CExecSock() {
|
||||
close2(m_iPid, GetRSock(), GetWSock());
|
||||
SetRSock(-1);
|
||||
SetWSock(-1);
|
||||
}
|
||||
|
||||
int popen2(int & iReadFD, int & iWriteFD, const CString & sCommand);
|
||||
void close2(int iPid, int iReadFD, int iWriteFD);
|
||||
|
||||
private:
|
||||
int m_iPid;
|
||||
};
|
||||
#endif // !_FILEUTILS_H
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Template.h"
|
||||
#include "FileUtils.h"
|
||||
#include "ZNCDebug.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Modules.h"
|
||||
#include "Client.h"
|
||||
#include "FileUtils.h"
|
||||
|
||||
class CMotdFileMod : public CGlobalModule {
|
||||
public:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "User.h"
|
||||
#include "znc.h"
|
||||
#include "ExecSock.h"
|
||||
|
||||
// Forward Declaration
|
||||
class CShellMod;
|
||||
|
||||
Reference in New Issue
Block a user