HostDnsServiceLinux.cpp revision 6098976ad1621117036ceaeb145cc3fc8703bbf1
/* $Id$ */
/** @file
* Linux specific DNS information fetching.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <iprt/initterm.h>
#include <iprt/semaphore.h>
#include <errno.h>
#include <poll.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <vector>
#include "../HostDnsService.h"
static int g_DnsMonitorStop[2];
class FileDescriptor
{
public:
virtual ~FileDescriptor() {
if (fd != -1)
}
int fileDescriptor() const {return fd;}
protected:
int fd;
};
class AutoNotify:public FileDescriptor
{
public:
{
}
};
struct InotifyEventWithName
{
struct inotify_event e;
};
{
}
int HostDnsServiceLinux::monitorWorker()
{
AutoNotify a;
int wd[2];
/* inotify inialization */
/**
* If /etc/resolv.conf exists we want to listen for movements: because
* # mv /etc/resolv.conf ...
* won't arm IN_DELETE_SELF on wd[0] instead it will fire IN_MOVE_FROM on wd[1].
*
* Because on some distributions /etc/resolv.conf is link, wd[0] can't detect deletion,
* it's recognizible on directory level (wd[1]) only.
*/
struct InotifyEventWithName combo;
while(true)
{
if (rc == -1)
continue;
("Debug Me"), VERR_INTERNAL_ERROR);
return VINF_SUCCESS; /* time to shutdown */
{
NOREF(r);
{
{
/* notifyAll() takes required locks */
notifyAll();
}
{
}
{
}
else
{
/**
* It shouldn't happen, in release we will just ignore in debug
* we will have to chance to look at into inotify_event
*/
AssertMsgFailed(("Debug Me!!!"));
}
}
{
{
{
/**
* Our file has been moved so we should change watching mode.
*/
("It shouldn't happen, further investigation is needed\n"));
}
}
else
{
("%RX32 event isn't expected, we are waiting for IN_MOVED|IN_CREATE\n",
{
/* alter folder watcher*/
/* Notify our listeners */
notifyAll();
}
}
}
else
{
/* It shouldn't happen */
AssertMsgFailed(("Shouldn't happen! Please debug me!"));
}
}
}
}
{
}