Skip to content

Commit

Permalink
add Timer cleanup to worker cleanup and fix signal handlers (see issue
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Sep 1, 2019
1 parent ef041d9 commit ab3dca2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

### v. 0.7.3

**Fix**: (`fio`) fixes an issue where timer cleanup wasn't performed after `fio_stop` (or SIGINT/SIGTERM). No a "clean slate" will be provided if `fio_start` is called more then once. Note: this may **break previous behavior**, which should be considered undocumented and unexpected behavior. (this fax **may** be deferred to version 0.8.x, still undecided). Credit to @fbrausse for opening issue #72.

**Fix**: (`fio`) fixes an issue where timer cleanup would be performed after the `AT_EXIT` state callbacks. Now the timer cleanup callbacks will be performed **before** the `AT_EXIT` callback (as they should). (See issue #72).

**Fix**: (`fio`) fixes an issue where timer cleanup would be performed after the `AT_EXIT` state callbacks. Now the timer cleanup callbacks will be performed **before** the `AT_EXIT` callback (as they should). (See issue #72).

**Fix**: (`fio`) fixes signal handler (re)establishment test to prevent recursive signal calling.

### v. 0.7.2

**Fix**: (`fio_tls`) fixes a memory leak in the trusted certificate chain. Credit to @fbrausse for opening PR #71.
Expand Down
26 changes: 15 additions & 11 deletions lib/facil/fio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,12 +1178,13 @@ static inline void fio_mark_time(void) {
/** Calculates the due time for a task, given it's interval */
static struct timespec fio_timer_calc_due(size_t interval) {
struct timespec now = fio_last_tick();
if (interval > 1000) {
now.tv_sec += interval / 1000;
interval -= interval / 1000;
if (interval >= 1000) {
unsigned long long secs = interval / 1000;
now.tv_sec += secs;
interval -= secs * 1000;
}
now.tv_nsec += (interval * 1000000UL);
if (now.tv_nsec > 1000000000L) {
if (now.tv_nsec >= 1000000000L) {
now.tv_nsec -= 1000000000L;
now.tv_sec += 1;
}
Expand Down Expand Up @@ -1346,7 +1347,7 @@ Section Start Marker
***************************************************************************** */

volatile uint8_t fio_signal_children_flag = 0;

volatile fio_lock_i fio_signal_set_flag = 0;
/* store old signal handlers to propegate signal handling */
static struct sigaction fio_old_sig_chld;
static struct sigaction fio_old_sig_pipe;
Expand Down Expand Up @@ -1415,15 +1416,15 @@ static void sig_int_handler(int sig) {
break;
}
/* propagate signale handling to previous existing handler (if any) */
if (old->sa_handler != SIG_IGN && old->sa_handler != SIG_DFL)
if (old && old->sa_handler != SIG_IGN && old->sa_handler != SIG_DFL)
old->sa_handler(sig);
}

/* setup handling for the SIGUSR1, SIGPIPE, SIGINT and SIGTERM signals. */
static void fio_signal_handler_setup(void) {
/* setup signal handling */
struct sigaction act;
if (fio_old_sig_int.sa_handler)
if (fio_trylock(&fio_signal_set_flag))
return;

memset(&act, 0, sizeof(act));
Expand Down Expand Up @@ -1457,8 +1458,9 @@ static void fio_signal_handler_setup(void) {

void fio_signal_handler_reset(void) {
struct sigaction old;
if (!fio_old_sig_int.sa_handler)
if (fio_signal_set_flag)
return;
fio_unlock(&fio_signal_set_flag);
memset(&old, 0, sizeof(old));
sigaction(SIGINT, &fio_old_sig_int, &old);
sigaction(SIGTERM, &fio_old_sig_term, &old);
Expand Down Expand Up @@ -3533,11 +3535,12 @@ static void __attribute__((destructor)) fio_lib_destroy(void) {
fio_data->active = 0;
fio_on_fork();
fio_defer_perform();
fio_timer_clear_all();
fio_defer_perform();
fio_state_callback_force(FIO_CALL_AT_EXIT);
fio_state_callback_clear_all();
fio_defer_perform();
fio_poll_close();
fio_timer_clear_all();
fio_free(fio_data);
/* memory library destruction must be last */
fio_mem_destroy();
Expand Down Expand Up @@ -3811,15 +3814,16 @@ static void fio_worker_cleanup(void) {
fio_force_close(fd2uuid(i));
}
}
fio_defer_perform();
fio_state_callback_force(FIO_CALL_ON_FINISH);
fio_timer_clear_all();
fio_defer_perform();
if (!fio_data->is_worker) {
kill(0, SIGINT);
while (wait(NULL) != -1)
;
}
fio_defer_perform();
fio_state_callback_force(FIO_CALL_ON_FINISH);
fio_defer_perform();
fio_signal_handler_reset();
if (fio_data->parent == getpid()) {
FIO_LOG_INFO(" --- Shutdown Complete ---\n");
Expand Down
2 changes: 1 addition & 1 deletion lib/facil/fio.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Version and helper macros

#define FIO_VERSION_MAJOR 0
#define FIO_VERSION_MINOR 7
#define FIO_VERSION_PATCH 2
#define FIO_VERSION_PATCH 3
#define FIO_VERSION_BETA 0

/* Automatically convert version data to a string constant - ignore these two */
Expand Down

0 comments on commit ab3dca2

Please sign in to comment.