From 889c707ba1a0c8b66b239df703c7228fd517d994 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Mon, 27 Aug 2012 21:07:38 +0200 Subject: [PATCH] Break out of the main loop on Control-C. Signed-off-by: Richard Cochran --- ptp4l.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ptp4l.c b/ptp4l.c index 2648fe2..d72c27a 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -17,6 +17,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include #include @@ -76,6 +77,12 @@ static struct config cfg_settings = { .cfg_ignore = 0, }; +static void handle_int_quit_term(int s) +{ + pr_notice("caught signal %d", s); + running = 0; +} + static void usage(char *progname) { fprintf(stderr, @@ -122,6 +129,19 @@ int main(int argc, char *argv[]) struct defaultDS *ds = &cfg_settings.dds; int phc_index = -1; + if (SIG_ERR == signal(SIGINT, handle_int_quit_term)) { + fprintf(stderr, "cannot handle SIGINT\n"); + return -1; + } + if (SIG_ERR == signal(SIGQUIT, handle_int_quit_term)) { + fprintf(stderr, "cannot handle SIGQUIT\n"); + return -1; + } + if (SIG_ERR == signal(SIGTERM, handle_int_quit_term)) { + fprintf(stderr, "cannot handle SIGTERM\n"); + return -1; + } + /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0];