Skip to content

Instantly share code, notes, and snippets.

@darkk
Created March 27, 2012 13:45
Show Gist options
  • Save darkk/2216008 to your computer and use it in GitHub Desktop.
Save darkk/2216008 to your computer and use it in GitHub Desktop.
Ugly waitpid_core_once :(
pid_t waitpid_core_once(pid_t pid, int *status, int options)
{
int status_holder;
pid_t retval;
if (!status)
status = &status_holder;
retval = waitpid(pid, status, options);
if (retval > 0 && WIFSIGNALED(*status) && WCOREDUMP(*status)) {
struct rlimit core;
memset(&core, 0xFF, sizeof(core));
if (getrlimit(RLIMIT_CORE, &core) == -1)
uwsgi_error("getrlimit(RLIMIT_CORE)");
uwsgi_log("DAMN! pid: %d was killed by signal (%d) and dumped core, limits are {soft: 0x%x, hard: 0x%x}, disabling further core dumps to avoid flood...\n",
retval, WTERMSIG(*status), core.rlim_cur, core.rlim_max);
core.rlim_cur = 0;
if (setrlimit(RLIMIT_CORE, &core) == -1)
uwsgi_error("setrlimit(RLIMIT_CORE)");
}
return retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment