Break out of the main loop on Control-C.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-08-27 21:07:38 +02:00
parent 2b819b6b76
commit 889c707ba1
1 changed files with 20 additions and 0 deletions

20
ptp4l.c
View File

@ -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 <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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];