17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
237c478bd9Sstevel@tonic-gate /* All Rights Reserved */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:systat.c 2.7 */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include "uucp.h"
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #define STATNAME(f, n) ((void)sprintf(f, "%s/%s", STATDIR, n))
317c478bd9Sstevel@tonic-gate #define S_SIZE 100
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate * make system status entry
357c478bd9Sstevel@tonic-gate * name -> system name
367c478bd9Sstevel@tonic-gate * text -> text string to read
377c478bd9Sstevel@tonic-gate * type -> ?
387c478bd9Sstevel@tonic-gate * return:
397c478bd9Sstevel@tonic-gate * none
407c478bd9Sstevel@tonic-gate */
417c478bd9Sstevel@tonic-gate void
systat(name,type,text,retry)427c478bd9Sstevel@tonic-gate systat(name, type, text, retry)
437c478bd9Sstevel@tonic-gate register int type;
447c478bd9Sstevel@tonic-gate char *name, *text;
457c478bd9Sstevel@tonic-gate long retry;
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate register FILE *fp;
487c478bd9Sstevel@tonic-gate int count;
497c478bd9Sstevel@tonic-gate char filename[MAXFULLNAME], line[S_SIZE];
507c478bd9Sstevel@tonic-gate time_t prestime;
517c478bd9Sstevel@tonic-gate long presretry = 0;
527c478bd9Sstevel@tonic-gate char *vec[5];
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate line[0] = '\0';
557c478bd9Sstevel@tonic-gate (void) time(&prestime);
567c478bd9Sstevel@tonic-gate count = 0;
577c478bd9Sstevel@tonic-gate STATNAME(filename, name);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate fp = fopen(filename, "r");
607c478bd9Sstevel@tonic-gate if (fp != NULL) {
617c478bd9Sstevel@tonic-gate if (fgets(line, S_SIZE, fp) != NULL)
627c478bd9Sstevel@tonic-gate if (getargs(line, vec, 4) == 4) {
637c478bd9Sstevel@tonic-gate count = atoi(vec[1]);
647c478bd9Sstevel@tonic-gate presretry = atol(vec[3]);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate if (count <= 0)
677c478bd9Sstevel@tonic-gate count = 0;
687c478bd9Sstevel@tonic-gate fclose(fp);
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate switch (type) {
727c478bd9Sstevel@tonic-gate /* if there is already a status file - don't change */
737c478bd9Sstevel@tonic-gate case SS_TIME_WRONG:
747c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE:
757c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE:
767c478bd9Sstevel@tonic-gate if (count > 1)
777c478bd9Sstevel@tonic-gate return;
787c478bd9Sstevel@tonic-gate break;
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /* reset count on successful call */
817c478bd9Sstevel@tonic-gate case SS_OK:
827c478bd9Sstevel@tonic-gate case SS_INPROGRESS:
837c478bd9Sstevel@tonic-gate case SS_CONVERSATION: /* failure during conversation - contact ok */
847c478bd9Sstevel@tonic-gate retry = 0;
857c478bd9Sstevel@tonic-gate count = 0;
867c478bd9Sstevel@tonic-gate break;
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate /* Startup failure means protocol mismatch--some administrative
897c478bd9Sstevel@tonic-gate * action must be taken
907c478bd9Sstevel@tonic-gate */
917c478bd9Sstevel@tonic-gate case SS_STARTUP:
927c478bd9Sstevel@tonic-gate retry = MAXRETRYTIME;
937c478bd9Sstevel@tonic-gate count = 0;
947c478bd9Sstevel@tonic-gate break;
957c478bd9Sstevel@tonic-gate default: /* increment count and set up retry time */
967c478bd9Sstevel@tonic-gate count++;
977c478bd9Sstevel@tonic-gate if (!retry) { /* use exponential backoff */
987c478bd9Sstevel@tonic-gate if (presretry < RETRYTIME)
997c478bd9Sstevel@tonic-gate retry = RETRYTIME;
1007c478bd9Sstevel@tonic-gate else {
1017c478bd9Sstevel@tonic-gate retry = presretry + presretry;
1027c478bd9Sstevel@tonic-gate if (retry > MAXRETRYTIME)
1037c478bd9Sstevel@tonic-gate retry = MAXRETRYTIME;
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate else { /* use specified time */
1077c478bd9Sstevel@tonic-gate if (retry < RETRYTIME)
1087c478bd9Sstevel@tonic-gate retry = RETRYTIME;
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate break;
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate fp = fopen(filename, "w");
1147c478bd9Sstevel@tonic-gate /* can't ASSERT since assert() calls systat() */
1157c478bd9Sstevel@tonic-gate if (fp == NULL) {
1167c478bd9Sstevel@tonic-gate errent(Ct_OPEN, filename, errno, __FILE__, __LINE__);
1177c478bd9Sstevel@tonic-gate cleanup(FAIL);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate (void) chmod(filename, PUB_FILEMODE);
1207c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%d %d %ld %ld %s %s\n",
1217c478bd9Sstevel@tonic-gate type, count, prestime, retry, text, name);
1227c478bd9Sstevel@tonic-gate (void) fclose(fp);
1237c478bd9Sstevel@tonic-gate return;
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate * check system status for call
128*55fea89dSDan Cross * name -> system to check
129*55fea89dSDan Cross * return:
1307c478bd9Sstevel@tonic-gate * 0 -> ok
1317c478bd9Sstevel@tonic-gate * >0 -> system status
1327c478bd9Sstevel@tonic-gate */
1337c478bd9Sstevel@tonic-gate int
callok(name)1347c478bd9Sstevel@tonic-gate callok(name)
1357c478bd9Sstevel@tonic-gate char *name;
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate register FILE *fp;
1387c478bd9Sstevel@tonic-gate register int t;
1397c478bd9Sstevel@tonic-gate long retrytime;
1407c478bd9Sstevel@tonic-gate int count, type;
1417c478bd9Sstevel@tonic-gate char filename[MAXFULLNAME], line[S_SIZE];
1427c478bd9Sstevel@tonic-gate time_t lasttime, prestime;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate STATNAME(filename, name);
1457c478bd9Sstevel@tonic-gate fp = fopen(filename, "r");
1467c478bd9Sstevel@tonic-gate if (fp == NULL)
1477c478bd9Sstevel@tonic-gate return(SS_OK);
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if (fgets(line, S_SIZE, fp) == NULL) {
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /* no data */
1527c478bd9Sstevel@tonic-gate fclose(fp);
1537c478bd9Sstevel@tonic-gate (void) unlink(filename);
1547c478bd9Sstevel@tonic-gate return(SS_OK);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate fclose(fp);
1587c478bd9Sstevel@tonic-gate (void) time(&prestime);
1597c478bd9Sstevel@tonic-gate sscanf(line, "%d%d%ld%ld", &type, &count, &lasttime, &retrytime);
1607c478bd9Sstevel@tonic-gate t = type;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate switch(t) {
1637c478bd9Sstevel@tonic-gate case SS_SEQBAD:
1647c478bd9Sstevel@tonic-gate case SS_LOGIN_FAILED:
1657c478bd9Sstevel@tonic-gate case SS_DIAL_FAILED:
1667c478bd9Sstevel@tonic-gate case SS_BAD_LOG_MCH:
1677c478bd9Sstevel@tonic-gate case SS_BADSYSTEM:
1687c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE:
1697c478bd9Sstevel@tonic-gate case SS_WRONG_MCH:
1707c478bd9Sstevel@tonic-gate case SS_RLOCKED:
1717c478bd9Sstevel@tonic-gate case SS_RUNKNOWN:
1727c478bd9Sstevel@tonic-gate case SS_RLOGIN:
1737c478bd9Sstevel@tonic-gate case SS_UNKNOWN_RESPONSE:
1747c478bd9Sstevel@tonic-gate case SS_CHAT_FAILED:
1757c478bd9Sstevel@tonic-gate case SS_CALLBACK_LOOP:
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate if (prestime - lasttime < retrytime) {
1787c478bd9Sstevel@tonic-gate logent("RETRY TIME NOT REACHED", "NO CALL");
1797c478bd9Sstevel@tonic-gate CDEBUG(4, "RETRY TIME (%ld) NOT REACHED\n", retrytime);
1807c478bd9Sstevel@tonic-gate return(type);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate return(SS_OK);
1847c478bd9Sstevel@tonic-gate default:
1857c478bd9Sstevel@tonic-gate return(SS_OK);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate }
188