Skip to content

Commit

Permalink
Cleanup signal transfer pipe on mce exit
Browse files Browse the repository at this point in the history
Makes valgrind output less noisy.
  • Loading branch information
spiiroin committed Aug 27, 2014
1 parent 9a21e6b commit 7eac331
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions mce.c
Expand Up @@ -280,6 +280,9 @@ static void install_signal_handlers(void)
/** Pipe used for transferring signals out of signal handler context */
static int signal_pipe[2] = {-1, -1};

/** I/O watch id for signal_pipe */
static guint signal_pipe_id = 0;

/** GIO callback for reading signals from pipe
*
* @param channel io channel for signal pipe
Expand Down Expand Up @@ -378,6 +381,20 @@ static void mce_tx_signal_cb(int sig)
}
}

/** Remove pipe and io watch for handling signals
*/
static void mce_quit_signal_pipe(void)
{
if( signal_pipe_id )
g_source_remove(signal_pipe_id), signal_pipe_id = 0;

if( signal_pipe[0] != -1 )
close(signal_pipe[0]), signal_pipe[0] = -1;

if( signal_pipe[1] != -1 )
close(signal_pipe[1]), signal_pipe[1] = -1;
}

/** Create a pipe and io watch for handling signal from glib mainloop
*/
static gboolean mce_init_signal_pipe(void)
Expand All @@ -391,9 +408,11 @@ static gboolean mce_init_signal_pipe(void)
if( (channel = g_io_channel_unix_new(signal_pipe[0])) == 0 )
goto EXIT;

if( !g_io_add_watch(channel,
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
mce_rx_signal_cb, 0) )
signal_pipe_id =
g_io_add_watch(channel,
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
mce_rx_signal_cb, 0);
if( !signal_pipe_id )
goto EXIT;

result = TRUE;
Expand Down Expand Up @@ -1051,6 +1070,9 @@ int main(int argc, char **argv)
mainloop = 0;
}

/* Close signal pipe & remove io watch for it */
mce_quit_signal_pipe();

/* Log a farewell message and close the log */
mce_log(LL_INFO, "Exiting...");

Expand Down

0 comments on commit 7eac331

Please sign in to comment.