Change how SIGINFO is handled -- set a flag (of sig_atomic_t), and check
that flag on every iteration of the loop. This avoids calling fprintf inside a signal handler, which is always somewhat icky. Reviewed by: bde
This commit is contained in:
parent
c918e9eece
commit
37e5b2c618
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=20195
@ -139,9 +139,10 @@ double tmax = 0.0; /* maximum round trip time */
|
|||||||
double tsum = 0.0; /* sum of all times, for doing average */
|
double tsum = 0.0; /* sum of all times, for doing average */
|
||||||
|
|
||||||
int reset_kerninfo;
|
int reset_kerninfo;
|
||||||
|
sig_atomic_t siginfo_p;
|
||||||
|
|
||||||
char *pr_addr();
|
char *pr_addr();
|
||||||
void catcher(), finish(), status();
|
void catcher(), finish(), status(), check_status();
|
||||||
|
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
@ -161,6 +162,7 @@ main(argc, argv)
|
|||||||
#ifdef IP_OPTIONS
|
#ifdef IP_OPTIONS
|
||||||
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
|
char rspace[3 + 4 * NROUTES + 1]; /* record route space */
|
||||||
#endif
|
#endif
|
||||||
|
struct sigaction si_sa;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do the stuff that we need root priv's for *first*, and
|
* Do the stuff that we need root priv's for *first*, and
|
||||||
@ -356,6 +358,14 @@ main(argc, argv)
|
|||||||
(void)signal(SIGALRM, catcher);
|
(void)signal(SIGALRM, catcher);
|
||||||
(void)signal(SIGINFO, status);
|
(void)signal(SIGINFO, status);
|
||||||
|
|
||||||
|
si_sa.sa_handler = status;
|
||||||
|
sigemtpyset(&si_sa.sa_mask);
|
||||||
|
si_sa.sa_flags = 0;
|
||||||
|
if (sigaction(SIGINFO, &si_sa, 0) == -1) {
|
||||||
|
perror("sigaction");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (tcgetattr(STDOUT_FILENO, &ts) != -1) {
|
if (tcgetattr(STDOUT_FILENO, &ts) != -1) {
|
||||||
reset_kerninfo = !(ts.c_lflag & NOKERNINFO);
|
reset_kerninfo = !(ts.c_lflag & NOKERNINFO);
|
||||||
ts.c_lflag |= NOKERNINFO;
|
ts.c_lflag |= NOKERNINFO;
|
||||||
@ -368,7 +378,7 @@ main(argc, argv)
|
|||||||
if ((options & F_FLOOD) == 0)
|
if ((options & F_FLOOD) == 0)
|
||||||
catcher(); /* start things going */
|
catcher(); /* start things going */
|
||||||
|
|
||||||
for (;;) {
|
for (;;check_status()) {
|
||||||
struct sockaddr_in from;
|
struct sockaddr_in from;
|
||||||
register int cc;
|
register int cc;
|
||||||
int fromlen;
|
int fromlen;
|
||||||
@ -739,21 +749,30 @@ tvsub(out, in)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
status()
|
status() {
|
||||||
|
siginfo_p = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
check_status()
|
||||||
{
|
{
|
||||||
double temp_min = nreceived ? tmin : 0;
|
double temp_min = nreceived ? tmin : 0;
|
||||||
(void)fprintf(stderr, "%ld/%ld packets received (%ld%%) "
|
|
||||||
"%.3f min / %.3f avg / %.3f max\n",
|
if (siginfo_p) {
|
||||||
nreceived, ntransmitted,
|
(void)fprintf(stderr, "%ld/%ld packets received (%ld%%) "
|
||||||
(ntransmitted ?
|
"%.3f min / %.3f avg / %.3f max\n",
|
||||||
100 - (int) (((ntransmitted - nreceived) * 100)
|
nreceived, ntransmitted,
|
||||||
/ ntransmitted)
|
(ntransmitted ?
|
||||||
: 0),
|
100 - (int) (((ntransmitted - nreceived) * 100)
|
||||||
temp_min,
|
/ ntransmitted)
|
||||||
((nreceived + nrepeats) ?
|
: 0),
|
||||||
(tsum / (nreceived + nrepeats))
|
temp_min,
|
||||||
: tsum),
|
(nreceived + nrepeats) ?
|
||||||
tmax);
|
tsum / (nreceived + nrepeats)
|
||||||
|
: tsum,
|
||||||
|
tmax);
|
||||||
|
siginfo_p = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user