1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:systat.c 2.7 */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #include "uucp.h" 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #define STATNAME(f, n) ((void)sprintf(f, "%s/%s", STATDIR, n)) 31*7c478bd9Sstevel@tonic-gate #define S_SIZE 100 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /* 34*7c478bd9Sstevel@tonic-gate * make system status entry 35*7c478bd9Sstevel@tonic-gate * name -> system name 36*7c478bd9Sstevel@tonic-gate * text -> text string to read 37*7c478bd9Sstevel@tonic-gate * type -> ? 38*7c478bd9Sstevel@tonic-gate * return: 39*7c478bd9Sstevel@tonic-gate * none 40*7c478bd9Sstevel@tonic-gate */ 41*7c478bd9Sstevel@tonic-gate void 42*7c478bd9Sstevel@tonic-gate systat(name, type, text, retry) 43*7c478bd9Sstevel@tonic-gate register int type; 44*7c478bd9Sstevel@tonic-gate char *name, *text; 45*7c478bd9Sstevel@tonic-gate long retry; 46*7c478bd9Sstevel@tonic-gate { 47*7c478bd9Sstevel@tonic-gate register FILE *fp; 48*7c478bd9Sstevel@tonic-gate int count; 49*7c478bd9Sstevel@tonic-gate char filename[MAXFULLNAME], line[S_SIZE]; 50*7c478bd9Sstevel@tonic-gate time_t prestime; 51*7c478bd9Sstevel@tonic-gate long presretry = 0; 52*7c478bd9Sstevel@tonic-gate char *vec[5]; 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate line[0] = '\0'; 55*7c478bd9Sstevel@tonic-gate (void) time(&prestime); 56*7c478bd9Sstevel@tonic-gate count = 0; 57*7c478bd9Sstevel@tonic-gate STATNAME(filename, name); 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate fp = fopen(filename, "r"); 60*7c478bd9Sstevel@tonic-gate if (fp != NULL) { 61*7c478bd9Sstevel@tonic-gate if (fgets(line, S_SIZE, fp) != NULL) 62*7c478bd9Sstevel@tonic-gate if (getargs(line, vec, 4) == 4) { 63*7c478bd9Sstevel@tonic-gate count = atoi(vec[1]); 64*7c478bd9Sstevel@tonic-gate presretry = atol(vec[3]); 65*7c478bd9Sstevel@tonic-gate } 66*7c478bd9Sstevel@tonic-gate if (count <= 0) 67*7c478bd9Sstevel@tonic-gate count = 0; 68*7c478bd9Sstevel@tonic-gate fclose(fp); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate switch (type) { 72*7c478bd9Sstevel@tonic-gate /* if there is already a status file - don't change */ 73*7c478bd9Sstevel@tonic-gate case SS_TIME_WRONG: 74*7c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE: 75*7c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE: 76*7c478bd9Sstevel@tonic-gate if (count > 1) 77*7c478bd9Sstevel@tonic-gate return; 78*7c478bd9Sstevel@tonic-gate break; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate /* reset count on successful call */ 81*7c478bd9Sstevel@tonic-gate case SS_OK: 82*7c478bd9Sstevel@tonic-gate case SS_INPROGRESS: 83*7c478bd9Sstevel@tonic-gate case SS_CONVERSATION: /* failure during conversation - contact ok */ 84*7c478bd9Sstevel@tonic-gate retry = 0; 85*7c478bd9Sstevel@tonic-gate count = 0; 86*7c478bd9Sstevel@tonic-gate break; 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /* Startup failure means protocol mismatch--some administrative 89*7c478bd9Sstevel@tonic-gate * action must be taken 90*7c478bd9Sstevel@tonic-gate */ 91*7c478bd9Sstevel@tonic-gate case SS_STARTUP: 92*7c478bd9Sstevel@tonic-gate retry = MAXRETRYTIME; 93*7c478bd9Sstevel@tonic-gate count = 0; 94*7c478bd9Sstevel@tonic-gate break; 95*7c478bd9Sstevel@tonic-gate default: /* increment count and set up retry time */ 96*7c478bd9Sstevel@tonic-gate count++; 97*7c478bd9Sstevel@tonic-gate if (!retry) { /* use exponential backoff */ 98*7c478bd9Sstevel@tonic-gate if (presretry < RETRYTIME) 99*7c478bd9Sstevel@tonic-gate retry = RETRYTIME; 100*7c478bd9Sstevel@tonic-gate else { 101*7c478bd9Sstevel@tonic-gate retry = presretry + presretry; 102*7c478bd9Sstevel@tonic-gate if (retry > MAXRETRYTIME) 103*7c478bd9Sstevel@tonic-gate retry = MAXRETRYTIME; 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate else { /* use specified time */ 107*7c478bd9Sstevel@tonic-gate if (retry < RETRYTIME) 108*7c478bd9Sstevel@tonic-gate retry = RETRYTIME; 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate break; 111*7c478bd9Sstevel@tonic-gate } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate fp = fopen(filename, "w"); 114*7c478bd9Sstevel@tonic-gate /* can't ASSERT since assert() calls systat() */ 115*7c478bd9Sstevel@tonic-gate if (fp == NULL) { 116*7c478bd9Sstevel@tonic-gate errent(Ct_OPEN, filename, errno, __FILE__, __LINE__); 117*7c478bd9Sstevel@tonic-gate cleanup(FAIL); 118*7c478bd9Sstevel@tonic-gate } 119*7c478bd9Sstevel@tonic-gate (void) chmod(filename, PUB_FILEMODE); 120*7c478bd9Sstevel@tonic-gate (void) fprintf(fp, "%d %d %ld %ld %s %s\n", 121*7c478bd9Sstevel@tonic-gate type, count, prestime, retry, text, name); 122*7c478bd9Sstevel@tonic-gate (void) fclose(fp); 123*7c478bd9Sstevel@tonic-gate return; 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* 127*7c478bd9Sstevel@tonic-gate * check system status for call 128*7c478bd9Sstevel@tonic-gate * name -> system to check 129*7c478bd9Sstevel@tonic-gate * return: 130*7c478bd9Sstevel@tonic-gate * 0 -> ok 131*7c478bd9Sstevel@tonic-gate * >0 -> system status 132*7c478bd9Sstevel@tonic-gate */ 133*7c478bd9Sstevel@tonic-gate int 134*7c478bd9Sstevel@tonic-gate callok(name) 135*7c478bd9Sstevel@tonic-gate char *name; 136*7c478bd9Sstevel@tonic-gate { 137*7c478bd9Sstevel@tonic-gate register FILE *fp; 138*7c478bd9Sstevel@tonic-gate register int t; 139*7c478bd9Sstevel@tonic-gate long retrytime; 140*7c478bd9Sstevel@tonic-gate int count, type; 141*7c478bd9Sstevel@tonic-gate char filename[MAXFULLNAME], line[S_SIZE]; 142*7c478bd9Sstevel@tonic-gate time_t lasttime, prestime; 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate STATNAME(filename, name); 145*7c478bd9Sstevel@tonic-gate fp = fopen(filename, "r"); 146*7c478bd9Sstevel@tonic-gate if (fp == NULL) 147*7c478bd9Sstevel@tonic-gate return(SS_OK); 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate if (fgets(line, S_SIZE, fp) == NULL) { 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate /* no data */ 152*7c478bd9Sstevel@tonic-gate fclose(fp); 153*7c478bd9Sstevel@tonic-gate (void) unlink(filename); 154*7c478bd9Sstevel@tonic-gate return(SS_OK); 155*7c478bd9Sstevel@tonic-gate } 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate fclose(fp); 158*7c478bd9Sstevel@tonic-gate (void) time(&prestime); 159*7c478bd9Sstevel@tonic-gate sscanf(line, "%d%d%ld%ld", &type, &count, &lasttime, &retrytime); 160*7c478bd9Sstevel@tonic-gate t = type; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate switch(t) { 163*7c478bd9Sstevel@tonic-gate case SS_SEQBAD: 164*7c478bd9Sstevel@tonic-gate case SS_LOGIN_FAILED: 165*7c478bd9Sstevel@tonic-gate case SS_DIAL_FAILED: 166*7c478bd9Sstevel@tonic-gate case SS_BAD_LOG_MCH: 167*7c478bd9Sstevel@tonic-gate case SS_BADSYSTEM: 168*7c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE: 169*7c478bd9Sstevel@tonic-gate case SS_WRONG_MCH: 170*7c478bd9Sstevel@tonic-gate case SS_RLOCKED: 171*7c478bd9Sstevel@tonic-gate case SS_RUNKNOWN: 172*7c478bd9Sstevel@tonic-gate case SS_RLOGIN: 173*7c478bd9Sstevel@tonic-gate case SS_UNKNOWN_RESPONSE: 174*7c478bd9Sstevel@tonic-gate case SS_CHAT_FAILED: 175*7c478bd9Sstevel@tonic-gate case SS_CALLBACK_LOOP: 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate if (prestime - lasttime < retrytime) { 178*7c478bd9Sstevel@tonic-gate logent("RETRY TIME NOT REACHED", "NO CALL"); 179*7c478bd9Sstevel@tonic-gate CDEBUG(4, "RETRY TIME (%ld) NOT REACHED\n", retrytime); 180*7c478bd9Sstevel@tonic-gate return(type); 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate return(SS_OK); 184*7c478bd9Sstevel@tonic-gate default: 185*7c478bd9Sstevel@tonic-gate return(SS_OK); 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate } 188