Skip to content
GitLab
Menu
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
62ba0617
Unverified
Commit
62ba0617
authored
May 16, 2022
by
jean-christophe81
Committed by
GitHub
May 16, 2022
Browse files
MON-13336-unknown-perl_connector-status correct decode child's exit status (#55)
parent
f015320d
Changes
2
Hide whitespace changes
Inline
Side-by-side
perl/src/policy.cc
View file @
62ba0617
...
...
@@ -72,16 +72,21 @@ void policy::start_second_timer() {
*
*/
void
policy
::
wait_pid
()
{
pid_t
child
;
int
exit_code
;
while
((
child
=
waitpid
(
-
1
,
&
exit_code
,
WNOHANG
))
>
0
)
{
pid_to_check_map
::
iterator
ended
=
_checks
.
find
(
child
);
siginfo_t
child_info
;
child_info
.
si_pid
=
0
;
while
(
!
waitid
(
P_ALL
,
0
,
&
child_info
,
WNOHANG
|
WEXITED
))
{
if
(
!
child_info
.
si_pid
)
{
// no exited child
break
;
}
pid_to_check_map
::
iterator
ended
=
_checks
.
find
(
child_info
.
si_pid
);
if
(
ended
==
_checks
.
end
())
{
log
::
core
()
->
error
(
"pid {} inconnu"
,
child
);
log
::
core
()
->
error
(
"pid {} inconnu"
,
child_info
.
si_pid
);
child_info
.
si_pid
=
0
;
continue
;
}
ended
->
second
->
set_exit_code
(
exit_code
);
ended
->
second
->
set_exit_code
(
child_info
.
si_status
);
_checks
.
erase
(
ended
);
child_info
.
si_pid
=
0
;
}
}
...
...
perl/test/connector.cc
View file @
62ba0617
...
...
@@ -45,6 +45,24 @@ static constexpr const char result[] =
"Centreon is wonderful
\n
"
"
\x00\x00\x00\x00
"
;
static
constexpr
const
char
result_warning
[]
=
"3
\x00
"
"4242
\x00
"
"1
\x00
"
"1
\x00
"
"
\x00
"
"Centreon is wonderful
\n
"
"
\x00\x00\x00\x00
"
;
static
constexpr
const
char
result_critical
[]
=
"3
\x00
"
"4242
\x00
"
"1
\x00
"
"2
\x00
"
"
\x00
"
"Centreon is wonderful
\n
"
"
\x00\x00\x00\x00
"
;
static
constexpr
std
::
size_t
count
=
300
;
static
constexpr
const
char
cmd3
[]
=
"2
\x00
"
;
...
...
@@ -289,8 +307,76 @@ TEST_F(TestConnector, ExecuteSingleScript) {
remove
(
script_path
.
c_str
());
ASSERT_EQ
(
retval
,
0
);
ASSERT_EQ
(
output
.
size
(),
(
sizeof
(
result
)
-
1
));
ASSERT_FALSE
(
memcmp
(
output
.
c_str
(),
result
,
sizeof
(
result
)
-
1
));
std
::
string
expected
(
result
,
result
+
sizeof
(
result
)
-
1
);
ASSERT_EQ
(
output
,
expected
);
}
TEST_F
(
TestConnector
,
ExecuteSingleWarningScript
)
{
// Write Perl script.
std
::
string
script_path
(
com
::
centreon
::
io
::
file_stream
::
temp_path
());
_write_file
(
script_path
.
c_str
(),
"#!/usr/bin/perl
\n
"
"
\n
"
"print
\"
Centreon is wonderful
\\
n
\"
;
\n
"
"exit 1;
\n
"
);
log
::
core
()
->
info
(
"write perl code to {}"
,
script_path
);
// Process.
p
.
exec
(
perl_connector
);
// Write command.
std
::
ostringstream
oss
;
oss
.
write
(
cmd1
,
sizeof
(
cmd1
)
-
1
);
oss
<<
script_path
;
oss
.
write
(
cmd2
,
sizeof
(
cmd2
)
-
1
);
write_cmd
(
oss
.
str
());
// Read reply.
std
::
string
output
{
std
::
move
(
read_reply
())};
int
retval
{
wait_for_termination
()};
// Remove temporary files.
remove
(
script_path
.
c_str
());
ASSERT_EQ
(
retval
,
0
);
std
::
string
expected
(
result_warning
,
result_warning
+
sizeof
(
result_warning
)
-
1
);
ASSERT_EQ
(
output
,
expected
);
}
TEST_F
(
TestConnector
,
ExecuteSingleCriticalScript
)
{
// Write Perl script.
std
::
string
script_path
(
com
::
centreon
::
io
::
file_stream
::
temp_path
());
_write_file
(
script_path
.
c_str
(),
"#!/usr/bin/perl
\n
"
"
\n
"
"print
\"
Centreon is wonderful
\\
n
\"
;
\n
"
"exit 2;
\n
"
);
log
::
core
()
->
info
(
"write perl code to {}"
,
script_path
);
// Process.
p
.
exec
(
perl_connector
);
// Write command.
std
::
ostringstream
oss
;
oss
.
write
(
cmd1
,
sizeof
(
cmd1
)
-
1
);
oss
<<
script_path
;
oss
.
write
(
cmd2
,
sizeof
(
cmd2
)
-
1
);
write_cmd
(
oss
.
str
());
// Read reply.
std
::
string
output
{
std
::
move
(
read_reply
())};
int
retval
{
wait_for_termination
()};
// Remove temporary files.
remove
(
script_path
.
c_str
());
ASSERT_EQ
(
retval
,
0
);
std
::
string
expected
(
result_critical
,
result_critical
+
sizeof
(
result_critical
)
-
1
);
ASSERT_EQ
(
output
,
expected
);
}
TEST_F
(
TestConnector
,
ExecuteSingleScriptLogFile
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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