1: # include   <ingres.h>
   2: # include   <symbol.h>
   3: # include   <opsys.h>
   4: # include   <aux.h>
   5: # include   "IIglobals.h"
   6: # include   <pipes.h>
   7: # include   <sccs.h>
   8: # include   <signal.h>
   9: 
  10: SCCSID(@(#)IIingres.c	8.1	12/31/84)
  11: 
  12: # define    CLOSED  '?'
  13: 
  14: 
  15: # ifdef xV7_UNIX
  16: char    *IImainpr = "ingres";
  17: # else xV7_UNIX
  18: char    *IImainpr = "/usr/bin/ingresx";
  19: # endif xV7_UNIX
  20: 
  21: char    IIPathname[41];
  22: 
  23: /*
  24: **	IIingres opens the needed pipes and
  25: **	forks an ingres process.
  26: **
  27: **	ingres recognizes the EQUEL flag followed by
  28: **	three control characters as being an equel processes
  29: **
  30: **	parameters to ingres are passed directly. only
  31: **	the first 9 are counted.
  32: */
  33: 
  34: IIingres(p1, p2, p3, p4, p5, p6, p7, p8, p9)
  35: char    *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
  36: {
  37:     int     pipes[4];       /* pipe vector buffer */
  38:     char        eoption[15];    /* dummy variable to hold -EQUEL option */
  39:     register char   *cp;
  40:     char        *argv[12];
  41:     register char   **ap;
  42:     extern      IIresync();
  43:     extern      *(IIinterrupt)(),   exit();
  44:     pb_t        pb;
  45: 
  46: #	ifdef xETR1
  47:     if (IIdebug)
  48:         printf("IIingres\n");
  49: #	endif
  50:     /* test if ingres is already invoked */
  51:     if (IIingpid)
  52:         IIsyserr("Attempt to invoke INGRES twice");
  53: 
  54:     IIgetpath();
  55:     /* open INGRES pipes */
  56:     if (pipe(&pipes[0]) || pipe(&pipes[2]))
  57:         IIsyserr("pipe error in IIingres");
  58: 
  59:     IIw_down = pipes[1];    /* file desc for equel->parser */
  60:     IIr_down = pipes[2];    /* file desc for parser->equel */
  61: 
  62:     /* catch interupts if they are not being ignored */
  63:     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  64:         signal(SIGINT, IIresync);
  65: 
  66:     /* set up equel option flag */
  67:     cp = eoption;
  68:     *cp++ = '-';
  69:     *cp++ = EQUEL;
  70:     *cp++ = pipes[0] | 0100;
  71:     *cp++ = pipes[1] | 0100;
  72:     *cp++ = CLOSED;
  73:     *cp++ = pipes[3] | 0100;
  74:     *cp++ = CLOSED; /* this will be the equel->ovqp pipe in the future */
  75:     *cp++ = CLOSED; /* old ovqp->equel pipe */
  76:     /* put "6.3" at end of flag for OVQP to not do flush after
  77: 	 * every tuple
  78: 	 */
  79:     *cp++ = '6';
  80:     *cp++ = '.';
  81:     *cp++ = '3';
  82:     *cp = '\0';
  83:     if (cp - eoption >= sizeof eoption)
  84:         IIsyserr("IIingres: too big an eoption");
  85: 
  86:     if ((IIingpid = fork()) < 0)
  87:         IIsyserr("IIingres:cant fork %d", IIingpid);
  88:     /* if parent, close the unneeded files and return */
  89:     if (IIingpid)
  90:     {
  91:         if (close(pipes[0]) || close(pipes[3]))
  92:             IIsyserr("close error 1 in IIingres");
  93:         IIinput = IIr_down;
  94:         IIpb_prime(&pb, PB_NOTYPE);
  95: #		ifdef xETR1
  96:         if (IIdebug)
  97:             printf("calling ingres with '%s' database %s\n", eoption, p1);
  98: #		endif
  99:         return;
 100:     }
 101:     /* the child overlays /usr/bin/ingres */
 102:     ap = argv;
 103:     *ap++ = "ingres";
 104:     *ap++ = eoption;
 105:     *ap++ = p1;
 106:     *ap++ = p2;
 107:     *ap++ = p3;
 108:     *ap++ = p4;
 109:     *ap++ = p5;
 110:     *ap++ = p6;
 111:     *ap++ = p7;
 112:     *ap++ = p8;
 113:     *ap++ = p9;
 114:     *ap = 0;
 115: # ifdef xV7_UNIX
 116:     execvp(IImainpr, argv);
 117: # else xV7_UNIX
 118:     execv(IImainpr, argv);
 119: # endif xV7_UNIX
 120:     IIsyserr("cannot exec INGRES in IIingres");
 121: }
 122: 
 123: /*
 124: **  IIGETPATH -- initialize the IIPathname variable
 125: **
 126: **	Parameters:
 127: **		none
 128: **
 129: **	Returns:
 130: **		none
 131: **
 132: **	Side Effects:
 133: **		Sets IIPathname to the home directory of the USERINGRES
 134: **		[unix.h] user.
 135: **
 136: **	Called By:
 137: **		IIingres.c
 138: **
 139: **	History:
 140: **		3/26/79 -- (marc) written
 141: */
 142: 
 143: IIgetpath()
 144: {
 145:     char            line[MAXLINE + 1];
 146:     static char     reenter;
 147:     register int        i;
 148:     register char       *lp;
 149:     struct iob      iobuf;
 150:     char            *field[UF_NFIELDS];
 151: 
 152:     if (reenter)
 153:         return;
 154:     else
 155:         reenter++;
 156: 
 157:     if ((i = IIfopen("/etc/passwd", &iobuf)) < 0)
 158:         IIsyserr("IIgetpath: no /etc/passwd");
 159: 
 160:     do
 161:     {
 162:         /* get a line from the passwd file */
 163:         i = 0;
 164:         for (lp = line; (*lp = IIgetc(&iobuf)) != '\n'; lp++)
 165:         {
 166:             if (*lp == -1)
 167:                 IIsyserr("IIgetpath: no user 'ingres' in /etc/passwd");
 168:             if (++i > sizeof line - 1)
 169:             {
 170:                 *lp = '\0';
 171:                 IIsyserr("IIgetpath: line overflow: \"%s\"",
 172:                 line);
 173:             }
 174:         }
 175:         *lp = '\0';
 176:         for (i = 0, lp = line; *lp != '\0'; lp++)
 177:         {
 178:             if (*lp == ':')
 179:             {
 180:                 *lp = '\0';
 181:                 if (i > UF_NFIELDS)
 182:                     IIsyserr("IIgetpath: too many fields in passwd \"%s\"",
 183:                     line);
 184:                 field[i++] = lp + 1;
 185:             }
 186:         }
 187:         /* check for enough fields for valid entry */
 188:         if (i < 3)
 189:             IIsyserr("IIgetpath: too few fields \"%s\"",
 190:             line);
 191:     }  while (!IIsequal(line, USERINGRES));
 192:     IIclose(&iobuf);
 193: 
 194:     /* check that pathname won't overflow static buffer */
 195:     if (field[i - 1] - field[i - 2] > sizeof IIPathname)
 196:         IIsyserr("IIgetpath: path too long \"%s\"", field[i - 2]);
 197: 
 198:     /* move pathname into buffer */
 199:     IIbmove(field[i - 2], IIPathname, field[i - 1] - field[i - 2]);
 200: }

Defined functions

IIgetpath defined in line 143; used 1 times
  • in line 54
IIingres defined in line 34; never used

Defined variables

IIPathname defined in line 21; used 5 times
IImainpr defined in line 18; used 2 times

Defined macros

CLOSED defined in line 12; used 3 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1200
Valid CSS Valid XHTML 1.0 Strict