home *** CD-ROM | disk | FTP | other *** search
Wrap
/* __ / // //__)_ / / (__/(__// (_)(_(_ the UUCP polling server (c)Copyright 1991,92 Ralf S. Engelschall, All Rights Reserved. (c)Copyright 1991,92 Cyvaned Systems, All Rights Reserved. Genesis : Fri Sep 20 23:26:29 1991 Last Change : Mon Aug 3 11:27:09 1992 Developed and debugged with SAS/C Compiler V5.10a running under AmigaOS 2.04 (37.175), Workbench 2.04 (37.67) on an european PAL-Amiga 2000 B Rev 4.4 with 3MB RAM and 16KB runtime stack. Ralf S. Engelschall rse@angle.sub.org */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dos.h> #include <proto/exec.h> #include <proto/dos.h> #include <dos/dos.h> #include <exec/types.h> #include <exec/nodes.h> #include <exec/tasks.h> #include <exec/ports.h> #include <devices/timer.h> #include <libraries/dos.h> #include <libraries/dosextens.h> #include <clib/exec_protos.h> #include <clib/dos_protos.h> #include <pragmas/exec_pragmas.h> #include <pragmas/dos_pragmas.h> #include "cus.h" #include "proto.h" #include "defines.h" #include "dbg.h" #include "rev.h" #include "stat.h" #define DEFAULT_RETRIES 0 #define DEFAULT_DELAY 0 #define DEFAULT_RESTRICTION 0 #define DEFAULT_PENDINGFILES 1 #define DEFAULT_PENDINGKBYTES 10 #define DEFAULT_ARGS "-7" #define DEFAULT_NOTIFYUSER "postmaster" #define JOBCTL_NOTSPECIFIED 0 #define JOBCTL_SWITCH 1 #define JOBCTL_ENABLE 2 #define JOBCTL_DISABLE 3 #define CHECK_NOTSPECIFIED 0 #define CHECK_TOABORT 1 #define CHECK_TOBREAK 2 #define CHECK_TOBREAK_DELAY 20 #define SPOOLDIR "uuspool:" #define LOG "uuspool:logfile" #define MODEMSETUP "uulib:modemsetup" #define LSYS "uulib:l.sys" #define CONFIG "uulib:config" #define FIELD "DefaultNode" #define DEFAULT_EXECCMND "uuxqt" #define UUCICO_DOSNAME "uucico" /* dependend return codes from uucico 115/115c/116/116a */ #define UUCICORC_SUCCESS 0 #define UUCICORC_FAILURE-IN-CALL-OR-PROTOCOL 5 #define UUCICORC_BREAK-OR-SOFTWARE-ERROR 10 #define TIMERMODE_RESTRICTION 1L #define TIMERMODE_SURVIVAL TIMERMODE_RESTRICTION << 1 #define TIMERMODE_DELAY TIMERMODE_SURVIVAL << 1 #define SURVIVALMODE_WHOLESESSION 1L #define SURVIVALMODE_ABORTION SURVIVALMODE_WHOLESESSION << 1 #define SURVIVALTIME_WHOLESESSION 60*60*3 /* 3 hours */ #define SURVIVALTIME_ABORTION 60 /* 60 seconds */ struct timermsg { struct timerequest tm_timereq; UBYTE tm_timermode; }; static char caSystem[RANGE_6BIT]; static char caCmnd[RANGE_7BIT]; static char caTmp[RANGE_7BIT]; static char *cpaArgv[RANGE_7BIT]; static char caEnvname[RANGE_6BIT]; static char caUucicoFile[RANGE_6BIT]; static int fork_rc; int main(int argc, char **argv) { unsigned int nRetriesMax = DEFAULT_RETRIES; unsigned int iRetries = 0; unsigned int nDelay = DEFAULT_DELAY; unsigned int nRestriction = DEFAULT_RESTRICTION; signed int nRestrictionTmp; unsigned int wJobcontrol = JOBCTL_NOTSPECIFIED; signed int nPendingFiles = DEFAULT_PENDINGFILES; signed int nPendingKBytes = DEFAULT_PENDINGKBYTES; unsigned int wCheck = CHECK_NOTSPECIFIED; unsigned int wInfo = HOSTINFO_NO; char opt; char *optarg; char *optstr; int optidx; char *cpConfig = CONFIG; char *cpLsys = LSYS; char *cpArgs = DEFAULT_ARGS; char *cpExeccmndá= DEFAULT_EXECCMND; char *cpLog = LOG; char *cpField = FIELD; char *cpSystemá= NULL; char *cpModemsetup = MODEMSETUP; char *cpEnvvar = NULL; char *cpNotifyuser = DEFAULT_NOTIFYUSER; BOOL fModemsetupá= FALSE; BOOL fAlways = FALSE; BOOL fProfane = FALSE; BOOL fExeccmnd = FALSE; BOOL fRestriction = FALSE; BOOL fPendingFiles = FALSE; BOOL fPendingKBytes = FALSE; BOOL fNotifyuser = FALSE; BOOL fWebreaked = FALSE; extern char caSystem[]; extern char caCmnd[]; extern char caTmp[]; struct MsgPort *timerport = NULL; ULONG timerport_sigmask; ULONG signals; struct timermsg *timermsg_restriction = NULL; struct timermsg *timermsg_survival = NULL; struct timermsg *timermsg_delay = NULL; struct timermsg *pMsg; UBYTE timerdeviceflag_restriction = 0; UBYTE timerdeviceflag_survival = 0; UBYTE timerdeviceflag_delay = 0; UBYTE active_timermsg = 0; UBYTE survivalmode = 0; int fork_signum = -1; ULONG fork_sigmask; struct Process *fork_pid; BPTR lock; struct Library *CheckBase = NULL; struct Process *PID; char *cpProgname; char *cp; int rc = DOSRC_SUCCESS; cpProgname = strupr(argv[0]); if ( (cp = strrchr(cpProgname, '/')) != NULL || (cp = strrchr(cpProgname, ':')) != NULL ) cpProgname = ++cp; if ((CheckBase = OpenLibrary(DOSNAME, 37L)) == NULL) { printf("%s R%d.%d needs AmigaOS 2.04 (37.xx) or higher.\n", cpProgname, ProgVersion, ProgRevision); printf("Before OS2.04 you should take %s R0.67 or lower.\n", cpProgname); cu(DOSRC_FAIL); } cpProgname = strlwr(cpProgname); PID = (struct Process *)FindTask(NULL); ulog(cpLog, cpProgname, "-", "Startup Release %d.%d %s [pid=%02d]", ProgVersion, ProgRevision, ProgDate, PID->pr_TaskNum); dbg(2, "processing argument line\n"); optidx = 1; optstr = "sSrdtuneEpPcjx"; for ( ; (optarg = argopt(argc, argv, optstr, &optidx, &opt)) != NULL; ) { switch(opt) { case 's': fProfane = FALSE; dbg(3, "fProfane = FALSE\n"); if (*optarg != NUL) { cpSystem = strlwr(strcvt(optarg)); dbg(3, "cpSystem = \"%s\"\n", cpSystem); } break; case 'S': fProfane = TRUE; dbg(3, "fProfane = TRUE\n"); if (*optarg != NUL) { cpSystem = strlwr(strcvt(optarg)); dbg(3, "cpSystem = \"%s\"\n", cpSystem); } break; case 'r': nRetriesMax = abs(atoi(optarg)); dbg(3, "nRetriesMax = %d\n", nRetriesMax); break; case 'd': nDelay = abs(atoi(optarg)); dbg(3, "nDelay = %d\n", nDelay); break; case 't': nRestriction = abs(atoi(optarg)); fRestriction = TRUE; dbg(3, "nRestriction = %d\n", nRestriction); break; case 'u': cpArgs = strcvt(optarg); dbg(3, "cpArgs = \"%s\"\n", cpArgs); break; case 'm': fModemsetup= TRUE; dbg(3, "fModemsetup = TRUE\n"); break; case 'n': fNotifyuser = TRUE; dbg(3, "fNotifyuser = TRUE\n"); if (*optarg != NUL) { cpNotifyuser = strcvt(optarg); dbg(3, "cpNotifyuser = \"%s\"\n", cpNotifyuser); } break; case 'e': fExeccmnd = FALSE; dbg(3, "fExeccmnd = FALSE\n"); cpExeccmnd = strcvt(optarg); dbg(3, "cpExeccmnd = \"%s\"\n", cpExeccmnd); break; case 'E': fExeccmnd = TRUE; dbg(3, "fExeccmnd = TRUE\n"); if (*optarg != NUL) { cpExeccmnd = strcvt(optarg); dbg(3, "cpExeccmnd = \"%s\"\n", cpExeccmnd); } break; case 'p': fPendingFiles = TRUE; dbg(3, "fPendingFiles = TRUE\n"); if (*optarg != NUL) { nPendingFiles = atoi(optarg); dbg(3, "nPendingFiles = %d\n", nPendingFiles); } break; case 'P': fPendingKBytes = TRUE; dbg(3, "fPendingKBytes = TRUE\n"); if (*optarg != NUL) { nPendingKBytes = atoi(optarg); dbg(3, "nPendingKBytes = %d\n", nPendingKBytes); } break; case 'a': fAlways = TRUE; dbg(3, "fAlways = TRUE\n"); break; case 'c': if (*optarg != NUL && abs(atoi(optarg)) == 1) { wCheck = CHECK_TOBREAK; dbg(3, "wCheck = CHECK_TOBREAK\n"); } else { wCheck = CHECK_TOABORT; dbg(3, "wCheck = CHECK_TOABORT\n"); } break; case 'j': if (*optarg != NUL) { if (abs(atoi(optarg)) == 0) { wJobcontrol = JOBCTL_DISABLE; dbg(3, "wJobcontrol = JOBCTL_DISABLE\n"); } else { wJobcontrol = JOBCTL_ENABLE; dbg(3, "wJobcontrol = JOBCTL_ENABLE\n"); } } else { wJobcontrol = JOBCTL_SWITCH; dbg(3, "wJobcontrol = JOBCTL_SWITCH\n"); } break; case 'i': wInfo = HOSTINFO_SHORT; dbg(3, "wInfo = HOSTINFO_SHORT\n"); break; case 'I': wInfo = HOSTINFO_LONG; dbg(3, "wInfo = HOSTINFO_LONG\n"); break; case 'x': dbglevel = abs(atoi(optarg)); break; case 'v': dbg(2, "giving version info\n"); giveversioninfo(cpProgname); cu(DOSRC_SUCCESS); case '?': dbg(2, "giving usage info\n"); giveusage(cpProgname); cu(DOSRC_SUCCESS); default : ulog(cpLog, cpProgname, "-", "Ignored bad option '%c'", opt); } } for ( ; optidx < argc; optidx++) ulog(cpLog, cpProgname, "-", "Ignored arg '%s'", argv[optidx]); if (cpSystem == NULL) { dbg(2, "getting default system name\n"); if ((cpSystem = getfield(cpConfig, cpField, caSystem)) == NULL) { ulog(cpLog, cpProgname, "-", "Failed because cannot get default hostname from '%s' field of '%s'", cpField, cpConfig); cu(DOSRC_FAIL); } truncdomain(cpSystem); dbg(2, "cpSystem = \"%s\"\n", cpSystem); } if (!inlsys(cpLsys, cpSystem)) { ulog(cpLog, cpProgname, "-", "Failed due to invalid hostname: %s", cpSystem); cu(DOSRC_FAIL); } if (wInfo != HOSTINFO_NO) { dbg(2, "giving info about current status\n"); hostinfo(cpProgname, cpLsys, cpConfig, cpSystem, wInfo); cu(DOSRC_SUCCESS); } sprintf(caEnvname, "%s.JOBCTL", cpProgname); if ((cpEnvvar = getenv(caEnvname)) == NULL) { ulog(cpLog, cpProgname, "-", "Failed to get job control enviroment %s", caEnvname); sprintf(caEnvname, "%s.JOBCTL=ENABLE", cpProgname); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set new job control enviroment %s", caEnvname); } if (wJobcontrol != JOBCTL_NOTSPECIFIED) { switch(wJobcontrol) { case JOBCTL_SWITCH : if (strcmp(cpEnvvar, "DISABLE") == 0) strcpy(caTmp, "ENABLE"); else strcpy(caTmp, "DISABLE"); break; case JOBCTL_ENABLE : strcpy(caTmp, "ENABLE"); break; case JOBCTL_DISABLE : strcpy(caTmp, "DISABLE"); break; } sprintf(caEnvname, "%s.JOBCTL=%s", cpProgname, caTmp); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set new job control enviroment %s", caEnvname); cu(DOSRC_SUCCESS); } if (strcmp(cpEnvvar, "DISABLE") == 0) { ulog(cpLog, cpProgname, "-", "Abort because we are currently disabled"); cu(DOSRC_SUCCESS); } if (wCheck != CHECK_NOTSPECIFIED) { if (IsProcRunning(UUCICO_DOSNAME)) { switch(wCheck) { case CHECK_TOABORT : ulog(cpLog, cpProgname, cpSystem, "abort due to `check' option and a already running uucico process"); cu(DOSRC_SUCCESS); case CHECK_TOBREAK : ulog(cpLog, cpProgname, cpSystem, "sending break signal to still running uucico process due to `check' option"); BreakProc(UUCICO_DOSNAME); ulog(cpLog, cpProgname, cpSystem, "waiting %d seconds sending break signal to still running uucico process due to `check' option", CHECK_TOBREAK_DELAY); Delay(50*CHECK_TOBREAK_DELAY); break; } } } if (!fProfane) { dbg(2, "calculating restriction time\n"); if ((nRestrictionTmp = timerestriction(cpLsys, cpSystem)) == -1) { printf("polling time violation for host %s\n", cpSystem); ulog(cpLog, cpProgname, cpSystem, "Failed due to polling time violation for host %s", cpSystem); cu(DOSRC_FAIL); } else { if (nRestriction == 0) nRestriction = nRestrictionTmp; dbg(2, "nRestriction = %d\n", nRestriction); } } else { if (!fRestriction) { dbg(2, "setting restriction time to zero due to left option and profanation\n"); nRestriction = 0; } } if (fAlways) { dbg(2, "setting enviroment of system \"%s\" to 'FAILED' because of 'always' option\n", cpSystem); sprintf(caEnvname, "%s.STAT.%s=FAILED", cpProgname, cpSystem); strupr(caEnvname); if (putenv(caEnvname) != 0) { ulog(cpLog, cpProgname, cpSystem, "Failed to set enviroment %s", caEnvname); } } else { dbg(2, "getting enviroment of system \"%s\"\n", cpSystem); sprintf(caEnvname, "%s.STAT.%s", cpProgname, cpSystem); if ((cpEnvvar = getenv(caEnvname)) == NULL) { ulog(cpLog, cpProgname, cpSystem, "Failed to get enviroment %s", caEnvname); sprintf(caEnvname, "%s.STAT.%s=FAILED", cpProgname, cpSystem); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set new enviroment %s", caEnvname); } else { if ((fPendingFiles && nPendingFiles != 0) || (fPendingKBytes && nPendingKBytes != 0)) { if (fPendingKBytes && nPendingKBytes != 0) { if (!PendingKBytes(SPOOLDIR, cpSystem, nPendingKBytes)) { ulog(cpLog, cpProgname, cpSystem, "Abort because not more/less or equal pending KBytes for host %s", cpSystem); cu(DOSRC_SUCCESS); } } if (fPendingFiles && nPendingFiles != 0) { if (!PendingFiles(SPOOLDIR, cpSystem, nPendingFiles)) { ulog(cpLog, cpProgname, cpSystem, "Abort because not more/less or equal pending Files for host %s", cpSystem); cu(DOSRC_SUCCESS); } } } else { if (strcmp(cpEnvvar, "SUCCESSFUL") == 0) { ulog(cpLog, cpProgname, cpSystem, "Abort because last time we had polled already successful"); cu(DOSRC_SUCCESS); } } } } ulog(cpLog, cpProgname, cpSystem, "OK Startup"); dbg(2, "create env of timers\n"); dbg(3, "create timer msgport\n"); if ((timerport = CreatePort(0, 0)) == NULL) cu(DOSRC_FAIL); dbg(3, "create IORequest struct for restriction timer\n"); if ((timermsg_restriction = (struct timermsg *)CreateExtIO(timerport, sizeof(struct timermsg))) == NULL) cu(DOSRC_FAIL); dbg(3, "open timer.device for restriction timer\n"); if ((timerdeviceflag_restriction = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)timermsg_restriction, 0)) != NULL) cu(DOSRC_FAIL); dbg(3, "create IORequest struct for survival timer\n"); if ((timermsg_survival = (struct timermsg *)CreateExtIO(timerport, sizeof(struct timermsg))) == NULL) cu(DOSRC_FAIL); dbg(3, "open timer.device for survival timer\n"); if ((timerdeviceflag_survival = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)timermsg_survival, 0)) != NULL) cu(DOSRC_FAIL); dbg(3, "create IORequest struct for delay timer\n"); if ((timermsg_delay = (struct timermsg *)CreateExtIO(timerport, sizeof(struct timermsg))) == NULL) cu(DOSRC_FAIL); dbg(3, "open timer.device for delay timer\n"); if ((timerdeviceflag_delay = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)timermsg_delay, 0)) != NULL) cu(DOSRC_FAIL); if (nRestriction) { timermsg_restriction->tm_timereq.tr_node.io_Command = TR_ADDREQUEST; timermsg_restriction->tm_timereq.tr_time.tv_secs = nRestriction * 60 - (fRestriction ? 0 : 30); timermsg_restriction->tm_timereq.tr_time.tv_micro = 0; timermsg_restriction->tm_timermode = TIMERMODE_RESTRICTION; dbg(2, "starting restriction timer with %d seconds\n", timermsg_restriction->tm_timereq.tr_time.tv_secs); SendIO((struct IORequest *)timermsg_restriction); active_timermsg = active_timermsg | TIMERMODE_RESTRICTION; } timermsg_survival->tm_timereq.tr_node.io_Command = TR_ADDREQUEST; timermsg_survival->tm_timereq.tr_time.tv_secs = SURVIVALTIME_WHOLESESSION; timermsg_survival->tm_timereq.tr_time.tv_micro = 0; timermsg_survival->tm_timermode = TIMERMODE_SURVIVAL; dbg(2, "starting survival timer with %d seconds\n", timermsg_survival->tm_timereq.tr_time.tv_secs); SendIO((struct IORequest *)timermsg_survival); active_timermsg = active_timermsg | TIMERMODE_SURVIVAL; survivalmode = SURVIVALMODE_WHOLESESSION; if (fModemsetup) { dbg(2, "setting up modem\n"); if (!setupmodem(cpModemsetup, cpLsys, cpSystem)) { ulog(cpLog, cpProgname, cpSystem, "Modem setup failed"); cu(DOSRC_FAIL); } ulog(cpLog, cpProgname, cpSystem, "Modem setup successful"); } dbg(3, "alloc signal for forking\n"); if ((fork_signum = AllocSignal(-1)) == -1) cu(DOSRC_FAIL); dbg(3, "locating uucico executable\n"); if ((lock = GetProgramDir()) != NULL) { if (NameFromLock(lock, caTmp, 256) != 0) { if (caTmp[strlen(caTmp)-1] != ':' && caTmp[strlen(caTmp)-1] != '/') { caTmp[strlen(caTmp)] = '/'; caTmp[strlen(caTmp)+2] = NUL; } } } else caTmp[0] = NUL; sprintf(caUucicoFile, "%s%s", caTmp, UUCICO_DOSNAME); for ( ; ; ) { dbg(2, "(re)entering outer loop (fork loop)\n"); if (iRetries == 0) ulog(cpLog, cpProgname, cpSystem, "Trying to poll host"); else ulog(cpLog, cpProgname, cpSystem, "Retrying (#%d) to poll host", iRetries); sprintf(caCmnd, "-%s%s %s", (fProfane) ? "S" : "s", cpSystem, cpArgs); dbg(2, "forking: %s %s\n", UUCICO_DOSNAME, caCmnd); if ((fork_pid = fork(caUucicoFile, caCmnd, &fork_rc, fork_signum)) == NULL) { ulog(cpLog, cpProgname, cpSystem, "FAILED because cannot fork %s %s", UUCICO_DOSNAME, caCmnd); cu(DOSRC_FAIL); } for ( ; ; ) { dbg(2, "(re)entering inner loop (wait loop)\n"); dbg(2, "go sleeping until wakeup\n"); timerport_sigmask = 1L << timerport->mp_SigBit; fork_sigmask = 1L << fork_signum; signals = Wait((ULONG)(fork_sigmask | timerport_sigmask | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D)); if (signals & timerport_sigmask) { dbg(2, "awakened through timer interrupt\n"); if (pMsg = (struct timermsg *)GetMsg(timerport)) { if (pMsg->tm_timermode == TIMERMODE_SURVIVAL) { active_timermsg = active_timermsg & ~(TIMERMODE_SURVIVAL); if (survivalmode == SURVIVALMODE_ABORTION) { ulog(cpLog, cpProgname, cpSystem, "interupted due to survival timeout for uucico abortion"); survivalmode = survivalmode & ~(SURVIVALMODE_ABORTION); cu(DOSRC_FAIL); } if (survivalmode == SURVIVALMODE_WHOLESESSION) { ulog(cpLog, cpProgname, cpSystem, "interupted due to survival timeout for whole session"); survivalmode = survivalmode & ~(SURVIVALMODE_WHOLESESSION); cu(DOSRC_FAIL); } continue; } if (pMsg->tm_timermode == TIMERMODE_RESTRICTION) { ulog(cpLog, cpProgname, cpSystem, "interupted due to restriction timeout of %d minute%s", nRestriction, (nRestriction != 1) ? "s" : "" ); ulog(cpLog, cpProgname, cpSystem, "sending break signal to abort uucico process"); Signal((struct Task *)fork_pid, SIGBREAKF_CTRL_C); fWebreaked = TRUE; dbg(2, "cancelling currently active survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); timermsg_survival->tm_timereq.tr_node.io_Command = TR_ADDREQUEST; timermsg_survival->tm_timereq.tr_time.tv_secs = SURVIVALTIME_ABORTION; timermsg_survival->tm_timereq.tr_time.tv_micro = 0; timermsg_survival->tm_timermode = TIMERMODE_SURVIVAL; dbg(2, "starting survival timer with %d seconds for abortion process\n", timermsg_survival->tm_timereq.tr_time.tv_secs); SendIO((struct IORequest *)timermsg_survival); active_timermsg = active_timermsg | TIMERMODE_SURVIVAL; survivalmode = SURVIVALMODE_ABORTION; fExeccmnd = TRUE; dbg(3, "fExeccmnd = TRUE\n"); continue; } if (pMsg->tm_timermode == TIMERMODE_DELAY) { ulog(cpLog, cpProgname, cpSystem, "interupted due to delay timer of %d second%s", nDelay, (nDelay != 1) ? "s" : "" ); active_timermsg = active_timermsg & ~(TIMERMODE_DELAY); break; } } } if (signals & SIGBREAKF_CTRL_C) { dbg(2, "awakened through ctrl-c signal\n"); ulog(cpLog, cpProgname, cpSystem, "interupted due to ctrl-c signal"); if (active_timermsg & TIMERMODE_DELAY) { dbg(2, "aborting delay timer\n"); AbortIO((struct IORequest *)timermsg_delay); WaitIO((struct IORequest *)timermsg_delay); active_timermsg = active_timermsg & ~(TIMERMODE_DELAY); dbg(2, "cancelling currently active survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); cu(DOSRC_FAIL); } else { ulog(cpLog, cpProgname, cpSystem, "sending break signal to abort uucico process"); Signal((struct Task *)fork_pid, SIGBREAKF_CTRL_C); dbg(2, "cancelling currently active survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); timermsg_survival->tm_timereq.tr_node.io_Command = TR_ADDREQUEST; timermsg_survival->tm_timereq.tr_time.tv_secs = SURVIVALTIME_ABORTION; timermsg_survival->tm_timereq.tr_time.tv_micro = 0; timermsg_survival->tm_timermode = TIMERMODE_SURVIVAL; dbg(2, "starting survival timer with %d seconds for abortion process\n", timermsg_survival->tm_timereq.tr_time.tv_secs); SendIO((struct IORequest *)timermsg_survival); active_timermsg = active_timermsg | TIMERMODE_SURVIVAL; survivalmode = survivalmode | SURVIVALMODE_ABORTION; fExeccmnd = TRUE; dbg(3, "fExeccmnd = TRUE\n"); continue; } } if (signals & SIGBREAKF_CTRL_D) { dbg(2, "awakened through ctrl-d signal\n"); ulog(cpLog, cpProgname, cpSystem, "interupted due to ctrl-d signal"); if (active_timermsg & TIMERMODE_DELAY) { dbg(2, "aborting delay timer\n"); AbortIO((struct IORequest *)timermsg_delay); WaitIO((struct IORequest *)timermsg_delay); active_timermsg = active_timermsg & ~(TIMERMODE_DELAY); dbg(2, "cancelling currently active survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); } else { ulog(cpLog, cpProgname, cpSystem, "sending break signal to abort uucico process"); Signal((struct Task *)fork_pid, SIGBREAKF_CTRL_C); dbg(2, "cancelling currently active survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); timermsg_survival->tm_timereq.tr_node.io_Command = TR_ADDREQUEST; timermsg_survival->tm_timereq.tr_time.tv_secs = SURVIVALTIME_ABORTION; timermsg_survival->tm_timereq.tr_time.tv_micro = 0; timermsg_survival->tm_timermode = TIMERMODE_SURVIVAL; dbg(2, "starting survival timer with %d seconds for abortion process\n", timermsg_survival->tm_timereq.tr_time.tv_secs); SendIO((struct IORequest *)timermsg_survival); active_timermsg = active_timermsg | TIMERMODE_SURVIVAL; survivalmode = survivalmode | SURVIVALMODE_ABORTION; } cu(DOSRC_FAIL); } if (signals & fork_sigmask) { dbg(2, "awakened through fork termination\n"); if (fork_rc == 0) { dbg(2, "uucico was succesfull\n"); ulog(cpLog, cpProgname, cpSystem, "finished (polling was successful)"); dbg(2, "setting enviroment to 'SUCCESSFUL'\n"); sprintf(caEnvname, "%s.STAT.%s=SUCCESSFUL", cpProgname, cpSystem); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set enviroment %s", caEnvname); fExeccmnd = TRUE; dbg(3, "fExeccmnd = TRUE\n"); cu(DOSRC_SUCCESS); } if (fork_rc == 5) { dbg(2, "uucico failure in call and/or protocol\n"); iRetries++; if (iRetries > nRetriesMax) { if (nRetriesMax != 0) ulog(cpLog, cpProgname, cpSystem, "stopped due to max retries of %d", nRetriesMax); dbg(2, "setting enviroment to 'FAILED'\n"); sprintf(caEnvname, "%s.STAT.%s=FAILED", cpProgname, cpSystem); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set enviroment %s", caEnvname); if (fNotifyuser) { ulog(cpLog, cpProgname, cpSystem, "notifying user `%s' about this failed session", cpNotifyuser); sprintf(caTmp, "session stopped due to max retries of %d", nRetriesMax); NotifyOnFailure(cpNotifyuser, cpSystem, caTmp); } cu(DOSRC_FAIL); } if (nDelay) { timermsg_delay->tm_timereq.tr_node.io_Command = TR_ADDREQUEST; timermsg_delay->tm_timereq.tr_time.tv_secs = nDelay; timermsg_delay->tm_timereq.tr_time.tv_micro = 0; timermsg_delay->tm_timermode = TIMERMODE_DELAY; dbg(2, "starting delay timer with %d seconds for retry procedure\n", timermsg_delay->tm_timereq.tr_time.tv_secs); SendIO((struct IORequest *)timermsg_delay); active_timermsg = active_timermsg | TIMERMODE_DELAY; continue; } break; } dbg(2, "uucico break/software failure\n"); if (survivalmode == SURVIVALMODE_ABORTION) { dbg(2, "cancelling currently active survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); survivalmode = survivalmode & ~(SURVIVALMODE_ABORTION); } dbg(2, "setting enviroment to 'FAILED'\n"); sprintf(caEnvname, "%s.STAT.%s=FAILED", cpProgname, cpSystem); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set enviroment %s", caEnvname); if (fNotifyuser) { if (fWebreaked) { ulog(cpLog, cpProgname, cpSystem, "notifying user `%s' about this failed session", cpNotifyuser); sprintf(caTmp, "session stopped due to restriction timeout of %d minute%s", nRestriction, (nRestriction != 1) ? "s" : ""); NotifyOnFailure(cpNotifyuser, cpSystem, caTmp); } } fExeccmnd = TRUE; dbg(3, "fExeccmnd = TRUE\n"); cu(DOSRC_FAIL); } } } cus: if (fork_signum != -1) { dbg(2, "freeing signal of forking\n"); FreeSignal(fork_signum); } if (active_timermsg & TIMERMODE_DELAY) { dbg(2, "aborting delay timer\n"); AbortIO((struct IORequest *)timermsg_delay); WaitIO((struct IORequest *)timermsg_delay); active_timermsg = active_timermsg & ~(TIMERMODE_DELAY); } if (active_timermsg & TIMERMODE_RESTRICTION) { dbg(2, "aborting restriction timer\n"); AbortIO((struct IORequest *)timermsg_restriction); WaitIO((struct IORequest *)timermsg_restriction); active_timermsg = active_timermsg & ~(TIMERMODE_RESTRICTION); } if (active_timermsg & TIMERMODE_SURVIVAL) { dbg(2, "aborting survival timer\n"); AbortIO((struct IORequest *)timermsg_survival); WaitIO((struct IORequest *)timermsg_survival); active_timermsg = active_timermsg & ~(TIMERMODE_SURVIVAL); } dbg(2, "delete env of timers\n"); if (timerdeviceflag_delay) { dbg(3, "closing timer.device of delay timer\n"); CloseDevice((struct IORequest *)timermsg_delay); } if (timerdeviceflag_restriction) { dbg(3, "closing timer.device of restriction timer\n"); CloseDevice((struct IORequest *)timermsg_restriction); } if (timerdeviceflag_survival) { dbg(3, "closing timer.device of survival timer\n"); CloseDevice((struct IORequest *)timermsg_survival); } if (timerport) { dbg(3, "delete timer msgport\n"); DeletePort(timerport); } if (timermsg_delay) { dbg(3, "delete IORequest struct of delay timer\n"); DeleteExtIO((struct IORequest *)timermsg_delay); } if (timermsg_restriction) { dbg(3, "delete IORequest struct of restriction timer\n"); DeleteExtIO((struct IORequest *)timermsg_restriction); } if (timermsg_survival) { dbg(3, "delete IORequest struct of surval timer\n"); DeleteExtIO((struct IORequest *)timermsg_survival); } if (fExeccmnd && strlen(cpExeccmnd) > 0) { ulog(cpLog, cpProgname, cpSystem, "Executing %s", cpExeccmnd); if (SystemCmndAsync(cpExeccmnd) == -1) ulog(cpLog, cpProgname, cpSystem, "Error executing %s", cpExeccmnd); } if (CheckBase) CloseLibrary(CheckBase); ulog(cpLog, cpProgname, (cpSystem) ? cpSystem : "-", "OK Exit"); dbg(3, "rc = %d\n", rc); dbg(2, "exit\n"); return rc; }