|
|
1.1 ! root 1: /* status.c ! 2: Routines to get and set the status for a system. ! 3: ! 4: Copyright (C) 1991, 1992 Ian Lance Taylor ! 5: ! 6: This file is part of the Taylor UUCP package. ! 7: ! 8: This program is free software; you can redistribute it and/or ! 9: modify it under the terms of the GNU General Public License as ! 10: published by the Free Software Foundation; either version 2 of the ! 11: License, or (at your option) any later version. ! 12: ! 13: This program is distributed in the hope that it will be useful, but ! 14: WITHOUT ANY WARRANTY; without even the implied warranty of ! 15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! 16: General Public License for more details. ! 17: ! 18: You should have received a copy of the GNU General Public License ! 19: along with this program; if not, write to the Free Software ! 20: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! 21: ! 22: The author of the program may be contacted at [email protected] or ! 23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254. ! 24: */ ! 25: ! 26: #include "uucp.h" ! 27: ! 28: #include "uudefs.h" ! 29: #include "uuconf.h" ! 30: #include "sysdep.h" ! 31: #include "system.h" ! 32: ! 33: #include <errno.h> ! 34: ! 35: #if SPOOLDIR_HDB || SPOOLDIR_SVR4 ! 36: ! 37: /* If we are using HDB spool layout, store status using HDB status ! 38: values. SVR4 is a variant of HDB. */ ! 39: ! 40: #define MAP_STATUS 1 ! 41: ! 42: static const int aiMapstatus[] = ! 43: { ! 44: 0, 13, 7, 6, 4, 20, 3, 2 ! 45: }; ! 46: #define CMAPENTRIES (sizeof (aiMapstatus) / sizeof (aiMapstatus[0])) ! 47: ! 48: #else /* ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 */ ! 49: ! 50: #define MAP_STATUS 0 ! 51: ! 52: #endif /* ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 */ ! 53: ! 54: /* Get the status of a system. This assumes that we are in the spool ! 55: directory. */ ! 56: ! 57: boolean ! 58: fsysdep_get_status (qsys, qret, pfnone) ! 59: const struct uuconf_system *qsys; ! 60: struct sstatus *qret; ! 61: boolean *pfnone; ! 62: { ! 63: char *zname; ! 64: FILE *e; ! 65: char *zline; ! 66: char *zend, *znext; ! 67: boolean fbad; ! 68: int istat; ! 69: ! 70: if (pfnone != NULL) ! 71: *pfnone = FALSE; ! 72: ! 73: zname = zsysdep_in_dir (".Status", qsys->uuconf_zname); ! 74: e = fopen (zname, "r"); ! 75: if (e == NULL) ! 76: { ! 77: if (errno != ENOENT) ! 78: { ! 79: ulog (LOG_ERROR, "fopen (%s): %s", zname, strerror (errno)); ! 80: ubuffree (zname); ! 81: return FALSE; ! 82: } ! 83: zline = NULL; ! 84: } ! 85: else ! 86: { ! 87: size_t cline; ! 88: ! 89: zline = NULL; ! 90: cline = 0; ! 91: if (getline (&zline, &cline, e) <= 0) ! 92: { ! 93: xfree ((pointer) zline); ! 94: zline = NULL; ! 95: } ! 96: (void) fclose (e); ! 97: } ! 98: ! 99: if (zline == NULL) ! 100: { ! 101: /* There is either no status file for this system, or it's been ! 102: truncated, so fake a good status. */ ! 103: qret->ttype = STATUS_COMPLETE; ! 104: qret->cretries = 0; ! 105: qret->ilast = 0; ! 106: qret->cwait = 0; ! 107: if (pfnone != NULL) ! 108: *pfnone = TRUE; ! 109: ubuffree (zname); ! 110: return TRUE; ! 111: } ! 112: ! 113: /* It turns out that scanf is not used much in this program, so for ! 114: the benefit of small computers we avoid linking it in. This is ! 115: basically ! 116: ! 117: sscanf (zline, "%d %d %ld %d", &qret->ttype, &qret->cretries, ! 118: &qret->ilast, &qret->cwait); ! 119: ! 120: except that it's done with strtol. */ ! 121: ! 122: fbad = FALSE; ! 123: istat = (int) strtol (zline, &zend, 10); ! 124: if (zend == zline) ! 125: fbad = TRUE; ! 126: ! 127: #if MAP_STATUS ! 128: /* On some systems it may be appropriate to map system dependent status ! 129: values on to our status values. */ ! 130: { ! 131: int i; ! 132: ! 133: for (i = 0; i < CMAPENTRIES; ++i) ! 134: { ! 135: if (aiMapstatus[i] == istat) ! 136: { ! 137: istat = i; ! 138: break; ! 139: } ! 140: } ! 141: } ! 142: #endif /* MAP_STATUS */ ! 143: ! 144: if (istat < 0 || istat >= (int) STATUS_VALUES) ! 145: istat = (int) STATUS_COMPLETE; ! 146: qret->ttype = (enum tstatus_type) istat; ! 147: znext = zend; ! 148: qret->cretries = (int) strtol (znext, &zend, 10); ! 149: if (zend == znext) ! 150: fbad = TRUE; ! 151: znext = zend; ! 152: qret->ilast = strtol (znext, &zend, 10); ! 153: if (zend == znext) ! 154: fbad = TRUE; ! 155: znext = zend; ! 156: qret->cwait = (int) strtol (znext, &zend, 10); ! 157: if (zend == znext) ! 158: fbad = TRUE; ! 159: ! 160: xfree ((pointer) zline); ! 161: ! 162: if (fbad) ! 163: { ! 164: ulog (LOG_ERROR, "%s: Bad status file format", zname); ! 165: ubuffree (zname); ! 166: return FALSE; ! 167: } ! 168: ! 169: ubuffree (zname); ! 170: ! 171: return TRUE; ! 172: } ! 173: ! 174: /* Set the status of a remote system. This assumes the system is ! 175: locked when this is called, and that the program is in the spool ! 176: directory. */ ! 177: ! 178: boolean ! 179: fsysdep_set_status (qsys, qset) ! 180: const struct uuconf_system *qsys; ! 181: const struct sstatus *qset; ! 182: { ! 183: char *zname; ! 184: FILE *e; ! 185: int istat; ! 186: ! 187: zname = zsysdep_in_dir (".Status", qsys->uuconf_zname); ! 188: ! 189: e = esysdep_fopen (zname, TRUE, FALSE, TRUE); ! 190: ubuffree (zname); ! 191: if (e == NULL) ! 192: return FALSE; ! 193: istat = (int) qset->ttype; ! 194: ! 195: #if MAP_STATUS ! 196: /* On some systems it may be appropriate to map istat onto a system ! 197: dependent number. */ ! 198: if (istat >= 0 && istat < CMAPENTRIES) ! 199: istat = aiMapstatus[istat]; ! 200: #endif /* MAP_STATUS */ ! 201: ! 202: fprintf (e, "%d %d %ld %d %s %s\n", istat, qset->cretries, ! 203: qset->ilast, qset->cwait, azStatus[(int) qset->ttype], ! 204: qsys->uuconf_zname); ! 205: if (fclose (e) != 0) ! 206: { ! 207: ulog (LOG_ERROR, "fclose: %s", strerror (errno)); ! 208: return FALSE; ! 209: } ! 210: ! 211: return TRUE; ! 212: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.