Skip to content

Commit

Permalink
More thread termination clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
robertswiecki committed Feb 19, 2017
1 parent 33fb284 commit 8d01b01
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ bool cmdlineParse(int argc, char *argv[], honggfuzz_t * hfuzz)
#endif
.threadsActiveCnt = 0,
.mainPid = getpid(),
.terminating = false,

.dictionaryFile = NULL,
.dictionaryCnt = 0,
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ typedef struct {
bool monitorSIGABRT;
uint32_t threadsActiveCnt;
pid_t mainPid;
bool terminating;

const char *dictionaryFile;
TAILQ_HEAD(, strings_t) dictq;
Expand Down
4 changes: 4 additions & 0 deletions fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ static void *fuzz_threadNew(void *arg)
return NULL;
}

if (ATOMIC_GET(hfuzz->terminating) == true) {
return NULL;
}

fuzz_fuzzLoop(hfuzz, &fuzzer);
}
}
Expand Down
18 changes: 13 additions & 5 deletions honggfuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ void sigHandler(int sig)
return;
}

sigReceived = sig;
if (ATOMIC_GET(sigReceived) != 0) {
static const char *const sigMsg = "Repeated termination signal caugth\n";
if (write(STDERR_FILENO, sigMsg, strlen(sigMsg) + 1) == -1) {
};
_exit(EXIT_FAILURE);
}

ATOMIC_SET(sigReceived, sig);
}

static void setupTimer(void)
Expand Down Expand Up @@ -184,7 +191,7 @@ int main(int argc, char **argv)
if (hfuzz.useScreen) {
display_display(&hfuzz);
}
if (sigReceived > 0) {
if (ATOMIC_GET(sigReceived) > 0) {
break;
}
if (ATOMIC_GET(hfuzz.threadsFinished) >= hfuzz.threadsMax) {
Expand All @@ -197,9 +204,10 @@ int main(int argc, char **argv)
display_fini();
}

if (sigReceived > 0) {
LOG_I("Signal %d (%s) received, terminating", sigReceived, strsignal(sigReceived));
return EXIT_SUCCESS;
if (ATOMIC_GET(sigReceived) > 0) {
LOG_I("Signal %d (%s) received, terminating", ATOMIC_GET(sigReceived),
strsignal(ATOMIC_GET(sigReceived)));
ATOMIC_SET(hfuzz.terminating, true);
}

fuzz_threadsStop(&hfuzz, threads);
Expand Down

0 comments on commit 8d01b01

Please sign in to comment.