Skip to content

Commit

Permalink
Log signal number on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
dennypage committed Feb 28, 2022
1 parent bc00923 commit efc17c7
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions dpinger.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

//
// Copyright (c) 2015-2020, Denny Page
// Copyright (c) 2015-2022, Denny Page
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -190,25 +190,6 @@ static uint16_t sequence_limit;
// Receive thread ready
static unsigned int recv_ready = 0;

//
// Termination handler
//
__attribute__ ((noreturn))
static void
term_handler(void)
{
// NB: This function may be simultaneously invoked by multiple threads
if (usocket_name)
{
(void) unlink(usocket_name);
}
if (pidfile_name)
{
(void) unlink(pidfile_name);
}
exit(0);
}


//
// Log for abnormal events
Expand All @@ -234,6 +215,28 @@ logger(
}


//
// Termination handler
//
__attribute__ ((noreturn))
static void
term_handler(
int signum)
{
// NB: This function may be simultaneously invoked by multiple threads
if (usocket_name)
{
(void) unlink(usocket_name);
}
if (pidfile_name)
{
(void) unlink(pidfile_name);
}
logger("exiting on signal %d\n", signum);
exit(0);
}


//
// Compute checksum for ICMP
//
Expand Down Expand Up @@ -840,7 +843,7 @@ get_length_arg(
static void
usage(void)
{
fprintf(stderr, "Dpinger version 3.1\n\n");
fprintf(stderr, "Dpinger version 3.2\n\n");
fprintf(stderr, "Usage:\n");
fprintf(stderr, " %s [-f] [-R] [-S] [-P] [-B bind_addr] [-s send_interval] [-l loss_interval] [-t time_period] [-r report_interval] [-d data_length] [-o output_file] [-A alert_interval] [-D latency_alarm] [-L loss_alarm] [-C alert_cmd] [-i identifier] [-u usocket] [-p pidfile] dest_addr\n\n", progname);
fprintf(stderr, " options:\n");
Expand Down

0 comments on commit efc17c7

Please sign in to comment.