Cover V02, I05
Listing 1
Listing 2


newping Revisited

Eric Horne

[Editor's Note: In the July/August issue of Sys Admin, we published an article by Eric Horne entitled "newping: Remote Host Downtime Detection." The article proved very interesting to readers, several of whom contacted us to mention a problem with the code and to offer both solutions to the problem and enhancements of the program. We are printing Eric's corrected code here, along with a submission from Adam Zell. We'd be interested in hearing from other readers who've worked with the newping code.]

Eric Horne writes:

It would seem that, in spite of the errors I introduced into the newping code, people really found newping a useful utility. An overwhelming number of readers sent in their comments about how useful the application was, or how they were going to use it. One particular reader went on to suggest that newping be called tcping. His logic was that when the next version of newping comes out, the older version won't be new anymore. So I have adopted the new name, tcping, for my application. Just goes to show that I learned as much from the readers, as (I hope) the readers did from me. Thank you!!

And reader Adam Zell writes:

Dear SA:

The newping article by Eric Horne in the July/August issue of SysAdmin was very informative, but unfortunately the implementation was flawed.

The major problem area of the program is in its signal handling. It uses the earlier signal() call, which is unreliable. If the alarm() goes off while inside the alarm signal handler, the handler itself may by interrupted. This could lead to inconsistent output.

By using System V's sigaction, this can be avoided. All alarm signals generated while in an alarm signal handler are blocked until the handler exits.

Another potential problem area in newping.c is the definitions of global variables. All of the global variables are accessed from the signal handlers, and thus should be declared volatile. Labeling a variable volatile tells the compiler not to optimize, and should be used on all variables accessed from a signal handler or goto.

Otherwise, the compiler may keep a variable's value in a register, not storing it immediately back into memory. Since a signal may occur at any time, if the value is not written back, the signal handler may be left with an old value.

There are also some minor bugs dealt with, in terms of option processing, K&R C, and older BSD constants. Also, extraneous variables were taken out and generally cleaned up. The resultant program (Listing 2) is ANSI and SVR4 compliant.

Adam Zell

About the Author

Eric T. Horne is a graduating senior from Cal Poly at San Luis Obispo. He worked as a programmer analyst for 9 months at Teradyne, Inc. (ST division), where he assisted system administrators and wrote several utility sh scripts to help manage and measure performance of systems. He will be graduating hopefully sometime in August, 1993. You may contact Eric at 40 San Antonio Street, Newbury Park, CA 91320