> There's a lot of common code here, but ipmpstat has
 > one new feature: adjusting the output based on window size.
 > In order to do this, ipmpstat tracks the window size using
 > TIOCGWINSZ, and also has a signal handler for SIGWINCH to dynamically
 > track changes to winsize.
 > 
 > The adjustments for winsize are a nice feature, and I would
 > like to extend this for all the *adm apps. But then the question
 > arises: who should dynamically track the winsize changes? The
 > options are
 > 1. tell the app to pass winsize to library when it calls the
 >    output functions. It's the caller's job to track the changes
 >    to winsize through signal handlers. This puts a lot of burden
 >    on the app (to track SIGWINCH) but keeps the library interface
 >    clean and free of side-effects.
 > 
 > 2. have the caller pass a boolean adjust_to_current_winsize 
 >    parameter when they set up the handle for printing output.
 >    This means that the library will install a signal handler
 >    for SIGWINCH (which may clobber user signal handlers for this
 >    signal). And if adjust_to_current_winsize is set to FALSE,
 >    then the output will potentially overflow the screen etc. 
 > 
 > Both options have advantages and disadvantages.  
 > Any opinions onw which one is more attractive?

Even if it's optional, having a library set up a signal handler is evil.

I presume the API you've created has a "output instance handle" of some
sort where you can store the number of rows.  I'd consider having the
library call TIOCGWINSZ right before the first time it prints a row (and
store away the result), and then have an oftm_winch() routine the
application can call to tell the library the window size has changed,
which will cause the library to call TIOCGWINSZ again and get the latest
information.  That should require only about 5 lines of code in the
application to setup the SIGWINCH handler and have that handler call the
ofmt_winch() API.  Further, I suspect most applications won't need to
worry about SIGWINCH because they complete immediately.  The SIGWINCH
handler was added for ipmpstat because "-p" mode runs until it's
explicitly terminated.

-- 
meem

Reply via email to