Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
664709e7
Commit
664709e7
authored
Apr 08, 2010
by
Michael Widenius
Browse files
Options
Browse Files
Download
Plain Diff
Merge with 5.1
parents
8ee9c636
4a462710
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
33 deletions
+14
-33
mysql-test/lib/My/SafeProcess/safe_process.cc
mysql-test/lib/My/SafeProcess/safe_process.cc
+14
-33
No files found.
mysql-test/lib/My/SafeProcess/safe_process.cc
View file @
664709e7
...
@@ -85,16 +85,17 @@ static void die(const char* fmt, ...)
...
@@ -85,16 +85,17 @@ static void die(const char* fmt, ...)
va_end
(
args
);
va_end
(
args
);
if
(
int
last_err
=
errno
)
if
(
int
last_err
=
errno
)
fprintf
(
stderr
,
"error: %d, %s
\n
"
,
last_err
,
strerror
(
last_err
));
fprintf
(
stderr
,
"error: %d, %s
\n
"
,
last_err
,
strerror
(
last_err
));
exit
(
1
);
exit
(
6
);
}
}
static
void
kill_child
(
voi
d
)
static
void
kill_child
(
bool
was_kille
d
)
{
{
int
status
=
0
;
int
status
=
0
;
message
(
"Killing child: %d"
,
child_pid
);
message
(
"Killing child: %d"
,
child_pid
);
// Terminate whole process group
// Terminate whole process group
if
(
!
was_killed
)
kill
(
-
child_pid
,
SIGKILL
);
kill
(
-
child_pid
,
SIGKILL
);
pid_t
ret_pid
=
waitpid
(
child_pid
,
&
status
,
0
);
pid_t
ret_pid
=
waitpid
(
child_pid
,
&
status
,
0
);
...
@@ -115,7 +116,7 @@ static void kill_child(void)
...
@@ -115,7 +116,7 @@ static void kill_child(void)
exit
(
exit_code
);
exit
(
exit_code
);
}
}
exit
(
1
);
exit
(
5
);
}
}
...
@@ -135,7 +136,7 @@ extern "C" void handle_signal(int sig)
...
@@ -135,7 +136,7 @@ extern "C" void handle_signal(int sig)
terminated
=
1
;
terminated
=
1
;
if
(
child_pid
>
0
)
if
(
child_pid
>
0
)
kill_child
();
kill_child
(
sig
==
SIGCHLD
);
// Ignore further signals
// Ignore further signals
signal
(
SIGTERM
,
SIG_IGN
);
signal
(
SIGTERM
,
SIG_IGN
);
...
@@ -240,7 +241,7 @@ int main(int argc, char* const argv[] )
...
@@ -240,7 +241,7 @@ int main(int argc, char* const argv[] )
// Close write end
// Close write end
close
(
pfd
[
1
]);
close
(
pfd
[
1
]);
if
(
execvp
(
child_argv
[
0
],
child_argv
)
<
0
)
execvp
(
child_argv
[
0
],
child_argv
);
die
(
"Failed to exec child"
);
die
(
"Failed to exec child"
);
}
}
...
@@ -257,39 +258,19 @@ int main(int argc, char* const argv[] )
...
@@ -257,39 +258,19 @@ int main(int argc, char* const argv[] )
/* Monitor loop */
/* Monitor loop */
message
(
"Started child %d, terminated: %d"
,
child_pid
,
terminated
);
message
(
"Started child %d, terminated: %d"
,
child_pid
,
terminated
);
while
(
!
terminated
)
while
(
!
terminated
)
{
{
// Check if parent is still alive
// Check if parent is still alive
if
(
kill
(
parent_pid
,
0
)
!=
0
){
if
(
kill
(
parent_pid
,
0
)
!=
0
)
{
message
(
"Parent is not alive anymore"
);
message
(
"Parent is not alive anymore"
);
break
;
break
;
}
}
/* Wait for parent or child to die */
// Check if child has exited, normally this will be
// detected immediately with SIGCHLD handler
int
status
=
0
;
pid_t
ret_pid
=
waitpid
(
child_pid
,
&
status
,
WNOHANG
);
if
(
ret_pid
==
child_pid
)
{
int
ret_code
=
2
;
if
(
WIFEXITED
(
status
))
{
// Process has exited, collect return status
ret_code
=
WEXITSTATUS
(
status
);
message
(
"Child exit: %d"
,
ret_code
);
// Exit with exit status of the child
exit
(
ret_code
);
}
if
(
WIFSIGNALED
(
status
))
message
(
"Child killed by signal: %d"
,
WTERMSIG
(
status
));
exit
(
ret_code
);
}
sleep
(
1
);
sleep
(
1
);
}
}
kill_child
();
kill_child
(
0
);
return
1
;
return
4
;
}
}
Write
Preview
Markdown
is supported
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