Re: Is snp(4) in working order?

From: Gary Jennejohn <gljennjohn_at_gmail.com>
Date: Thu, 19 Aug 2021 18:33:44 UTC
On Thu, 19 Aug 2021 20:14:49 +0300
Konstantin Belousov <kostikbel@gmail.com> wrote:

> On Thu, Aug 19, 2021 at 04:12:24PM +0200, Bertrand Petit wrote:
> > 
> > 	I'm wondering if, on a 12.2 host, the snp(4) device is out of order or
> > if I'm improperly using it.
> > 
> > 	Here is the situation: a GPS receiver connected to the host through
> > USB (umodem driver) feeding ntpd and keeping it happy. On this setup I perform
> > the following calls as root in a dedicated process:
> > 
> >   int a=open("/dev/cuaU0", O_RDONLY|O_NONBLOCK);
> >   isatty(a); /* Yes it is */
> >   int b=open("/dev/snp", O_RDONLY);
> >   ioctl(b, SNPSTTY, &a);
> >   int pending; ioctl(b, FIONREAD, &pending); /* Empty */
> >   char buf; read(b, 1, &buf);
> > 
> > I ommited error handling for brevity, all calls are successfull except read()
> > which never return.
> > 
> > 	I expected to be able to read the same bytes stream as ntpd does but I
> > get nothing. Am I misusing the snp(4) interface or is it non-functioning?
> > 
> > 	[As a side note: I could also had used gpsd but hooking ntpd directly
> > to the serial device yields a far better jitter.]  
> Did you tried watch(8) first?
> 
> I just used watch successfully over /dev/pts/N pseudoterminal.
> 

I thought about using watch(8) too.

If nothing else, reading the source of /usr/src/usr.sbin/watch/watch.c
will give you a good idea about how to correctly use snp(4) in your
C-code.  Pay particuar attention to how FIONREAD is used in main().

-- 
Gary Jennejohn