Home | History | Annotate | Download | only in ntpd

Lines Matching refs:up

270 	gpsd_start,		/* start up driver */
374 static int syslogok(clockprocT * const pp, gpsd_unitT * const up);
420 gpsd_unitT * const up)
423 || (0 == up->logthrottle )
424 || (LOGTHROTTLE == up->logthrottle );
426 up->logthrottle = LOGTHROTTLE;
483 "GPSD_JSON: failed to get socket address, giving up.");
498 * Start: allocate a unit pointer and set up the runtime data
506 gpsd_unitT * up;
518 while ((up = *uscan) != NULL && up->unit != (unit & 0x7F))
519 uscan = &up->next_unit;
520 if (up == NULL) {
522 up = emalloc_zero(sizeof(*up));
523 *uscan = up;
524 ++up->refcount;
527 up->logname = estrdup(refnumtoa(&peer->srcadr));
528 up->unit = unit & 0x7F;
529 up->fdt = -1;
530 up->addr = s_gpsd_addr;
531 up->tickpres = TICKOVER_LOW;
541 up->device = estrdup(tmpName);
542 } else if (-1 == myasprintf(&up->device, "%s%u", s_dev_stem, up->unit)) {
544 up->logname);
547 devname = up->device;
548 up->device = ntp_realpath(devname);
549 if (NULL == up->device) {
551 up->logname, devname);
556 if (-1 == lstat(up->device, &sb)) {
558 up->logname, up->device);
563 up->logname, up->device);
567 /* All set up, just increment use count. */
568 ++up->refcount;
572 pp->unitptr = (caddr_t)up;
588 /* If the daemon name lookup failed, just give up now. */
589 if (NULL == up->addr) {
590 msyslog(LOG_ERR, "%s: no GPSD socket address, giving up",
591 up->logname);
597 refnumtoa(&peer->srcadr), up->device));
598 up->mode = MODE_OP_MODE(peer->ttl);
599 if (up->mode > MODE_OP_MAXVAL)
600 up->mode = 0;
602 up->pps_peer = peer;
604 enter_opmode(peer, up->mode);
610 INSIST (up);
611 if (!--up->refcount) {
612 *uscan = up->next_unit;
613 free(up->device);
614 free(up);
629 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
635 if (up == NULL)
639 if (peer != up->pps_peer) {
642 up->logname, pp->io.fd));
646 if (up->fdt != -1)
647 close(up->fdt);
650 if (!--up->refcount) {
653 if (*uscan == up)
654 *uscan = up->next_unit;
657 free(up->logname);
658 free(up->device);
659 free(up);
675 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
695 pdst = up->buffer + up->buflen;
696 edst = up->buffer + sizeof(up->buffer) - 1; /* for trailing NUL */
702 while (pdst != up->buffer && pdst[-1] <= ' ')
706 up->buflen = pdst - up->buffer;
708 pdst = up->buffer;
711 if (ch > ' ' || pdst != up->buffer)
715 up->buflen = pdst - up->buffer;
716 up->tickover = TICKOVER_LOW;
725 gpsd_unitT * const up )
741 else if (0 != up->tc_breply)
750 up->tc_recv,
751 up->tc_breply, up->tc_nosync,
752 up->tc_sti_recv, up->tc_sti_used,
753 up->tc_pps_recv, up->tc_pps_used);
756 up->tc_breply = 0;
757 up->tc_recv = 0;
758 up->tc_nosync = 0;
759 up->tc_sti_recv = 0;
760 up->tc_sti_used = 0;
761 up->tc_pps_recv = 0;
762 up->tc_pps_used = 0;
769 gpsd_unitT * const up )
789 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
792 if (peer == up->pps_peer)
793 poll_secondary(peer, pp, up);
795 poll_primary(peer, pp, up);
808 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
810 if (peer == up->pps_peer) {
811 DTOLFP(pp->fudgetime1, &up->pps_fudge2);
816 DTOLFP(pp->fudgetime1, &up->pps_fudge);
817 DTOLFP(pp->fudgetime2, &up->sti_fudge);
819 if (MODE_OP_MODE(up->mode ^ peer->ttl)) {
820 leave_opmode(peer, up->mode);
821 up->mode = MODE_OP_MODE(peer->ttl);
822 enter_opmode(peer, up->mode);
833 gpsd_unitT * const up )
845 if (up->logthrottle)
846 --up->logthrottle;
847 if (up->tickover)
848 --up->tickover;
849 switch (up->tickover) {
858 up->logname, s_req_version));
862 } else if (-1 != up->fdt) {
870 else if (-1 != up->fdt)
877 if (-1 == pp->io.fd && -1 != up->fdt)
886 gpsd_unitT * const up )
891 up->ppscount2 = max(0, (up->ppscount2 - 1));
892 if (0 == up->ppscount2) {
907 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
909 if (peer == up->pps_peer)
910 timer_secondary(peer, pp, up);
912 timer_primary(peer, pp, up);
925 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
928 up->logname, MODE_OP_MODE(mode)));
931 up->fl_rawsti = 0;
932 up->ppscount = PPS_MAXCOUNT / 2;
934 up->fl_pps = 0;
935 up->fl_sti = 0;
946 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
949 up->logname, MODE_OP_MODE(mode)));
952 up->fl_rawsti = 0;
953 up->ppscount = 0;
955 up->fl_pps = 0;
956 up->fl_sti = 0;
982 gpsd_unitT * const up )
984 if (up->fl_sti && up->fl_pps) {
986 add_clock_sample(peer, pp, up->sti_stamp, up->pps_recvt);
987 peer->precision = up->pps_prec;
989 up->fl_pps = 0;
990 up->fl_sti = 0;
991 ++up->tc_sti_used;
1005 gpsd_unitT * const up )
1007 if (up->fl_pps2) {
1009 add_clock_sample(peer, pp, up->pps_stamp2, up->pps_recvt2);
1010 peer->precision = up->pps_prec;
1012 up->ppscount2 = min(PPS2_MAXCOUNT, (up->ppscount2 + 2));
1013 if ((PPS2_MAXCOUNT == up->ppscount2) &&
1017 up->fl_pps2 = 0;
1018 ++up->tc_pps_used;
1028 gpsd_unitT * const up )
1030 if (up->fl_sti) {
1031 add_clock_sample(peer, pp, up->sti_stamp, up->sti_recvt);
1032 peer->precision = up->sti_prec;
1034 up->fl_sti = 0;
1035 ++up->tc_sti_used;
1044 gpsd_unitT * const up )
1047 if (!up->fl_sti)
1057 if (up->fl_pps) {
1058 up->ppscount = min(PPS_MAXCOUNT,
1059 (up->ppscount + PPS_INCCOUNT));
1060 if ((PPS_MAXCOUNT == up->ppscount) && up->fl_rawsti) {
1061 up->fl_rawsti = 0;
1064 up->logname);
1067 up->ppscount = max(0, (up->ppscount - PPS_DECCOUNT));
1068 if ((0 == up->ppscount) && !up->fl_rawsti) {
1069 up->fl_rawsti = -1;
1072 up->logname);
1077 if (up->fl_rawsti)
1078 eval_serial(peer, pp, up);
1080 eval_strict(peer, pp, up);
1243 /* look up a boolean value. This essentially returns a tribool:
1445 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1450 if (NULL == path || strcmp(path, up->device))
1455 up->fl_watch = -1;
1457 up->fl_watch = 0;
1459 up->logname, (up->fl_watch & 1)));
1471 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1489 if ( ! up->fl_vers)
1492 up->logname, revision, release,
1494 up->proto_version = PROTO_VERSION(pvhi, pvlo);
1495 up->fl_vers = -1;
1497 if (syslogok(pp, up))
1500 up->logname);
1506 up->pf_nsec = -(up->proto_version >= PROTO_VERSION(3,9));
1511 up->pf_toff = -(up->proto_version >= PROTO_VERSION(3,10));
1526 if (up->fl_watch)
1534 snprintf(up->buffer, sizeof(up->buffer),
1536 up->device, (up->pf_toff ? ",\"pps\":true" : ""));
1537 buf = up->buffer;
1540 if (len != write(pp->io.fd, buf, len) && (syslogok(pp, up))) {
1546 up->logname);
1559 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1575 if ( ! up->pf_toff)
1576 ++up->tc_sti_recv;
1577 ++up->tc_nosync;
1578 up->fl_sti = 0;
1579 up->fl_pps = 0;
1580 up->fl_nosync = -1;
1583 up->fl_nosync = 0;
1588 if ( ! up->pf_toff) {
1589 ++up->tc_sti_recv;
1593 if (convert_ascii_time(&up->sti_stamp, gps_time)) {
1596 up->logname,
1597 gmprettydate(&up->sti_stamp),
1598 gmprettydate(&up->sti_recvt),
1605 up->sti_local = *rtime;
1606 up->sti_recvt = *rtime;
1607 L_SUB(&up->sti_recvt, &up->sti_fudge);
1608 up->fl_sti = -1;
1610 ++up->tc_breply;
1611 up->fl_sti = 0;
1628 up->sti_prec = clamped_precision(xlog2);
1640 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1644 ++up->tc_pps_recv;
1649 if (up->fl_nosync)
1652 up->pps_local = *rtime;
1657 if (up->pf_nsec) {
1658 if ( ! get_binary_time(&up->pps_recvt2, jctx,
1661 if ( ! get_binary_time(&up->pps_stamp2, jctx,
1665 if ( ! get_binary_time(&up->pps_recvt2, jctx,
1668 if ( ! get_binary_time(&up->pps_stamp2, jctx,
1677 jctx, 0, "precision", up->sti_prec);
1678 up->pps_prec = clamped_precision(xlog2);
1681 up->pps_recvt = up->pps_recvt2;
1682 L_SUB(&up->pps_recvt , &up->pps_fudge );
1683 L_SUB(&up->pps_recvt2, &up->pps_fudge2);
1684 pp->lastrec = up->pps_recvt;
1689 up->pps_stamp = up->pps_recvt;
1690 L_ADDUF(&up->pps_stamp, 0x80000000u);
1691 up->pps_stamp.l_uf = 0;
1693 if (NULL != up->pps_peer)
1694 save_ltc(up->pps_peer->procptr,
1695 gmprettydate(&up->pps_stamp2));
1698 up->logname,
1699 gmprettydate(&up->pps_stamp2),
1700 gmprettydate(&up->pps_recvt2)));
1702 up->fl_pps = (0 != (pp->sloppyclockflag & CLK_FLAG2)) - 1;
1703 up->fl_pps2 = -1;
1708 up->logname));
1709 ++up->tc_breply;
1721 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1723 ++up->tc_sti_recv;
1726 up->pf_toff = -1;
1729 if (up->fl_nosync)
1732 if ( ! get_binary_time(&up->sti_recvt, jctx,
1735 if ( ! get_binary_time(&up->sti_stamp, jctx,
1738 L_SUB(&up->sti_recvt, &up->sti_fudge);
1739 up->sti_local = *rtime;
1740 up->fl_sti = -1;
1742 save_ltc(pp, gmprettydate(&up->sti_stamp));
1745 up->logname,
1746 gmprettydate(&up->sti_stamp),
1747 gmprettydate(&up->sti_recvt)));
1752 up->logname));
1753 ++up->tc_breply;
1764 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1769 up->logname, ulfptoa(rtime, 6),
1770 up->buflen, up->buffer));
1775 if (!json_parse_record(&up->json_parse, up->buffer, up->buflen)) {
1776 ++up->tc_breply;
1781 clsid = json_object_lookup_string(&up->json_parse, 0, "class");
1783 ++up->tc_breply;
1788 process_tpv(peer, &up->json_parse, rtime);
1790 process_pps(peer, &up->json_parse, rtime);
1792 process_toff(peer, &up->json_parse, rtime);
1794 process_version(peer, &up->json_parse, rtime);
1796 process_watch(peer, &up->json_parse, rtime);
1799 ++up->tc_recv;
1802 if (up->pps_peer)
1804 up->pps_peer, up->pps_peer->procptr, up);
1811 if (up->fl_pps && up->fl_sti) {
1813 diff = up->sti_local;
1814 L_SUB(&diff, &up->pps_local);
1816 up->fl_pps = 0; /* pps too old */
1818 up->fl_sti = 0; /* serial data too old */
1822 switch (up->mode) {
1825 eval_serial(peer, pp, up);
1829 eval_strict(peer, pp, up);
1833 eval_auto(peer, pp, up);
1845 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1848 if (syslogok(pp, up))
1851 up->logname, pp->io.fd);
1854 up->logname, pp->io.fd));
1858 up->tickover = up->tickpres;
1859 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH);
1860 up->fl_vers = 0;
1861 up->fl_sti = 0;
1862 up->fl_pps = 0;
1863 up->fl_watch = 0;
1873 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1879 if (NULL == up->addr)
1880 up->addr = s_gpsd_addr;
1881 ai = up->addr;
1882 up->addr = ai->ai_next;
1885 up->fdt = socket(
1887 if (-1 == up->fdt) {
1888 if (syslogok(pp, up))
1891 up->logname);
1899 rc = fcntl(up->fdt, F_SETFL, O_NONBLOCK, 1);
1901 if (syslogok(pp, up))
1904 up->logname);
1914 rc = setsockopt(up->fdt, IPPROTO_TCP, TCP_NODELAY,
1917 if (syslogok(pp, up))
1920 up->logname);
1926 rc = connect(up->fdt, ai->ai_addr, ai->ai_addrlen);
1930 up->logname, up->fdt));
1934 if (syslogok(pp, up))
1937 up->logname);
1947 up->logname, up->fdt));
1949 pp->io.fd = up->fdt;
1950 up->fdt = -1;
1952 if (syslogok(pp, up))
1955 up->logname);
1964 if (-1 != up->fdt)
1965 close(up->fdt);
1967 up->fdt = -1;
1968 up->tickover = up->tickpres;
1969 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH);
1979 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
1989 up->logname, up->fdt));
1996 pfd.fd = up->fdt;
2008 FD_SET(up->fdt, &wset);
2009 rc = select(up->fdt+1, NULL, &wset, NULL, &tout);
2010 if (0 == rc || !(FD_ISSET(up->fdt, &wset)))
2018 up->tickover = TICKOVER_LOW;
2023 rc = getsockopt(up->fdt, SOL_SOCKET, SO_ERROR, (void *)&ec, &lc);
2029 if (syslogok(pp, up))
2033 up->logname, up->fdt, ec, errtxt);
2037 up->logname, up->fdt, ec, errtxt));
2041 up->logname, up->fdt));
2045 pp->io.fd = up->fdt;
2046 up->fdt = -1;
2048 if (syslogok(pp, up))
2051 up->logname);
2057 if (-1 != up->fdt) {
2059 up->logname, up->fdt));
2060 close(up->fdt);
2062 up->fdt = -1;
2063 up->tickover = up->tickpres;
2064 up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH);
2205 gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr;
2226 mprintf("%s[%s]: '%s'\n", up->logname, what, s_lbuf);