home *** CD-ROM | disk | FTP | other *** search
- /*
- * System Dependent Application Message Handling
- * Two Queue Approach
- * Unix/Xenix V Queue Implementation
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include "ctstdr.h"
- #include "ctoptn.h"
- #include "ctstrc.h"
- #include "cterrc.h"
- #include "ctcomm.h"
- #include "ctmssg.h"
- #include <errno.h>
-
- /* LTYPE is defined in ctmssg.h */
-
- #define DIR_SEP '/'
- #define DIR_PAR '.'
-
- COUNT no_demon;
- LOCAL TEXT dir_sepstr[] = {
- DIR_SEP,
- '\0'};
- LOCAL UCOUNT msgsiz;
- LOCAL LONG pid;
-
- extern COUNT uerr_cod;
- extern TEXT ct_buf[];
- extern int errno;
-
- /* assumes that MAX_NAME (usually 64) << SECSIZ (usually 128) */
-
- TEXT *getcwd();
-
- LOCAL COUNT reduce(sp,i) /* processes unix style path names with ../ & ./ */
- PFAST TEXT *sp;
- PFAST COUNT i;
- {
- FAST TEXT *tp;
-
- tp = sp + i;
- while (*tp) {
- if (*tp == DIR_PAR) {
- if (*(tp - 1) == DIR_SEP) {
- if (*(tp + 1) == DIR_SEP) {
- strcpy(sp + i,tp + 2);
- return(reduce(sp,i+1));
- } else if (*(tp + 1) == DIR_PAR && *(tp + 2) == DIR_SEP) {
- for (i -= 3; i >= 0; i--)
- if (sp[i] == DIR_SEP) {
- strcpy(sp + i,tp + 2);
- return(reduce(sp,i + 1));
- }
- return(uerr_cod = ABNM_ERR);
- }
- }
- }
- tp++;
- i++;
- }
- return(NO_ERROR);
- }
-
- /* copies a file name, after modifying name to a fully specified form */
- COUNT fulnam(dp, tp,maxlen)
- PFAST TEXT *dp,*tp;
- COUNT maxlen;
- {
- COUNT bpos;
-
- if (*tp != DIR_SEP) {
- if (getcwd(ct_buf,maxlen) == NULL) /* get current directory */
- return(uerr_cod = ABDR_ERR);
- if (ct_buf[1]) /* more than root */
- strcat(ct_buf,dir_sepstr);
- bpos = strlen(ct_buf);
- strcat(ct_buf,tp);
- if (reduce(ct_buf,bpos))
- return(uerr_cod);
- } else {
- strcpy(ct_buf,tp);
- if (reduce(ct_buf,1))
- return(uerr_cod);
- }
-
- if (strlen(ct_buf) > maxlen)
- return(uerr_cod = AFLN_ERR);
- strcpy(dp,ct_buf);
- return(NO_ERROR);
- }
-
- TEXT *getmids(apsize,pmsg)
- UCOUNT apsize;
- MESSAGE *pmsg;
- {
- TEXT *retval,pidbuf[16];
-
- TEXT *mballc();
- key_t ftok();
-
- /* get server msg id */
- uerr_cod = 0;
- if ((srvkey = ftok(SERVER,'q')) == NOKEY)
- uerr_cod = ASKY_ERR;
- else if ((srvid = msgget(srvkey,0)) < 0)
- uerr_cod = ASID_ERR;
-
- /* get application (local) msg id */
- else if ((appkey = ftok(SERVER2,'q')) == NOKEY)
- uerr_cod = AAKY_ERR;
- else if ((apxid = msgget(appkey,0)) < 0)
- uerr_cod = AAID_ERR;
- if (uerr_cod)
- return(NULL);
-
- /* get space for message structure required by system */ /* ???? */
- if ((retval = mballc(1,apsize + LTYPE)) == NULL) {
- uerr_cod = ASPC_ERR;
- return(NULL);
- }
- msgsiz = apsize;
-
- if (pmsg->mfunc == TST_STPUSR || pmsg->mfunc == TST_DEDUSR ||
- no_demon != 0 || (pid = fork()) == 0 || pid == -1L) {
- /* child process continues application */
-
- /* application message id into mpntr member of message header */
- pmsg->mpntr = pid = getpid();
-
- /* return pointer to actual text portion */
- return(retval + LTYPE);
- } else {
- /* parent becomes watchdog for termination via ctdemn */
- sprintf(pidbuf,"%d",(int) pid);
- /*
- * Add, after pidbuf and before the NULL in execlp(),
- * optional ASCII strings with signal numbers to be
- * ignored by crdemn IF AND ONLY IF your application promises
- * to ignore these signals. Alternatively, you may modify
- * ctdemn.c so that it ignores these particular signals.
- */
- execlp("ctdemn","ctdemn",pidbuf,NULL);
- fprintf(stderr,
- "\nApplication could not invoke \"ctdemn.\" Unix errno=%d.\n",errno);
- exit(2);
- }
-
- }
-
- COUNT ridmids()
- {
- /* 2 queue approach requires no action */
- return(NO_ERROR);
- }
-
- COUNT ctrqst(msgadr,pmsg)
- PFAST TEXT *msgadr; /* ptr to message area */
- MESSAGE *pmsg; /* ptr to message header */
- {
- int msglen;
-
- /* copy message header */
- cpybuf(msgadr,pmsg,sizeof(MESSAGE));
- msglen = sizeof(MESSAGE) + pmsg->mdlen;
-
- /* send message: ordinarily an interprocess comm call (e.g., q call) */
- msgadr -= LTYPE;
- *((LONG *) msgadr) = 1L;
-
- snd_retry:
- if (msgsnd(srvid,msgadr,msglen,0) < 0) {
- if (errno == EINTR)
- goto snd_retry;
- else
- return(uerr_cod = ARQS_ERR);
- } else
- return(NO_ERROR);
- }
-
- COUNT ctrspn(msgadr,pmsg)
- PFAST TEXT **msgadr;
- MESSAGE *pmsg;
- {
- /* get response: interprocess comm call which leaves answer in apxmsg */
- /* read only process id messages */
- rcv_retry:
- if (msgrcv(apxid,*msgadr - LTYPE,msgsiz,pid,0) < 0) {
- if (errno == EINTR)
- goto rcv_retry;
- else
- return(uerr_cod = ARSP_ERR);
- }
-
- /* copy message header */
- cpybuf(pmsg,*msgadr,sizeof(MESSAGE));
-
- return(NO_ERROR);
- }
-
- /* return application queueid so that demon may clear output queue */
- int getapxid()
- {
- return(apxid);
- }
-
- /* end of ctamsg.c */
-
-