Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
centreon
centreon-connectors
Commits
1e4014d7
Commit
1e4014d7
authored
Oct 02, 2014
by
Matthieu Kermagoret
Browse files
Perl: do not add invalid FD to the list of FD to close.
This fixes #5797.
parent
abca02e9
Changes
4
Hide whitespace changes
Inline
Side-by-side
perl/src/embedded_perl.cc
View file @
1e4014d7
...
...
@@ -190,7 +190,18 @@ pid_t embedded_perl::run(std::string const& cmd, int fds[3]) {
}
else
if
(
!
child
)
{
// Child
// Close existing file descriptors.
pipe_handle
::
close_all_handles
();
try
{
pipe_handle
::
close_all_handles
();
}
catch
(
std
::
exception
const
&
e
)
{
std
::
cerr
<<
"could not close all inherited FDs: "
<<
e
.
what
()
<<
std
::
endl
;
exit
(
3
);
}
catch
(...)
{
std
::
cerr
<<
"could not close all inherited FDs"
<<
std
::
endl
;
exit
(
3
);
}
// Setup process.
close
(
in_pipe
[
1
]);
...
...
perl/src/pipe_handle.cc
View file @
1e4014d7
...
...
@@ -26,6 +26,7 @@
#include
"com/centreon/concurrency/mutex.hh"
#include
"com/centreon/connector/perl/pipe_handle.hh"
#include
"com/centreon/exceptions/basic.hh"
#include
"com/centreon/logging/logger.hh"
using
namespace
com
::
centreon
;
using
namespace
com
::
centreon
::
connector
::
perl
;
...
...
@@ -97,7 +98,10 @@ void pipe_handle::close() throw () {
if
(
it
!=
gl_fds
->
end
())
gl_fds
->
erase
(
it
);
}
::
close
(
_fd
);
if
(
::
close
(
_fd
)
!=
0
)
{
char
const
*
msg
(
strerror
(
errno
));
log_error
(
logging
::
medium
)
<<
"could not close pipe FD: "
<<
msg
;
}
_fd
=
-
1
;
}
return
;
...
...
@@ -112,10 +116,17 @@ void pipe_handle::close_all_handles() {
it
(
gl_fds
->
begin
()),
end
(
gl_fds
->
end
());
it
!=
end
;
++
it
)
++
it
)
{
int
retval
;
do
{
::
close
(
*
it
);
}
while
(
EINTR
==
errno
);
retval
=
::
close
(
*
it
);
}
while
((
retval
!=
0
)
&&
(
EINTR
==
errno
));
if
(
retval
!=
0
)
{
char
const
*
msg
(
strerror
(
errno
));
gl_fds
->
erase
(
gl_fds
->
begin
(),
it
);
throw
(
basic_error
()
<<
msg
);
}
}
gl_fds
->
clear
();
return
;
}
...
...
@@ -165,7 +176,7 @@ unsigned long pipe_handle::read(void* data, unsigned long size) {
void
pipe_handle
::
set_fd
(
int
fd
)
{
close
();
_fd
=
fd
;
{
if
(
_fd
>=
0
)
{
concurrency
::
locker
lock
(
gl_fdsm
);
gl_fds
->
insert
(
fd
);
}
...
...
perl/test/embedded_perl/run_simple_1.cc
View file @
1e4014d7
/*
** Copyright 2012-201
3
Merethis
** Copyright 2012-201
4
Merethis
**
** This file is part of Centreon Perl Connector.
**
...
...
@@ -24,6 +24,7 @@
#include
<string>
#include
<sys/wait.h>
#include
"com/centreon/connector/perl/embedded_perl.hh"
#include
"com/centreon/connector/perl/pipe_handle.hh"
#include
"com/centreon/io/file_stream.hh"
#include
"com/centreon/logging/engine.hh"
...
...
@@ -42,6 +43,7 @@ using namespace com::centreon::connector::perl;
int
main
(
int
argc
,
char
*
argv
[],
char
*
env
[])
{
// Initialization.
logging
::
engine
::
load
();
pipe_handle
::
load
();
embedded_perl
::
load
(
&
argc
,
&
argv
,
&
env
);
// Return value.
...
...
@@ -85,6 +87,7 @@ int main(int argc, char* argv[], char* env[]) {
// Unload.
embedded_perl
::
unload
();
pipe_handle
::
unload
();
logging
::
engine
::
unload
();
return
(
retval
);
...
...
perl/test/embedded_perl/run_simple_2.cc
View file @
1e4014d7
/*
** Copyright 2012-201
3
Merethis
** Copyright 2012-201
4
Merethis
**
** This file is part of Centreon Perl Connector.
**
...
...
@@ -24,6 +24,7 @@
#include
<string>
#include
<sys/wait.h>
#include
"com/centreon/connector/perl/embedded_perl.hh"
#include
"com/centreon/connector/perl/pipe_handle.hh"
#include
"com/centreon/io/file_stream.hh"
#include
"com/centreon/logging/engine.hh"
...
...
@@ -42,6 +43,7 @@ using namespace com::centreon::connector::perl;
int
main
(
int
argc
,
char
*
argv
[],
char
*
env
[])
{
// Initialization.
logging
::
engine
::
load
();
pipe_handle
::
load
();
embedded_perl
::
load
(
&
argc
,
&
argv
,
&
env
);
// Return value.
...
...
@@ -89,6 +91,7 @@ int main(int argc, char* argv[], char* env[]) {
// Unload.
embedded_perl
::
unload
();
pipe_handle
::
unload
();
logging
::
engine
::
unload
();
return
(
retval
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment