static void ualarm_AST(Alarm *a) { int iss; unsigned long now[2]; iss = sys$gettim(now); if (VMSERR(iss)) lib$signal(iss); if (a->function == UAL_SET || a->function == UAL_CLEAR) { if (a0->function == UAL_ACTIVE) { iss = sys$cantim(a0,PSL$C_USER); if (VMSERR(iss)) lib$signal(iss); iss = lib$subx(a0->remain, now, a->remain); if (VMSERR(iss)) lib$signal(iss); if (a->remain[1] & 0x80000000) a->remain[0] = a->remain[1] = 0; } if (a->function == UAL_SET) { a->function = a0->function; a0->function = UAL_ACTIVE; a0->repeat = a->repeat; if (a0->repeat) { a0->interval[0] = a->interval[0]; a0->interval[1] = a->interval[1]; } a0->delay[0] = a->delay[0]; a0->delay[1] = a->delay[1]; iss = lib$subx(now, a0->delay, a0->remain); if (VMSERR(iss)) lib$signal(iss); iss = sys$setimr(0,a0->delay,ualarm_AST,a0); if (VMSERR(iss)) lib$signal(iss); } else { a->function = a0->function; a0->function = UAL_NULL; } iss = sys$setef(alarm_ef); if (VMSERR(iss)) lib$signal(iss); } else if (a->function == UAL_ACTIVE) { if (a->repeat) { iss = lib$subx(now, a->interval, a->remain); if (VMSERR(iss)) lib$signal(iss); iss = sys$setimr(0,a->interval,ualarm_AST,a); if (VMSERR(iss)) lib$signal(iss); } else { a->function = UAL_NULL; } iss = sys$wake(0,0); if (VMSERR(iss)) lib$signal(iss); lib$signal(SS$_ASTFLT); } else { lib$signal(SS$_BADPARAM); } }
STATUS TMhrnow( HRSYSTIME *stime) { struct _generic_64 timadr; unsigned __int64 a100nsec; PTR tz_cb; STATUS status; status = sys$gettim(&timadr); if (status != SS$_NORMAL) return TM_GETTIME_ERR; stime->tv_sec = TMconv(&timadr); /* get seconds since Jan 1, 1970 */ /* Adjust for timezone */ status = TMtz_init(&tz_cb); if (status != OK) return TM_GETTIME_ERR; stime->tv_sec -= TMtz_search(tz_cb, TM_TIMETYPE_LOCAL, stime->tv_sec); /* ** get nanoseconds since last second. VMS gives 64 bit time as number ** of 100 nsec units since Nov 17, 1858. We mod with 10 million to get ** number of 100 nsec units since last second, then convert to nsec. */ a100nsec = timadr.gen64$q_quadword; stime->tv_nsec = (a100nsec % 10000000) * 100; return OK; }
/* * ---------------------------------------------------- * Get current clock time in milliseconds * Fill-in the structure with the absolute time * of system clock. * * Arguments: * atp - pointer to structure of absolute time * ---------------------------------------------------- */ void sys_get_curr_time(ABS_TIME *atp) { uint4 status, systim[2]; status = sys$gettim(systim); if (status & 1) { atp->at_usec = (systim[0] / 10) % 1000000; atp->at_sec = (uint4)(((((double)systim[1]) * MAX_INT) + (double)systim[0]) / 10000000.0); return; } rts_error(VARLSTCNT(1) status); }
int RAND_poll(void) { long pid, iosb[2]; int status = 0; struct { short length, code; long *buffer; int *retlen; } item[32], *pitem; unsigned char data_buffer[256]; short total_length = 0; struct items_data_st *pitems_data; pitems_data = items_data; pitem = item; /* Setup */ while (pitems_data->length && (total_length + pitems_data->length <= 256)) { pitem->length = pitems_data->length; pitem->code = pitems_data->code; pitem->buffer = (long *)&data_buffer[total_length]; pitem->retlen = 0; total_length += pitems_data->length; pitems_data++; pitem++; } pitem->length = pitem->code = 0; /* * Scan through all the processes in the system and add entropy with * results from the processes that were possible to look at. * However, view the information as only half trustable. */ pid = -1; /* search context */ while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0)) != SS$_NOMOREPROC) { if (status == SS$_NORMAL) { RAND_add( (PTR_T)data_buffer, total_length, total_length/2); } } sys$gettim(iosb); RAND_add( (PTR_T)iosb, sizeof(iosb), sizeof(iosb)/2); return 1; }
XtInputMask XETrapAppPending(XtAppContext app) { TimerEventRec *te_ptr; #ifndef VMS struct timeval cur_time; #else /* vms */ vms_time cur_time; long efnMask = 0L; int status; #endif /* vms */ XtInputMask retmask = XtAppPending(app); /* Prime XtIMEvent */ retmask &= ~(XtIMTimer | XtIMAlternateInput); /* clear timer & input */ /* Now test for timer */ te_ptr = app->timerQueue; while (te_ptr != NULL) { #ifndef vms (void)gettimeofday(&cur_time, NULL); FIXUP_TIMEVAL(cur_time); #else sys$gettim(&cur_time); #endif /* vms */ if (IS_AT_OR_AFTER(te_ptr->te_timer_value, cur_time)) { /* this timer is due to fire */ retmask |= XtIMTimer; break; } te_ptr = te_ptr->te_next; } /* Now test for alternate input */ #ifndef vms if (app->outstandingQueue != NULL) { retmask |= XtIMAlternateInput; } #else /* vms */ if ((app->Input_EF_Mask != 0L) && ((status=SYS$READEF(1,&efnMask)) == 1)) { /* we have input configured & retrieved the efn cluster 0 */ efnMask &= app->Input_EF_Mask; /* mask out non-input */ if (efnMask) /* any left? */ { /* yes, an alt-input efn is set */ retmask |= XtIMAlternateInput; } } #endif /* vms */ return(retmask); }
void set_valid_time() { /* Set valid utc time */ #if defined(OS_ELN) pwr_tTime current_time; int sts; sys$gettim( ¤t_time); if ( current_time.tv_nsec < 10400000) { current_time.tv_nsec = 10400000; ker$set_time( &sts, ¤t_time); } #endif }
static int set_context(long * context) { int status; signed long long timevalue; status = sys$gettim(&timevalue); context[0] = timevalue; // fix later int item_code; int len = 0; item_code = JPI$_CPUTIM; status = lib$getjpi (&item_code, 0, 0, &context[1], 0, &len); item_code = JPI$_BUFIO; status = lib$getjpi (&item_code, 0, 0, &context[2], 0, &len); item_code = JPI$_DIRIO; status = lib$getjpi (&item_code, 0, 0, &context[3], 0, &len); item_code = JPI$_PAGEFLTS; status = lib$getjpi (&item_code, 0, 0, &context[4], 0, &len); }
time_tOs * time_Os ( pwr_tStatus *status, time_tOs *tp ) { static time_tOs os_time; pwr_dStatus(sts, status, TIME__SUCCESS); if (tp == NULL) tp = &os_time; *sts = sys$gettim(tp); return tp; }
int clock_gettime ( clockid_t clockid, struct timespec *pt ) { unsigned long sts; pwr_tVaxTime vt; pwr_tVaxTime tmp; pwr_tVaxTime ofs = {0x4beb4000, 0x007c9567}; int divisor = 10000000; struct tm *tmpTm; unsigned long t = 0; if (clockid != CLOCK_REALTIME) { errno = EINVAL; return -1; } sts = sys$gettim(&vt); sts = lib$subx(&vt, &ofs, &tmp); if (EVEN(sts)) { errno = sts; return -1; } sts = lib$ediv(&divisor, &tmp, &pt->tv_sec, &pt->tv_nsec); if (EVEN(sts)) { errno = sts; return -1; } pt->tv_nsec *= 100; tmpTm = localtime(&pt->tv_sec); pt->tv_sec -= tmpTm->tm_gmtoff - tmpTm->tm_isdst * 3600; return 0; }
main() { $DESCRIPTOR(secs,"0 00:00:20.00"); sys$gettim(&now); sys$bintim(&secs,&step1); if (now<0) printf("now less than 0\n"); if (step1<0) printf("step1 less than 0\n"); now=now-step1; sys$schdwk(0,0,&now,&step1); printf("before hiber %x\n",time(0)); sys$hiber(); sys$hiber(); sys$hiber(); printf("after hiber %x\n",time(0)); }
Boolean Process::getCPUTime (Uint32& i32) const { int status = SS$_NORMAL; long lKernelTicks = 0; long lExecTicks = 0; long lSuperTicks = 0; long lUserTicks = 0; long lTotalTicks = 0; long avcpucnt; __int64 pstartime; __int64 qcurtime; float fTotalTicks; float fpercntime; struct k1_arglist { // kernel call arguments long lCount; // number of arguments long epid; long *pKernelTicks; long *pExecTicks; long *pSuperTicks; long *pUserTicks; } getcputickskargs = {5}; // init to 5 arguments item_list itmlst3[2]; getcputickskargs.epid = pInfo.pid; getcputickskargs.pKernelTicks = &lKernelTicks; getcputickskargs.pExecTicks = &lExecTicks; getcputickskargs.pSuperTicks = &lSuperTicks; getcputickskargs.pUserTicks = &lUserTicks; status = sys$cmkrnl (GetCPUTicks, &getcputickskargs); if (!$VMS_STATUS_SUCCESS (status)) { return false; } lTotalTicks = lKernelTicks + lExecTicks + lSuperTicks + lUserTicks; fTotalTicks = lTotalTicks; // 10 millisec ticks fTotalTicks = fTotalTicks * 10000000; // 100 nanosec ticks pstartime = pInfo.p_stime; // 100 nanosec ticks itmlst3[0].wlength = 4; itmlst3[0].wcode = SYI$_AVAILCPU_CNT; itmlst3[0].pbuffer = &avcpucnt; itmlst3[0].pretlen = NULL; itmlst3[1].wlength = 0; itmlst3[1].wcode = 0; itmlst3[1].pbuffer = NULL; itmlst3[1].pretlen = NULL; status = sys$getsyiw (0, 0, 0, itmlst3, 0, 0, 0); if (!$VMS_STATUS_SUCCESS (status)) { return false; } status = sys$gettim (&qcurtime); if (!$VMS_STATUS_SUCCESS (status)) { return false; } fpercntime = avcpucnt; fpercntime = fpercntime * (qcurtime - pstartime); fpercntime = (fTotalTicks / fpercntime) * 100; i32 = fpercntime; return true; }
void ccp_tr_writedb1(ccp_action_record *rec) { ccp_action_record request; ccp_db_header *db; jnl_buffer *jb; sgmnt_addrs *csa; int4 curr_time[2]; uint4 status, *p1, *p2, *top; if ((db = rec->v.h) == NULL) return; csa = db->segment; assert(csa->nl->ccp_state == CCST_RDMODE || csa->nl->ccp_state == CCST_CLOSED || csa->nl->ccp_state == CCST_OPNREQ); if (JNL_ENABLED(csa->hdr)) { assert(csa->jnl->channel != 0); jb = csa->jnl->jnl_buff; if (jb->blocked != 0) { /* jnl writes from a previous write mode are not done yet; try again later */ if ((status = sys$setimr(0, delta_100_msec, ccp_writedb5, db, 0)) != SS$_NORMAL) ccp_signal_cont(status); /***** Is this reasonable? *****/ return; } jb->epoch_tn = db->wm_iosb.valblk[CCP_VALBLK_EPOCH_TN]; jb->freeaddr = jb->dskaddr = ROUND_UP(db->wm_iosb.valblk[CCP_VALBLK_JNL_ADDR], DISK_BLOCK_SIZE); /* lastaddr is no longer a field in jnl_buff * jb->lastaddr = db->wm_iosb.valblk[CCP_VALBLK_LST_ADDR]; */ jb->free = jb->dsk = 0; } /* Note: We must clear these flags prior to changing state or a set from ccp_exitwm_blkast may be missed */ db->quantum_expired = FALSE; db->tick_in_progress = FALSE; if (db->remote_wakeup) { for (p2 = NULL, p1 = csa->lock_addrs[0], top = p1 + SIZEOF(int4) * NUM_CLST_LCKS; *p1 != 0 && p1 <= top; ++p1) { if ((*p1 & NODENUMBER) == (process_id & NODENUMBER)) { crit_wake(p1); if (p2 == NULL) p2 = p1; *p1 = 0; } else if (p2 != NULL) { *p2++ = *p1; *p1 = 0; } } db->remote_wakeup = FALSE; status = ccp_enq(0, LCK$K_CRMODE, &db->lock_iosb, LCK$M_CONVERT | LCK$M_SYNCSTS, NULL, 0, ccp_lkrqwake1, db, ccp_lkdowake_blkast, PSL$C_USER, 0); /***** Check error status here? *****/ } db->glob_sec->freeze = 0; /* db->glob_sec->wcs_active_lvl = db->glob_sec->n_bts / 2; */ db->drop_lvl = 0; sys$gettim(curr_time); lib$add_times(curr_time, db->glob_sec->ccp_quantum_interval, &db->start_wm_time); csa->nl->ccp_state = CCST_WRTGNT; if (db->blocking_ast_received) { status = sys$dclast(ccp_exitwm_blkast, &db->exitwm_timer_id, PSL$C_USER); if (status != SS$_NORMAL) ccp_signal_cont(status); /***** Is this reasonable? *****/ } csa->nl->ccp_crit_blocked = FALSE; ++csa->nl->ccp_cycle; status = sys$setimr(0, &db->glob_sec->ccp_quantum_interval, ccp_quantum_interrupt, &db->quantum_timer_id, 0); if (status != SS$_NORMAL) ccp_signal_cont(status); /***** Is this reasonable? *****/ db->dirty_buffers_acquired = FALSE; ccp_pndg_proc_wake(&db->write_wait); status = ccp_enq(0, LCK$K_EXMODE, &db->flush_iosb, LCK$M_CONVERT | LCK$M_SYNCSTS, NULL, 0, ccp_reqdrtbuf_interrupt, db, NULL, PSL$C_USER, 0); if (status == SS$_SYNCH) { request.action = CCTR_GOTDRT; request.pid = 0; request.v.h = db; ccp_act_request(&request); } /***** Check error status here? *****/ }
/* * init_timer - initialize the timer data structures */ void init_timer(void) { /* * Initialize... */ alarm_flag = 0; alarm_overflow = 0; adjust_timer = 1; stats_timer = 0; huffpuff_timer = 0; interface_timer = 0; current_time = 0; timer_overflows = 0; timer_xmtcalls = 0; timer_timereset = 0; #if !defined(SYS_WINNT) /* * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT * seconds from now and they continue on every 2**EVENT_TIMEOUT * seconds. */ # if !defined(VMS) # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) if (timer_create (CLOCK_REALTIME, NULL, &ntpd_timerid) == # ifdef SYS_VXWORKS ERROR # else -1 # endif ) { fprintf (stderr, "timer create FAILED\n"); exit (0); } (void) signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT); itimer.it_interval.tv_nsec = itimer.it_value.tv_nsec = 0; timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL); # else (void) signal_no_reset(SIGALRM, alarming); nap_time = 1; itimer.it_interval.tv_sec = itimer.it_value.tv_sec = nap_time; itimer.it_interval.tv_usec = itimer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); # endif # else /* VMS */ vmsinc[0] = 10000000; /* 1 sec */ vmsinc[1] = 0; lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc); sys$gettim(&vmstimer); /* that's "now" as abstime */ lib$addx(&vmsinc, &vmstimer, &vmstimer); sys$setimr(0, &vmstimer, alarming, alarming, 0); # endif /* VMS */ #else /* SYS_WINNT */ /* * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds * Under Windows/NT, */ WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); if (WaitableTimerHandle == NULL) { msyslog(LOG_ERR, "CreateWaitableTimer failed: %m"); exit(1); } else { DWORD Period = (1<<EVENT_TIMEOUT) * 1000; LARGE_INTEGER DueTime; DueTime.QuadPart = Period * 10000i64; if (!SetWaitableTimer(WaitableTimerHandle, &DueTime, Period, NULL, NULL, FALSE) != NO_ERROR) { msyslog(LOG_ERR, "SetWaitableTimer failed: %m"); exit(1); } } #endif /* SYS_WINNT */ }
int sysbintim (char *ci_, DATENT *obfr) { static char bigbfr[MAXBFR]; /* FIXME */ static char midbfr[MAXBFR]; $DESCRIPTOR(DSCx,bigbfr); $DESCRIPTOR(midnite,midbfr); DATENT base; int j; int num = strlen(ci_); char *c_, *d_, *e_; if (num >= (MAXBFR-1)) num = (MAXBFR-1); for (j = 0; j < num; j++) bigbfr[j] = _toupper(ci_[j]); bigbfr[num] = '\0'; /* * Compute the base of the current day, to use in keyword-dates: */ sys$gettim (obfr); sysasctim (midbfr, obfr, MAXDAY); strcpy (&midbfr[11], zeros); midnite.dsc$a_pointer = midbfr; midnite.dsc$w_length = strlen(midbfr); sys$bintim (&midnite, obfr); base = *obfr; if (strabbr (bigbfr, "TODAY", num, 3)) num = 0; else if (strabbr (bigbfr, "YESTERDAY", num, 1)) { lib$subx (base, day, obfr, 0); num = 0; } else if (strabbr (bigbfr, "TOMORROW", num, 3)) { lib$addx (base, day, obfr, 0); num = 0; } /* * $BINTIM cannot parse the ':' used in DCL to separate date, time. * Convert this to a trailing space and supply trailing zeros. Also, * if the year and/or month is not given, supply these: */ else { register int dash = 0; d_ = zeros; for (c_ = bigbfr; *c_; c_++) { if (*c_ == '-') dash++; else { if (*c_ == ':' && dash) *c_ = ' '; if (*c_ == ' ') { if (*d_) d_ += 3; break; } if (ispunct(*c_) && *d_) d_ += 3; } } if (*d_ && !dash) d_ += 3; e_ = dash ? c_ : bigbfr; if (*c_ || !dash) { if (*c_ == ' ') c_++; while (*c_ && *d_) { if (ispunct(*c_)) d_ += 3; c_++; } if (*d_) strcpy (c_, d_); } else /* Default to midnight for time */ strcpy (c_, zeros); /* * Insert month (mmm) and year (yyyy) if omitted, since * $BINTIM does not permit *gaps*, but only loss of significance. */ if (dash < 2) { char time[sizeof(zeros)+2]; strcpy (time, e_); *e_ = '\0'; if (dash == 1) /* dd-mmm given */ { strncpy (e_, midbfr+6, 5); strcpy (e_+5, time); } else /* dash==0, assume 'hh' of 'hh:mm' */ { strcpy (bigbfr, midbfr); strcpy (bigbfr+12, time); } } DSCx.dsc$w_length = strlen(bigbfr); if ((num = sys$bintim (&DSCx, obfr)) == SS$_NORMAL) num = 0; } return (num); }
lispval Ndumplisp() { register struct exec *workp; register lispval argptr, temp; char *fname; register ISD *Isd; register int i; extern lispval reborn; struct exec work,old; extern etext; extern int dmpmode,holend,curhbeg,usehole,holesize; int extra_cref_page = 0; char *start_of_data; int descrip, des2, count, ax,mode; char buf[5000],stabname[100],tbuf[BUFSIZ]; int fp,fp1; union { char Buffer[512]; struct { IHD Ihd; IHA Iha; IHS Ihs; IHI Ihi; } Header; } Buffer; /* VMS Header */ /* * Dumpmode is always 413!! */ mode = 0413; pagsiz = Igtpgsz(); pagrnd = pagsiz - 1; workp = &work; workp->a_magic = mode; if (holesize) { workp->a_text = ((unsigned)curhbeg) & (~pagrnd); if (((unsigned)curhbeg) & pagrnd) extra_cref_page = 1; start_of_data = (char *) (((((unsigned) (&holend)) -1) & (~pagrnd)) + pagsiz); } else { workp->a_text = ((((unsigned) (&etext)) -1) & (~pagrnd)) + pagsiz; start_of_data = (char *)workp->a_text; } workp->a_data = (unsigned) sbrk(0) - (unsigned)start_of_data; workp->a_bss = 0; workp->a_syms = 0; workp->a_entry = (unsigned) gstart(); workp->a_trsize = 0; workp->a_drsize = 0; fname = "savedlisp"; /* set defaults */ reborn = CNIL; argptr = lbot->val; if (argptr != nil) { temp = argptr->d.car; if((TYPE(temp))==ATOM) fname = temp->a.pname; } /* * Open the new executable file */ strcpy(buf,fname); if (index(buf,'.') == 0) strcat(buf,".exe"); if ((descrip = creat(buf,0777)) < 0) error("Dumplisp failed",FALSE); /* * Create the VMS header */ for(i = 0; i < 512; i++) Buffer.Buffer[i] = 0; /* Clear Header */ Buffer.Header.Ihd.size = sizeof(Buffer.Header); Buffer.Header.Ihd.activoff = sizeof(IHD); Buffer.Header.Ihd.symdbgoff = sizeof(IHD) + sizeof(IHA); Buffer.Header.Ihd.imgidoff = sizeof(IHD) + sizeof(IHA) + sizeof(IHS); Buffer.Header.Ihd.majorid[0] = '0'; Buffer.Header.Ihd.majorid[1] = '2'; Buffer.Header.Ihd.minorid[0] = '0'; Buffer.Header.Ihd.minorid[1] = '2'; Buffer.Header.Ihd.imgtype = IHD_EXECUTABLE; Buffer.Header.Ihd.privreqs[0] = -1; Buffer.Header.Ihd.privreqs[1] = -1; Buffer.Header.Ihd.lnkflags.nopobufs = 1; Buffer.Header.Ihd.imgiocnt = 250; Buffer.Header.Iha.tfradr1 = SYS$IMGSTA; Buffer.Header.Iha.tfradr2 = workp->a_entry; strcpy(Buffer.Header.Ihi.imgnam+1,"SAVEDLISP"); Buffer.Header.Ihi.imgnam[0] = 9; Buffer.Header.Ihi.imgid[0] = 0; Buffer.Header.Ihi.imgid[1] = '0'; sys$gettim(Buffer.Header.Ihi.linktime); strcpy(Buffer.Header.Ihi.linkid+1," Opus 38"); Buffer.Header.Ihi.linkid[0] = 8; Isd = (ISD *)&Buffer.Buffer[sizeof(Buffer.Header)]; /* Text ISD */ Isd->size = ISDSIZE_TEXT; Isd->pagcnt = workp->a_text >> 9; Isd->vpnpfc.vpn = 0; Isd->flags.type = ISD_NORMAL; Isd->vbn = 3; Isd = (ISD *)((char *)Isd + Isd->size); /* Hole ISDs (if necessary) */ if (usehole) { /* Copy on Ref ISD for possible extra text page */ if(extra_cref_page) { Isd->size = ISDSIZE_TEXT; Isd->pagcnt = 1; Isd->vpnpfc.vpn = (((unsigned)curhbeg) & (~pagrnd)) >> 9; Isd->flags.type = ISD_NORMAL; Isd->flags.crf = 1; Isd->flags.wrt = 1; Isd->vbn = (workp->a_text >> 9) + 3; Isd = (ISD *)((char *)Isd + Isd->size); } /* Demand Zero ISD for rest of Hole */ Isd->size = ISDSIZE_DZRO; Isd->pagcnt = ((((unsigned)&holend) - (unsigned)curhbeg) & (~pagrnd)) >> 9; Isd->vpnpfc.vpn = ((((unsigned)curhbeg) & (~pagrnd)) >> 9) + extra_cref_page; Isd->flags.type = ISD_NORMAL; Isd->flags.dzro = 1; Isd->flags.wrt = 1; Isd = (ISD *)((char *)Isd + Isd->size); } /* Data ISD */ Isd->size = ISDSIZE_TEXT; Isd->pagcnt = workp->a_data >> 9; Isd->vpnpfc.vpn = ((unsigned)start_of_data) >> 9; Isd->flags.type = ISD_NORMAL; Isd->flags.crf = 1; Isd->flags.wrt = 1; Isd->vbn = (workp->a_text >> 9) + 3; if (holesize) { /* * Correct the Data ISD */ Isd->vbn += extra_cref_page; } Isd = (ISD *)((char *)Isd + Isd->size); /* Stack ISD */ Isd->size = ISDSIZE_DZRO; Isd->pagcnt = ISDSTACK_SIZE; Isd->vpnpfc.vpn = ISDSTACK_BASE; Isd->flags.type = ISD_USERSTACK; Isd->flags.dzro = 1; Isd->flags.wrt = 1; Isd = (ISD *)((char *)Isd + Isd->size); /* End of ISD List */ Isd->size = 0; Isd = (ISD *)((char *)Isd + 2); /* * Make the rest of the header -1s */ for (i = ((char *)Isd - Buffer.Buffer); i < 512; i++) Buffer.Buffer[i] = -1; /* * Write the VMS Header */ if (write(descrip,Buffer.Buffer,512) == -1) error("Dumplisp failed",FALSE); #if EUNICE_UNIX_OBJECT_FILE_CFASL /* * Get the UNIX symbol table file header */ des2 = open(gstab(),0); if (des2 >= 0) { old.a_magic = 0; if (read(des2,(char *)&old,sizeof(old)) >= 0) { if (N_BADMAG(old)) { lseek(des2,512,0); /* Try block #1 */ read(des2,(char *)&old,sizeof(old)); } if (!N_BADMAG(old)) work.a_syms = old.a_syms; } } #endif EUNICE_UNIX_OBJECT_FILE_CFASL /* * Update the UNIX header so that the extra cref page is * considered part of data space. */ if (extra_cref_page) work.a_data += 512; /* * Write the UNIX header */ if (write(descrip,&work,sizeof(work)) == -1) error("Dumplisp failed",FALSE); /* * seek to 1024 (end of headers) */ if (lseek(descrip,1024,0) == -1) error("Dumplisp failed",FALSE); /* * write the world */ if (write(descrip,0,workp->a_text) == -1) error("Dumplisp failed",FALSE); if (extra_cref_page) if (write(descrip,(((unsigned)curhbeg) & pagrnd), pagsiz) == -1) error("Dumplisp failed",FALSE); if (write(descrip,start_of_data,workp->a_data) == -1) error("Dumplisp failed",FALSE); #if !EUNICE_UNIX_OBJECT_FILE_CFASL /* * VMS OBJECT files: We are done with the executable file */ close(descrip); /* * Now try to write the symbol table file! */ strcpy(buf,gstab()); strcpy(stabname,fname); if (index(stabname,'.') == 0) strcat(stabname,".stb"); else strcpy(index(stabname,'.'), ".stb"); /* Use Link/Unlink to rename the symbol table */ if (!strncmp(gstab(),"tmp:",4)) if (link(buf,stabname) >= 0) if (unlink(buf) >= 0) return(nil); /* Copy the symbol table */ if ((fp = open(buf,0)) < 0) error("Symbol table file not there\n",FALSE); fp1 = creat(stabname,0666,"var"); while((i = read(fp,buf,5000)) > 0) if (write(fp1,buf,i) == -1) { close(fp); close(fp1); error("Error writing symbol table\n",FALSE); } close(fp); close(fp1); if (i < 0) error("Error reading symbol table\n",FALSE); if (!strncmp(gstab(),"tmp:",4)) unlink(gstab); /* * Done */ reborn = 0; return(nil); #else EUNICE_UNIX_OBJECT_FILE_CFASL /* * UNIX OBJECT files: append the new symbol table */ if(des2>0 && work.a_syms) { count = old.a_text + old.a_data + (old.a_magic == 0413 ? 1024 : sizeof(old)); if(-1==lseek(des2,count,0)) error("Could not seek to stab",FALSE); for(count = old.a_syms;count > 0; count -=BUFSIZ) { ax = read(des2,tbuf,(int)(count < BUFSIZ ? count : BUFSIZ)); if(ax==0) { printf("Unexpected end of syms",count); fflush(stdout); break; } else if(ax > 0) write(descrip,tbuf,ax); else error("Failure to write dumplisp stab",FALSE); } if(-1 == lseek(des2,(long) ((old.a_magic == 0413 ? 1024 : sizeof(old)) + old.a_text + old.a_data + old.a_trsize + old.a_drsize + old.a_syms), 0)) error(" Could not seek to string table ",FALSE); for( ax = 1 ; ax > 0;) { ax = read(des2,tbuf,BUFSIZ); if(ax > 0) write(descrip,tbuf,ax); else if (ax < 0) error("Error in string table read ",FALSE); } } close(descrip); if(des2>0) close(des2); reborn = 0; return(nil); #endif EUNICE_UNIX_OBJECT_FILE_CFASL }
gtcm_server() { static readonly int4 reptim[2] = {-100000, -1}; /* 10ms */ static readonly int4 wait[2] = {-1000000, -1}; /* 100ms */ void gtcm_ch(), gtcm_exi_handler(), gtcm_init_ast(), gtcm_int_unpack(), gtcm_mbxread_ast(), gtcm_neterr(), gtcm_read_ast(), gtcm_remove_from_action_queue(), gtcm_shutdown_ast(), gtcm_write_ast(), la_freedb(); bool gtcm_link_accept(); bool alid; char buff[512]; char *h = NULL; char *la_getdb(); char nbuff[256]; char *pak = NULL; char reply; unsigned short outlen; int4 closewait[2] = {0, -1}; int4 inid = 0, mdl = 0, nid = 0, days = 0; int4 lic_status; int4 lic_x; int4 lm_mdl_nid(); uint4 status; int i, receive(), value; mstr name1, name2; struct NTD *cmu_ntdroot(); connection_struct *prev_curr_entry; struct dsc$descriptor_s dprd; struct dsc$descriptor_s dver; $DESCRIPTOR(node_name, nbuff); $DESCRIPTOR(proc_name, "GTCM_SERVER"); $DESCRIPTOR(timout, buff); DCL_THREADGBL_ACCESS; GTM_THREADGBL_INIT; assert(0 == EMPTY_QUEUE); /* check so dont need gdsfhead everywhere */ common_startup_init(GTCM_GNP_SERVER_IMAGE); /* Side-effect: Sets skip_dbtriggers to TRUE for non-trigger platforms */ gtm_env_init(); /* read in all environment variables */ name1.addr = "GTCMSVRNAM"; name1.len = SIZEOF("GTCMSVRNAM") - 1; status = trans_log_name(&name1, &name2, nbuff); if (SS$_NORMAL == status) { proc_name.dsc$a_pointer = nbuff; proc_name.dsc$w_length = node_name.dsc$w_length = name2.len; } else if (SS$_NOLOGNAM == status) { MEMCPY_LIT(nbuff, "GTCMSVR"); node_name.dsc$w_length = SIZEOF("GTCMSVR") - 1; } else rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status); sys$setprn(&proc_name); status = lib$get_foreign(&timout, 0, &outlen, 0); if ((status & 1) && (6 > outlen)) { for (i = 0; i < outlen; i++) { value = value * 10; if (buff[i] <= '9' && buff[i] >= '0') value += buff[i] - 48; else break; } if (outlen && (i == outlen)) { cm_timeout = TRUE; closewait[0] = value * -10000000; } } dprd.dsc$w_length = cm_prd_len; dprd.dsc$b_dtype = DSC$K_DTYPE_T; dprd.dsc$b_class = DSC$K_CLASS_S; dprd.dsc$a_pointer= cm_prd_name; dver.dsc$w_length = cm_ver_len; dver.dsc$b_dtype = DSC$K_DTYPE_T; dver.dsc$b_class = DSC$K_CLASS_S; dver.dsc$a_pointer= cm_ver_name; ast_init(); licensed = TRUE; lkid = 2; # ifdef NOLICENSE lid = 1; # else /* this code used to be scattered to discourage reverse engineering, but since it now disabled, that seems pointless */ lic_status = ((NULL == (h = la_getdb(LMDB))) ? LP_NOCNFDB : SS$_NORMAL); lic_status = ((1 == (lic_status & 1)) ? lm_mdl_nid(&mdl, &nid, &inid) : lic_status); lic_status = ((1 == (lic_status & 1)) ? lp_licensed(h, &dprd, &dver, mdl, nid, &lid, &lic_x, &days, pak) : lic_status); if (LP_NOCNFDB != lic_status) la_freedb(h); if (1 == (lic_status & 1)) { licensed = TRUE; if (days < 14) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ERR_WILLEXPIRE); } else { licensed = FALSE; sys$exit(lic_status); } # endif gtcm_ast_avail = astq_dyn_avail - GTCM_AST_OVRHD; stp_init(STP_INITSIZE); rts_stringpool = stringpool; cache_init(); procnum = 0; get_proc_info(0, TADR(login_time), &image_count); memset(proc_to_clb, 0, SIZEOF(proc_to_clb)); status = cmi_init(&node_name, 0, 0, gtcm_init_ast, gtcm_link_accept); if (!(status & 1)) { rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) ((status ^ 3) | 4)); sys$exit(status); } ntd_root = cmu_ntdroot(); ntd_root->mbx_ast = gtcm_mbxread_ast; ntd_root->err = gtcm_neterr; gtcm_connection = FALSE; lib$establish(gtcm_ch); gtcm_exi_blk.exit_hand = >cm_exi_handler; gtcm_exi_blk.arg_cnt = 1; gtcm_exi_blk.cond_val = >cm_exi_condition; sys$dclexh(>cm_exi_blk); INVOKE_INIT_SECSHR_ADDRS; initialize_pattern_table(); assert(run_time); /* Should have been set by common_startup_init */ while (!cm_shutdown) { if (blkdlist) gtcml_chkreg(); assert(!lib$ast_in_prog()); status = sys$dclast(>cm_remove_from_action_queue, 0, 0); if (SS$_NORMAL != status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) CMERR_CMSYSSRV, 0, status, 0); if (INTERLOCK_FAIL == curr_entry) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) CMERR_CMINTQUE); if (EMPTY_QUEUE != curr_entry) { switch (*curr_entry->clb_ptr->mbf) { case CMMS_L_LKCANALL: reply = gtcmtr_lkcanall(); break; case CMMS_L_LKCANCEL: reply = gtcmtr_lkcancel(); break; case CMMS_L_LKREQIMMED: reply = gtcmtr_lkreqimmed(); break; case CMMS_L_LKREQNODE: reply = gtcmtr_lkreqnode(); break; case CMMS_L_LKREQUEST: reply = gtcmtr_lkrequest(); break; case CMMS_L_LKRESUME: reply = gtcmtr_lkresume(); break; case CMMS_L_LKACQUIRE: reply = gtcmtr_lkacquire(); break; case CMMS_L_LKSUSPEND: reply = gtcmtr_lksuspend(); break; case CMMS_L_LKDELETE: reply = gtcmtr_lkdelete(); break; case CMMS_Q_DATA: reply = gtcmtr_data(); break; case CMMS_Q_GET: reply = gtcmtr_get(); break; case CMMS_Q_KILL: reply = gtcmtr_kill(); break; case CMMS_Q_ORDER: reply = gtcmtr_order(); break; case CMMS_Q_PREV: reply = gtcmtr_zprevious(); break; case CMMS_Q_PUT: reply = gtcmtr_put(); break; case CMMS_Q_QUERY: reply = gtcmtr_query(); break; case CMMS_Q_ZWITHDRAW: reply = gtcmtr_zwithdraw(); break; case CMMS_S_INITPROC: reply = gtcmtr_initproc(); break; case CMMS_S_INITREG: reply = gtcmtr_initreg(); break; case CMMS_S_TERMINATE: reply = gtcmtr_terminate(TRUE); break; case CMMS_E_TERMINATE: reply = gtcmtr_terminate(FALSE); break; case CMMS_U_LKEDELETE: reply = gtcmtr_lke_clearrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf); break; case CMMS_U_LKESHOW: reply = gtcmtr_lke_showrep(curr_entry->clb_ptr, curr_entry->clb_ptr->mbf); break; case CMMS_B_BUFRESIZE: reply = CM_WRITE; value = *(unsigned short *)(curr_entry->clb_ptr->mbf + 1); if (value > curr_entry->clb_ptr->mbl) { free(curr_entry->clb_ptr->mbf); curr_entry->clb_ptr->mbf = malloc(value); } *curr_entry->clb_ptr->mbf = CMMS_C_BUFRESIZE; curr_entry->clb_ptr->mbl = value; curr_entry->clb_ptr->cbl = 1; break; case CMMS_B_BUFFLUSH: reply = gtcmtr_bufflush(); break; case CMMS_Q_INCREMENT: reply = gtcmtr_increment(); break; default: reply = FALSE; if (SS$_NORMAL == status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_BADGTMNETMSG, 1, (int)*curr_entry->clb_ptr->mbf); break; } if (curr_entry) /* curr_entry can be NULL if went through gtcmtr_terminate */ { status = sys$gettim(&curr_entry->lastact[0]); if (SS$_NORMAL != status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status); /* curr_entry is used by gtcm_mbxread_ast to determine if it needs to defer the interrupt message */ prev_curr_entry = curr_entry; if (CM_WRITE == reply) { /* if ast == gtcm_write_ast, let it worry */ curr_entry->clb_ptr->ast = gtcm_write_ast; curr_entry = EMPTY_QUEUE; cmi_write(prev_curr_entry->clb_ptr); } else { curr_entry = EMPTY_QUEUE; if (1 == (prev_curr_entry->int_cancel.laflag & 1)) { /* valid interrupt cancel msg, handle in gtcm_mbxread_ast */ status = sys$dclast(gtcm_int_unpack, prev_curr_entry, 0); if (SS$_NORMAL != status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(1) status); } else if (CM_READ == reply) { prev_curr_entry->clb_ptr->ast = gtcm_read_ast; cmi_read(prev_curr_entry->clb_ptr); } } } } else if (1 < astq_dyn_avail) { # ifdef GTCM_REPTIM /* if reptim is not needed - and smw doesn't know why it would be - remove this */ status = sys$schdwk(0, 0, &wait[0], &reptim[0]); # else status = sys$schdwk(0, 0, &wait[0], 0); # endif sys$hiber(); sys$canwak(0, 0); } if (cm_timeout && (0 == gtcm_users)) sys$setimr(efn_ignore, closewait, gtcm_shutdown_ast, &cm_shutdown, 0); } }
int RAND_poll_ex(RAND_poll_fn cb, void *arg) { /* determine the number of items in the JPI array */ struct items_data_st item_entry; int item_entry_count = OSSL_NELEM(items_data); /* Create the JPI itemlist array to hold item_data content */ struct { short length, code; int *buffer; int *retlen; } item[item_entry_count], *pitem; struct items_data_st *pitems_data; int data_buffer[(item_entry_count * 2) + 4]; /* 8 bytes per entry max */ int iosb[2]; int sys_time[2]; int *ptr; int i, j ; int tmp_length = 0; int total_length = 0; /* Setup itemlist for GETJPI */ pitems_data = items_data; for (pitem = item; pitems_data->length != 0; pitem++) { pitem->length = pitems_data->length; pitem->code = pitems_data->code; pitem->buffer = &data_buffer[total_length]; pitem->retlen = 0; /* total_length is in longwords */ total_length += pitems_data->length / 4; pitems_data++; } pitem->length = pitem->code = 0; /* Fill data_buffer with various info bits from this process */ if (sys$getjpiw(EFN$C_ENF, NULL, NULL, item, &iosb, 0, 0) != SS$_NORMAL) return 0; /* Now twist that data to seed the SSL random number init */ for (i = 0; i < total_length; i++) { sys$gettim((struct _generic_64 *)&sys_time[0]); srand(sys_time[0] * data_buffer[0] * data_buffer[1] + i); if (i == (total_length - 1)) { /* for JPI$_FINALEXC */ ptr = &data_buffer[i]; for (j = 0; j < 4; j++) { data_buffer[i + j] = ptr[j]; /* OK to use rand() just to scramble the seed */ data_buffer[i + j] ^= (sys_time[0] ^ rand()); tmp_length++; } } else { /* OK to use rand() just to scramble the seed */ data_buffer[i] ^= (sys_time[0] ^ rand()); } } total_length += (tmp_length - 1); /* size of seed is total_length*4 bytes (64bytes) */ cb(arg, (PTR_T)data_buffer, total_length * 4, total_length * 2); return 1; }
int gettimeofday (struct timeval *tp, void *tpz) { long ret; #ifdef __VAX long quad[2]; long quad1[2]; long div_100ns_to_secs; long div_100ns_to_usecs; long quo,rem; long quo1,rem1; #else __int64 quad; __qdiv_t ans1,ans2; #endif /* In case of error, tv_usec = 0 and tv_sec = VMS condition code. The return from function is also set to -1. This is not exactly as per the manual page. */ tp->tv_usec = 0; #ifdef __VAX if (base_adjust[0]==0 && base_adjust[1]==0) { #else if (base_adjust==0) { /* Need to determine epoch adjustment */ #endif ret=sys$bintim(&dscepoch,&base_adjust); if (1 != (ret &&1)) { tp->tv_sec = ret; return -1; } } ret=sys$gettim(&quad); /* Get VMS system time */ if ((1 && ret) == 1) { #ifdef __VAX quad[0] -= base_adjust[0]; /* convert to epoch offset */ quad[1] -= base_adjust[1]; /* convert 2nd half of quadword */ div_100ns_to_secs = DIV_100NS_TO_SECS; div_100ns_to_usecs = DIV_100NS_TO_USECS; lib$ediv(&div_100ns_to_secs,&quad,&quo,&rem); quad1[0] = rem; quad1[1] = 0L; lib$ediv(&div_100ns_to_usecs,&quad1,&quo1,&rem1); tp->tv_sec = quo; /* Whole seconds */ tp->tv_usec = quo1; /* Micro-seconds */ #else quad -= base_adjust; /* convert to epoch offset */ ans1=qdiv(quad,DIV_100NS_TO_SECS); ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS); tp->tv_sec = ans1.quot; /* Whole seconds */ tp->tv_usec = ans2.quot; /* Micro-seconds */ #endif } else { tp->tv_sec = ret; return -1; } # ifdef VMSISH_TIME # ifdef RTL_USES_UTC if (VMSISH_TIME) tp->tv_sec = _toloc(tp->tv_sec); # else if (!VMSISH_TIME) tp->tv_sec = _toutc(tp->tv_sec); # endif # endif return 0; } #endif /* Do not use H A S _ N A N O S L E E P * so that Perl Configure doesn't scan for it. * The TIME_HIRES_NANOSLEEP is set by Makefile.PL. */ #if !defined(HAS_USLEEP) && defined(TIME_HIRES_NANOSLEEP) #define HAS_USLEEP #define usleep hrt_unanosleep /* could conflict with ncurses for static build */ void hrt_unanosleep(unsigned long usec) /* This is used to emulate usleep. */ { struct timespec res; res.tv_sec = usec/1000/1000; res.tv_nsec = ( usec - res.tv_sec*1000*1000 ) * 1000; nanosleep(&res, NULL); } #endif /* #if !defined(HAS_USLEEP) && defined(TIME_HIRES_NANOSLEEP) */ #if !defined(HAS_USLEEP) && defined(HAS_SELECT) #ifndef SELECT_IS_BROKEN #define HAS_USLEEP #define usleep hrt_usleep /* could conflict with ncurses for static build */ void hrt_usleep(unsigned long usec) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = usec; select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL, &tv); } #endif #endif /* #if !defined(HAS_USLEEP) && defined(HAS_SELECT) */ #if !defined(HAS_USLEEP) && defined(WIN32) #define HAS_USLEEP #define usleep hrt_usleep /* could conflict with ncurses for static build */ void hrt_usleep(unsigned long usec) { long msec; msec = usec / 1000; Sleep (msec); }
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 */
bool TouchFile(const string& path) { int i; FibDesc.dsc$w_length = sizeof (Fib); FibDesc.dsc$b_dtype = DSC$K_DTYPE_Z; FibDesc.dsc$b_class = DSC$K_CLASS_S; FibDesc.dsc$a_pointer = (char *) &Fib; DevDesc.dsc$b_dtype = DSC$K_DTYPE_T; DevDesc.dsc$b_class = DSC$K_CLASS_S; DevDesc.dsc$a_pointer = &Nam.nam$t_dvi[1]; FileName.dsc$b_dtype = DSC$K_DTYPE_T; FileName.dsc$b_class = DSC$K_CLASS_S; MyAtr.atr$w_size = sizeof (Rdate); MyAtr.atr$w_type = ATR$C_REVDATE; MyAtr.atr$l_addr = &Rdate; MyAtr.fill = 0; struct stat sbuf; status = sys$gettim(&CurTime); check_status(status, "sys$gettim", "TouchFile"); if (stat(path.c_str(), &sbuf) != 0) { // File does not exist, create it: int fd = open(path.c_str(), O_WRONLY | O_CREAT, 0666); if (fd < 0) { return false; } close(fd); return true; } // File does exist: /* initialize RMS structures, we need a NAM to retrieve the FID */ Fab = cc$rms_fab; Fab.fab$l_fna = (char *) path.c_str(); /* name of file */ Fab.fab$b_fns = strlen(path.c_str()); Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */ Nam = cc$rms_nam; Nam.nam$l_esa = EName; /* expanded filename */ Nam.nam$b_ess = sizeof (EName); Nam.nam$l_rsa = RName; /* resultant filename */ Nam.nam$b_rss = sizeof (RName); /* do $PARSE and $SEARCH here */ status = sys$parse(&Fab); check_rms_status(status, Fab.fab$l_stv, "sys$parse", "parse_name"); // Open the file. DevDesc.dsc$w_length = Nam.nam$t_dvi[0]; status = sys$assign(&DevDesc, &DevChan, 0, 0); check_status(status, "sys$assign", "assign_name"); // Get current file revision date. FileName.dsc$a_pointer = Nam.nam$l_name; FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver; /* Initialize the FIB */ for (i = 0; i < 3; i++) { Fib.fib$w_fid[i] = Nam.nam$w_fid[i]; Fib.fib$w_did[i] = Nam.nam$w_did[i]; } status = sys$qiow( 0, DevChan, IO$_ACCESS, &Iosb, 0, 0, &FibDesc, (__int64) & FileName, 0, 0, (__int64) & MyAtr, 0); if ((status & 1) == 1) { status = Iosb.iosb$w_status; } check_status (status, "sys$qio", "get_attr"); // Get current time. Rdate = CurTime; // Set new file revision time. status = sys$qiow( 0, DevChan, IO$_MODIFY, &Iosb, 0, 0, &FibDesc, (__int64) & FileName, 0, 0, (__int64) & MyAtr, 0); if ((status & 1) == 1) { status = Iosb.iosb$w_status; } check_status(status, "sys$qio", "set_attr"); // Release file. status = sys$dassgn (DevChan); check_status(status, "sys$dassgn", "deassign_name"); return true; }
/* Wait for either Timer, Alternate Input, or an X Event to arrive */ int XETrapWaitForSomething(XtAppContext app) { #ifndef vms return(_XtWaitForSomething(app, FALSE, FALSE, FALSE, FALSE, TRUE #ifdef XTHREADS , FALSE #endif /* XTHREADS */ , 0L)); #else /* vms */ #define IS_AFTER(t1,t2) (((t2).high > (t1).high) \ ||(((t2).high == (t1).high)&& ((t2).low > (t1).low))) long retval = 0L; TimerEventRec *te_ptr; vms_time cur_time,result_time; int status = 0; long quotient, remainder = 0; int d; if (app->timerQueue!= NULL) { /* check timeout queue */ cur_time.low = cur_time.high = result_time.low = result_time.high = 0; te_ptr = app->timerQueue; sys$gettim(&cur_time); if ((IS_AFTER(app->timerQueue->te_timer_value, cur_time)) && (app->timerQueue->te_proc != 0)) { /* it's fired! return! */ return(0); } /* Jump through hoops to get the time specified in the queue into * milliseconds */ status = lib$sub_times (&(te_ptr->te_timer_value.low), &cur_time, &result_time); /* * See if this timer has expired. A timer is considered expired * if it's value in the past (the NEGTIM case) or if there is * less than one integral milli second before it would go off. */ if (status == LIB$_NEGTIM || (result_time.high == -1 && result_time.low > -10000)) { /* We've got a timer and it's ready to fire! */ return(0); } else if ((status & 1) == 1) { lib$ediv (&(10000), &result_time, "ient, &remainder); quotient *= -1; /* flip the sign bit */ return(XMultiplexInput(app->count, &(app->list[0L]), app->Input_EF_Mask, quotient, 0L, &retval)); } else { status = -1; } } return((status == -1 ? -1 : XMultiplexInput(app->count, &(app->list[0L]), app->Input_EF_Mask, 0L, 0L, &retval))); #endif /* vms */ }
/* * init_timer - initialize the timer data structures */ void init_timer(void) { # if defined SYS_WINNT & !defined(SYS_CYGWIN32) HANDLE hToken = INVALID_HANDLE_VALUE; TOKEN_PRIVILEGES tkp; # endif /* SYS_WINNT */ /* * Initialize... */ alarm_flag = 0; alarm_overflow = 0; adjust_timer = 1; stats_timer = 0; huffpuff_timer = 0; interface_timer = 0; current_time = 0; timer_overflows = 0; timer_xmtcalls = 0; timer_timereset = 0; #if !defined(SYS_WINNT) /* * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT * seconds from now and they continue on every 2**EVENT_TIMEOUT * seconds. */ # if !defined(VMS) # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) if (timer_create (CLOCK_REALTIME, NULL, &ntpd_timerid) == # ifdef SYS_VXWORKS ERROR # else -1 # endif ) { fprintf (stderr, "timer create FAILED\n"); exit (0); } (void) signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT); itimer.it_interval.tv_nsec = itimer.it_value.tv_nsec = 0; timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL); # else (void) signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT); itimer.it_interval.tv_usec = itimer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); # endif # else /* VMS */ vmsinc[0] = 10000000; /* 1 sec */ vmsinc[1] = 0; lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc); sys$gettim(&vmstimer); /* that's "now" as abstime */ lib$addx(&vmsinc, &vmstimer, &vmstimer); sys$setimr(0, &vmstimer, alarming, alarming, 0); # endif /* VMS */ #else /* SYS_WINNT */ _tzset(); /* * Get privileges needed for fiddling with the clock */ /* get the current process token handle */ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { msyslog(LOG_ERR, "OpenProcessToken failed: %m"); exit(1); } /* get the LUID for system-time privilege. */ LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; /* one privilege to set */ tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; /* get set-time privilege for this process. */ AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); /* cannot test return value of AdjustTokenPrivileges. */ if (GetLastError() != ERROR_SUCCESS) { msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m"); } /* * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds * Under Windows/NT, */ WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); if (WaitableTimerHandle == NULL) { msyslog(LOG_ERR, "CreateWaitableTimer failed: %m"); exit(1); } else { DWORD Period = (1<<EVENT_TIMEOUT) * 1000; LARGE_INTEGER DueTime; DueTime.QuadPart = Period * 10000i64; if (!SetWaitableTimer(WaitableTimerHandle, &DueTime, Period, NULL, NULL, FALSE) != NO_ERROR) { msyslog(LOG_ERR, "SetWaitableTimer failed: %m"); exit(1); } } #endif /* SYS_WINNT */ }
/* * init_timer - initialize the timer data structures */ void init_timer(void) { /* * Initialize... */ alarm_flag = FALSE; alarm_overflow = 0; adjust_timer = 1; stats_timer = SECSPERHR; leapf_timer = SECSPERDAY; huffpuff_timer = 0; interface_timer = 0; current_time = 0; timer_overflows = 0; timer_xmtcalls = 0; timer_timereset = 0; #ifndef SYS_WINNT /* * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT * seconds from now and they continue on every 2**EVENT_TIMEOUT * seconds. */ # ifndef VMS # ifdef HAVE_TIMER_CREATE if (TC_ERR == timer_create(CLOCK_REALTIME, NULL, &timer_id)) { msyslog(LOG_ERR, "timer_create failed, %m"); exit(1); } # endif signal_no_reset(SIGALRM, alarming); itimer.it_interval.tv_sec = itimer.it_value.tv_sec = (1 << EVENT_TIMEOUT); itimer.it_interval.itv_frac = itimer.it_value.itv_frac = 0; set_timer_or_die(&itimer); # else /* VMS follows */ vmsinc[0] = 10000000; /* 1 sec */ vmsinc[1] = 0; lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc); sys$gettim(&vmstimer); /* that's "now" as abstime */ lib$addx(&vmsinc, &vmstimer, &vmstimer); sys$setimr(0, &vmstimer, alarming, alarming, 0); # endif /* VMS */ #else /* SYS_WINNT follows */ /* * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds * Under Windows/NT, */ WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); if (WaitableTimerHandle == NULL) { msyslog(LOG_ERR, "CreateWaitableTimer failed: %m"); exit(1); } else { DWORD Period; LARGE_INTEGER DueTime; BOOL rc; Period = (1 << EVENT_TIMEOUT) * 1000; DueTime.QuadPart = Period * 10000i64; rc = SetWaitableTimer(WaitableTimerHandle, &DueTime, Period, NULL, NULL, FALSE); if (!rc) { msyslog(LOG_ERR, "SetWaitableTimer failed: %m"); exit(1); } } #endif /* SYS_WINNT */ }
show_system(){ int i; struct item_list_3 lst[14], syilst[4]; char scsnode[16]; char procname[15]; char proclen; char version[16]; int versionlen; unsigned long long boottime; int boottimelen; unsigned long upid,epid; unsigned long upidlen,epidlen; unsigned long state,statelen; unsigned long pri,prilen; unsigned long pagep, pageplen; unsigned long pageg, pageglen; unsigned long pagef, pageflen; unsigned int dirio, diriolen, bufio, bufiolen; int jpistatus; int sts; int retscsnodelen; unsigned long long now; char timestr[23]; $DESCRIPTOR(atimenow, timestr); char timestr2[23]; $DESCRIPTOR(atimenow2, timestr2); sys$gettim(&now); sys$asctim(0,&atimenow,&now,0); syilst[0].buflen=16; syilst[0].item_code=SYI$_VERSION; syilst[0].bufaddr=version; syilst[0].retlenaddr=&versionlen; syilst[1].buflen=16; syilst[1].item_code=SYI$_BOOTTIME; syilst[1].bufaddr=&boottime; syilst[1].retlenaddr=&boottimelen; syilst[2].buflen=16; syilst[2].item_code=SYI$_SCSNODE; syilst[2].bufaddr=scsnode; syilst[2].retlenaddr=&retscsnodelen; syilst[3].buflen=0; syilst[3].item_code=0; sts=sys$getsyi(0,0,0,syilst,0,0,0); long long delta = boottime - now; int deltalen; sys$asctim(0,&atimenow2,&delta,0); lst[0].buflen=15; lst[0].item_code=JPI$_PRCNAM; lst[0].bufaddr=procname; lst[0].retlenaddr=&proclen; lst[1].buflen=4; lst[1].item_code=JPI$_PID; lst[1].bufaddr=&epid; lst[1].retlenaddr=&epidlen; lst[2].buflen=4; lst[2].item_code=JPI$_MASTER_PID; lst[2].bufaddr=&upid; lst[2].retlenaddr=&upidlen; lst[3].buflen=4; lst[3].item_code=JPI$_STATE; lst[3].bufaddr=&state; lst[3].retlenaddr=&statelen; lst[4].buflen=4; lst[4].item_code=JPI$_PAGEFLTS; lst[4].bufaddr=&pagef; lst[4].retlenaddr=&pageflen; lst[5].buflen=4; lst[5].item_code=JPI$_PRI; lst[5].bufaddr=&pri; lst[5].retlenaddr=&prilen; lst[6].buflen=4; lst[6].item_code=JPI$_PPGCNT; lst[6].bufaddr=&pagep; lst[6].retlenaddr=&pageplen; lst[7].buflen=4; lst[7].item_code=JPI$_GPGCNT; lst[7].bufaddr=&pageg; lst[7].retlenaddr=&pageglen; lst[8].buflen=4; lst[8].item_code=JPI$_DIRIO; lst[8].bufaddr=&dirio; lst[8].retlenaddr=&diriolen; lst[9].buflen=4; lst[9].item_code=JPI$_BUFIO; lst[9].bufaddr=&bufio; lst[9].retlenaddr=&diriolen; lst[10].buflen=4; lst[10].item_code=JPI$_CPUTIM; lst[10].bufaddr=δ lst[10].retlenaddr=&deltalen; lst[11].buflen=0; lst[11].item_code=0; // printf(" FreeVMS V0.0 on node %6s NN-OOO-2003 PP:QQ:RR.SS Uptime TT XX:YY:ZZ\n",scsnode); #ifdef __x86_64__ int bits = 64; #endif #ifdef __i386__ int bits = 32; #endif #ifndef FREEVMS_BUILD #define FREEVMS_BUILD 1 #endif printf(" FreeVMS %d V%s build %d on node %6s %s Uptime %s\n", bits,version, FREEVMS_BUILD, scsnode, timestr, timestr2); printf(" Pid Process Name State Pri I/O CPU Page flts Pages\n"); do { jpistatus=sys$getjpi(0,0,0,lst,0,0,0); if (jpistatus == SS$_NORMAL) delta = -delta * 100000; // check multiplication sys$asctim(0,&atimenow2,&delta,0); printf("%8x %-15s %-6s %3x %9x %17s %6x %6x\n",epid,procname,states[state],31-pri,dirio+bufio,atimenow2.dsc$a_pointer,pagef,pagep+pageg); } while (jpistatus == SS$_NORMAL); //} while (jpistatus != SS$_NOMOREPROC); }