/* * acts_close - close and prepare for next call. * * In ClOSE state no further protocol actions are required * other than to close and release the device and prepare to * dial the next number if necessary. */ void acts_close( struct peer *peer ) { struct actsunit *up; struct refclockproc *pp; char lockfile[128]; int dtr; pp = peer->procptr; up = pp->unitptr; if (pp->io.fd != -1) { report_event(PEVNT_CLOCK, peer, "close"); dtr = TIOCM_DTR; if (ioctl(pp->io.fd, TIOCMBIC, &dtr) < 0) msyslog(LOG_ERR, "acts: ioctl(TIOCMBIC) failed: %m"); io_closeclock(&pp->io); pp->io.fd = -1; } if (pp->sloppyclockflag & CLK_FLAG2) { snprintf(lockfile, sizeof(lockfile), LOCKFILE, up->unit); unlink(lockfile); } if (up->msgcnt == 0 && up->retry > 0) { if (sys_phone[up->retry] != NULL) { up->state = S_IDLE; up->timer = REDIAL; return; } } up->state = S_IDLE; up->timer = 0; }
static void neoclock4x_shutdown(int unit, struct peer *peer) { struct neoclock4x_unit *up; struct refclockproc *pp; int sl232; if(NULL != peer) { pp = peer->procptr; if(pp != NULL) { up = pp->unitptr; if(up != NULL) { if(-1 != pp->io.fd) { #if defined(TIOCMSET) && (defined(TIOCM_RTS) || defined(CIOCM_RTS)) /* turn on RTS, and DTR for power supply */ /* NeoClock4x is powered from serial line */ if(ioctl(pp->io.fd, TIOCMGET, (caddr_t)&sl232) == -1) { msyslog(LOG_CRIT, "NeoClock4X(%d): can't query RTS/DTR state: %m", unit); } #ifdef TIOCM_RTS /* turn on RTS, and DTR for power supply */ sl232 &= ~(TIOCM_DTR | TIOCM_RTS); #else /* turn on RTS, and DTR for power supply */ sl232 &= ~(CIOCM_DTR | CIOCM_RTS); #endif if(ioctl(pp->io.fd, TIOCMSET, (caddr_t)&sl232) == -1) { msyslog(LOG_CRIT, "NeoClock4X(%d): can't set RTS/DTR to power neoclock4x: %m", unit); } #endif io_closeclock(&pp->io); } free(up); pp->unitptr = NULL; } } } msyslog(LOG_ERR, "NeoClock4X(%d): shutdown", unit); NLOG(NLOG_CLOCKINFO) msyslog(LOG_INFO, "NeoClock4X(%d): receiver shutdown done", unit); }
/* * fg_shutdown - shut down the clock */ static void fg_shutdown( int unit, struct peer *peer ) { struct refclockproc *pp; struct fgunit *up; pp = peer->procptr; up = (struct fgunit *)pp->unitptr; io_closeclock(&pp->io); free(up); }
/* * ulink_shutdown - shut down the clock */ static void ulink_shutdown( int unit, struct peer *peer ) { register struct ulinkunit *up; struct refclockproc *pp; pp = peer->procptr; up = (struct ulinkunit *)pp->unitptr; io_closeclock(&pp->io); free(up); }
/* * tpro_shutdown - shut down the clock */ static void tpro_shutdown( int unit, struct peer *peer ) { register struct tprounit *up; struct refclockproc *pp; pp = peer->procptr; up = pp->unitptr; io_closeclock(&pp->io); if (NULL != up) free(up); }
/* * dumbclock_shutdown - shut down the clock */ static void dumbclock_shutdown( int unit, struct peer *peer ) { register struct dumbclock_unit *up; struct refclockproc *pp; pp = peer->procptr; up = pp->unitptr; if (-1 != pp->io.fd) io_closeclock(&pp->io); if (NULL != up) free(up); }
/* * fg_shutdown - shut down the clock */ static void fg_shutdown( int unit, struct peer *peer ) { struct refclockproc *pp; struct fgunit *up; pp = peer->procptr; up = pp->unitptr; if (pp->io.fd != -1) io_closeclock(&pp->io); if (up != NULL) free(up); }
/* * wwvb_shutdown - shut down the clock */ static void wwvb_shutdown( int unit, struct peer *peer ) { struct refclockproc * pp; struct wwvbunit * up; pp = peer->procptr; up = pp->unitptr; if (-1 != pp->io.fd) io_closeclock(&pp->io); if (NULL != up) free(up); }
/* * arc_shutdown - shut down the clock */ static void arc_shutdown( int unit, struct peer *peer ) { register struct arcunit *up; struct refclockproc *pp; peer->action = dummy_event_handler; pp = peer->procptr; up = (struct arcunit *)pp->unitptr; if (-1 != pp->io.fd) io_closeclock(&pp->io); if (NULL != up) free(up); }
/* * leitch_shutdown - shut down a LEITCH clock */ static void leitch_shutdown( int unit, struct peer *peer ) { struct leitchunit *leitch; if (unit >= MAXUNITS) { return; } leitch = &leitchunits[unit]; if (-1 != leitch->leitchio.fd) io_closeclock(&leitch->leitchio); #ifdef DEBUG if (debug) fprintf(stderr, "leitch_shutdown()\n"); #endif }
/* * chu_shutdown - shut down the clock */ static void chu_shutdown( int unit, /* instance number (not used) */ struct peer *peer /* peer structure pointer */ ) { struct chuunit *up; struct refclockproc *pp; pp = peer->procptr; up = pp->unitptr; if (up == NULL) return; io_closeclock(&pp->io); #ifdef ICOM if (up->fd_icom > 0) close(up->fd_icom); #endif /* ICOM */ free(up); }
static void gpsd_shutdown( int unit, peerT * peer) { clockprocT * const pp = peer->procptr; gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; UNUSED_ARG(unit); if (up) { free(up->device); free(up); } pp->unitptr = (caddr_t)NULL; if (-1 != pp->io.fd) io_closeclock(&pp->io); pp->io.fd = -1; LOGIF(CLOCKINFO, (LOG_NOTICE, "%s: shutdown", refnumtoa(&peer->srcadr))); }
static void gpsd_stop_socket( peerT * const peer) { clockprocT * const pp = peer->procptr; gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; if (-1 != pp->io.fd) io_closeclock(&pp->io); pp->io.fd = -1; if (syslogok(pp, up)) msyslog(LOG_INFO, "%s: closing socket to GPSD", refnumtoa(&peer->srcadr)); up->tickover = up->tickpres; up->tickpres = min(up->tickpres + 5, TICKOVER_HIGH); up->fl_vers = 0; up->fl_tpv = 0; up->fl_pps = 0; up->fl_watch = 0; }
/* * vme_shutdown - shut down a VME clock */ static void vme_shutdown( int unit ) { register struct vmeunit *vme; if (unit >= MAXUNITS) { msyslog(LOG_ERR, "vme_shutdown: unit %d invalid", unit); return; } if (!unitinuse[unit]) { msyslog(LOG_ERR, "vme_shutdown: unit %d not in use", unit); return; } /* * Tell the I/O module to turn us off. We're history. */ unmap_vme(); vme = vmeunits[unit]; io_closeclock(&vme->io); unitinuse[unit] = 0; }
/* * acts_timeout - called on timeout */ static void acts_timeout( struct peer *peer ) { struct actsunit *up; struct refclockproc *pp; int fd; char device[20]; char lockfile[128], pidbuf[8]; char tbuf[SMAX]; /* * The state machine is driven by messages from the modem, when * first stated and at timeout. */ pp = peer->procptr; up = (struct actsunit *)pp->unitptr; pp->sloppyclockflag &= ~CLK_FLAG1; if (sys_phone[up->retry] == NULL && !(pp->sloppyclockflag & CLK_FLAG3)) { msyslog(LOG_ERR, "acts: no phones"); return; } switch(up->state) { /* * System poll event. Lock the modem port and open the device. */ case S_IDLE: /* * Lock the modem port. If busy, retry later. Note: if * something fails between here and the close, the lock * file may not be removed. */ if (pp->sloppyclockflag & CLK_FLAG2) { snprintf(lockfile, sizeof(lockfile), LOCKFILE, up->unit); fd = open(lockfile, O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd < 0) { msyslog(LOG_ERR, "acts: port busy"); return; } snprintf(pidbuf, sizeof(pidbuf), "%d\n", (u_int)getpid()); write(fd, pidbuf, strlen(pidbuf)); close(fd); } /* * Open the device in raw mode and link the I/O. */ if (!pp->io.fd) { snprintf(device, sizeof(device), DEVICE, up->unit); fd = refclock_open(device, SPEED232, LDISC_ACTS | LDISC_RAW | LDISC_REMOTE); if (fd == 0) { msyslog(LOG_ERR, "acts: open fails"); return; } pp->io.fd = fd; if (!io_addclock(&pp->io)) { msyslog(LOG_ERR, "acts: addclock fails"); close(fd); pp->io.fd = 0; return; } } /* * If the port is directly connected to the device, skip * the modem business and send 'T' for Spectrabum. */ if (pp->sloppyclockflag & CLK_FLAG3) { if (write(pp->io.fd, "T", 1) < 0) { msyslog(LOG_ERR, "acts: write %m"); return; } up->state = S_FIRST; up->timer = CONNECT; return; } /* * Initialize the modem. This works with Hayes commands. */ #ifdef DEBUG if (debug) printf("acts: setup %s\n", MODEM_SETUP); #endif if (write(pp->io.fd, MODEM_SETUP, strlen(MODEM_SETUP)) < 0) { msyslog(LOG_ERR, "acts: write %m"); return; } up->state = S_OK; up->timer = SETUP; return; /* * In OK state the modem did not respond to setup. */ case S_OK: msyslog(LOG_ERR, "acts: no modem"); break; /* * In DTR state we are waiting for the modem to settle down * before hammering it with a dial command. */ case S_DTR: snprintf(tbuf, sizeof(tbuf), "DIAL #%d %s", up->retry, sys_phone[up->retry]); report_event(PEVNT_CLOCK, peer, tbuf); #ifdef DEBUG if (debug) printf("%s\n", tbuf); #endif write(pp->io.fd, sys_phone[up->retry], strlen(sys_phone[up->retry])); write(pp->io.fd, "\r", 1); up->state = S_CONNECT; up->timer = ANSWER; return; /* * In CONNECT state the call did not complete. */ case S_CONNECT: msyslog(LOG_ERR, "acts: no answer"); break; /* * In FIRST state no messages were received. */ case S_FIRST: msyslog(LOG_ERR, "acts: no messages"); break; /* * In CLOSE state hangup is complete. Close the doors and * windows and get some air. */ case S_CLOSE: /* * Close the device and unlock a shared modem. */ if (pp->io.fd) { io_closeclock(&pp->io); close(pp->io.fd); if (pp->sloppyclockflag & CLK_FLAG2) { snprintf(lockfile, sizeof(lockfile), LOCKFILE, up->unit); unlink(lockfile); } pp->io.fd = 0; } /* * If messages were received, fold the tent and wait for * the next poll. If no messages and there are more * numbers to dial, retry after a short wait. */ up->bufptr = pp->a_lastcode; up->timer = 0; up->state = S_IDLE; if ( up->msgcnt == 0) { up->retry++; if (sys_phone[up->retry] == NULL) up->retry = 0; else up->timer = SETUP; } else { up->retry = 0; } up->msgcnt = 0; return; } acts_disc(peer); }