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

Defined functions

IIgetpath defined in line 134; used 1 times
  • in line 43
IIingres defined in line 12; never used

Defined variables

IImainpr defined in line 9; used 3 times

Defined macros

CLOSED defined in line 7; used 1 times
  • in line 65
Last modified: 1995-02-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2769
Valid CSS Valid XHTML 1.0 Strict