-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExecSock.h
49 lines (42 loc) · 1.01 KB
/
ExecSock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* 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 "zncconfig.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