Prevent handle leaks. Get stderr when snapshotting/removing snapshot in backup hook

This commit is contained in:
Martin 2016-01-14 20:59:46 +01:00
parent 344a69740a
commit d47668fb5f
12 changed files with 77 additions and 17 deletions

View File

@ -69,7 +69,11 @@ CAcceptThread::CAcceptThread( unsigned int nWorkerThreadsPerMaster, unsigned sho
{
WorkerThreadsPerMaster=nWorkerThreadsPerMaster;
s=socket(AF_INET,SOCK_STREAM,0);
int type = SOCK_STREAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
s=socket(AF_INET, type, 0);
if(s<1)
{
Server->Log("Creating SOCKET failed. Port "+convert((int)uPort)+" may already be in use",LL_ERROR);

View File

@ -38,7 +38,11 @@ void CLoadbalancerClient::operator ()(void)
rc = WSAStartup(MAKEWORD(2,2), &wsadata);
if(rc == SOCKET_ERROR) return;
#endif
SOCKET s=socket(AF_INET,SOCK_STREAM,0);
int type = SOCK_STREAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
SOCKET s=socket(AF_INET, type,0);
if(s<1)
{
Server->Log("Creating SOCKET failed (LB)",LL_ERROR);

View File

@ -973,7 +973,12 @@ IPipe* CServer::ConnectStream(std::string pServer, unsigned short pPort, unsigne
server.sin_port=htons(pPort);
server.sin_family=AF_INET;
SOCKET s=socket(AF_INET, SOCK_STREAM, 0);
int type = SOCK_STREAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
SOCKET s=socket(AF_INET, type, 0);
if(s==SOCKET_ERROR)
{
return NULL;

View File

@ -48,7 +48,11 @@ CServiceAcceptor::CServiceAcceptor(IService * pService, std::string pName, unsig
if(rc == SOCKET_ERROR) return;
#endif
s=socket(AF_INET,SOCK_STREAM,0);
int type = SOCK_STREAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
s=socket(AF_INET,type,0);
if(s<1)
{
Server->Log(name+": Creating SOCKET failed",LL_ERROR);

View File

@ -117,7 +117,11 @@ std::string Connector::getResponse(const std::string &cmd, const std::string &ar
pw=trim(getFile(pwfile_change));
}
SOCKET p=socket(AF_INET, SOCK_STREAM, 0);
int type = SOCK_STREAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
SOCKET p=socket(AF_INET, type, 0);
sockaddr_in addr;
memset(&addr,0,sizeof(sockaddr_in));
if(!LookupBlocking(client, &addr.sin_addr))

View File

@ -110,6 +110,9 @@ bool File::Open(std::string pfn, int mode)
return false;
}
#if defined(O_CLOEXEC)
flags |= O_CLOEXEC;
#endif
fd=open64((fn).c_str(), flags|O_LARGEFILE, imode);

View File

@ -815,7 +815,11 @@ bool CClientThread::ProcessPacket(CRData *data)
break;
}
hFile=open64(filename.c_str(), O_RDONLY|O_LARGEFILE);
int flags = O_RDONLY | O_LARGEFILE;
#if defined(O_CLOEXEC)
flags |= O_CLOEXEC;
#endif
hFile=open64(filename.c_str(), flags);
if(hFile == INVALID_HANDLE_VALUE)
{
@ -1601,7 +1605,11 @@ bool CClientThread::GetFileBlockdiff(CRData *data, bool with_metadata)
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
#endif
#else //_WIN32
hFile=open64(filename.c_str(), O_RDONLY|O_LARGEFILE);
int flags = O_RDONLY | O_LARGEFILE;
#if defined(O_CLOEXEC)
flags |= O_CLOEXEC;
#endif
hFile=open64(filename.c_str(), flags);
#endif //_WIN32
if(hFile == INVALID_HANDLE_VALUE)
@ -1817,7 +1825,11 @@ bool CClientThread::GetFileHashAndMetadata( CRData* data )
hFile=CreateFileW(Server->ConvertToWchar(filename).c_str(), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
#endif
#else //_WIN32
hFile=open64(filename.c_str(), O_RDONLY|O_LARGEFILE);
int flags = O_RDONLY | O_LARGEFILE;
#if defined(O_CLOEXEC)
flags |= O_CLOEXEC;
#endif
hFile=open64(filename.c_str(), flags);
#endif //_WIN32
if(hFile == INVALID_HANDLE_VALUE)

View File

@ -113,7 +113,11 @@ bool CTCPFileServ::Start(_u16 tcpport,_u16 udpport, std::string pServername, boo
if(tcpport!=0)
{
mSocket=socket(AF_INET,SOCK_STREAM,0);
int type = SOCK_STREAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
mSocket=socket(AF_INET, type, 0);
if(mSocket<1) return false;
#ifndef DISABLE_WINDOW_SIZE

View File

@ -110,7 +110,11 @@ void CUDPThread::init(_u16 udpport,std::string servername, bool use_fqdn)
use_fqdn_=use_fqdn;
{
udpsock=socket(AF_INET,SOCK_DGRAM,0);
int type = SOCK_DGRAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
udpsock=socket(AF_INET, type, 0);
int optval=1;
int rc=setsockopt(udpsock, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(int));

View File

@ -2157,7 +2157,7 @@ bool IndexThread::deleteShadowcopy(SCDirs *dir)
int rc = os_popen("/etc/urbackup/"+scriptname+" "+guidToString(dir->ref->ssetid)+" "+escapeDirParam(dir->ref->volpath)
+" "+escapeDirParam(dir->dir)+" "+escapeDirParam(dir->target)+" "+escapeDirParam(dir->orig_target)
+ (dir->ref->clientsubname.empty() ? "" : (" " + escapeDirParam(dir->ref->clientsubname))), loglines);
+ (dir->ref->clientsubname.empty() ? "" : (" " + escapeDirParam(dir->ref->clientsubname)))+" 2>&1", loglines);
if(rc!=0)
{
VSSLog("Error removing snapshot to "+dir->target, LL_ERROR);
@ -2645,7 +2645,7 @@ int IndexThread::execute_hook(std::string script_name, bool incr, std::string se
#endif
std::string output;
int rc = os_popen(quoted_script_name + " " + (incr ? "1" : "0") + " \"" + server_token + "\" " + convert(index_group), output);
int rc = os_popen(quoted_script_name + " " + (incr ? "1" : "0") + " \"" + server_token + "\" " + convert(index_group)+" 2>&1", output);
if (rc != 0 && !output.empty())
{
@ -4449,7 +4449,7 @@ bool IndexThread::start_shadowcopy_lin( SCDirs * dir, std::string &wpath, bool f
std::string loglines;
int rc = os_popen("/etc/urbackup/"+scriptname+" "+guidToString(ssetid)+" "+escapeDirParam(dir->ref->target)+" "+
escapeDirParam(dir->dir)+" "+escapeDirParam(dir->orig_target)
+ (index_clientsubname.empty()?"":(" " + escapeDirParam(index_clientsubname))), loglines);
+ (index_clientsubname.empty()?"":(" " + escapeDirParam(index_clientsubname)))+" 2>&1", loglines);
if(rc!=0)
{

View File

@ -766,7 +766,11 @@ namespace
bool ping_server(void)
{
SOCKET udpsock=socket(AF_INET,SOCK_DGRAM,0);
int type = SOCK_DGRAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
SOCKET udpsock=socket(AF_INET, type,0);
std::string server=Server->getServerParameter("ping_server");
@ -1143,8 +1147,12 @@ bool has_network_device(void)
int nInterfaces;
int i;
int type = SOCK_DGRAM;
#if !defined(_WIN32) && defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
/* Get a socket handle. */
sck = socket(AF_INET, SOCK_DGRAM, 0);
sck = socket(AF_INET, type, 0);
if(sck < 0)
{
return true;

View File

@ -156,7 +156,11 @@ void FileClient::bindToNewInterfaces()
if(std::find(broadcast_iface_addrs.begin(), broadcast_iface_addrs.end(), source_addr.sin_addr.s_addr)!=broadcast_iface_addrs.end())
continue;
SOCKET udpsock=socket(AF_INET,SOCK_DGRAM,0);
int type = SOCK_DGRAM;
#if defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
SOCKET udpsock=socket(AF_INET, type,0);
if(udpsock==-1)
{
Server->Log(std::string("Error creating socket for interface ")+std::string(ifap->ifa_name), LL_ERROR);
@ -210,7 +214,11 @@ void FileClient::bindToNewInterfaces()
Server->Log("Getting interface ips failed. errno="+convert(errno)+
". Server may not listen properly on all network devices when discovering clients.", LL_ERROR);
SOCKET udpsock=socket(AF_INET,SOCK_DGRAM,0);
int type = SOCK_DGRAM;
#if defined(SOCK_CLOEXEC)
type |= SOCK_CLOEXEC;
#endif
SOCKET udpsock=socket(AF_INET, type,0);
if(udpsock==-1)
{
Server->Log("Error creating socket", LL_ERROR);