Subject: bin/19657: bug in irdaattach (or maybe daemon(3))
To: None <>
From: None <>
List: netbsd-bugs
Date: 01/03/2003 14:14:11
>Number:         19657
>Category:       bin
>Synopsis:       'irdaattach -f' can't be used in `...` because of the daemon() call
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 03 11:15:00 PST 2003
>Originator:     Steven M. Bellovin
>Release:        NetBSD 1.6_STABLE
AT&T Labs Research
System: NetBSD 1.6_STABLE NetBSD 1.6_STABLE (BERKSHIRE.nosound) #4: Sat Nov 16 20:31:26 EST 2002 i386
Architecture: i386
Machine: i386
	I'd like to have this in rc.local:

	/usr/pkg/bin/irs -Y -c -y /dev/ptyqf -d `/usr/sbin/irdaattach -f tty01`

	where the 'irdaattach -f' prints the name of the irframe device.
	However, although the printf() in irdaattach is before the
	call to daemon(), stdout isn't flushed, it seems; that means that
	the pipeline doesn't work.  (That can be demonstrated easily
	by running

		irdaattach -f /dev/tty01 | cat

	and comparing its output to

		irdaattach -f /dev/tty01
	even without the entire pipeline.)

	See above.
	The obvious thing to do is to put a fflush(stdout) call
	after the printf, or -- better yet, given -p -- before the
	line that checks opt_detach and calls daemon().  (You want
	the fflush() before the sigsuspend.)

	A better thing might be to put the fflush() calls into
	daemon(), but daemon() doesn't know if stdio is in use
	on those fds.  Still, I suspect it wouldn't hurt, given that
	exit() would already be doing that for stdout and stderr.

	While you're at it -- 'irdaattach -p' should take a filename
	argument, to make it easier to use it together with -f, and to
	simplify the creation some day of an rc.d file for it.