From f5bf2ec4ccb909aad45ca92b2b0ec549830d4f7b Mon Sep 17 00:00:00 2001 From: deuce <> Date: Thu, 21 Apr 2011 10:06:59 +0000 Subject: [PATCH] Finally track down the "two instances of SyncTERM running, one using 100% CPU" problem and kill it once and for all by doing terrible terrible things. Essentially, the problem stems from SDL installing an atexit() handler and cryptlib calling exit() after a fork(). This causes the child to attempt to shut down SDL (which isn't running in the child) which apparently spins. I've "fixed" this by overriding exit()!!! So any exit() call will not call atexit() functions from SyncTERM anymore. I haven't yet decided if this is a cryptlib bug or an SDL bug, though I'm leaning toward SDL. --- src/syncterm/st_crypt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/syncterm/st_crypt.c b/src/syncterm/st_crypt.c index f70ede65f0..c0b2199f6d 100644 --- a/src/syncterm/st_crypt.c +++ b/src/syncterm/st_crypt.c @@ -1,6 +1,7 @@ /* Copyright (C), 2007 by Stephen Hurd */ #include <stdio.h> /* NULL */ +#include <unistd.h> /* _exit() */ #include "st_crypt.h" #include <xp_dl.h> @@ -19,6 +20,22 @@ void exit_crypt() #else +/* + * cryptlib calls fork() to gather entropy. + * It then calls exit(). + * This calls the atexit() handlers. + * SDL_Exit is in there... + * SDL doesn't exist in the forked child. + * This causes the child to spin FOREVER + * Eating your CPU. + * So, we will break exit(3). + */ +void exit(int code) +{ + fclose(fopen("/tmp/Dumbass", "w")); + _exit(code); +} + struct crypt_funcs cl; int init_crypt(void) -- GitLab