home *** CD-ROM | disk | FTP | other *** search
Wrap
/* UUPoll -- uucico polling server This programm is designed to provide us with the ability to control the UUCP polling procedure in a more comfortable way. It controls the uucico command automatically, so we have not to think about it. Intead of invoking uucico manually with the desired options all we have to do is calling this program with optional arguments. Genesis : Fri Sep 20 23:26:29 1991 Last Change : Fri Jun 19 14:47:01 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.muc.sub.org */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dos.h> #include <proto/exec.h> #include <proto/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 "cus.h" #include "proto.h" #include "defines.h" #include "dbg.h" #include "rev.h" #include "status.h" #define DEFAULT_RETRIES 0 #define DEFAULT_DELAY 0 #define DEFAULT_RESTRICTION 0 #define DEFAULT_PENDINGFILES 1 #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 release 1.15d */ #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 30 /* 30 seconds */ 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]; struct timermsg { struct timerequest tm_timereq; UBYTE tm_timermode; }; 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; unsigned int nPendingFiles = DEFAULT_PENDINGFILES; 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 fPendingwork = FALSE; BOOL fNotifyuser = FALSE; BOOL fWebreaked = FALSE; extern char caSystem[]; extern char caCmnd[]; extern char caTmp[]; struct MsgPort *timerport = NULL; struct MsgPort *forkport = NULL; ULONG timerport_sigmask; ULONG forkport_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; struct ProcID *forkprocID = NULL; struct FORKENV *forkprocENV = NULL; struct Process *PID; char *cpProgname; char *cp; int rc = DOSRC_SUCCESS; cpProgname = strlwr(argv[0]); if ( (cp = strrchr(cpProgname, '/')) != NULL || (cp = strrchr(cpProgname, ':')) != NULL ) cpProgname = ++cp; PID = (struct Process *)FindTask(NULL); ulog(cpLog, cpProgname, "-", "Startup Release %s.%02d (%s) [PID:%02d]", Version, Revision, Date, PID->pr_TaskNum); dbg(2, "processing argument line\n"); optidx = 1; optstr = "sSrdtueEnpcjx"; 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 '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 'a': fAlways = TRUE; dbg(3, "fAlways = TRUE\n"); break; case 'p': fPendingwork = TRUE; dbg(3, "fPendingwork = TRUE\n"); if (*optarg != NUL) { nPendingFiles = abs(atoi(optarg)); dbg(3, "nPendingFiles = %d\n", nPendingFiles); } 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 '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 'n': fNotifyuser = TRUE; dbg(3, "fNotifyuser = TRUE\n"); if (*optarg != NUL) { cpNotifyuser = strcvt(optarg); dbg(3, "cpNotifyuser = \"%s\"\n", cpNotifyuser); } break; case 'x': dbglevel = abs(atoi(optarg)); break; case 'i': if (*optarg != NUL) { if (abs(atoi(optarg)) == 0) { wInfo = HOSTINFO_SHORT; dbg(3, "wInfo = HOSTINFO_SHORT\n"); } else { wInfo = HOSTINFO_LONG; dbg(3, "wInfo = HOSTINFO_LONG\n"); } } else { wInfo = HOSTINFO_SHORT; dbg(3, "wInfo = HOSTINFO_SHORT\n"); } 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.%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.%s", cpProgname, cpSystem); if ((cpEnvvar = getenv(caEnvname)) == NULL) { ulog(cpLog, cpProgname, cpSystem, "Failed to get enviroment %s", caEnvname); sprintf(caEnvname, "%s.%s=FAILED", cpProgname, cpSystem); strupr(caEnvname); if (putenv(caEnvname) != 0) ulog(cpLog, cpProgname, cpSystem, "Failed to set new enviroment %s", caEnvname); } else { if (fPendingwork && nPendingFiles > 0) { if (!PendingWork(SPOOLDIR, cpSystem, nPendingFiles)) { ulog(cpLog, cpProgname, cpSystem, "Abort because not enough or no pending work 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 forkprocess\n"); dbg(3, "create fork msgport\n"); if ((forkport = CreatePort(0, 0)) == NULL) CU(DOSRC_FAIL); dbg(3, "alloc mem for forkprocess ID struct\n"); if ((forkprocID = (struct ProcID *)calloc(sizeof(struct ProcID), 1)) == NULL) CU(DOSRC_FAIL); dbg(3, "alloc mem for forkprocess ENV struct\n"); if ((forkprocENV = (struct FORKENV *)calloc(sizeof(struct FORKENV), 1)) == NULL) CU(DOSRC_FAIL); 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"); } for ( ; ; ) { dbg(2, "(re)entering outer loop (spawn loop)\n"); if (iRetries == 0) ulog(cpLog, cpProgname, cpSystem, "Trying to poll host"); else ulog(cpLog, cpProgname, cpSystem, "Retrying (#%d) to poll host", iRetries); forkprocENV->priority = (long)(PID->pr_Task.tc_Node.ln_Pri); forkprocENV->stack = (long)(PID->pr_StackSize); forkprocENV->std_in = (long)(PID->pr_CIS); forkprocENV->std_out = (long)(PID->pr_COS); forkprocENV->console = (long)(PID->pr_WindowPtr); forkprocENV->msgport = forkport; sprintf(caCmnd, "%s -%s%s %s", UUCICO_DOSNAME, (fProfane) ? "S" : "s", cpSystem, cpArgs); dbg(2, "forking: %s\n", caCmnd); splitarg(cpaArgv, caCmnd); if (forkv(UUCICO_DOSNAME, cpaArgv, forkprocENV, forkprocID) == -1) { 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; forkport_sigmask = 1L << forkport->mp_SigBit; signals = Wait( (ULONG)(timerport_sigmask | forkport_sigmask | SIGBREAKF_CTRL_C) ); 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 *)(forkprocID->process), 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 *)(forkprocID->process), 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 & forkport_sigmask) { dbg(2, "awakened through forkprocess termination\n"); rc = wait(forkprocID); if (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.%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 (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.%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.%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 (fExeccmnd && strlen(cpExeccmnd) > 0) { ulog(cpLog, cpProgname, cpSystem, "Spawning %s", cpExeccmnd); sprintf(caCmnd, "run <nil: >nil: %s", cpExeccmnd); if (system(caCmnd) == -1) ulog(cpLog, cpProgname, cpSystem, "Error spawning %s", cpExeccmnd); } 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); } dbg(2, "delete env of forkprocess\n"); if (forkport) { dbg(3, "delete fork msgport\n"); DeletePort(forkport); } if (forkprocENV) { dbg(3, "freeing mem for ENV of forkprocess\n"); free(forkprocENV); } if (forkprocID) { dbg(3, "freeing mem for ID of forkprocess\n"); free(forkprocID); } ulog(cpLog, cpProgname, (cpSystem) ? cpSystem : "-", "OK Exit"); dbg(3, "rc = %d\n", rc); dbg(2, "exit\n"); return rc; }