Exemplo n.º 1
0
pwr_tBoolean
sect_Lock (
  pwr_tStatus		*sts,
  sect_sHead		*shp,
  sect_sMutex		*mp
)
{
  pwr_tStatus		lsts = 1;

#if defined(OS_ELN)
  ELN$LOCK_AREA((AREA)shp->area, *mp);
#elif defined(OS_VMS)
  {
    sect_sMutexEntry	*ep;
    int			i;

    /* Get free list entry.  */

    while ( 1) {
      i = _REMQHI(&mp->freeroot, (void **)&ep);
      if ( i == 1)
        continue;
      else if (i == 3) 
        sleep(1);
      else
        break;
    }

    /* Insert in ownership list.  */

    while ((i = _INSQTI(ep, &mp->ownerroot)) == 1);
    if (i == 0) {

      /* Contention, we must wait for the resource.  */

      lsts = sys$ascefc(64, &shp->namedsc, 0, 0);
      if (ODD(lsts)) lsts = sys$waitfr(ep->flag);
      if (ODD(lsts)) lsts = sys$clref(ep->flag);
    }
  }
#elif defined(OS_LYNX)
  while (sem_wait(mp) != 0) {
    if (errno != EINTR) {
      perror("sect_Lock: sem_wait ");
      lsts = 2;
      break;
    }
  }
#elif defined OS_POSIX
  while (posix_sem_wait(mp) != 0) {
    if (errno != EINTR) {
      perror("sect_Lock: sem_wait ");
      lsts = 2;
      break;
    }
  }
#endif

  errh_ReturnOrBugcheck(ODD(lsts), sts, lsts, "");
}
Exemplo n.º 2
0
VMS_PROC_STUFF *
get_vms_process_stuff ()
{
  /*
    Return a process_stuff structure
    
    We use 1-23 as our event flags to simplify implementing
    a VMS `select' call. 
    */
  int i;
  VMS_PROC_STUFF *vs;

  for (i=1, vs = procList; i<MAX_EVENT_FLAGS; i++, vs++)
    {
      if (!vs->busy)
	{
	  vs->busy = 1;
	  vs->inputChan = 0;
	  vs->pid = 0;
	  sys$clref (vs->eventFlag);
	  return (vs);
	}
    }
  return ((VMS_PROC_STUFF *)0);
}
Exemplo n.º 3
0
static void
waitTime (
  pwr_tTime		*t
)
{
  pwr_tStatus		sts;
  pwr_tTime		now;
  pwr_tTime		then = *t;
  char tims[24];
  short len;
  struct dsc$descriptor_s tims_desc = {
    sizeof(tims)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,};

#if 0
  subTime(&then, nowTime(&now));
#endif

  if ((int)then.tv_sec > 0 || ((int)then.tv_sec == 0 && then.tv_nsec > 0)) {
#if defined OS_VMS || defined OS_ELN
    int			tv_nsec;
    int			vmstime[2];
    int			multiplier = -10000000;	      /* Used to convert 1 s to 100 ns, delta time.  */
    static pwr_tTime	tick = {0, 10000000};

    addTime(&then, &tick);
    tv_nsec = -then.tv_nsec/100;   /* Convert to 100 ns.  */
    sts = lib$emul(&then.tv_sec, &multiplier, &tv_nsec, vmstime);

#if defined OS_VMS
    tims_desc.dsc$a_pointer = tims;
    sys$asctim( &len, &tims_desc, vmstime, 0);
    tims[len] = '\0';
    printf("  %s\n", tims);
#if 0
    sts = sys$clref(timerFlag);
    sts = sys$setimr(timerFlag, vmstime, 0, 0, 0);
    sts = sys$waitfr(timerFlag);
#endif
#elif defined OS_ELN
    eln$time_string(tims, vmstime);
    tims[23] = '\0';
    printf("  %s\n", tims);
#if 0
    ker$wait_any(&sts, NULL, vmstime);
#endif
#endif

#elif defined OS_LYNX
    pwr_tTime rmt;

    nanosleep(&then, &rmt);
#endif
  }
}
Exemplo n.º 4
0
static int exe$synch(unsigned int efn, struct _iosb *iosb)
{
    if (!iosb)
    {
        sys$waitfr(efn);
        return SS$_NORMAL;
    }
    if (iosb->iosb$w_status)
    {
        return SS$_NORMAL;
    }
again:
    sys$waitfr(efn);
    if (iosb->iosb$w_status & 0xff)
        return iosb->iosb$w_status;
    sys$clref(efn);
    goto again;
}
Exemplo n.º 5
0
pwr_tBoolean
sect_InitLock (
  pwr_tStatus		*sts,
  sect_sHead		*shp,
  sect_sMutex		*mp
)
{
  pwr_tStatus		lsts = 1;

#ifdef	OS_ELN
  ELN$INITIALIZE_AREA_LOCK((AREA)shp->area, *mp, &lsts);

#elif defined(OS_VMS)
  {
    pwr_tUInt32		i;

    /* Clear mutex variable and build free list.  */

    memset(mp, 0, sizeof(*mp));
    lsts = sys$ascefc(64, &shp->namedsc, 0, 0);
    if (ODD(lsts)) {
      for (i=0; i<32; i++) {
	while (_INSQTI(&mp->list[i].entry, &mp->freeroot) == 1);
	mp->list[i].flag = 64+i;
	lsts = sys$clref(mp->list[i].flag);
	if (EVEN(lsts)) break;
      }
    }
  }

#elif defined(OS_LYNX)
  if (sem_init(mp, 1, 1) != 0) {
    errh_Error("sect_InitLock: sem_init, errno: %d", errno);
    lsts = 2;
  }
#elif defined OS_POSIX
  if (posix_sem_init_shared(mp, ftok(shp->name, 'P'), 1) != 0) {
    errh_Error("sect_InitLock: sem_init(%s), errno: %d", shp->name, errno);
    lsts = 2;
  }  
#endif

  errh_ReturnOrBugcheck(ODD(lsts), sts, lsts, "");
}
Exemplo n.º 6
0
asmlinkage int exe$setimr  (unsigned int efn, signed long long *daytim,
                            void (*astadr)(long), unsigned
                            long reqidt, unsigned int flags)
{
    unsigned long long time;
    /** test time location - MISSING */
    /** test astcnt - MISSING */
    /** decrement jib tqcnt, test and maybe MWAIT - MISSING */
    /** allocate tqe */
    struct _tqe * t=kmalloc(sizeof(struct _tqe),GFP_KERNEL);
    struct _cpu * cpu=smp$gl_cpu_data[smp_processor_id()];
    memset(t,0,sizeof(struct _tqe));
    t->tqe$b_type=DYN$C_TQE;
    /** clear event flag */
    exe$clref(efn);
    /** fifth nonzero argument test */
    /** wrong use TODO use chk_cputim field */
    if (flags) t->tqe$b_rqtype=TQE$M_CHK_CPUTIM;
    if (!daytim) return SS$_ACCVIO;
    /** if negative, then relative time */
    /** set absolute bit - MISSING */
    if (*daytim<0)
    {
        time=exe$gq_systime-*daytim;
    }
    else
    {
        time=*daytim;
    }
    //printk("astadr %x\n",astadr);
    /** store access mode in tqe - MISSING */
    /** if no astadr, decrease astcnt and set quota bit - MISSING */
    t->tqe$l_ast=astadr;
    //  printk("astadr2 %x\n",t->tqe$l_fpc);
    t->tqe$l_astprm=reqidt;
    t->tqe$q_time=time;
    t->tqe$b_rqtype=TQE$C_TMSNGL;
    t->tqe$l_pid=ctl$gl_pcb->pcb$l_pid;
    t->tqe$b_efn=efn;
    //printast((struct _acb * )t);
    /** insert in timer queue */
    exe$instimq(t);
}
Exemplo n.º 7
0
void  term_setup(bool ctrlc_enable)

{
	uint4	status;
	io_terminator   outofbands;

	status = sys$clref(efn_outofband);
	assert(status == SS$_WASSET || status == SS$_WASCLR);
	outofband = 0;

	if (io_std_device.in->type == tt)
	{
		ctrlc_on = ctrlc_enable ;
		if (ctrlc_on)
			std_dev_outofband_msk |= CTRLC_MSK;
		iott_resetast(io_std_device.in);
	}else
		ctrlc_on = FALSE;
}
Exemplo n.º 8
0
/*
 * plc_LoopWait()
 *
 * Description:
 *  Returns False if a slip is detected.
 *  The plc_sLoopWait structure must be initialized with a call to
 *  plc_LoopInit.
 */ 
pwr_tBoolean plc_LoopWait (
  plc_sLoopWait	  *p,
  unsigned int	  DeltaTime /* ms */
) {
  unsigned int Next, Tick, Seconds;
  pwr_tVaxTime    WaitTime;
  pwr_tUInt32  Diff;

  Next = p->LastLoop + DeltaTime / 10;
  if (Next < p->LastLoop)
    p->LoopOflw = 1;
  p->LastLoop = Next;
  
  plc_LoopGetVmsUpTime (&Seconds, &Tick);
  if (Tick < p->LastTick)
    p->TickOflw = 1;
  p->LastTick = Tick;

  /* Reset overflow flags if both flags have been set */
  if (p->LoopOflw && p->TickOflw)
    p->LoopOflw = p->TickOflw = 0; 
  

  /* Return if there is a slip */ 
  if (!p->LoopOflw && !p->TickOflw) {
    if (Tick > Next) 
      return FALSE;

  } else if (!p->LoopOflw && p->TickOflw) 
      return FALSE;


  Diff = (Next - Tick) * 10;	  /* ms */
  plc_ConvMSToLI(Diff, &WaitTime);
  sys$clref(p->TimerFlag);
  sys$setimr(p->TimerFlag, &WaitTime, 0, 0, 0);
  sys$waitfr(p->TimerFlag);

  return TRUE;  
}
Exemplo n.º 9
0
static void
waitClock (
  time_tClock		diff,
  int			*tmo_ms
)
{
#if defined OS_VMS || defined OS_ELN
    pwr_tStatus		sts;
    int			sec;
    int			nsec;
    int			vmstime[2];
    int			multiplier = -10000000;	      /* Used to convert 1 s to 100 ns, delta time.  */

    sec = diff / CLK_TCK;
    nsec = - (diff % CLK_TCK * 10000000 / CLK_TCK);   /* Convert to 100 ns.  */
    sts = lib$emul(&sec, &multiplier, &nsec, vmstime);

# if defined OS_VMS
    sts = sys$clref(timer_flag);
    sts = sys$setimr(timer_flag, vmstime, 0, 0, 0);
    sts = sys$waitfr(timer_flag);
# elif defined OS_ELN
    ker$wait_any(&sts, NULL, vmstime);
# endif

#elif defined OS_POSIX
//    pwr_tTime  rmt;
//    pwr_tTime  wait;
    static int tics_per_sec = 0;

    if (tics_per_sec == 0) {
      tics_per_sec = sysconf(_SC_CLK_TCK);
    }
//    printf("waitClock: %d\n", diff);
//    time_ClockToD(NULL, (pwr_tDeltaTime *)&wait, diff);
    *tmo_ms = diff * 1000 / tics_per_sec;
//    *tmo_ms = wait.tv_sec * 1000 + wait.tv_nsec / 1000000;
//    nanosleep(&wait, &rmt);
#endif
}
Exemplo n.º 10
0
int
child_execute_job (char *argv, struct child *child)
{
  int i;
  static struct dsc$descriptor_s cmddsc;
  static struct dsc$descriptor_s pnamedsc;
  static struct dsc$descriptor_s ifiledsc;
  static struct dsc$descriptor_s ofiledsc;
  static struct dsc$descriptor_s efiledsc;
  int have_redirection = 0;
  int have_append = 0;
  int have_newline = 0;

  int spflags = CLI$M_NOWAIT;
  int status;
  char *cmd = alloca (strlen (argv) + 512), *p, *q;
  char ifile[256], ofile[256], efile[256];
  int comnamelen;
  char procname[100];
  int in_string;

  /* Parse IO redirection.  */

  ifile[0] = 0;
  ofile[0] = 0;
  efile[0] = 0;
  child->comname = NULL;

  DB (DB_JOBS, ("child_execute_job (%s)\n", argv));

  while (isspace ((unsigned char)*argv))
    argv++;

  if (*argv == 0)
    return 0;

  sprintf (procname, "GMAKE_%05x", getpid () & 0xfffff);
  pnamedsc.dsc$w_length = strlen(procname);
  pnamedsc.dsc$a_pointer = procname;
  pnamedsc.dsc$b_dtype = DSC$K_DTYPE_T;
  pnamedsc.dsc$b_class = DSC$K_CLASS_S;

  in_string = 0;
  /* Handle comments and redirection. */
  for (p = argv, q = cmd; *p; p++, q++)
    {
      if (*p == '"')
        in_string = !in_string;
      if (in_string)
        {
          *q = *p;
          continue;
        }
      switch (*p)
        {
        case '#':
          *p-- = 0;
          *q-- = 0;
          break;
        case '\\':
          p++;
          if (*p == '\n')
            p++;
          if (isspace ((unsigned char)*p))
            {
              do { p++; } while (isspace ((unsigned char)*p));
              p--;
            }
          *q = *p;
          break;
        case '<':
          p = vms_redirect (&ifiledsc, ifile, p);
          *q = ' ';
          have_redirection = 1;
          break;
        case '>':
          have_redirection = 1;
          if (*(p-1) == '2')
            {
              q--;
              if (strncmp (p, ">&1", 3) == 0)
                {
                  p += 3;
                  strcpy (efile, "sys$output");
                  efiledsc.dsc$w_length = strlen(efile);
                  efiledsc.dsc$a_pointer = efile;
                  efiledsc.dsc$b_dtype = DSC$K_DTYPE_T;
                  efiledsc.dsc$b_class = DSC$K_CLASS_S;
                }
              else
                  p = vms_redirect (&efiledsc, efile, p);
            }
          else
            {
              if (*(p+1) == '>')
                {
                  have_append = 1;
                  p += 1;
                }
              p = vms_redirect (&ofiledsc, ofile, p);
            }
          *q = ' ';
          break;
        case '\n':
          have_newline = 1;
        default:
          *q = *p;
          break;
        }
    }
  *q = *p;
  while (isspace ((unsigned char)*--q))
    *q = '\0';

  if (strncmp (cmd, "builtin_", 8) == 0)
    {
      child->pid = 270163;
      child->efn = 0;
      child->cstatus = 1;

      DB (DB_JOBS, (_("BUILTIN [%s][%s]\n"), cmd, cmd+8));

      p = cmd + 8;

      if ((*(p) == 'c')
          && (*(p+1) == 'd')
          && ((*(p+2) == ' ') || (*(p+2) == '\t')))
        {
          p += 3;
          while ((*p == ' ') || (*p == '\t'))
            p++;
          DB (DB_JOBS, (_("BUILTIN CD %s\n"), p));
          if (chdir (p))
            return 0;
          else
            return 1;
        }
      else if ((*(p) == 'r')
               && (*(p+1) == 'm')
               && ((*(p+2) == ' ') || (*(p+2) == '\t')))
        {
          int in_arg;

          /* rm  */
          p += 3;
          while ((*p == ' ') || (*p == '\t'))
            p++;
          in_arg = 1;

          DB (DB_JOBS, (_("BUILTIN RM %s\n"), p));
          while (*p)
            {
              switch (*p)
                {
                case ' ':
                case '\t':
                  if (in_arg)
                    {
                      *p++ = ';';
                      in_arg = 0;
                    }
                  break;
                default:
                  break;
                }
              p++;
            }
        }
      else
        {
          printf (_("Unknown builtin command '%s'\n"), cmd);
          fflush (stdout);
          return 0;
        }
    }

  /* Create a *.com file if either the command is too long for
     lib$spawn, or the command contains a newline, or if redirection
     is desired. Forcing commands with newlines into DCLs allows to
     store search lists on user mode logicals.  */

  if (strlen (cmd) > MAXCMDLEN
      || (have_redirection != 0)
      || (have_newline != 0))
    {
      FILE *outfile;
      char c;
      char *sep;
      int alevel = 0;   /* apostrophe level */

      if (strlen (cmd) == 0)
        {
          printf (_("Error, empty command\n"));
          fflush (stdout);
          return 0;
        }

      outfile = output_tmpfile (&child->comname, "sys$scratch:CMDXXXXXX.COM");
      if (outfile == 0)
        pfatal_with_name (_("fopen (temporary file)"));
      comnamelen = strlen (child->comname);

      if (ifile[0])
        {
          fprintf (outfile, "$ assign/user %s sys$input\n", ifile);
          DB (DB_JOBS, (_("Redirected input from %s\n"), ifile));
          ifiledsc.dsc$w_length = 0;
        }

      if (efile[0])
        {
          fprintf (outfile, "$ define sys$error %s\n", efile);
          DB (DB_JOBS, (_("Redirected error to %s\n"), efile));
          efiledsc.dsc$w_length = 0;
        }

      if (ofile[0])
        if (have_append)
          {
            fprintf (outfile, "$ set noon\n");
            fprintf (outfile, "$ define sys$output %.*s\n", comnamelen-3, child->comname);
            DB (DB_JOBS, (_("Append output to %s\n"), ofile));
            ofiledsc.dsc$w_length = 0;
          }
        else
          {
            fprintf (outfile, "$ define sys$output %s\n", ofile);
            DB (DB_JOBS, (_("Redirected output to %s\n"), ofile));
            ofiledsc.dsc$w_length = 0;
          }

      p = sep = q = cmd;
      for (c = '\n'; c; c = *q++)
        {
          switch (c)
            {
            case '\n':
              /* At a newline, skip any whitespace around a leading $
                 from the command and issue exactly one $ into the DCL. */
              while (isspace ((unsigned char)*p))
                p++;
              if (*p == '$')
                p++;
              while (isspace ((unsigned char)*p))
                p++;
              fwrite (p, 1, q - p, outfile);
              fputc ('$', outfile);
              fputc (' ', outfile);
              /* Reset variables. */
              p = sep = q;
              break;

              /* Nice places for line breaks are after strings, after
                 comma or space and before slash. */
            case '"':
              q = vms_handle_apos (q);
              sep = q;
              break;
            case ',':
            case ' ':
              sep = q;
              break;
            case '/':
            case '\0':
              sep = q - 1;
              break;
            default:
              break;
            }
          if (sep - p > 78)
            {
              /* Enough stuff for a line. */
              fwrite (p, 1, sep - p, outfile);
              p = sep;
              if (*sep)
                {
                  /* The command continues.  */
                  fputc ('-', outfile);
                }
              fputc ('\n', outfile);
            }
        }

      if (*p)
        {
          fwrite (p, 1, --q - p, outfile);
          fputc ('\n', outfile);
        }

      if (have_append)
        {
          fprintf (outfile, "$ deassign sys$output ! 'f$verify(0)\n");
          fprintf (outfile, "$ append:=append\n");
          fprintf (outfile, "$ delete:=delete\n");
          fprintf (outfile, "$ append/new %.*s %s\n", comnamelen-3, child->comname, ofile);
          fprintf (outfile, "$ delete %.*s;*\n", comnamelen-3, child->comname);
          DB (DB_JOBS, (_("Append %.*s and cleanup\n"), comnamelen-3, child->comname));
        }

      fclose (outfile);

      sprintf (cmd, "$ @%s", child->comname);

      DB (DB_JOBS, (_("Executing %s instead\n"), cmd));
    }

  cmddsc.dsc$w_length = strlen(cmd);
  cmddsc.dsc$a_pointer = cmd;
  cmddsc.dsc$b_dtype = DSC$K_DTYPE_T;
  cmddsc.dsc$b_class = DSC$K_CLASS_S;

  child->efn = 0;
  while (child->efn < 32 || child->efn > 63)
    {
      status = lib$get_ef ((unsigned long *)&child->efn);
      if (!(status & 1))
        {
          if (child->comname)
            {
              if (!ISDB (DB_JOBS))
                unlink (child->comname);
              free (child->comname);
            }
          return 0;
        }
    }

  sys$clref (child->efn);

  vms_jobsefnmask |= (1 << (child->efn - 32));

  /*
    LIB$SPAWN  [command-string]
    [,input-file]
    [,output-file]
    [,flags]
    [,process-name]
    [,process-id] [,completion-status-address] [,byte-integer-event-flag-num]
    [,AST-address] [,varying-AST-argument]
    [,prompt-string] [,cli] [,table]
  */

#ifndef DONTWAITFORCHILD
  /*
   * Code to make ctrl+c and ctrl+y working.
   * The problem starts with the synchronous case where after lib$spawn is
   * called any input will go to the child. But with input re-directed,
   * both control characters won't make it to any of the programs, neither
   * the spawning nor to the spawned one. Hence the caller needs to spawn
   * with CLI$M_NOWAIT to NOT give up the input focus. A sys$waitfr
   * has to follow to simulate the wanted synchronous behaviour.
   * The next problem is ctrl+y which isn't caught by the crtl and
   * therefore isn't converted to SIGQUIT (for a signal handler which is
   * already established). The only way to catch ctrl+y, is an AST
   * assigned to the input channel. But ctrl+y handling of DCL needs to be
   * disabled, otherwise it will handle it. Not to mention the previous
   * ctrl+y handling of DCL needs to be re-established before make exits.
   * One more: At the time of LIB$SPAWN signals are blocked. SIGQUIT will
   * make it to the signal handler after the child "normally" terminates.
   * This isn't enough. It seems reasonable for simple command lines like
   * a 'cc foobar.c' spawned in a subprocess but it is unacceptable for
   * spawning make. Therefore we need to abort the process in the AST.
   *
   * Prior to the spawn it is checked if an AST is already set up for
   * ctrl+y, if not one is set up for a channel to SYS$COMMAND. In general
   * this will work except if make is run in a batch environment, but there
   * nobody can press ctrl+y. During the setup the DCL handling of ctrl+y
   * is disabled and an exit handler is established to re-enable it.
   * If the user interrupts with ctrl+y, the assigned AST will fire, force
   * an abort to the subprocess and signal SIGQUIT, which will be caught by
   * the already established handler and will bring us back to common code.
   * After the spawn (now /nowait) a sys$waitfr simulates the /wait and
   * enables the ctrl+y be delivered to this code. And the ctrl+c too,
   * which the crtl converts to SIGINT and which is caught by the common
   * signal handler. Because signals were blocked before entering this code
   * sys$waitfr will always complete and the SIGQUIT will be processed after
   * it (after termination of the current block, somewhere in common code).
   * And SIGINT too will be delayed. That is ctrl+c can only abort when the
   * current command completes. Anyway it's better than nothing :-)
   */

  if (!setupYAstTried)
    tryToSetupYAst();
  status = lib$spawn (&cmddsc,                                  /* cmd-string */
                      (ifiledsc.dsc$w_length == 0)?0:&ifiledsc, /* input-file */
                      (ofiledsc.dsc$w_length == 0)?0:&ofiledsc, /* output-file */
                      &spflags,                                 /* flags */
                      &pnamedsc,                                /* proc name */
                      &child->pid, &child->cstatus, &child->efn,
                      0, 0,
                      0, 0, 0);
  if (status & 1)
    {
      status= sys$waitfr (child->efn);
      vmsHandleChildTerm(child);
    }
#else
  status = lib$spawn (&cmddsc,
                      (ifiledsc.dsc$w_length == 0)?0:&ifiledsc,
                      (ofiledsc.dsc$w_length == 0)?0:&ofiledsc,
                      &spflags,
                      &pnamedsc,
                      &child->pid, &child->cstatus, &child->efn,
                      vmsHandleChildTerm, child,
                      0, 0, 0);
#endif

  if (!(status & 1))
    {
      printf (_("Error spawning, %d\n") ,status);
      fflush (stdout);
      switch (status)
        {
        case 0x1c:
          errno = EPROCLIM;
          break;
        default:
          errno = EFAIL;
        }
    }

  return (status & 1);
}
Exemplo n.º 11
0
asmlinkage int exe$enq(unsigned int efn, unsigned int lkmode, struct _lksb *lksb, unsigned int flags, void *resnam, unsigned int parid, void (*astadr)(), unsigned long astprm, void (*blkastadr)(), unsigned int acmode, unsigned int rsdm_id) {
  int convert;
  int retval=SS$_NORMAL;
  int sts;

  // some tests. one only for now, should be more.
  if (lkmode>LCK$K_EXMODE) return SS$_BADPARAM;

  vmslock(&SPIN_SCS,IPL$_SCS); // check. probably too early
  convert=flags&LCK$M_CONVERT;
  if (!convert) {
    /* new lock */
    struct _rsb * res = 0;
    struct _rsb * old;
    struct _lkb * lck = 0, *par = 0;
    struct dsc$descriptor * resnamdsc;
    int sserror=0;

    resnamdsc=resnam;
    if (resnamdsc->dsc$w_length==0 || resnamdsc->dsc$w_length>RSB$K_MAXLEN) { 
      sserror=SS$_IVBUFLEN;
      goto error;
    }
    if (flags&LCK$M_EXPEDITE)
      if (lkmode!=LCK$K_NLMODE) {
	sserror=SS$_UNSUPPORTED;
	goto error;
      }

    if (lkmode!=LCK$K_NLMODE) {
      sserror=SS$_UNSUPPORTED;
      goto error;
    }

    res=kmalloc(sizeof(struct _rsb),GFP_KERNEL);
    memset(res,0,sizeof(struct _rsb));
    lck=kmalloc(sizeof(struct _lkb),GFP_KERNEL);
    memset(lck,0,sizeof(struct _lkb));

    lck->lkb$b_efn=efn;
    lck->lkb$l_flags=flags;
    lck->lkb$b_rqmode=lkmode;
    lck->lkb$l_cplastadr=astadr;
    lck->lkb$l_blkastadr=blkastadr;
    lck->lkb$l_astprm=astprm;
    lck->lkb$l_pid=current->pcb$l_pid;
    lck->lkb$l_lksb=lksb;
    qhead_init(&lck->lkb$l_sqfl);
    qhead_init(&lck->lkb$l_ownqfl);

    strncpy(res->rsb$t_resnam,resnamdsc->dsc$a_pointer,resnamdsc->dsc$w_length);
    res->rsb$b_rsnlen=resnamdsc->dsc$w_length;

    setipl(IPL$_SCS);
    // do scs spinlock
    //setipl(IPL$_ASTDEL);

    if (flags&LCK$M_SYSTEM) {
      /* priv checks */
    } else {
	
    }

    if (parid==0) {
      //list_add(&res->lr_childof, &ns->ns_root_list);
      //this is added to lck$gl_rrsfl down below, I think
    } else {
      //check valid lock
      // check lock access mode
      par=lockidtbl[parid];
      if (current->pcb$l_pid != par->lkb$l_pid) {
	vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
	return SS$_IVLOCKID;
      }
      //check if parent granted, if not return SS$_PARNOTGRANT;
      if (par->lkb$b_state!=LKB$K_CONVERT  || par->lkb$b_state!=LKB$K_GRANTED) 
	if ((par->lkb$l_flags & LCK$M_CONVERT) == 0) {
	    vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
	    return SS$_PARNOTGRANT;
	}
      par->lkb$w_refcnt++;
      res->rsb$l_parent = par->lkb$l_rsb; // should not be here?
      //check if uic-specific resource
      //check if system-wide
      //charge lock against quota
      //list_add(&res->lr_childof, &parent->lr_children);
      //res->rsb$l_rtrsb=enq_find_oldest_parent(r,p->lkb$l_rsb);
      lck->lkb$l_parent=par;
    }

    old=find_reshashtbl(resnamdsc);
    if (!old) {
      lck$gl_rsbcnt++;
      lck$gl_lckcnt++;
      if (flags & LCK$M_SYNCSTS) retval=SS$_SYNCH;
      qhead_init(&res->rsb$l_grqfl);
      qhead_init(&res->rsb$l_cvtqfl);
      qhead_init(&res->rsb$l_wtqfl);
      //insque(&lck->lkb$l_sqfl,res->rsb$l_grqfl);
      lck->lkb$l_rsb=res;
      insert_reshashtbl(res);
      if (parid==0) {
	insque(&res->rsb$l_rrsfl,lck$gl_rrsfl);
	qhead_init(&res->rsb$l_srsfl);
	res->rsb$b_depth=0;
	res->rsb$l_rtrsb=res;
	exe$clref(lck->lkb$b_efn);
	insque(&lck->lkb$l_ownqfl,&current->pcb$l_lockqfl);
	//?if (q->flags & LKB$M_DCPLAST) 
	
	lksb->lksb$l_lkid=insert_lck(lck);
	lksb->lksb$w_status=SS$_NORMAL;
	
	sts = lck$grant_lock(lck ,res ,-1,lkmode,flags,efn,res->rsb$b_ggmode);

	goto end;
      } else {
	// it has a parid non-zero
	res->rsb$l_csid=par->lkb$l_rsb->rsb$l_csid;
	par->lkb$l_rsb->rsb$w_refcnt++;
	res->rsb$b_depth=par->lkb$l_rsb->rsb$b_depth+1;
	//check maxdepth
	if (res->rsb$b_depth>10) { // pick a number ?
	  retval=SS$_EXDEPTH;
	  goto error;
	}
	res->rsb$l_rtrsb=par->lkb$l_rsb->rsb$l_rtrsb;
	insque(&res->rsb$l_srsfl,&par->lkb$l_rsb->rsb$l_srsfl);
	if (par->lkb$l_csid) { //remote
	  lck$snd_granted(lck);
	} else {
	  sts = lck$grant_lock(lck,res,-1,lkmode,flags,efn,res->rsb$b_ggmode);
	}
      }
    } else {
      /* old, found in resource hash table */
      /* something else? */
      int granted = 0;
      if (flags & LCK$M_SYNCSTS) retval=SS$_SYNCH;
      kfree(res);
      res=old;
      lck->lkb$l_rsb=res;

      //after, also check whether something in cvtqfl or wtqfl -> insque wtqfl

      if (0!=test_bit(res->rsb$b_ggmode,&lck$ar_compat_tbl[lck->lkb$b_rqmode])) {
	if (aqempty(res->rsb$l_wtqfl)) {
	  granted=1;
	  //sts = lck$grant_lock(lck ,res ,-1,lkmode,flags,efn);
	} else {
	  if (flags&LCK$M_NOQUEUE) {
	    res->rsb$w_lckcnt--;
	    kfree(lck);
	    vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
	    return SS$_NOTQUEUED;
	  } else {
	    lck->lkb$b_state=LKB$K_WAITING;
	    insque(&lck->lkb$l_sqfl,res->rsb$l_wtqfl);
	    lksb->lksb$w_status=0;
	    lck->lkb$l_status|=LKB$M_ASYNC;
	    maybe_blkast(res,lck);
	  }
	}
      } else {
	// if not compatible
	if (flags&LCK$M_NOQUEUE) {
	  res->rsb$w_lckcnt--;
	  kfree(lck);
	  vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
	  return SS$_NOTQUEUED;
	} else {
	  lck->lkb$b_state=LKB$K_WAITING;
	  insque(&lck->lkb$l_sqfl,res->rsb$l_wtqfl);
	  lksb->lksb$w_status=0;
	  lck->lkb$l_status|=LKB$M_ASYNC;
	  maybe_blkast(res,lck);
	  // insque(&lck->lkb$l_ownqfl,&current->pcb$l_lockqfl);
	}
      }

      lksb->lksb$l_lkid=insert_lck(lck);
      lksb->lksb$w_status=SS$_NORMAL;

      if ((granted & 1)==1) {
	if (0/*par->lkb$l_csid*/) { //remote
	  lck$snd_granted(lck);
	} else {
	  sts = lck$grant_lock(lck, res, -1,lkmode,flags,efn,res->rsb$b_ggmode);
	}
      }
    }
  end:
    /* raise ipl */
    vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
    return retval;
  error:
    /* ipl back */
    kfree(res);
    kfree(lck);
    vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
    return sserror;
    
  } else { // convert
    /* convert */
    int granted = 0, newmodes = 0;
    struct _lkb * lck;
    struct _rsb * res;
    void * dummy;
    int newmode;
    lck=lockidtbl[lksb->lksb$l_lkid];
    res=lck->lkb$l_rsb;
    if (lck->lkb$b_state!=LKB$K_GRANTED) {
      vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
      return SS$_CVTUNGRANT;
    }
    lck->lkb$b_efn=efn;
    lck->lkb$l_flags=flags;
    lck->lkb$b_rqmode=lkmode;
    lck->lkb$l_cplastadr=astadr;
    lck->lkb$l_blkastadr=blkastadr;
    lck->lkb$l_astprm=astprm;
    lck->lkb$l_lksb=lksb;
    remque(&lck->lkb$l_sqfl,&lck->lkb$l_sqfl);// ?
    //remque(&res->rsb$l_grqfl,dummy); // superfluous
    if (aqempty(res->rsb$l_cvtqfl) && aqempty(res->rsb$l_grqfl)) {
      sts = lck$grant_lock(lck ,res,lck->lkb$b_grmode,lkmode,flags,efn,-1);
      vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
      return SS$_NORMAL;
    } else { // convert, something in cvtqfl or grqfl
      if (res->rsb$b_cgmode!=lck->lkb$b_grmode) {
	newmode=res->rsb$b_ggmode;
      } else {
	newmode=find_highest(lck,res);
	newmodes= 0;
      }
      if (test_bit(lkmode,&lck$ar_compat_tbl[newmode])) {
	//sts = lck$grant_lock(lck,res,lck->lkb$b_grmode,lkmode,flags,efn);
	granted = 1;
      }
    }

    if (granted) {
      if (newmodes) {
	res->rsb$b_fgmode=newmode;
	res->rsb$b_ggmode=newmode;
	res->rsb$b_cgmode=newmode;
      }
      sts = lck$grant_lock(lck,res,lck->lkb$b_grmode,lkmode /*newmode*/,flags,efn,res->rsb$b_ggmode);
      grant_queued(res,newmode,1,1);
    } else {
      int wasempty=aqempty(&res->rsb$l_cvtqfl);
      lck->lkb$b_rqmode=lkmode;
      insque(&lck->lkb$l_sqfl,res->rsb$l_cvtqfl);
      lck->lkb$b_state=LKB$K_CONVERT;
      lksb->lksb$w_status=0;
      lck->lkb$l_status|=LKB$M_ASYNC;
      maybe_blkast(res,lck);
      if (wasempty)
	res->rsb$b_cgmode=newmode;
      sts=SS$_NORMAL;
    }
    vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
    return sts;
  }
  vmsunlock(&SPIN_SCS,IPL$_ASTDEL);
}
Exemplo n.º 12
0
/* ------------------------------------------------------------------
 * Reset transfer table to normal settings.
 *
 * - Intent: Put back all state that was or could have been changed
 *   due to prior deferral(s).
 *    - Would be easier to implement this assumption if this routine
 *      were changed to delegate responsibility as does the
 *      corresponding set routine.
 * - Note that all events are reenabled before user's handler
 *   would be executed (assuming one is appropriate for this event
 *   and has been specified)
 *    => It's possible to have handler-in-handler execution.
 *    => If no handler executed, would lose other deferred events due
 *       to reset of all pending.
 * - If M profiling is active, some entries should be set to the
 *       op_mprof* routines.
 * - Return value indicates whether reset type matches set type.
 *   If it does not, this indicates an "abnormal" path.
 *    - Should still reset the table in this case.
 *    - BUT: Consider also calling a reset routine for all setters
 *      that have been logged, to allow them to reset themselves,
 *      (for example, to reset TP timer & flags, or anything else
 *      that could cause unintended effects if left set after
 *      deferred events have been cleared).
 * - May need to update behavior to ensure it doesn't miss a
 *   critical event between registration of first event
 *   and clearing of all events. This seems problematic only if
 *   the following are true:
 *    - Two events are deferred at one time (call them A and B).
 *    - An M exception handler (ZTRAP or device) is required to
 *      execute due to B and perform action X.
 *    - Either no handler executes due to A, or the handler that
 *      does execute does not perform action X in response to B
 *      (this includes the possibility of performing X but not
 *       as needed by B, e.g. perhaps it should happen for both
 *       A and B but only happens for A).
 *   Seems like most or all of these can be addressed by carefully
 *   specifying coding requirements on M handlers.
 * ------------------------------------------------------------------
 */
boolean_t xfer_reset_handlers(int4 event_type)
{
	int4		e_type;
	boolean_t	reset_type_is_set_type;
	int4		status;
	int 		e, ei, e_tot = 0;

	/* ------------------------------------------------------------------
	 * Note: If reset routine can preempt path from handler to
	 * set routine (e.g. clearing event before acting on it),
	 * these assertions can fail.
	 * Should not happen in current design.
	 * ------------------------------------------------------------------
	 */
	assert(0 < num_deferred);
	assert(0 < xfer_table_events[event_type]);
	if (is_tracing_on)
	{
		FIX_XFER_ENTRY(xf_linefetch, op_mproflinefetch);
		FIX_XFER_ENTRY(xf_linestart, op_mproflinestart);
		FIX_XFER_ENTRY(xf_forchk1, op_mprofforchk1);
	} else
	{
		FIX_XFER_ENTRY(xf_linefetch, op_linefetch);
		FIX_XFER_ENTRY(xf_linestart, op_linestart);
		FIX_XFER_ENTRY(xf_forchk1, op_forchk1);
	}
	FIX_XFER_ENTRY(xf_forloop, op_forloop);
	FIX_XFER_ENTRY(xf_zbfetch, op_zbfetch);
	FIX_XFER_ENTRY(xf_zbstart, op_zbstart);
	FIX_XFER_ENTRY(xf_ret, opp_ret);
	FIX_XFER_ENTRY(xf_retarg, op_retarg);
	DBGDFRDEVNT((stderr, "xfer_reset_handlers: Reset xfer_table for event type %d.\n", event_type));
	reset_type_is_set_type =  (event_type == first_event);
#	ifdef DEBUG
	if (!reset_type_is_set_type)
 		rts_error(VARLSTCNT(4) ERR_DEFEREVENT, 2, event_type, first_event);
#	endif

#	ifdef DEBUG_DEFERRED_EVENT
	/* Note: concurrent modification of array elements means events that occur during this section will
	 * cause inconsistent totals.
	 */
	for (ei = no_event; ei < DEFERRED_EVENTS; ei++)
		e_tot += xfer_table_events[ei];
	if (1 < e_tot)
	{
		DBGDFRDEVNT((stderr, "xfer_reset_handlers: Event Log:\n"));
		for (ei=no_event; ei<DEFERRED_EVENTS; ei++)
			DBGDFRDEVNT((stderr, "xfer_reset_handlers:   Event type %d: count was %d.\n",
				     ei, xfer_table_events[ei]));
	}
#	endif

	/* -------------------------------------------------------------------------
	 * Kluge(?): set all locations to nonzero value to
	 * prevent interleaving with reset activities.
	 *
	 * Would be better to aswp with 0:
	 * - Won't lose any new events that way.
	 * -------------------------------------------------------------------------
	 */
	for (e_type = 1; DEFERRED_EVENTS > e_type; e_type++)
	{
		xfer_table_events[e_type] = 1;
	}

	/* -------------------------------------------------------------------------
	 * Reset external event modules that need it.
	 * (Should do this in a more modular fashion.)
	 * None
	 * -------------------------------------------------------------------------
	 */

	/* --------------------------------------------
	 * Reset private variables.
	 * --------------------------------------------
	 */
	first_event = no_event;
	num_deferred = 0;
	ctrap_action_is = 0;
	outofband = 0;
#	ifdef VMS
	status = sys$clref(efn_outofband);
	assert(SS$_WASSET == status);
	assertpro((SS$_WASSET == status) || (SS$_WASCLR == status));
#	endif
	/* ******************************************************************
	 * There is a race here:
	 * If a new event interrupts after previous line and before
	 * corresponding assignment in next loop, it will be missed.
	 * For most events, we're going to an M handler anyway, so it won't
	 * matter (assuming the handler would handle all pending events).
	 * But if not going to an M handler (e.g. if resetting zbreak/zstep),
	 * could miss another event.
	 *
	 * Better (to avoid missing any events):
	 *      aswp xfer_table_events elements (as described above), and
	 * check here if still zero. If not, must have missed that event
	 * since aswp, possibly before num_deferred was reset => never set
	 * xfer_table => should do that now.
	 *      If more than one is nonzero, choose first arbitrarily
	 * unless first_event is now set -- unless it is, we've lost track of
	 * which event was first.
	 * ******************************************************************
	 */
	/* Clear to allow new events to be reset only after we're all done. */
	for (e_type = 1; DEFERRED_EVENTS > e_type; e_type++)
		xfer_table_events[e_type] = FALSE;
	return reset_type_is_set_type;
}
Exemplo n.º 13
0
static int 
vms_ualarm(int mseconds, int interval)
{
    Alarm *a, abase;
    struct item_list3 {
        word length;
        word code;
        void *bufaddr;
        void *retlenaddr;
    } ;
    static struct item_list3 itmlst[2];
    static int first = 1;
    unsigned long asten;
    int iss, enabled;

    if (first) {
        first = 0;
        itmlst[0].code       = JPI$_ASTEN;
        itmlst[0].length     = sizeof(asten);
        itmlst[0].retlenaddr = NULL;
        itmlst[1].code       = 0;
        itmlst[1].length     = 0;
        itmlst[1].bufaddr    = NULL;
        itmlst[1].retlenaddr = NULL;

        iss = lib$get_ef(&alarm_ef);
        if (VMSERR(iss)) lib$signal(iss);

        a0 = &alarm_base;
        a0->function = UAL_NULL;
    }
    itmlst[0].bufaddr    = &asten;
    
    iss = sys$getjpiw(0,0,0,itmlst,0,0,0);
    if (VMSERR(iss)) lib$signal(iss);
    if (!(asten&0x08)) return -1;

    a = &abase;
    if (mseconds) {
        a->function = UAL_SET;
    } else {
        a->function = UAL_CLEAR;
    }

    us_to_VMS(mseconds, a->delay);
    if (interval) {
        us_to_VMS(interval, a->interval);
        a->repeat = 1;
    } else 
        a->repeat = 0;

    iss = sys$clref(alarm_ef);
    if (VMSERR(iss)) lib$signal(iss);

    iss = sys$dclast(ualarm_AST,a,0);
    if (VMSERR(iss)) lib$signal(iss);

    iss = sys$waitfr(alarm_ef);
    if (VMSERR(iss)) lib$signal(iss);

    if (a->function == UAL_ACTIVE) 
        return VMS_to_us(a->remain);
    else
        return 0;
}
Exemplo n.º 14
0
pwr_tUInt32 bck_WaitBackup (
		void *context,
		pwr_tBoolean timeout)
{
  pwr_tUInt32 sts;
  pwr_tObjid objid;
  pwr_tInt32 c;
  pwr_tTime t;
  pwr_tVaxTime tmo;
  pwr_tVaxTime tmptime;
  pwr_sClass_Backup_Conf *backup_confp;	/* Backup_Conf object pointer */
  $DESCRIPTOR (timeunitdsc, "0 0:0:0.1");	/* 0.1 second units */
  int cycletime;

#ifdef OS_ELN
  pwr_tInt32 res;
  pwr_tVaxTime *tmop;
#endif

#ifdef OS_VMS
  $DESCRIPTOR (efcname, BCK_EFC_NAME);
#endif

/*
 * Initialize
 */

#ifdef OS_ELN
  if (!areas_mapped) {
    BCK_MAP_AREAS;
    areas_mapped = TRUE;
  }
#endif

/*
 * Find the local Backup_Conf object
 */

  sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid);
  while (ODD (sts)) {
    sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp);
    if (ODD (sts)) break;
    sts = gdh_GetNextObject (objid, &objid);
  }
  if (EVEN (sts)) return sts;		/* Something wrong, quit */

/*
 * Pick up argument information
 */

  if (context == NULL) time_GetTime(&t);
  else {
    t = *(pwr_tTime *)context;
    free (context);
  }

#ifdef OS_ELN
  tmop = NULL;
#else
  timed_out = FALSE;  
  sts = sys$ascefc (BCK_EFC, &efcname, 0, 0);
  if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif

  if (timeout) {
    cycletime = backup_confp->CycleSlow * 2;
    if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2;

#ifdef OS_ELN
    tmo = eln$time_value (&timeunitdsc);
#else
    sts = sys$bintim (&timeunitdsc, &tmo);
    if (EVEN (sts)) lib$signal (sts);		/* BUG, should not happen */
#endif

    lib$mult_delta_time (
		&cycletime,		/* multiplier */
		&tmo);			/* delta_time (modified) */
    sys$gettim (&tmptime);
    lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */

#ifdef OS_ELN
    tmop = &tmo;
#else
    sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif
  }

/*
 * Loop, and wait for things to happen
 */

  while (TRUE) {
#ifdef OS_ELN
    ker$clear_event (NULL, bck_write_done);
    ker$wait_any (NULL, &res, tmop, bck_write_done);

    /* Check for timeout */

    if (res == 0) return SS$_TIMEOUT;
#else

    sts = sys$clref (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
    sts = sys$waitfr (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */

    /* Check for timeout */

    if (timed_out) return SS$_TIMEOUT;

#endif

    /* Check if both cycles done */

    if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) 
        continue;
    if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) 
        continue;

    break;

  } /* Loop */

#ifdef OS_VMS
  sys$cantim (4711, 0);
#endif

  return 1;	/* Done. */

} /* bck_WaitBackup */
Exemplo n.º 15
0
int
child_execute_job (char *argv, struct child *child)
{
  int i;
  static struct dsc$descriptor_s cmddsc;
  static struct dsc$descriptor_s pnamedsc;
  static struct dsc$descriptor_s ifiledsc;
  static struct dsc$descriptor_s ofiledsc;
  static struct dsc$descriptor_s efiledsc;
  int have_redirection = 0;
  int have_append = 0;
  int have_newline = 0;

  int spflags = CLI$M_NOWAIT;
  int status;
  char *cmd = alloca (strlen (argv) + 512), *p, *q;
  char ifile[256], ofile[256], efile[256];
  int comnamelen;
  char procname[100];
  int in_string;

  /* Parse IO redirection.  */

  ifile[0] = 0;
  ofile[0] = 0;
  efile[0] = 0;
  child->comname = NULL;

  DB (DB_JOBS, ("child_execute_job (%s)\n", argv));

  while (isspace ((unsigned char)*argv))
    argv++;

  if (*argv == 0)
    return 0;

  sprintf (procname, "GMAKE_%05x", getpid () & 0xfffff);
  pnamedsc.dsc$w_length = strlen(procname);
  pnamedsc.dsc$a_pointer = procname;
  pnamedsc.dsc$b_dtype = DSC$K_DTYPE_T;
  pnamedsc.dsc$b_class = DSC$K_CLASS_S;

  in_string = 0;
  /* Handle comments and redirection.
     For ONESHELL, the redirection must be on the first line. Any other
     redirection token is handled by DCL, that is, the pipe command with
     redirection can be used, but it should not be used on the first line
     for ONESHELL. */
  for (p = argv, q = cmd; *p; p++, q++)
    {
      if (*p == '"')
        in_string = !in_string;
      if (in_string)
        {
          *q = *p;
          continue;
        }
      switch (*p)
        {
        case '#':
          *p-- = 0;
          *q-- = 0;
          break;
        case '\\':
          p++;
          if (*p == '\n')
            p++;
          if (isspace ((unsigned char)*p))
            {
              do { p++; } while (isspace ((unsigned char)*p));
              p--;
            }
          *q = *p;
          break;
        case '<':
          if (have_newline==0)
            {
              p = vms_redirect (&ifiledsc, ifile, p);
              *q = ' ';
              have_redirection = 1;
            }
          else
            *q = *p;
          break;
        case '>':
          if (have_newline==0)
            {
              have_redirection = 1;
              if (*(p-1) == '2')
                {
                  q--;
                  if (strncmp (p, ">&1", 3) == 0)
                    {
                      p += 2;
                      strcpy (efile, "sys$output");
                      efiledsc.dsc$w_length = strlen(efile);
                      efiledsc.dsc$a_pointer = efile;
                      efiledsc.dsc$b_dtype = DSC$K_DTYPE_T;
                      efiledsc.dsc$b_class = DSC$K_CLASS_S;
                    }
                  else
                    p = vms_redirect (&efiledsc, efile, p);
                }
              else
                {
                  if (*(p+1) == '>')
                    {
                      have_append = 1;
                      p += 1;
                    }
                  p = vms_redirect (&ofiledsc, ofile, p);
                }
              *q = ' ';
            }
          else
            *q = *p;
          break;
        case '\n':
          have_newline++;
        default:
          *q = *p;
          break;
        }
    }
  *q = *p;
  while (isspace ((unsigned char)*--q))
    *q = '\0';


#define VMS_EMPTY_ECHO "write sys$output \"\""
  if (have_newline == 0)
    {
      /* multiple shells */
      if (strncmp(cmd, "builtin_", 8) == 0)
        {
          child->pid = 270163;
          child->efn = 0;
          child->cstatus = 1;

          DB(DB_JOBS, (_("BUILTIN [%s][%s]\n"), cmd, cmd + 8));

          p = cmd + 8;

          if ((*(p) == 'c') && (*(p + 1) == 'd')
              && ((*(p + 2) == ' ') || (*(p + 2) == '\t')))
            {
              p += 3;
              while ((*p == ' ') || (*p == '\t'))
                p++;
              DB(DB_JOBS, (_("BUILTIN CD %s\n"), p));
              if (chdir(p))
                return 0;
              else
                return 1;
            }
          else if ((*(p) == 'e')
              && (*(p+1) == 'c')
              && (*(p+2) == 'h')
              && (*(p+3) == 'o')
              && ((*(p+4) == ' ') || (*(p+4) == '\t') || (*(p+4) == '\0')))
            {
              /* This is not a real builtin, it is a built in pre-processing
                 for the VMS/DCL echo (write sys$output) to ensure the to be echoed
                 string is correctly quoted (with the DCL quote character '"'). */
              char *vms_echo;
              p += 4;
              if (*p == '\0')
                cmd = VMS_EMPTY_ECHO;
              else
                {
                  p++;
                  while ((*p == ' ') || (*p == '\t'))
                    p++;
                  if (*p == '\0')
                    cmd = VMS_EMPTY_ECHO;
                  else
                    {
                      vms_echo = alloca(strlen(p) + sizeof VMS_EMPTY_ECHO);
                      strcpy(vms_echo, VMS_EMPTY_ECHO);
                      vms_echo[sizeof VMS_EMPTY_ECHO - 2] = '\0';
                      strcat(vms_echo, p);
                      strcat(vms_echo, "\"");
                      cmd = vms_echo;
                    }
                }
              DB (DB_JOBS, (_("BUILTIN ECHO %s->%s\n"), p, cmd));
            }
          else
            {
              printf(_("Unknown builtin command '%s'\n"), cmd);
              fflush(stdout);
              return 0;
            }
        }
      /* expand ':' aka 'do nothing' builtin for bash and friends */
      else if (cmd[0]==':' && cmd[1]=='\0')
        {
          cmd = "continue";
        }
    }
  else
    {
      /* todo: expand ':' aka 'do nothing' builtin for bash and friends */
      /* For 'one shell' expand all the
           builtin_echo
         to
           write sys$output ""
         where one is  ......7 bytes longer.
         At the same time ensure that the echo string is properly terminated.
         For that, allocate a command buffer big enough for all possible expansions
         (have_newline is the count), then expand, copy and terminate. */
      char *tmp_cmd;
      int nloff = 0;
      int vlen = 0;
      int clen = 0;
      int inecho;

      tmp_cmd = alloca(strlen(cmd) + (have_newline + 1) * 7 + 1);
      tmp_cmd[0] = '\0';
      inecho = 0;
      while (cmd[nloff])
        {
          if (inecho)
            {
              if (clen < nloff - 1)
                {
                  memcpy(&tmp_cmd[vlen], &cmd[clen], nloff - clen - 1);
                  vlen += nloff - clen - 1;
                  clen = nloff;
                }
              inecho = 0;
              tmp_cmd[vlen] = '"';
              vlen++;
              tmp_cmd[vlen] = '\n';
              vlen++;
            }
          if (strncmp(&cmd[nloff], "builtin_", 8) == 0)
            {
              /* ??? */
              child->pid = 270163;
              child->efn = 0;
              child->cstatus = 1;

              DB (DB_JOBS, (_("BUILTIN [%s][%s]\n"), &cmd[nloff], &cmd[nloff+8]));
              p = &cmd[nloff + 8];
              if ((*(p) ==        'e')
                  && (*(p + 1) == 'c')
                  && (*(p + 2) == 'h')
                  && (*(p + 3) == 'o')
                  && ((*(p + 4) == ' ') || (*(p + 4) == '\t') || (*(p + 4) == '\0')))
                {
                  if (clen < nloff - 1)
                    {
                      memcpy(&tmp_cmd[vlen], &cmd[clen], nloff - clen - 1);
                      vlen += nloff - clen - 1;
                      clen = nloff;
                      if (inecho)
                        {
                          inecho = 0;
                          tmp_cmd[vlen] = '"';
                          vlen++;
                        }
                      tmp_cmd[vlen] = '\n';
                      vlen++;
                    }
                  inecho = 1;
                  p += 4;
                  while ((*p == ' ') || (*p == '\t'))
                    p++;
                  clen = p - cmd;
                  memcpy(&tmp_cmd[vlen], VMS_EMPTY_ECHO,
                      sizeof VMS_EMPTY_ECHO - 2);
                  vlen += sizeof VMS_EMPTY_ECHO - 2;
                }
              else
                {
                  printf (_("Builtin command is unknown or unsupported in .ONESHELL: '%s'\n"), &cmd[nloff]);
                  fflush(stdout);
                  return 0;
                }
            }
          nloff = nextnl(cmd, nloff + 1);
        }
      if (clen < nloff)
        {
          memcpy(&tmp_cmd[vlen], &cmd[clen], nloff - clen);
          vlen += nloff - clen;
          clen = nloff;
          if (inecho)
            {
              inecho = 0;
              tmp_cmd[vlen] = '"';
              vlen++;
            }
        }

      tmp_cmd[vlen] = '\0';

      cmd = tmp_cmd;
    }

#ifdef USE_DCL_COM_FILE
  /* Enforce the creation of a command file.
     Then all the make environment variables are written as DCL symbol
     assignments into the command file as well, so that they are visible
     in the sub-process but do not affect the current process.
     Further, this way DCL reads the input stream and therefore does
     'forced' symbol substitution, which it doesn't do for one-liners when
     they are 'lib$spawn'ed. */
#else
  /* Create a *.com file if either the command is too long for
     lib$spawn, or the command contains a newline, or if redirection
     is desired. Forcing commands with newlines into DCLs allows to
     store search lists on user mode logicals.  */
  if (strlen (cmd) > MAXCMDLEN
      || (have_redirection != 0)
      || (have_newline != 0))
#endif
    {
      FILE *outfile;
      char c;
      char *sep;
      int alevel = 0;   /* apostrophe level */
      int tmpstrlen;
      char *tmpstr;
      if (strlen (cmd) == 0)
        {
          printf (_("Error, empty command\n"));
          fflush (stdout);
          return 0;
        }

      outfile = output_tmpfile (&child->comname, "sys$scratch:CMDXXXXXX.COM");
      /*                                          012345678901234567890 */
#define TMP_OFFSET 12
#define TMP_LEN 9
      if (outfile == 0)
        pfatal_with_name (_("fopen (temporary file)"));
      comnamelen = strlen (child->comname);
      tmpstr = &child->comname[TMP_OFFSET];
      tmpstrlen = TMP_LEN;
      /* The whole DCL "script" is executed as one action, and it behaves as
         any DCL "script", that is errors stop it but warnings do not. Usually
         the command on the last line, defines the exit code.  However, with
         redirections there is a prolog and possibly an epilog to implement
         the redirection.  Both are part of the script which is actually
         executed. So if the redirection encounters an error in the prolog,
         the user actions will not run; if in the epilog, the user actions
         ran, but output is not captured. In both error cases, the error of
         redirection is passed back and not the exit code of the actions. The
         user should be able to enable DCL "script" verification with "set
         verify". However, the prolog and epilog commands are not shown. Also,
         if output redirection is used, the verification output is redirected
         into that file as well. */
      fprintf (outfile, "$ %.*s_1 = \"''f$verify(0)'\"\n", tmpstrlen, tmpstr);
      if (ifile[0])
        {
          fprintf (outfile, "$ assign/user %s sys$input\n", ifile);
          DB (DB_JOBS, (_("Redirected input from %s\n"), ifile));
          ifiledsc.dsc$w_length = 0;
        }

      if (efile[0])
        {
          fprintf (outfile, "$ define sys$error %s\n", efile);
          DB (DB_JOBS, (_("Redirected error to %s\n"), efile));
          efiledsc.dsc$w_length = 0;
        }

      if (ofile[0])
        if (have_append)
          {
            fprintf (outfile, "$ define sys$output %.*s\n", comnamelen-3, child->comname);
            fprintf (outfile, "$ on error then $ goto %.*s\n", tmpstrlen, tmpstr);
            DB (DB_JOBS, (_("Append output to %s\n"), ofile));
            ofiledsc.dsc$w_length = 0;
          }
        else
          {
            fprintf (outfile, "$ define sys$output %s\n", ofile);
            DB (DB_JOBS, (_("Redirected output to %s\n"), ofile));
            ofiledsc.dsc$w_length = 0;
          }
#ifdef USE_DCL_COM_FILE
      /* Export the child environment into DCL symbols */
      if (child->environment != 0)
        {
          char **ep = child->environment;
          char *valstr;
          while (*ep != 0)
            {
              valstr = strchr(*ep, '=');
              if (valstr == NULL)
                continue;
              fprintf(outfile, "$ %.*s=\"%s\"\n", valstr - *ep, *ep,
                  valstr + 1);
              ep++;
            }
        }
#endif
      fprintf (outfile, "$ %.*s_ = f$verify(%.*s_1)\n", tmpstrlen, tmpstr, tmpstrlen, tmpstr);

      /* TODO: give 78 a name! Whether 78 is a good number is another question.
         Trim, split and write the command lines.
         Splitting of a command is done after 78 output characters at an
         appropriate place (after strings, after comma or space and
         before slash): appending a hyphen indicates that the DCL command
         is being continued.
         Trimming is to skip any whitespace around - including - a
         leading $ from the command to ensure writing exactly one "$ "
         at the beginning of the line of the output file. Trimming is
         done when a new command is seen, indicated by a '\n' (outside
         of a string).
         The buffer so far is written and reset, when a new command is
         seen, when a split was done and at the end of the command.
         Only for ONESHELL there will be several commands separated by
         '\n'. But there can always be multiple continuation lines. */
      p = sep = q = cmd;
      for (c = '\n'; c; c = *q++)
        {
          switch (c)
          {
          case '\n':
            if (q > p)
              {
                fwrite(p, 1, q - p, outfile);
                p = q;
              }
            fputc('$', outfile);
            fputc(' ', outfile);
            while (isspace((unsigned char) *p))
              p++;
            if (*p == '$')
              p++;
            while (isspace((unsigned char) *p))
              p++;
            q = sep = p;
            break;
          case '"':
            q = vms_handle_apos(q);
            sep = q;
            break;
          case ',':
          case ' ':
            sep = q;
            break;
          case '/':
          case '\0':
            sep = q - 1;
            break;
          default:
            break;
          }
          if (sep - p > 78)
            {
              /* Enough stuff for a line. */
              fwrite(p, 1, sep - p, outfile);
              p = sep;
              if (*sep)
                {
                  /* The command continues.  */
                  fputc('-', outfile);
                }
              fputc('\n', outfile);
            }
        }

      if (*p)
        {
          fwrite(p, 1, --q - p, outfile);
          fputc('\n', outfile);
        }

      if (have_append)
        {
          fprintf (outfile, "$ %.*s: ! 'f$verify(0)\n", tmpstrlen, tmpstr);
          fprintf (outfile, "$ %.*s_2 = $status\n", tmpstrlen, tmpstr);
          fprintf (outfile, "$ on error then $ exit\n");
          fprintf (outfile, "$ deassign sys$output\n");
          if (efile[0])
            fprintf (outfile, "$ deassign sys$error\n");
          fprintf (outfile, "$ append:=append\n");
          fprintf (outfile, "$ delete:=delete\n");
          fprintf (outfile, "$ append/new %.*s %s\n", comnamelen-3, child->comname, ofile);
          fprintf (outfile, "$ delete %.*s;*\n", comnamelen-3, child->comname);
          fprintf (outfile, "$ exit '%.*s_2 + (0*f$verify(%.*s_1))\n", tmpstrlen, tmpstr, tmpstrlen, tmpstr);
          DB (DB_JOBS, (_("Append %.*s and cleanup\n"), comnamelen-3, child->comname));
        }

      fclose (outfile);

      sprintf (cmd, "$ @%s", child->comname);

      DB (DB_JOBS, (_("Executing %s instead\n"), cmd));
    }

  cmddsc.dsc$w_length = strlen(cmd);
  cmddsc.dsc$a_pointer = cmd;
  cmddsc.dsc$b_dtype = DSC$K_DTYPE_T;
  cmddsc.dsc$b_class = DSC$K_CLASS_S;

  child->efn = 0;
  while (child->efn < 32 || child->efn > 63)
    {
      status = lib$get_ef ((unsigned long *)&child->efn);
      if (!(status & 1))
        {
          if (child->comname)
            {
              if (!ISDB (DB_JOBS))
                unlink (child->comname);
              free (child->comname);
            }
          return 0;
        }
    }

  sys$clref (child->efn);

  vms_jobsefnmask |= (1 << (child->efn - 32));

  /*
    LIB$SPAWN  [command-string]
    [,input-file]
    [,output-file]
    [,flags]
    [,process-name]
    [,process-id] [,completion-status-address] [,byte-integer-event-flag-num]
    [,AST-address] [,varying-AST-argument]
    [,prompt-string] [,cli] [,table]
  */

#ifndef DONTWAITFORCHILD
  /*
   * Code to make ctrl+c and ctrl+y working.
   * The problem starts with the synchronous case where after lib$spawn is
   * called any input will go to the child. But with input re-directed,
   * both control characters won't make it to any of the programs, neither
   * the spawning nor to the spawned one. Hence the caller needs to spawn
   * with CLI$M_NOWAIT to NOT give up the input focus. A sys$waitfr
   * has to follow to simulate the wanted synchronous behaviour.
   * The next problem is ctrl+y which isn't caught by the crtl and
   * therefore isn't converted to SIGQUIT (for a signal handler which is
   * already established). The only way to catch ctrl+y, is an AST
   * assigned to the input channel. But ctrl+y handling of DCL needs to be
   * disabled, otherwise it will handle it. Not to mention the previous
   * ctrl+y handling of DCL needs to be re-established before make exits.
   * One more: At the time of LIB$SPAWN signals are blocked. SIGQUIT will
   * make it to the signal handler after the child "normally" terminates.
   * This isn't enough. It seems reasonable for simple command lines like
   * a 'cc foobar.c' spawned in a subprocess but it is unacceptable for
   * spawning make. Therefore we need to abort the process in the AST.
   *
   * Prior to the spawn it is checked if an AST is already set up for
   * ctrl+y, if not one is set up for a channel to SYS$COMMAND. In general
   * this will work except if make is run in a batch environment, but there
   * nobody can press ctrl+y. During the setup the DCL handling of ctrl+y
   * is disabled and an exit handler is established to re-enable it.
   * If the user interrupts with ctrl+y, the assigned AST will fire, force
   * an abort to the subprocess and signal SIGQUIT, which will be caught by
   * the already established handler and will bring us back to common code.
   * After the spawn (now /nowait) a sys$waitfr simulates the /wait and
   * enables the ctrl+y be delivered to this code. And the ctrl+c too,
   * which the crtl converts to SIGINT and which is caught by the common
   * signal handler. Because signals were blocked before entering this code
   * sys$waitfr will always complete and the SIGQUIT will be processed after
   * it (after termination of the current block, somewhere in common code).
   * And SIGINT too will be delayed. That is ctrl+c can only abort when the
   * current command completes. Anyway it's better than nothing :-)
   */

  if (!setupYAstTried)
    tryToSetupYAst();
  status = lib$spawn (&cmddsc,                                  /* cmd-string */
                      (ifiledsc.dsc$w_length == 0)?0:&ifiledsc, /* input-file */
                      (ofiledsc.dsc$w_length == 0)?0:&ofiledsc, /* output-file */
                      &spflags,                                 /* flags */
                      &pnamedsc,                                /* proc name */
                      &child->pid, &child->cstatus, &child->efn,
                      0, 0,
                      0, 0, 0);
  if (status & 1)
    {
      status= sys$waitfr (child->efn);
      vmsHandleChildTerm(child);
    }
#else
  status = lib$spawn (&cmddsc,
                      (ifiledsc.dsc$w_length == 0)?0:&ifiledsc,
                      (ofiledsc.dsc$w_length == 0)?0:&ofiledsc,
                      &spflags,
                      &pnamedsc,
                      &child->pid, &child->cstatus, &child->efn,
                      vmsHandleChildTerm, child,
                      0, 0, 0);
#endif

  if (!(status & 1))
    {
      printf (_("Error spawning, %d\n") ,status);
      fflush (stdout);
      switch (status)
        {
        case 0x1c:
          errno = EPROCLIM;
          break;
        default:
          errno = EFAIL;
        }
    }

  return (status & 1);
}
Exemplo n.º 16
0
asmlinkage int exe$getjpi(unsigned int efn, unsigned int *pidadr, void * prcnam, void *itmlst, struct _iosb *iosb, void (*astadr)(), unsigned long long astprm)
{
    struct _pcb * p;
    int sts;
    struct item_list_3 * it=itmlst;
    /** test list item entries */
    /** use pidadr - MISSING */
    /** clear event flag */
    exe$clref(efn);
    /** find next pcb */
    sts=exe$pscan_next_id(&p);
    if (sts==0)
        return SS$_NOMOREPROC;
    /** invoke nampid - MISSING */
    /** if other node, cwps - MISSING */
    /** iosb writecheck - MISSING */
    /** if ast, check ast quota and charge - MISSING */
    /** writetest for buffer descriptors - MISSING */
    /** gather some usual informastion - TODO still more remains */
    while (it->item_code)
    {
        switch (it->item_code)
        {
        case JPI$_PRCNAM:
            memcpy(it->bufaddr,&p->pcb$t_lname,15);
            break;

        case JPI$_PID:
            memcpy(it->bufaddr,&p->pcb$l_epid,4);
            break;

        case JPI$_MASTER_PID:
            memcpy(it->bufaddr,&p->pcb$l_pid,4);
            break;

        case JPI$_STATE:
            *(unsigned long *)it->bufaddr=p->pcb$w_state;
            break;

        case JPI$_PRI:
            *(unsigned long *)it->bufaddr=p->pcb$b_pri;
            break;

        case JPI$_PAGEFLTS:
            *(unsigned long *)it->bufaddr=p->pcb$l_phd->phd$l_pageflts;
            break;

        case JPI$_PPGCNT:
            *(unsigned long *)it->bufaddr=p->pcb$l_ppgcnt;
            break;

        case JPI$_GPGCNT:
            *(unsigned long *)it->bufaddr=p->pcb$l_gpgcnt;
            break;

        case JPI$_WSAUTH:
            *(unsigned long *)it->bufaddr=p->pcb$l_phd->phd$l_wsauth;
            break;

        case JPI$_WSQUOTA:
            *(unsigned long *)it->bufaddr=p->pcb$l_phd->phd$l_wsquota;
            break;

        case JPI$_WSSIZE:
            *(unsigned long *)it->bufaddr=p->pcb$l_phd->phd$l_wssize;
            break;

        case JPI$_WSAUTHEXT:
            *(unsigned long *)it->bufaddr=p->pcb$l_phd->phd$l_wsauthext;
            break;

        case JPI$_WSEXTENT:
            *(unsigned long *)it->bufaddr=p->pcb$l_phd->phd$l_wsextent;
            break;

        case JPI$_BIOCNT:
            *(unsigned short *)it->bufaddr=p->pcb$w_biocnt;
            break;

        case JPI$_BIOLM:
            *(unsigned short *)it->bufaddr=p->pcb$w_biolm;
            break;

        case JPI$_DIOCNT:
            *(unsigned short *)it->bufaddr=p->pcb$w_diocnt;
            break;

        case JPI$_DIOLM:
            *(unsigned short *)it->bufaddr=p->pcb$w_diolm;
            break;

        case JPI$_CPUTIM:
            *(long long *)it->bufaddr=p->pcb$l_phd->phd$l_cputim;
            break;

        case JPI$_DIRIO:
            *(unsigned int *)it->bufaddr=p->pcb$l_phd->phd$l_diocnt;
            break;

        case JPI$_BUFIO:
            *(unsigned int *)it->bufaddr=p->pcb$l_phd->phd$l_biocnt;
            break;

        }
        it++;
    }

    /** post event flag */
    struct _pcb * pcb = ctl$gl_pcb;
    sch$postef(pcb->pcb$l_pid, PRI$_NULL, efn);

    /** eventual ast queue - MISSING */

    /** eventual iosb write */
    if (iosb)
        iosb->iosb$w_status=SS$_NORMAL;

    return SS$_NORMAL;

    /** handle target process, kast etc - MISSING */
    /** handle target process, status, state - MISSING */

}