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];