On Tue, Jan 26, 2016 at 07:24:05PM +0100, Theo Buehler wrote: > On Tue, Jan 26, 2016 at 11:40:44AM -0600, Chris Bennett wrote: > > I found this in several other files in lpr src directories. > > Doesn't seem to get used in any lp* files or connect with anything > > higher up. > > > > Am I looking at this correctly or way off? > > It is used. Read up on sigaction(2) and alarm(3). > > The high level explanation is in the first part of this commit message > from NetBSD > http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.sbin/lpr/common_source/rmjob.c?rev=1.15&content-type=text/x-cvsweb-markup&only_with_tag=MAIN > > In fact, it's all visible in this code snippet you touched: > > } else { > struct sigaction osa, nsa; > > // initialize new sigaction structure nsa > // alarmer is the function to be executed > memset(&nsa, 0, sizeof(nsa)); > nsa.sa_handler = alarmer; > sigemptyset(&nsa.sa_mask); > nsa.sa_flags = 0; > > // install nsa to act on SIGALRM, > // save old sigact structure osa > (void)sigaction(SIGALRM, &nsa, &osa); > > // raise sigalrm (execute alarmer, i.e., do nothing) > // after wait time seconds. > alarm(wait_time); > > // if first write fails, bail out and inform admin of > // "Lost connection" > i = strlen(buf); > // try to write all of buf into rem > if (write(rem, buf, i) != i) > fatal("Lost connection"); > > // read rem and write it to stdout. > while ((i = read(rem, buf, sizeof(buf))) > 0) > (void)fwrite(buf, 1, i, stdout); > > // turn current alarm off > alarm(0); > // re-install osa > (void)sigaction(SIGALRM, &osa, NULL); > > // close rem > (void)close(rem); > }
I actually started to think I was wrong after I posted diff. Was reading man pages about signals just now. I didn't know there was an alarm man page, thanks. It looks like I need to rewrite code to use setitimer since alarm is now obsolete. Chris
