Skip to content

Commit

Permalink
Merge pull request allinurl#1466 from aeter/feature/1363-handle-curse…
Browse files Browse the repository at this point in the history
…s-ctrl-c

Close allinurl#1363 - stop program on ctrl-c (SIGINT)
  • Loading branch information
allinurl authored May 27, 2019
2 parents 900b322 + 51e922a commit 0a724b6
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/goaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ house_keeping (void)
free (gwsreader);
}

static void
cleanup (int ret)
{
/* done, restore tty modes and reset terminal into
* non-visual mode */
if (!conf.output_stdout)
endwin ();

/* unable to process valid data */
if (ret)
output_logerrors (glog);

house_keeping ();
}

/* Open the pidfile whose name is specified in the given path and write
* the daemonized given pid. */
static void
Expand Down Expand Up @@ -1327,6 +1342,12 @@ handle_signal_action (int sig_number)

stop_ws_server (gwswriter, gwsreader);
conf.stop_processing = 1;

if (!conf.output_stdout) {
cleanup(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
}

break;
case SIGPIPE:
fprintf (stderr, "SIGPIPE caught!\n");
Expand Down Expand Up @@ -1522,16 +1543,7 @@ main (int argc, char **argv)

/* clean */
clean:
/* done, restore tty modes and reset terminal into
* non-visual mode */
if (!conf.output_stdout)
endwin ();

/* unable to process valid data */
if (ret)
output_logerrors (glog);

house_keeping ();
cleanup(ret);

return ret ? EXIT_FAILURE : EXIT_SUCCESS;
}

0 comments on commit 0a724b6

Please sign in to comment.