Ack with comments.
1) Maybe you should use osaf_nanosleep() instead of sleep() here?
2) Agree with Mathi that you should handle EINTR
3) When I read the man page for waitpid(), I think it is a bit unclear
if the status variable has a defined value when waitipid() returns zero.
Maybe it would be safer to treat the status variable as undefined in
this case?
4) You need to add the following includes:
#include <signal.h> // for kill()
#include <sys/wait.h> // for waitpid()
#include <stdint.h> // for uint32_t
/ Anders Widell
On 04/02/2015 02:17 PM, Hans Nordeback wrote:
> osaf/services/infrastructure/nid/nodeinit.c | 24 ++++++++++++++++++++++++
> 1 files changed, 24 insertions(+), 0 deletions(-)
>
>
> diff --git a/osaf/services/infrastructure/nid/nodeinit.c
> b/osaf/services/infrastructure/nid/nodeinit.c
> --- a/osaf/services/infrastructure/nid/nodeinit.c
> +++ b/osaf/services/infrastructure/nid/nodeinit.c
> @@ -1108,6 +1108,30 @@ void cleanup(NID_SPAWN_INFO *service)
> nid_close_ipc();
> select_fd = -1;
>
> + pid_t w_pid;
> + int status;
> + uint32_t no_of_retries = 0;
> + const uint32_t MAX_NO_RETRIES = 5;
> +
> + if (check_process(service)) {
> + // send abort signal to process to generate a core dump
> + LOG_ER("Sending SIGABRT to %s, pid=%d", service->serv_name,
> service->pid);
> + if (kill(service->pid, SIGABRT) >= 0) {
> + // wait a short period for process to exit
> + do {
> + w_pid = waitpid(service->pid, &status, WNOHANG);
> + if (w_pid < 0) {
> + break;
> + } else {
> + if (!WIFEXITED(status) &&
> !WIFSIGNALED(status)) {
> + sleep(1);
> + }
> + }
> + } while (!WIFEXITED(status) && !WIFSIGNALED(status) &&
> ++no_of_retries < MAX_NO_RETRIES);
> + }
> + }
> +
> + // if sending abort signal did not succeed, fallback to sigkill
> if (check_process(service)) {
> LOG_ER("Sending SIGKILL to %s, pid=%d", service->serv_name,
> service->pid);
> kill(service->pid, SIGKILL);
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel