148652Sbostic /*-
2*62386Sbostic * Copyright (c) 1985, 1993
3*62386Sbostic * The Regents of the University of California. All rights reserved.
448652Sbostic *
548652Sbostic * %sccs.include.proprietary.c%
648652Sbostic */
748652Sbostic
813672Ssam #ifndef lint
9*62386Sbostic static char sccsid[] = "@(#)systat.c 8.1 (Berkeley) 06/06/93";
1048652Sbostic #endif /* not lint */
1113672Ssam
1213672Ssam #include "uucp.h"
1313672Ssam
1423675Sbloom #define STATNAME(f, n) sprintf(f, "%s/%s/%s", Spool, "STST", n)
1513672Ssam #define S_SIZE 100
1613672Ssam
1723675Sbloom /*LINTLIBRARY*/
1823675Sbloom
1918622Sralph /*
2018622Sralph * make system status entry
2113672Ssam * return codes: none
2213672Ssam */
systat(name,type,text)2313672Ssam systat(name, type, text)
2413672Ssam char *name, *text;
2513672Ssam int type;
2613672Ssam {
2713672Ssam char filename[MAXFULLNAME], line[S_SIZE];
2817838Sralph int count, oldtype;
2913672Ssam register FILE *fp;
3017838Sralph time_t prestime, rtry;
3113672Ssam
3213672Ssam if (type == 0)
3313672Ssam return;
3413672Ssam line[0] = '\0';
3513672Ssam time(&prestime);
3613672Ssam count = 0;
3713672Ssam STATNAME(filename, name);
3813672Ssam
3913672Ssam fp = fopen(filename, "r");
4013672Ssam if (fp != NULL) {
4113672Ssam fgets(line, S_SIZE, fp);
4217838Sralph sscanf(line, "%d %d", &oldtype, &count);
4313672Ssam if (count <= 0)
4413672Ssam count = 0;
4513672Ssam fclose(fp);
4617838Sralph /* If merely 'wrong time', don't change existing STST */
4717838Sralph if (type == SS_WRONGTIME && oldtype != SS_INPROGRESS)
4817838Sralph return;
4913672Ssam }
5013672Ssam
5117838Sralph rtry = Retrytime;
5217838Sralph /* if failures repeat, don't try so often,
5317838Sralph * to forstall a 'MAX RECALLS' situation.
5417838Sralph */
5517838Sralph if (type == SS_FAIL) {
5613672Ssam count++;
5717838Sralph if (count > 5) {
5817838Sralph rtry = rtry * (count-5);
5917838Sralph if (rtry > ONEDAY/2)
6017838Sralph rtry = ONEDAY/2;
6117838Sralph }
6217838Sralph }
6313672Ssam
6417838Sralph
6517838Sralph #ifdef VMS
6617838Sralph unlink(filename);
6717838Sralph #endif VMS
6813672Ssam fp = fopen(filename, "w");
6933957Srick if (fp == NULL) {
7033957Srick syslog(LOG_ERR, "fopen(%s) failed: %m", filename);
7133957Srick cleanup(FAIL);
7233957Srick }
7317838Sralph fprintf(fp, "%d %d %ld %ld %s %s\n", type, count, prestime, rtry, text, name);
7413672Ssam fclose(fp);
7513672Ssam }
7613672Ssam
7733957Srick /*
7833957Srick * remove system status entry
7913672Ssam *
8013672Ssam * return codes: none
8113672Ssam */
rmstat(name)8213672Ssam rmstat(name)
8313672Ssam char *name;
8413672Ssam {
8513672Ssam char filename[MAXFULLNAME];
8613672Ssam
8713672Ssam STATNAME(filename, name);
8813672Ssam unlink(filename);
8913672Ssam }
9013672Ssam
9123675Sbloom /*
9223675Sbloom * check system status for call
9313672Ssam *
9413672Ssam * return codes 0 - ok | >0 system status
9513672Ssam */
callok(name)9613672Ssam callok(name)
9713672Ssam char *name;
9813672Ssam {
9913672Ssam char filename[MAXFULLNAME], line[S_SIZE];
10013672Ssam register FILE *fp;
10117838Sralph time_t lasttime, prestime, retrytime;
10217838Sralph long t1, t2;
10313672Ssam int count, type;
10413672Ssam
10513672Ssam STATNAME(filename, name);
10613672Ssam fp = fopen(filename, "r");
10713672Ssam if (fp == NULL)
10813672Ssam return(SS_OK);
10913672Ssam
11013672Ssam if (fgets(line, S_SIZE, fp) == NULL) {
11113672Ssam /* no data */
11213672Ssam fclose(fp);
11313672Ssam unlink(filename);
11413672Ssam return(SS_OK);
11513672Ssam }
11613672Ssam
11713672Ssam fclose(fp);
11813672Ssam time(&prestime);
11917838Sralph sscanf(line, "%d%d%ld%ld", &type, &count, &t1, &t2);
12017838Sralph lasttime = t1;
12117838Sralph retrytime = t2;
12213672Ssam
12313672Ssam switch(type) {
12413672Ssam case SS_BADSEQ:
12513672Ssam case SS_CALLBACK:
12613672Ssam case SS_NODEVICE:
12713672Ssam case SS_INPROGRESS: /*let LCK take care of it */
12813672Ssam return(SS_OK);
12913672Ssam
13013672Ssam case SS_FAIL:
13113672Ssam if (count > MAXRECALLS) {
13213672Ssam logent("MAX RECALLS", "NO CALL");
13313672Ssam DEBUG(4, "MAX RECALL COUNT %d\n", count);
13417838Sralph if (Debug) {
13517838Sralph logent("debugging", "continuing anyway");
13617838Sralph return SS_OK;
13717838Sralph }
13817838Sralph return type;
13913672Ssam }
14013672Ssam
14113672Ssam if (prestime - lasttime < retrytime) {
14213672Ssam logent("RETRY TIME NOT REACHED", "NO CALL");
14317838Sralph DEBUG(4, "RETRY TIME (%ld) NOT REACHED\n", retrytime);
14417838Sralph if (Debug) {
14517838Sralph logent("debugging", "continuing anyway");
14617838Sralph return SS_OK;
14717838Sralph }
14817838Sralph return type;
14913672Ssam }
15013672Ssam
15117838Sralph return SS_OK;
15213672Ssam default:
15317838Sralph return SS_OK;
15413672Ssam }
15513672Ssam }
156