-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEBUG-ONLY] Enhance jb->blocked assert in jnl_write.c to account for…
… defunct processes If the process id corresponding to jb->blocked was abnormally killed (e.g. kill -9), it is possible the process is still alive but in a defunct state (when another process comes into jnl_write.c after having salvaged crit etc.) if the parent process has not yet done a waitpid() on this abnormally terminated child. In that case, the following assert would fail. 266 assert((!jb->blocked) || (FALSE == is_proc_alive(jb->blocked, 0))); This is now addressed by using the new is_defunct_pid() function in the assert.
- Loading branch information
Showing
3 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/**************************************************************** | ||
* * | ||
* Copyright (c) 2019 YottaDB LLC and/or its subsidiaries. * | ||
* All rights reserved. * | ||
* * | ||
* This source code contains the intellectual property * | ||
* of its copyright holder(s), and is made available * | ||
* under a license. If you do not know the terms of * | ||
* the license, please stop and do not read further. * | ||
* * | ||
****************************************************************/ | ||
|
||
#include "mdef.h" | ||
|
||
#include "gtm_stdio.h" | ||
|
||
#include "is_defunct_pid.h" | ||
|
||
#ifdef DEBUG | ||
GBLREF uint4 process_id; | ||
#endif | ||
|
||
/* ---------------------------------------------- | ||
* Check if input pid is a defunct process (zombie) | ||
* | ||
* Arguments: | ||
* pid - process ID | ||
* | ||
* Return: | ||
* TRUE - If process is a defunct process (i.e. shows up as <defunct> in ps -ef listing) | ||
* FALSE - Otherwise | ||
* ---------------------------------------------- | ||
*/ | ||
|
||
boolean_t is_defunct_pid(int4 pid) | ||
{ | ||
int status; | ||
char procfilename[64]; | ||
boolean_t is_defunct; | ||
FILE *fp; | ||
char pidstate; | ||
|
||
assert(0 != pid); | ||
assert(process_id != pid); | ||
is_defunct = FALSE; /* by default it is not a defunct process */ | ||
# ifdef __linux__ | ||
/* open the /proc/<pid>/stat file */ | ||
SNPRINTF(procfilename, sizeof(procfilename), "/proc/%d/stat", (int)pid); | ||
fp = fopen(procfilename, "r"); | ||
if (NULL != fp) | ||
{ | ||
fscanf(fp, "%*d %*s %c", &pidstate); | ||
is_defunct = ('Z' == pidstate); | ||
fclose(fp); | ||
} | ||
# else | ||
/* This is likely MacOS or Cygwin. Those ports need to implement this functionality using other methods | ||
* (maybe do a "system" call with a "ps -ef | grep defunct" if nothing else is possible). | ||
*/ | ||
# error unsupported platform | ||
# endif | ||
return is_defunct; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/**************************************************************** | ||
* * | ||
* Copyright (c) 2019 YottaDB LLC and/or its subsidiaries. * | ||
* All rights reserved. * | ||
* * | ||
* This source code contains the intellectual property * | ||
* of its copyright holder(s), and is made available * | ||
* under a license. If you do not know the terms of * | ||
* the license, please stop and do not read further. * | ||
* * | ||
****************************************************************/ | ||
|
||
#ifndef IS_DEFUNCT_PID_INCLUDED | ||
#define IS_DEFUNCT_PID_INCLUDED | ||
|
||
boolean_t is_defunct_pid(int4 pid); | ||
|
||
#endif /* IS_DEFUNCT_PID_INCLUDED */ |