|| command->GetImpersonationLevel() == ImpersonationLevel::ImpersonateRoot) {
TCHAR szPath[MAX_PATH];
- if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath))) {
+ if (GetModuleFileName(nullptr, szPath, ARRAYSIZE(szPath))) {
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpVerb = _T("runas");
sei.lpFile = "cmd.exe";
if (!command || vm.count("help")) {
if (!command)
- CLICommand::ShowCommands(argc, argv, NULL);
+ CLICommand::ShowCommands(argc, argv, nullptr);
std::cout << visibleDesc << std::endl
<< "Report bugs at <https://github.com/Icinga/icinga2>" << std::endl
}
if (getgid() != gr->gr_gid) {
- if (!vm.count("reload-internal") && setgroups(0, NULL) < 0) {
+ if (!vm.count("reload-internal") && setgroups(0, nullptr) < 0) {
Log(LogCritical, "cli")
<< "setgroups() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
Log(LogCritical, "cli")
#ifdef _WIN32
static int SetupService(bool install, int argc, char **argv)
{
- SC_HANDLE schSCManager = OpenSCManager(
- NULL,
- NULL,
- SC_MANAGER_ALL_ACCESS);
+ SC_HANDLE schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
- if (NULL == schSCManager) {
+ if (!schSCManager) {
printf("OpenSCManager failed (%d)\n", GetLastError());
return 1;
}
TCHAR szPath[MAX_PATH];
- if (!GetModuleFileName(NULL, szPath, MAX_PATH)) {
+ if (!GetModuleFileName(nullptr, szPath, MAX_PATH)) {
printf("Cannot install service (%d)\n", GetLastError());
return 1;
}
SC_HANDLE schService = OpenService(schSCManager, "icinga2", SERVICE_ALL_ACCESS);
- if (schService != NULL) {
+ if (schService) {
SERVICE_STATUS status;
ControlService(schService, SERVICE_CONTROL_STOP, &status);
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
szArgs.CStr(),
- NULL,
- NULL,
- NULL,
+ nullptr,
+ nullptr,
+ nullptr,
scmUser.c_str(),
- NULL);
+ nullptr);
- if (schService == NULL) {
+ if (!schService) {
printf("CreateService failed (%d)\n", GetLastError());
CloseServiceHandle(schSCManager);
return 1;
printf("Service uninstalled successfully\n");
} else {
if (!ChangeServiceConfig(schService, SERVICE_NO_CHANGE, SERVICE_AUTO_START,
- SERVICE_ERROR_NORMAL, szArgs.CStr(), NULL, NULL, NULL, scmUser.c_str(), NULL, NULL)) {
+ SERVICE_ERROR_NORMAL, szArgs.CStr(), nullptr, nullptr, nullptr, scmUser.c_str(), nullptr, nullptr)) {
printf("ChangeServiceConfig failed (%d)\n", GetLastError());
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
return 1;
}
- if (!StartService(schService, 0, NULL)) {
+ if (!StartService(schService, 0, nullptr)) {
printf("StartService failed (%d)\n", GetLastError());
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
l_SvcStatus.dwServiceSpecificExitCode = 0;
ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
- l_Job = CreateJobObject(NULL, NULL);
+ l_Job = CreateJobObject(nullptr, nullptr);
for (;;) {
LPSTR arg = argv[0];
char *uargs = strdup(args.CStr());
- BOOL res = CreateProcess(NULL, uargs, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ BOOL res = CreateProcess(nullptr, uargs, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi);
free(uargs);
if (argc > 1 && strcmp(argv[1], "--scm") == 0) {
SERVICE_TABLE_ENTRY dispatchTable[] = {
{ "icinga2", ServiceMain },
- { NULL, NULL }
+ { nullptr, nullptr }
};
StartServiceCtrlDispatcher(dispatchTable);
static std::string GetIcingaInstallPath(void)
{
char szFileName[MAX_PATH];
- if (!GetModuleFileName(NULL, szFileName, sizeof(szFileName)))
+ if (!GetModuleFileName(nullptr, szFileName, sizeof(szFileName)))
return "";
if (!PathRemoveFileSpec(szFileName))
static std::string GetIcingaDataPath(void)
{
char path[MAX_PATH];
- if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path)))
+ if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, path)))
throw std::runtime_error("SHGetFolderPath failed");
return std::string(path) + "\\icinga2";
}
BYTE pvData[MAX_PATH];
DWORD cbData = sizeof(pvData) - 1;
DWORD lType;
- if (RegQueryValueEx(hKey, NULL, NULL, &lType, pvData, &cbData) == ERROR_SUCCESS && lType == REG_SZ) {
+ if (RegQueryValueEx(hKey, nullptr, nullptr, &lType, pvData, &cbData) == ERROR_SUCCESS && lType == REG_SZ) {
pvData[cbData] = '\0';
return (char *)pvData;
*/
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
- CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
+ CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
//AllocConsole();
int rc;
} else if (strcmp(lpCmdLine, "upgrade-nsis") == 0) {
rc = UpgradeNSIS();
} else {
- MessageBox(NULL, "This application should only be run by the MSI installer package.", "Icinga 2 Installer", MB_ICONWARNING);
+ MessageBox(nullptr, "This application should only be run by the MSI installer package.", "Icinga 2 Installer", MB_ICONWARNING);
rc = 1;
}
std::string url = wUrl.ToStdString();
- ConnectForm f(NULL, new Url(url));
+ ConnectForm f(nullptr, new Url(url));
if (f.ShowModal() != wxID_OK)
return false;
pUrl = new Url(argv[1].ToStdString());
}
- MainForm *m = new MainForm(NULL, pUrl);
+ MainForm *m = new MainForm(nullptr, pUrl);
m->Show();
return true;
REGISTER_TYPE(Application);
boost::signals2::signal<void (void)> Application::OnReopenLogs;
-Application::Ptr Application::m_Instance = NULL;
+Application::Ptr Application::m_Instance = nullptr;
bool Application::m_ShuttingDown = false;
bool Application::m_RequestRestart = false;
bool Application::m_RequestReopenLogs = false;
*/
void Application::OnConfigLoaded(void)
{
- m_PidFile = NULL;
+ m_PidFile = nullptr;
- ASSERT(m_Instance == NULL);
+ ASSERT(m_Instance == nullptr);
m_Instance = this;
}
Application::~Application(void)
{
- m_Instance = NULL;
+ m_Instance = nullptr;
}
void Application::Exit(int rc)
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
- sigaction(SIGPIPE, &sa, NULL);
+ sigaction(SIGPIPE, &sa, nullptr);
#endif /* _WIN32 */
Loader::ExecuteDeferredInitializers();
for (int i = 1; i < argc; i++)
new_argv[i + 1] = argv[i];
- new_argv[argc + 1] = NULL;
+ new_argv[argc + 1] = nullptr;
(void) execvp(new_argv[0], new_argv);
perror("execvp");
#ifndef _WIN32
char buffer[MAXPATHLEN];
- if (getcwd(buffer, sizeof(buffer)) == NULL) {
+ if (!getcwd(buffer, sizeof(buffer))) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("getcwd")
<< boost::errinfo_errno(errno));
if (!foundSlash) {
const char *pathEnv = getenv("PATH");
- if (pathEnv != NULL) {
+ if (pathEnv) {
std::vector<String> paths;
boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));
}
}
- if (realpath(executablePath.CStr(), buffer) == NULL) {
+ if (!realpath(executablePath.CStr(), buffer)) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("realpath")
<< boost::errinfo_errno(errno)
#else /* _WIN32 */
char FullExePath[MAXPATHLEN];
- if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath)))
+ if (!GetModuleFileName(nullptr, FullExePath, sizeof(FullExePath)))
BOOST_THROW_EXCEPTION(win32_error()
<< boost::errinfo_api_function("GetModuleFileName")
<< errinfo_win32_error(GetLastError()));
"gdb",
"-p",
my_pid_str,
- NULL
+ nullptr
};
argv = const_cast<char **>(uargv);
} else {
"detach",
"-ex",
"quit",
- NULL
+ nullptr
};
argv = const_cast<char **>(uargv);
}
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
- sigaction(signum, &sa, NULL);
+ sigaction(signum, &sa, nullptr);
Application::Ptr instance = Application::GetInstance();
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
- sigaction(SIGABRT, &sa, NULL);
+ sigaction(SIGABRT, &sa, nullptr);
#endif /* _WIN32 */
std::cerr << "Caught SIGABRT." << std::endl
instance->RequestShutdown();
- SetConsoleCtrlHandler(NULL, FALSE);
+ SetConsoleCtrlHandler(nullptr, FALSE);
return TRUE;
}
bool Application::IsProcessElevated(void) {
BOOL fIsElevated = FALSE;
DWORD dwError = ERROR_SUCCESS;
- HANDLE hToken = NULL;
+ HANDLE hToken = nullptr;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
dwError = GetLastError();
if (hToken) {
CloseHandle(hToken);
- hToken = NULL;
+ hToken = nullptr;
}
if (ERROR_SUCCESS != dwError) {
- LPSTR mBuf = NULL;
+ LPSTR mBuf = nullptr;
if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), mBuf, 0, NULL))
+ nullptr, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), mBuf, 0, nullptr))
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to format error message, last error was: " + dwError));
else
BOOST_THROW_EXCEPTION(std::runtime_error(mBuf));
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
- sigaction(SIGABRT, &sa, NULL);
+ sigaction(SIGABRT, &sa, nullptr);
#endif /* _WIN32 */
String fname = GetCrashReportFilename();
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = &Application::SigAbrtHandler;
- sigaction(SIGABRT, &sa, NULL);
+ sigaction(SIGABRT, &sa, nullptr);
#else /* _WIN32 */
SetUnhandledExceptionFilter(&Application::SEHUnhandledExceptionFilter);
#endif /* _WIN32 */
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = &Application::SigIntTermHandler;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
+ sigaction(SIGINT, &sa, nullptr);
+ sigaction(SIGTERM, &sa, nullptr);
sa.sa_handler = &Application::SigUsr1Handler;
- sigaction(SIGUSR1, &sa, NULL);
+ sigaction(SIGUSR1, &sa, nullptr);
#else /* _WIN32 */
SetConsoleCtrlHandler(&Application::CtrlHandler, TRUE);
#endif /* _WIN32 */
{
ObjectLock olock(this);
- if (m_PidFile != NULL)
+ if (m_PidFile)
fclose(m_PidFile);
/* There's just no sane way of getting a file descriptor for a
* C++ ofstream which is why we're using FILEs here. */
m_PidFile = fopen(filename.CStr(), "r+");
- if (m_PidFile == NULL)
+ if (!m_PidFile)
m_PidFile = fopen(filename.CStr(), "w");
- if (m_PidFile == NULL) {
+ if (!m_PidFile) {
Log(LogCritical, "Application")
<< "Could not open PID file '" << filename << "'.";
BOOST_THROW_EXCEPTION(std::runtime_error("Could not open PID file '" + filename + "'"));
{
ObjectLock olock(this);
- if (m_PidFile != NULL)
- {
+ if (m_PidFile) {
if (unlink) {
String pidpath = GetPidPath();
::unlink(pidpath.CStr());
fclose(m_PidFile);
}
- m_PidFile = NULL;
+ m_PidFile = nullptr;
}
/**
{
FILE *pidfile = fopen(filename.CStr(), "r");
- if (pidfile == NULL)
+ if (!pidfile)
return 0;
#ifndef _WIN32
std::list<String>& ContextFrame::GetFrames(void)
{
- if (l_Frames.get() == NULL)
+ if (!l_Frames.get())
l_Frames.reset(new std::list<String>());
return *l_Frames;
if (dst->__do_catch(src, &thrown_ptr, 1))
return thrown_ptr;
else
- return NULL;
+ return nullptr;
#else /* __GLIBCXX__ */
const libcxx_type_info *srcInfo = static_cast<const libcxx_type_info *>(src);
const libcxx_type_info *dstInfo = static_cast<const libcxx_type_info *>(dst);
if (dstInfo->can_catch(srcInfo, adj))
return adj;
else
- return NULL;
+ return nullptr;
#endif /* __GLIBCXX__ */
}
SetLastExceptionStack(stack);
#ifndef NO_CAST_EXCEPTION
- if (ex && boost::get_error_info<StackTraceErrorInfo>(*ex) == NULL)
+ if (ex && !boost::get_error_info<StackTraceErrorInfo>(*ex))
*ex << StackTraceErrorInfo(stack);
}
#endif /* NO_CAST_EXCEPTION */
SetLastExceptionContext(context);
#ifndef NO_CAST_EXCEPTION
- if (ex && boost::get_error_info<ContextTraceErrorInfo>(*ex) == NULL)
+ if (ex && !boost::get_error_info<ContextTraceErrorInfo>(*ex))
*ex << ContextTraceErrorInfo(context);
#endif /* NO_CAST_EXCEPTION */
try {
boost::rethrow_exception(eptr);
} catch (const std::exception& ex) {
- return DiagnosticInformation(ex, verbose, pt ? &stack : NULL, pc ? &context : NULL);
+ return DiagnosticInformation(ex, verbose, pt ? &stack : nullptr, pc ? &context : nullptr);
}
return boost::diagnostic_information(eptr);
}
posix_error::posix_error(void)
- : m_Message(NULL)
+ : m_Message(nullptr)
{ }
posix_error::~posix_error(void) throw()
return msgbuf.str();
}
-I2_BASE_API String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = NULL, ContextTrace *context = NULL);
+I2_BASE_API String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr);
I2_BASE_API String DiagnosticInformation(boost::exception_ptr eptr, bool verbose = true);
class I2_BASE_API posix_error : virtual public std::exception, virtual public boost::exception {
* Constructor for the FIFO class.
*/
FIFO::FIFO(void)
- : m_Buffer(NULL), m_DataSize(0), m_AllocSize(0), m_Offset(0)
+ : m_Buffer(nullptr), m_DataSize(0), m_AllocSize(0), m_Offset(0)
{ }
/**
char *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
- if (newBuffer == NULL)
+ if (!newBuffer)
BOOST_THROW_EXCEPTION(std::bad_alloc());
m_Buffer = newBuffer;
if (count > m_DataSize)
count = m_DataSize;
- if (buffer != NULL)
+ if (buffer)
std::memcpy(buffer, m_Buffer + m_Offset, count);
return count;
if (count > m_DataSize)
count = m_DataSize;
- if (buffer != NULL)
+ if (buffer)
std::memcpy(buffer, m_Buffer + m_Offset, count);
m_DataSize -= count;
{
#if YAJL_MAJOR < 2
yajl_gen_config conf = { pretty_print, "" };
- yajl_gen handle = yajl_gen_alloc(&conf, NULL);
+ yajl_gen handle = yajl_gen_alloc(&conf, nullptr);
#else /* YAJL_MAJOR */
- yajl_gen handle = yajl_gen_alloc(NULL);
+ yajl_gen handle = yajl_gen_alloc(nullptr);
if (pretty_print)
yajl_gen_config(handle, yajl_gen_beautify, 1);
#endif /* YAJL_MAJOR */
static const yajl_callbacks callbacks = {
DecodeNull,
DecodeBoolean,
- NULL,
- NULL,
+ nullptr,
+ nullptr,
DecodeNumber,
DecodeString,
DecodeStartMap,
JsonContext context;
#if YAJL_MAJOR < 2
- handle = yajl_alloc(&callbacks, &cfg, NULL, &context);
+ handle = yajl_alloc(&callbacks, &cfg, nullptr, &context);
#else /* YAJL_MAJOR */
- handle = yajl_alloc(&callbacks, NULL, &context);
+ handle = yajl_alloc(&callbacks, nullptr, &context);
yajl_config(handle, yajl_dont_validate_strings, 1);
yajl_config(handle, yajl_allow_comments, 1);
#endif /* YAJL_MAJOR */
#ifdef _WIN32
HMODULE hModule = LoadLibrary(path.CStr());
- if (hModule == NULL) {
+ if (!hModule) {
BOOST_THROW_EXCEPTION(win32_error()
<< boost::errinfo_api_function("LoadLibrary")
<< errinfo_win32_error(GetLastError())
#else /* _WIN32 */
void *hModule = dlopen(path.CStr(), RTLD_NOW | RTLD_GLOBAL);
- if (hModule == NULL) {
+ if (!hModule) {
BOOST_THROW_EXCEPTION(std::runtime_error("Could not load library '" + path + "': " + dlerror()));
}
#endif /* _WIN32 */
/**
* Reads data from the stream.
*
- * @param buffer The buffer where data should be stored. May be NULL if you're
+ * @param buffer The buffer where data should be stored. May be nullptr if you're
* not actually interested in the data.
* @param count The number of bytes to read from the queue.
* @returns The number of bytes actually read.
{
public:
inline ObjectLock(void)
- : m_Object(NULL), m_Locked(false)
+ : m_Object(nullptr), m_Locked(false)
{ }
inline ~ObjectLock(void)
inline void Lock(void)
{
- ASSERT(!m_Locked && m_Object != NULL);
+ ASSERT(!m_Locked && m_Object);
LockMutex(m_Object);
Field ObjectType::GetFieldInfo(int id) const
{
if (id == 0)
- return Field(1, "String", "type", NULL, NULL, 0, 0);
+ return Field(1, "String", "type", nullptr, nullptr, 0, 0);
else
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
}
REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactoryVA<type>)
#define REGISTER_PRIMITIVE_TYPE_NOINST(type, base, prototype) \
- REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, NULL)
+ REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, nullptr)
}
#endif /* _WIN32 */
{
#ifdef _WIN32
- m_Overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ m_Overlapped.hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
#endif /* _WIN32 */
}
{
struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
- if (cmsg == NULL || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_len != CMSG_LEN(sizeof(int) * 3)) {
+ if (cmsg == nullptr || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_len != CMSG_LEN(sizeof(int) * 3)) {
std::cerr << "Invalid 'spawn' request: FDs missing" << std::endl;
return Empty;
}
argv[i] = strdup(arg.CStr());
}
- argv[arguments->GetLength()] = NULL;
+ argv[arguments->GetLength()] = nullptr;
// build envp
int envc = 0;
/* count existing environment variables */
- while (environ[envc] != NULL)
+ while (environ[envc])
envc++;
char **envp = new char *[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 2];
}
envp[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0)] = strdup("LC_NUMERIC=C");
- envp[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 1] = NULL;
+ envp[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 1] = nullptr;
extraEnvironment.reset();
sigset_t mask;
sigemptyset(&mask);
- sigprocmask(SIG_SETMASK, &mask, NULL);
+ sigprocmask(SIG_SETMASK, &mask, nullptr);
if (icinga2_execvpe(argv[0], argv, envp) < 0) {
char errmsg[512];
(void)close(fds[2]);
// free arguments
- for (int i = 0; argv[i] != NULL; i++)
+ for (int i = 0; argv[i]; i++)
free(argv[i]);
delete[] argv;
// free environment
- for (int i = 0; envp[i] != NULL; i++)
+ for (int i = 0; envp[i]; i++)
free(envp[i]);
delete[] envp;
{
sigset_t mask;
sigfillset(&mask);
- sigprocmask(SIG_SETMASK, &mask, NULL);
+ sigprocmask(SIG_SETMASK, &mask, nullptr);
rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) {
{
for (int tid = 0; tid < IOTHREADS; tid++) {
#ifdef _WIN32
- l_Events[tid] = CreateEvent(NULL, TRUE, FALSE, NULL);
+ l_Events[tid] = CreateEvent(nullptr, TRUE, FALSE, nullptr);
#else /* _WIN32 */
# ifdef HAVE_PIPE2
if (pipe2(l_EventFDs[tid], O_CLOEXEC) < 0) {
void Process::IOThreadProc(int tid)
{
#ifdef _WIN32
- HANDLE *handles = NULL;
- HANDLE *fhandles = NULL;
+ HANDLE *handles = nullptr;
+ HANDLE *fhandles = nullptr;
#else /* _WIN32 */
- pollfd *pfds = NULL;
+ pollfd *pfds = nullptr;
#endif /* _WIN32 */
int count = 0;
double now;
if (*outReadPipe == INVALID_HANDLE_VALUE)
return FALSE;
- *outWritePipe = CreateFile(pipeName, GENERIC_WRITE, 0, securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | writeMode, NULL);
+ *outWritePipe = CreateFile(pipeName, GENERIC_WRITE, 0, securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | writeMode, nullptr);
if (*outWritePipe == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
/* LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;
SIZE_T cbSize;
- if (!InitializeProcThreadAttributeList(NULL, 1, 0, &cbSize) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ if (!InitializeProcThreadAttributeList(nullptr, 1, 0, &cbSize) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
BOOST_THROW_EXCEPTION(win32_error()
<< boost::errinfo_api_function("InitializeProcThreadAttributeList")
<< errinfo_win32_error(GetLastError()));
rgHandles[2] = GetStdHandle(STD_INPUT_HANDLE);
if (!UpdateProcThreadAttribute(lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
- rgHandles, sizeof(rgHandles), NULL, NULL))
+ rgHandles, sizeof(rgHandles), nullptr, nullptr))
BOOST_THROW_EXCEPTION(win32_error()
<< boost::errinfo_api_function("UpdateProcThreadAttribute")
<< errinfo_win32_error(GetLastError()));
LPCH pEnvironment = GetEnvironmentStrings();
size_t ioffset = 0, offset = 0;
- char *envp = NULL;
+ char *envp = nullptr;
for (;;) {
size_t len = strlen(pEnvironment + ioffset);
envp = static_cast<char *>(realloc(envp, offset + len + 1));
- if (envp == NULL)
+ if (!envp)
BOOST_THROW_EXCEPTION(std::bad_alloc());
strcpy(envp + offset, pEnvironment + ioffset);
envp = static_cast<char *>(realloc(envp, offset + skv.GetLength() + 1));
- if (envp == NULL)
+ if (!envp)
BOOST_THROW_EXCEPTION(std::bad_alloc());
strcpy(envp + offset, skv.CStr());
envp = static_cast<char *>(realloc(envp, offset + 1));
- if (envp == NULL)
+ if (!envp)
BOOST_THROW_EXCEPTION(std::bad_alloc());
envp[offset] = '\0';
- if (!CreateProcess(NULL, args, NULL, NULL, TRUE,
- 0 /*EXTENDED_STARTUPINFO_PRESENT*/, envp, NULL, &si.StartupInfo, &pi)) {
+ if (!CreateProcess(nullptr, args, nullptr, nullptr, TRUE,
+ 0 /*EXTENDED_STARTUPINFO_PRESENT*/, envp, nullptr, &si.StartupInfo, &pi)) {
DWORD error = GetLastError();
CloseHandle(outWritePipe);
CloseHandle(outWritePipeDup);
class I2_BASE_API ScriptGlobal
{
public:
- static Value Get(const String& name, const Value *defaultValue = NULL);
+ static Value Get(const String& name, const Value *defaultValue = nullptr);
static void Set(const String& name, const Value& value);
static bool Exists(const String& name);
Array::Ptr array = dynamic_pointer_cast<Array>(input);
- if (array != NULL)
+ if (array)
return SerializeArray(array, attributeTypes);
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(input);
- if (dict != NULL)
+ if (dict)
return SerializeDictionary(dict, attributeTypes);
return SerializeObject(input, attributeTypes);
Array::Ptr array = dynamic_pointer_cast<Array>(input);
- if (array != NULL)
+ if (array)
return DeserializeArray(array, safe_mode, attributeTypes);
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(input);
- ASSERT(dict != NULL);
+ ASSERT(dict);
if ((safe_mode && !object) || !dict->Contains("type"))
return DeserializeDictionary(dict, safe_mode, attributeTypes);
void Listen(void);
Socket::Ptr Accept(void);
- bool Poll(bool read, bool write, struct timeval *timeout = NULL);
+ bool Poll(bool read, bool write, struct timeval *timeout = nullptr);
void MakeNonBlocking(void);
m_Sockets[tid].erase(se->m_FD);
m_FDChanged[tid] = true;
- epoll_ctl(m_PollFDs[tid], EPOLL_CTL_DEL, se->m_FD, NULL);
+ epoll_ctl(m_PollFDs[tid], EPOLL_CTL_DEL, se->m_FD, nullptr);
se->m_FD = INVALID_SOCKET;
se->m_Events = false;
* Constructor for the SocketEvents class.
*/
SocketEvents::SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject)
- : m_ID(m_NextID++), m_FD(socket->GetFD()), m_EnginePrivate(NULL)
+ : m_ID(m_NextID++), m_FD(socket->GetFD()), m_EnginePrivate(nullptr)
{
boost::call_once(l_SocketIOOnceFlag, &SocketEvents::InitializeEngine);
Object *LifesupportObject;
SocketEventDescriptor(void)
- : Events(POLLIN), EventInterface(NULL), LifesupportObject(NULL)
+ : Events(POLLIN), EventInterface(nullptr), LifesupportObject(nullptr)
{ }
};
m_Count = backtrace(m_Frames, sizeof(m_Frames) / sizeof(m_Frames[0]));
#else /* HAVE_BACKTRACE_SYMBOLS */
# ifdef _WIN32
- m_Count = CaptureStackBackTrace(0, sizeof(m_Frames) / sizeof(m_Frames), m_Frames, NULL);
+ m_Count = CaptureStackBackTrace(0, sizeof(m_Frames) / sizeof(m_Frames), m_Frames, nullptr);
# else /* _WIN32 */
m_Count = 0;
# endif /* _WIN32 */
m_Count = 0;
while (StackWalk64(architecture, GetCurrentProcess(), GetCurrentThread(),
- &frame, exi->ContextRecord, NULL, &SymFunctionTableAccess64,
- &SymGetModuleBase64, NULL) && m_Count < sizeof(m_Frames) / sizeof(m_Frames[0])) {
+ &frame, exi->ContextRecord, nullptr, &SymFunctionTableAccess64,
+ &SymGetModuleBase64, nullptr) && m_Count < sizeof(m_Frames) / sizeof(m_Frames[0])) {
m_Frames[m_Count] = reinterpret_cast<void *>(frame.AddrPC.Offset);
m_Count++;
}
#ifdef _WIN32
INITIALIZE_ONCE([]() {
(void) SymSetOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
- (void) SymInitialize(GetCurrentProcess(), NULL, TRUE);
+ (void) SymInitialize(GetCurrentProcess(), nullptr, TRUE);
});
#endif /* _WIN32 */
# ifdef HAVE_BACKTRACE_SYMBOLS
char **messages = backtrace_symbols(m_Frames, m_Count);
- for (int i = ignoreFrames + 1; i < m_Count && messages != NULL; ++i) {
+ for (int i = ignoreFrames + 1; i < m_Count && messages; ++i) {
String message = messages[i];
char *sym_begin = strchr(messages[i], '(');
if (sym_begin) {
char *sym_end = strchr(sym_begin, '+');
- if (sym_end != NULL) {
+ if (sym_end) {
String sym = String(sym_begin + 1, sym_end);
String sym_demangled = Utility::DemangleSymbolName(sym);
struct I2_BASE_API StreamReadContext
{
StreamReadContext(void)
- : Buffer(NULL), Size(0), MustRead(true), Eof(false)
+ : Buffer(nullptr), Size(0), MustRead(true), Eof(false)
{ }
~StreamReadContext(void)
/**
* Reads data from the stream without removing it from the stream buffer.
*
- * @param buffer The buffer where data should be stored. May be NULL if you're
+ * @param buffer The buffer where data should be stored. May be nullptr if you're
* not actually interested in the data.
* @param count The number of bytes to read from the queue.
* @param allow_partial Whether to allow partial reads.
/**
* Reads data from the stream.
*
- * @param buffer The buffer where data should be stored. May be NULL if you're
+ * @param buffer The buffer where data should be stored. May be nullptr if you're
* not actually interested in the data.
* @param count The number of bytes to read from the queue.
* @param allow_partial Whether to allow partial reads.
* Constructor for the StreamLogger class.
*/
StreamLogger::StreamLogger(void)
- : m_Stream(NULL), m_OwnsStream(false)
+ : m_Stream(nullptr), m_OwnsStream(false)
{ }
void StreamLogger::Stop(bool runtimeRemoved)
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
- int rc = getaddrinfo(node.IsEmpty() ? NULL : node.CStr(),
+ int rc = getaddrinfo(node.IsEmpty() ? nullptr : node.CStr(),
service.CStr(), &hints, &result);
if (rc != 0) {
int fd = INVALID_SOCKET;
- for (addrinfo *info = result; info != NULL; info = info->ai_next) {
+ for (addrinfo *info = result; info != nullptr; info = info->ai_next) {
fd = socket(info->ai_family, info->ai_socktype, info->ai_protocol);
if (fd == INVALID_SOCKET) {
SOCKET fd = INVALID_SOCKET;
- for (addrinfo *info = result; info != NULL; info = info->ai_next) {
+ for (addrinfo *info = result; info != nullptr; info = info->ai_next) {
fd = socket(info->ai_family, info->ai_socktype, info->ai_protocol);
if (fd == INVALID_SOCKET) {
boost::thread *Thread;
WorkerThread(ThreadState state = ThreadDead)
- : State(state), Zombie(false), Utilization(0), LastUpdate(0), Thread(NULL)
+ : State(state), Zombie(false), Utilization(0), LastUpdate(0), Thread(nullptr)
{ }
void UpdateUtilization(ThreadState state = ThreadUnspecified);
}
if (!m_SSLIndexInitialized) {
- m_SSLIndex = SSL_get_ex_new_index(0, const_cast<char *>("TlsStream"), NULL, NULL, NULL);
+ m_SSLIndex = SSL_get_ex_new_index(0, const_cast<char *>("TlsStream"), nullptr, nullptr, nullptr);
m_SSLIndexInitialized = true;
}
rc = SSL_write(m_SSL.get(), buffer, count);
if (rc > 0) {
- m_SendQ->Read(NULL, rc, true);
+ m_SendQ->Read(nullptr, rc, true);
success = true;
}
if (m_ErrorCode != 0) {
Log(LogWarning, "TlsStream")
- << "OpenSSL error: " << ERR_error_string(m_ErrorCode, NULL);
+ << "OpenSSL error: " << ERR_error_string(m_ErrorCode, nullptr);
} else {
Log(LogWarning, "TlsStream", "TLS stream was disconnected.");
}
}
if (!cakey.IsEmpty()) {
- if (!SSL_CTX_load_verify_locations(sslContext.get(), cakey.CStr(), NULL)) {
+ if (!SSL_CTX_load_verify_locations(sslContext.get(), cakey.CStr(), nullptr)) {
Log(LogCritical, "SSL")
<< "Error loading and verifying locations in ca key file '" << cakey << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\"";
BOOST_THROW_EXCEPTION(openssl_error()
STACK_OF(X509_NAME) *cert_names;
cert_names = SSL_load_client_CA_file(cakey.CStr());
- if (cert_names == NULL) {
+ if (!cert_names) {
Log(LogCritical, "SSL")
<< "Error loading client ca key file '" << cakey << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\"";
BOOST_THROW_EXCEPTION(openssl_error()
X509 *cert;
BIO *fpcert = BIO_new(BIO_s_file());
- if (fpcert == NULL) {
+ if (!fpcert) {
Log(LogCritical, "SSL")
<< "Error creating new BIO: " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\"";
BOOST_THROW_EXCEPTION(openssl_error()
<< boost::errinfo_file_name(pemfile));
}
- cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL);
- if (cert == NULL) {
+ cert = PEM_read_bio_X509_AUX(fpcert, nullptr, nullptr, nullptr);
+ if (!cert) {
Log(LogCritical, "SSL")
<< "Error on bio X509 AUX reading pem file '" << pemfile << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\"";
BOOST_THROW_EXCEPTION(openssl_error()
<< boost::errinfo_file_name(keyfile));
}
- if (!PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, 0, NULL)) {
+ if (!PEM_write_bio_PrivateKey(bio, key, nullptr, nullptr, 0, 0, nullptr)) {
EVP_PKEY_free(key);
EC_KEY_free(eckey);
BIO_free(bio);
if (!ca) {
String san = "DNS:" + cn;
- X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(NULL, NULL, NID_subject_alt_name, const_cast<char *>(san.CStr()));
+ X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(nullptr, nullptr, NID_subject_alt_name, const_cast<char *>(san.CStr()));
if (subjectAltNameExt) {
/* OpenSSL 0.9.8 requires STACK_OF(X509_EXTENSION), otherwise we would just use stack_st_X509_EXTENSION. */
STACK_OF(X509_EXTENSION) *exts = sk_X509_EXTENSION_new_null();
X509V3_CTX ctx;
X509V3_set_ctx_nodb(&ctx);
- X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
+ X509V3_set_ctx(&ctx, cert, cert, nullptr, nullptr, 0);
const char *attr;
else
attr = "critical,CA:FALSE";
- X509_EXTENSION *basicConstraintsExt = X509V3_EXT_conf_nid(NULL, &ctx, NID_basic_constraints, const_cast<char *>(attr));
+ X509_EXTENSION *basicConstraintsExt = X509V3_EXT_conf_nid(nullptr, &ctx, NID_basic_constraints, const_cast<char *>(attr));
if (basicConstraintsExt) {
X509_add_ext(cert, basicConstraintsExt, -1);
if (!ca) {
String san = "DNS:" + cn;
- X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(NULL, &ctx, NID_subject_alt_name, const_cast<char *>(san.CStr()));
+ X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(nullptr, &ctx, NID_subject_alt_name, const_cast<char *>(san.CStr()));
if (subjectAltNameExt) {
X509_add_ext(cert, subjectAltNameExt, -1);
X509_EXTENSION_free(subjectAltNameExt);
return std::shared_ptr<X509>();
}
- EVP_PKEY *privkey = PEM_read_bio_PrivateKey(cakeybio, NULL, NULL, NULL);
+ EVP_PKEY *privkey = PEM_read_bio_PrivateKey(cakeybio, nullptr, nullptr, nullptr);
if (!privkey) {
Log(LogCritical, "SSL")
BIO *bio = BIO_new(BIO_s_mem());
BIO_write(bio, (const void *)cert.CStr(), cert.GetLength());
- X509 *rawCert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL);
+ X509 *rawCert = PEM_read_bio_X509_AUX(bio, nullptr, nullptr, nullptr);
BIO_free(bio);
X509_STORE_add_cert(store, caCertificate.get());
X509_STORE_CTX *csc = X509_STORE_CTX_new();
- X509_STORE_CTX_init(csc, store, certificate.get(), NULL);
+ X509_STORE_CTX_init(csc, store, certificate.get(), nullptr);
int rc = X509_verify_cert(csc);
const char *message = ERR_error_string(code, errbuf);
- if (message == NULL)
+ if (!message)
message = "Unknown error.";
tmp << code << ", \"" << message << "\"";
void Type::Register(const Type::Ptr& type)
{
- VERIFY(GetByName(type->GetName()) == NULL);
+ VERIFY(!GetByName(type->GetName()));
ScriptGlobal::Set("Types." + type->GetName(), type);
}
return GetBaseType()->GetFieldInfo(id);
if (real_id == 0)
- return Field(0, "String", "name", "", NULL, 0, 0);
+ return Field(0, "String", "name", "", nullptr, 0, 0);
else if (real_id == 1)
- return Field(1, "Object", "prototype", "", NULL, 0, 0);
+ return Field(1, "Object", "prototype", "", nullptr, 0, 0);
else if (real_id == 2)
- return Field(2, "Type", "base", "", NULL, 0, 0);
+ return Field(2, "Type", "base", "", nullptr, 0, 0);
throw std::runtime_error("Invalid field ID.");
}
ObjectFactory TypeType::GetFactory(void) const
{
- return NULL;
+ return nullptr;
}
int status;
char *realname = abi::__cxa_demangle(sym.CStr(), 0, 0, &status);
- if (realname != NULL) {
+ if (realname) {
result = String(realname);
free(realname);
}
dir = strdup(path.CStr());
#endif /* _WIN32 */
- if (dir == NULL)
+ if (!dir)
BOOST_THROW_EXCEPTION(std::bad_alloc());
String result;
char *dir = strdup(path.CStr());
String result;
- if (dir == NULL)
+ if (!dir)
BOOST_THROW_EXCEPTION(std::bad_alloc());
#ifndef _WIN32
#else /* _WIN32 */
struct timeval tv;
- int rc = gettimeofday(&tv, NULL);
+ int rc = gettimeofday(&tv, nullptr);
VERIFY(rc >= 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
dirp = opendir(path.CStr());
- if (dirp == NULL)
+ if (!dirp)
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("opendir")
<< boost::errinfo_errno(errno)
#ifdef _MSC_VER
tm *temp = localtime(&tempts);
- if (temp == NULL) {
+ if (!temp) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("localtime")
<< boost::errinfo_errno(errno));
tmthen = *temp;
#else /* _MSC_VER */
- if (localtime_r(&tempts, &tmthen) == NULL) {
+ if (!localtime_r(&tempts, &tmthen)) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("localtime_r")
<< boost::errinfo_errno(errno));
String result = "Unknown error.";
DWORD rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, 0, (char *)&message,
- 0, NULL);
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, code, 0, (char *)&message,
+ 0, nullptr);
if (rc != 0) {
result = String(message);
hints.ai_flags = AI_CANONNAME;
addrinfo *result;
- int rc = getaddrinfo(hostname.CStr(), NULL, &hints, &result);
+ int rc = getaddrinfo(hostname.CStr(), nullptr, &hints, &result);
if (rc != 0)
- result = NULL;
+ result = nullptr;
if (result) {
if (strcmp(result->ai_canonname, "localhost") != 0)
#ifdef _MSC_VER
tm *result = localtime(&ts);
- if (result == NULL) {
+ if (!result) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("localtime")
<< boost::errinfo_errno(errno));
#else /* _MSC_VER */
tm result;
- if (localtime_r(&ts, &result) == NULL) {
+ if (!localtime_r(&ts, &result)) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("localtime_r")
<< boost::errinfo_errno(errno));
char line[1024];
std::ostringstream msgbuf;
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (fgets(line, sizeof(line), fp))
msgbuf << line;
pclose(fp);
/* You are using a distribution which supports LSB. */
FILE *fp = popen("type lsb_release >/dev/null 2>&1 && lsb_release -s -i 2>&1", "r");
- if (fp != NULL) {
+ if (fp) {
std::ostringstream msgbuf;
char line[1024];
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (fgets(line, sizeof(line), fp))
msgbuf << line;
int status = pclose(fp);
if (WEXITSTATUS(status) == 0) {
fp = popen("type lsb_release >/dev/null 2>&1 && lsb_release -s -r 2>&1", "r");
- if (fp != NULL) {
+ if (fp) {
std::ostringstream msgbuf;
char line[1024];
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (fgets(line, sizeof(line), fp))
msgbuf << line;
int status = pclose(fp);
if (WEXITSTATUS(status) == 0) {
/* OS X */
fp = popen("type sw_vers >/dev/null 2>&1 && sw_vers -productName 2>&1", "r");
- if (fp != NULL) {
+ if (fp) {
std::ostringstream msgbuf;
char line[1024];
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (fgets(line, sizeof(line), fp))
msgbuf << line;
int status = pclose(fp);
if (WEXITSTATUS(status) == 0) {
fp = popen("type sw_vers >/dev/null 2>&1 && sw_vers -productVersion 2>&1", "r");
- if (fp != NULL) {
+ if (fp) {
std::ostringstream msgbuf;
char line[1024];
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (fgets(line, sizeof(line), fp))
msgbuf << line;
int status = pclose(fp);
if (WEXITSTATUS(status) == 0) {
String Utility::GetPlatformName(void)
{
String platformName;
- if (!ReleaseHelper(&platformName, NULL))
+ if (!ReleaseHelper(&platformName, nullptr))
return "Unknown";
return platformName;
}
String Utility::GetPlatformVersion(void)
{
String platformVersion;
- if (!ReleaseHelper(NULL, &platformVersion))
+ if (!ReleaseHelper(nullptr, &platformVersion))
return "Unknown";
return platformVersion;
}
String Utility::GetIcingaDataPath(void)
{
char path[MAX_PATH];
- if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path)))
+ if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, path)))
return "";
return String(path) + "\\icinga2";
}
if (!IsObject())
return false;
- return (dynamic_cast<T *>(boost::get<Object::Ptr>(m_Value).get()) != NULL);
+ return dynamic_cast<T *>(boost::get<Object::Ptr>(m_Value).get());
}
/**
CLICommand::Ptr& command, bool autocomplete);
static void ShowCommands(int argc, char **argv,
- boost::program_options::options_description *visibleDesc = NULL,
- boost::program_options::options_description *hiddenDesc = NULL,
- ArgumentCompletionCallback globalArgCompletionCallback = NULL,
+ boost::program_options::options_description *visibleDesc = nullptr,
+ boost::program_options::options_description *hiddenDesc = nullptr,
+ ArgumentCompletionCallback globalArgCompletionCallback = nullptr,
bool autocomplete = false, int autoindex = -1);
private:
extern "C" void dbg_eval(const char *text)
{
- Expression *expr = NULL;
+ Expression *expr = nullptr;
try {
ScriptFrame frame;
extern "C" void dbg_eval_with_value(const Value& value, const char *text)
{
- Expression *expr = NULL;
+ Expression *expr = nullptr;
try {
ScriptFrame frame;
extern "C" void dbg_eval_with_object(Object *object, const char *text)
{
- Expression *expr = NULL;
+ Expression *expr = nullptr;
try {
ScriptFrame frame;
}
if (state >= static_cast<int>(matches.size()))
- return NULL;
+ return nullptr;
return strdup(matches[state].CStr());
}
command += line;
- Expression *expr = NULL;
+ Expression *expr = nullptr;
try {
lines[fileName] = command;
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = &SigHupHandler;
- sigaction(SIGHUP, &sa, NULL);
+ sigaction(SIGHUP, &sa, nullptr);
#endif /* _WIN32 */
ApiListener::UpdateObjectAuthority();
<< "FAILED: This probably means you have a fault configuration.\n";
return false;
} else {
- InfoLog *OFile = NULL;
+ InfoLog *OFile = nullptr;
bool OConsole = false;
if (vm.count("include-objects")) {
if (vm.count("console"))
InfoLogLine(log, 0, LogWarning)
<< "Failed to open Object-write-stream, not printing objects\n\n";
delete OFile;
- OFile = NULL;
+ OFile = nullptr;
} else
InfoLogLine(log)
<< "Printing all objects to " << path+"-objects\n";
#ifdef _MSC_VER
tm *temp = localtime(&now);
- if (temp == NULL) {
+ if (!temp) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("localtime")
<< boost::errinfo_errno(errno));
tmthen = *temp;
#else /* _MSC_VER */
- if (localtime_r(&now, &tmthen) == NULL) {
+ if (!localtime_r(&now, &tmthen)) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("localtime_r")
<< boost::errinfo_errno(errno));
"\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n"
"\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n"
"\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\n"
- "\t" "last_update=" << static_cast<long>(time(NULL)) << "\n"
+ "\t" "last_update=" << static_cast<long>(time(nullptr)) << "\n"
"\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n"
"\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n"
"\t" "passive_checks_enabled=" << CompatUtility::GetCheckablePassiveChecksEnabled(checkable) << "\n"
}
ConfigCompilerContext::ConfigCompilerContext(void)
- : m_ObjectsFP(NULL)
+ : m_ObjectsFP(nullptr)
{ }
void ConfigCompilerContext::OpenObjectsFile(const String& filename)
void ConfigCompilerContext::CancelObjectsFile(void)
{
delete m_ObjectsFP;
- m_ObjectsFP = NULL;
+ m_ObjectsFP = nullptr;
#ifdef _WIN32
_unlink(m_ObjectsTempFile.CStr());
void ConfigCompilerContext::FinishObjectsFile(void)
{
delete m_ObjectsFP;
- m_ObjectsFP = NULL;
+ m_ObjectsFP = nullptr;
#ifdef _WIN32
_unlink(m_ObjectsPath.CStr());
*parent = frame.Locals;
if (dhint)
- *dhint = NULL;
+ *dhint = nullptr;
} else if (frame.Self.IsObject() && frame.Locals != frame.Self.Get<Object::Ptr>() && frame.Self.Get<Object::Ptr>()->HasOwnField(m_Variable)) {
*parent = frame.Self;
*parent = ScriptGlobal::GetGlobals();
if (dhint)
- *dhint = NULL;
+ *dhint = nullptr;
} else
*parent = frame.Self;
try {
for (Expression *aexpr : m_Expressions) {
- ExpressionResult element = aexpr->Evaluate(frame, m_Inline ? dhint : NULL);
+ ExpressionResult element = aexpr->Evaluate(frame, m_Inline ? dhint : nullptr);
CHECK_RESULT(element);
result = element.GetValue();
}
{
Value vparent;
String vindex;
- DebugHint *psdhint = NULL;
+ DebugHint *psdhint = nullptr;
bool free_psd = false;
if (dhint)
if (psdhint)
*dhint = new DebugHint(psdhint->GetChild(*index));
else
- *dhint = NULL;
+ *dhint = nullptr;
}
if (free_psd)
ExpressionResult BreakpointExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
{
- ScriptBreakpoint(frame, NULL, GetDebugInfo());
+ ScriptBreakpoint(frame, nullptr, GetDebugInfo());
return Empty;
}
public:
virtual ~Expression(void);
- ExpressionResult Evaluate(ScriptFrame& frame, DebugHint *dhint = NULL) const;
- virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint = NULL) const;
+ ExpressionResult Evaluate(ScriptFrame& frame, DebugHint *dhint = nullptr) const;
+ virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint = nullptr) const;
virtual const DebugInfo& GetDebugInfo(void) const;
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const = 0;
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
String idoName = MacroProcessor::ResolveMacros("$ido_name$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
if (resolvedMacros && !useResolvedMacros)
return;
isslCaPath = GetSslCapath();
isslCipher = GetSslCipher();
- host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
+ host = (!ihost.IsEmpty()) ? ihost.CStr() : nullptr;
port = GetPort();
- socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : NULL;
- user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL;
- passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
- db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
-
- sslKey = (!isslKey.IsEmpty()) ? isslKey.CStr() : NULL;
- sslCert = (!isslCert.IsEmpty()) ? isslCert.CStr() : NULL;
- sslCa = (!isslCa.IsEmpty()) ? isslCa.CStr() : NULL;
- sslCaPath = (!isslCaPath.IsEmpty()) ? isslCaPath.CStr() : NULL;
- sslCipher = (!isslCipher.IsEmpty()) ? isslCipher.CStr() : NULL;
+ socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : nullptr;
+ user = (!iuser.IsEmpty()) ? iuser.CStr() : nullptr;
+ passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : nullptr;
+ db = (!idb.IsEmpty()) ? idb.CStr() : nullptr;
+
+ sslKey = (!isslKey.IsEmpty()) ? isslKey.CStr() : nullptr;
+ sslCert = (!isslCert.IsEmpty()) ? isslCert.CStr() : nullptr;
+ sslCa = (!isslCa.IsEmpty()) ? isslCa.CStr() : nullptr;
+ sslCaPath = (!isslCaPath.IsEmpty()) ? isslCaPath.CStr() : nullptr;
+ sslCipher = (!isslCipher.IsEmpty()) ? isslCipher.CStr() : nullptr;
/* connection */
if (!mysql_init(&m_Connection)) {
ipasswd = GetPassword();
idb = GetDatabase();
- host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL;
- port = (!iport.IsEmpty()) ? iport.CStr() : NULL;
- user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL;
- passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL;
- db = (!idb.IsEmpty()) ? idb.CStr() : NULL;
+ host = (!ihost.IsEmpty()) ? ihost.CStr() : nullptr;
+ port = (!iport.IsEmpty()) ? iport.CStr() : nullptr;
+ user = (!iuser.IsEmpty()) ? iuser.CStr() : nullptr;
+ passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : nullptr;
+ db = (!idb.IsEmpty()) ? idb.CStr() : nullptr;
- m_Connection = PQsetdbLogin(host, port, NULL, NULL, db, user, passwd);
+ m_Connection = PQsetdbLogin(host, port, nullptr, nullptr, db, user, passwd);
if (!m_Connection)
return;
size_t length = utf8s.GetLength();
char *to = new char[utf8s.GetLength() * 2 + 1];
- PQescapeStringConn(m_Connection, to, utf8s.CStr(), length, NULL);
+ PQescapeStringConn(m_Connection, to, utf8s.CStr(), length, nullptr);
String result = String(to);
{
double interval;
- if (GetStateType() == StateTypeSoft && GetLastCheckResult() != NULL)
+ if (GetStateType() == StateTypeSoft && GetLastCheckResult() != nullptr)
interval = GetRetryInterval();
else
interval = GetCheckInterval();
bool Checkable::HasBeenChecked(void) const
{
- return GetLastCheckResult() != NULL;
+ return GetLastCheckResult() != nullptr;
}
double Checkable::GetLastCheck(void) const
bool local = !endpoint || endpoint == Endpoint::GetLocalEndpoint();
if (local) {
- GetCheckCommand()->Execute(this, cr, NULL, false);
+ GetCheckCommand()->Execute(this, cr, nullptr, false);
} else {
Dictionary::Ptr macros = new Dictionary();
GetCheckCommand()->Execute(this, cr, macros, false);
void AddGroup(const String& name);
- bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr<Dependency> *failedDependency = NULL, int rstack = 0) const;
+ bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr<Dependency> *failedDependency = nullptr, int rstack = 0) const;
AcknowledgementType GetAcknowledgement(void);
String second = def.SubStr(pos + 1).Trim();
- ParseTimeSpec(first, begin, NULL, reference);
+ ParseTimeSpec(first, begin, nullptr, reference);
/* If the second definition starts with a number we need
* to add the first word from the first definition, e.g.:
second = first.SubStr(0, xpos + 1) + second;
}
- ParseTimeSpec(second, NULL, end, reference);
+ ParseTimeSpec(second, nullptr, end, reference);
} else {
ParseTimeSpec(def, begin, end, reference);
}
{
Value resolvedCommand;
if (!arguments || command.IsObjectType<Array>() || command.IsObjectType<Function>())
- resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, NULL,
+ resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, nullptr,
EscapeMacroShellArg, resolvedMacros, useResolvedMacros, recursionLevel + 1);
else {
Array::Ptr arr = new Array();
typedef std::vector<ResolverSpec> ResolverList;
static Value ResolveMacros(const Value& str, const ResolverList& resolvers,
- const CheckResult::Ptr& cr = nullptr, String *missingMacro = NULL,
+ const CheckResult::Ptr& cr = nullptr, String *missingMacro = nullptr,
const EscapeCallback& escapeFn = EscapeCallback(),
const Dictionary::Ptr& resolvedMacros = nullptr,
bool useResolvedMacros = false, int recursionLevel = 0);
String name = kv.second;
Value value = MacroProcessor::ResolveMacros(name, macroResolvers, cr,
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros,
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros,
useResolvedMacros);
if (value.IsObjectType<Array>())
auto it = allStats.find(statsKey);
if (it == allStats.end()) {
- std::vector<AggregatorState *> newStats(m_Aggregators.size(), NULL);
+ std::vector<AggregatorState *> newStats(m_Aggregators.size(), nullptr);
it = allStats.insert(std::make_pair(statsKey, newStats)).first;
}
{
ICorRuntimeHost *runtimeHost;
- if (FAILED(CorBindToRuntimeEx(NULL, NULL,
+ if (FAILED(CorBindToRuntimeEx(nullptr, nullptr,
STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC,
CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void **)&runtimeHost))) {
return;
runtimeHost->Start();
- IUnknownPtr punkAppDomain = NULL;
+ IUnknownPtr punkAppDomain = nullptr;
runtimeHost->GetDefaultDomain(&punkAppDomain);
punkAppDomain->QueryInterface(__uuidof(mscorlib::_AppDomain), (void **)&l_AppDomain);
HRESULT hr = CLSIDFromProgID(L"System.Collections.Hashtable", &clsid);
mscorlib::IDictionaryPtr pHashtable;
- CoCreateInstance(clsid, NULL, CLSCTX_ALL, __uuidof(mscorlib::IDictionary), (void **)&pHashtable);
+ CoCreateInstance(clsid, nullptr, CLSCTX_ALL, __uuidof(mscorlib::IDictionary), (void **)&pHashtable);
ObjectLock olock(args);
for (const Dictionary::Pair& kv : args) {
variant_t result = pType->InvokeMember_3(methodName.CStr(),
mscorlib::BindingFlags_InvokeMethod,
- NULL,
+ nullptr,
vtObject,
psa);
SAFEARRAY *psa = SafeArrayCreateVector(VT_VARIANT, 0, 0);
int lState = pType->InvokeMember_3("State",
mscorlib::BindingFlags_GetField,
- NULL,
+ nullptr,
vtResult,
psa);
cr->SetState(static_cast<ServiceState>(lState));
bstr_t sOutput = pType->InvokeMember_3("Output",
mscorlib::BindingFlags_GetField,
- NULL,
+ nullptr,
vtResult,
psa);
cr->SetOutput(static_cast<const char *>(sOutput));
bstr_t sPerformanceData = pType->InvokeMember_3("PerformanceData",
mscorlib::BindingFlags_GetField,
- NULL,
+ nullptr,
vtResult,
psa);
SafeArrayDestroy(psa);
String name = kv.second;
Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
envMacros->Set(kv.first, value);
}
vtObject = it->second;
} else {
String clr_assembly = MacroProcessor::ResolveMacros("$clr_assembly$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
String clr_type = MacroProcessor::ResolveMacros("$clr_type$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
if (resolvedMacros && !useResolvedMacros)
return;
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
String missingLagWarning;
String missingLagCritical;
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
String dummyText = MacroProcessor::ResolveMacros("$dummy_text$", resolvers, checkable->GetLastCheckResult(),
- NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
+ nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros);
if (resolvedMacros && !useResolvedMacros)
return;
String prefix;
if (service) {
- prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, NULL, std::bind(&GraphiteWriter::EscapeMacroMetric, _1));
+ prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, nullptr, std::bind(&GraphiteWriter::EscapeMacroMetric, _1));
} else {
- prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, NULL, std::bind(&GraphiteWriter::EscapeMacroMetric, _1));
+ prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, nullptr, std::bind(&GraphiteWriter::EscapeMacroMetric, _1));
}
String prefixPerfdata = prefix + ".perfdata";
resolvers.emplace_back("icinga", IcingaApplication::GetInstance());
if (service) {
- String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric);
+ String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric);
{
ObjectLock olock(this);
m_ServiceOutputFile << line << "\n";
}
} else {
- String line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric);
+ String line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric);
{
ObjectLock olock(this);
ScriptFrame frame;
expr->Evaluate(frame);
delete expr;
- expr = NULL;
+ expr = nullptr;
WorkQueue upq;
std::vector<ConfigItem::Ptr> newItems;
Array::Ptr results = new Array();
Dictionary::Ptr resultInfo = new Dictionary();
- Expression *expr = NULL;
+ Expression *expr = nullptr;
Value exprResult;
try {
using namespace icinga;
EventQueue::EventQueue(const String& name)
- : m_Name(name), m_Filter(NULL)
+ : m_Name(name), m_Filter(nullptr)
{ }
EventQueue::~EventQueue(void)
String filter = HttpUtility::GetLastParameter(params, "filter");
- Expression *ufilter = NULL;
+ Expression *ufilter = nullptr;
if (!filter.IsEmpty())
ufilter = ConfigCompiler::CompileText("<API query>", filter);
void FilterUtility::CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **permissionFilter)
{
if (permissionFilter)
- *permissionFilter = NULL;
+ *permissionFilter = nullptr;
if (permission.IsEmpty())
return;
frame.Sandboxed = true;
Dictionary::Ptr uvars = new Dictionary();
- Expression *ufilter = NULL;
+ Expression *ufilter = nullptr;
if (query->Contains("filter")) {
String filter = HttpUtility::GetLastParameter(query, "filter");
{
public:
static Type::Ptr TypeFromPluralName(const String& pluralName);
- static void CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **filter = NULL);
+ static void CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **filter = nullptr);
static std::vector<Value> GetFilterTargets(const QueryDescription& qd, const Dictionary::Ptr& query,
const ApiUser::Ptr& user, const String& variableName = String());
static bool EvaluateFilter(ScriptFrame& frame, Expression *filter,
if (m_State == HttpRequestStart || m_State == HttpRequestHeaders)
FinishHeaders();
- WriteBody(NULL, 0);
+ WriteBody(nullptr, 0);
m_Stream->Write("\r\n", 2);
}
m_Stream->Write(buffer, rc);
}
} else {
- WriteBody(NULL, 0);
+ WriteBody(nullptr, 0);
m_Stream->Write("\r\n", 2);
}
InitializeOpenSSL();
BIO *csrbio = BIO_new_file(csrfile.CStr(), "r");
- X509_REQ *req = PEM_read_bio_X509_REQ(csrbio, NULL, NULL, NULL);
+ X509_REQ *req = PEM_read_bio_X509_REQ(csrbio, nullptr, nullptr, nullptr);
if (!req) {
Log(LogCritical, "SSL")
/* XXX (requires OpenSSL >= 1.0.0)
time_t now;
time(&now);
- ASN1_TIME *tm = ASN1_TIME_adj(NULL, now, 0, 0);
+ ASN1_TIME *tm = ASN1_TIME_adj(nullptr, now, 0, 0);
int day, sec;
ASN1_TIME_diff(&day, &sec, tm, X509_get_notBefore(certRequest.get()));
<< "{" << std::endl
<< "\t" << "static ObjectFactory GetFactory(void)" << std::endl
<< "\t" << "{" << std::endl
- << "\t\t" << "return NULL;" << std::endl
+ << "\t\t" << "return nullptr;" << std::endl
<< "\t" << "}" << std::endl
<< "};" << std::endl << std::endl;
}
if (field.Type.IsName)
nameref = "\"" + field.Type.TypeName + "\"";
else
- nameref = "NULL";
+ nameref = "nullptr";
m_Impl << "\t\t" << "case " << num << ":" << std::endl
<< "\t\t\t" << "return Field(" << num << ", \"" << ftype << "\", \"" << field.Name << "\", \"" << (field.NavigationName.empty() ? field.Name : field.NavigationName) << "\", " << nameref << ", " << field.Attributes << ", " << field.Type.ArrayRank << ");" << std::endl;
char *dir = strdup(path.c_str());
std::string result;
- if (dir == NULL)
+ if (!dir)
throw std::bad_alloc();
#ifndef _WIN32