mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
parent
2cf0df2675
commit
9ea51aa86e
@ -806,7 +806,7 @@ bool Utility::SetFileOwnership(const String& file, const String& user, const Str
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
void Utility::SetNonBlocking(int fd)
|
void Utility::SetNonBlocking(int fd, bool nb)
|
||||||
{
|
{
|
||||||
int flags = fcntl(fd, F_GETFL, 0);
|
int flags = fcntl(fd, F_GETFL, 0);
|
||||||
|
|
||||||
@ -816,14 +816,19 @@ void Utility::SetNonBlocking(int fd)
|
|||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
if (nb)
|
||||||
|
flags |= O_NONBLOCK;
|
||||||
|
else
|
||||||
|
flags &= ~O_NONBLOCK;
|
||||||
|
|
||||||
|
if (fcntl(fd, F_SETFL, flags) < 0) {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
<< boost::errinfo_api_function("fcntl")
|
<< boost::errinfo_api_function("fcntl")
|
||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utility::SetCloExec(int fd)
|
void Utility::SetCloExec(int fd, bool cloexec)
|
||||||
{
|
{
|
||||||
int flags = fcntl(fd, F_GETFD, 0);
|
int flags = fcntl(fd, F_GETFD, 0);
|
||||||
|
|
||||||
@ -833,7 +838,12 @@ void Utility::SetCloExec(int fd)
|
|||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
|
if (cloexec)
|
||||||
|
flags |= FD_CLOEXEC;
|
||||||
|
else
|
||||||
|
flags &= ~FD_CLOEXEC;
|
||||||
|
|
||||||
|
if (fcntl(fd, F_SETFD, flags) < 0) {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
<< boost::errinfo_api_function("fcntl")
|
<< boost::errinfo_api_function("fcntl")
|
||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
@ -841,13 +851,13 @@ void Utility::SetCloExec(int fd)
|
|||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
void Utility::SetNonBlockingSocket(SOCKET s)
|
void Utility::SetNonBlockingSocket(SOCKET s, bool nb)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
SetNonBlocking(s);
|
SetNonBlocking(s, nb);
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
unsigned long lTrue = 1;
|
unsigned long lflag = nb;
|
||||||
ioctlsocket(s, FIONBIO, &lTrue);
|
ioctlsocket(s, FIONBIO, &lflag);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +96,11 @@ public:
|
|||||||
static String FormatErrorNumber(int code);
|
static String FormatErrorNumber(int code);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static void SetNonBlocking(int fd);
|
static void SetNonBlocking(int fd, bool nb = true);
|
||||||
static void SetCloExec(int fd);
|
static void SetCloExec(int fd, bool cloexec = true);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
static void SetNonBlockingSocket(SOCKET s);
|
static void SetNonBlockingSocket(SOCKET s, bool nb = true);
|
||||||
|
|
||||||
static String EscapeShellCmd(const String& s);
|
static String EscapeShellCmd(const String& s);
|
||||||
static String EscapeShellArg(const String& s);
|
static String EscapeShellArg(const String& s);
|
||||||
|
@ -94,11 +94,7 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int fd;
|
int fd = open(commandPath.CStr(), O_RDONLY | O_NONBLOCK);
|
||||||
|
|
||||||
do {
|
|
||||||
fd = open(commandPath.CStr(), O_RDONLY);
|
|
||||||
} while (fd < 0 && errno == EINTR);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
Log(LogCritical, "ExternalCommandListener")
|
Log(LogCritical, "ExternalCommandListener")
|
||||||
@ -106,6 +102,8 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utility::SetNonBlocking(fd, false);
|
||||||
|
|
||||||
FILE *fp = fdopen(fd, "r");
|
FILE *fp = fdopen(fd, "r");
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user