void print_instruction() { list_chkpage(); obpt = &outbuf[0]; memset(obpt, SP, ASM_OUT_BUFF); obpt += 10; i2hex((curr_addr - SIZEOF(rhdtyp)), obpt, 8); curr_addr += (instidx - prev_idx); obpt += 10; for( ; prev_idx < instidx; prev_idx++) { i2hex(code_buf[prev_idx], obpt, 2); obpt += 2; } obpt += 10; *obpt++ = '\n'; *obpt++ = '\t'; *obpt++ = '\t'; *obpt++ = '\t'; *obpt++ = '\t'; *obpt++ = '\t'; *obpt++ = '\t'; assert( instruction.opcode_mnemonic != NULL ); SET_OBPT_STR(instruction.opcode_mnemonic, STRLEN(instruction.opcode_mnemonic)) *obpt++ = instruction.opcode_suffix; *obpt++ = '\t'; instruction.num_operands = (instruction.num_operands > grp_prefix) ? \ (instruction.num_operands - grp_prefix) : instruction.num_operands; switch (instruction.num_operands) { case 0 : break; case 1 : /* single operand assumed to be in the source operand only.. */ assert(instruction.destination_operand_class == undefined_class); print_source_operand(); break; case 2 : print_source_operand(); *obpt++ = ','; print_destination_operand(); break; default : GTMASSERT; } /* Now reset the instruction structure */ emit_eoi(); reset_instruction(); }
int upd_log_init(recvpool_user who) { char log_file[MAX_FN_LEN + 1], file_suffix_str[MAX_FN_LEN + 1], pid_str[9], *file_suffix; int status = SS_NORMAL, len; strcpy(log_file, recvpool.gtmrecv_local->log_file); if (UPDPROC == who) file_suffix = UPDPROC_LOG_FILE_SUFFIX; else { if (UPD_HELPER_READER == who) strcpy(file_suffix_str, UPDHELPER_READER_LOG_FILE_SUFFIX); else /* UPD_HELPER_WRITER == who */ strcpy(file_suffix_str, UPDHELPER_WRITER_LOG_FILE_SUFFIX); i2hex(process_id, pid_str, 8); pid_str[8] = '\0'; strcat(file_suffix_str, pid_str); file_suffix = file_suffix_str; } strcat(log_file, file_suffix); len = strlen(log_file); if (!util_is_log_open() || UPDPROC != who || 0 != memcmp(log_file, recvpool.upd_proc_local->log_file, len)) { util_log_open(log_file, len); if (UPDPROC == who) { memcpy(recvpool.upd_proc_local->log_file, log_file, len+1); /* +1 for '\0' */ gtm_event_log_init(); } } return(status); }
void cce_start(void) { int4 status; uint4 prvadr[2], prvprv[2]; static readonly $DESCRIPTOR(proc,"GT.CX_CONTROL"); static readonly $DESCRIPTOR(image,"GTM$DIST:CCP.EXE"); static readonly uic = 65540; /* uic = [1,4] */ $DESCRIPTOR(ccp,""); unsigned char success[] = "GT.CX Cluster controller started with PID = "; uint4 pid; uint4 baspri; struct FAB ccp_fab; struct NAM ccp_nam; unsigned char ccp_namebuf[63]; /* max image name allowable for creprc */ prvadr[1] = 0; prvadr[0] = PRV$M_DETACH | PRV$M_OPER | PRV$M_SYSNAM | PRV$M_SYSLCK | PRV$M_TMPMBX; status = sys$setprv(TRUE, &prvadr[0], FALSE, &prvprv[0]); if (status == SS$_NORMAL) { baspri = 5; cli_get_num("PRIORITY",&baspri); ccp_fab = cc$rms_fab; ccp_fab.fab$l_fna = image.dsc$a_pointer; ccp_fab.fab$b_fns = image.dsc$w_length; ccp_fab.fab$l_nam = &ccp_nam; ccp_nam = cc$rms_nam; ccp_nam.nam$l_esa = ccp_namebuf; ccp_nam.nam$b_ess = SIZEOF(ccp_namebuf); ccp_nam.nam$b_nop = NAM$M_SYNCHK; status = sys$parse (&ccp_fab); if (!(status & 1)) { lib$signal(status); return; } ccp.dsc$a_pointer = ccp_namebuf; ccp.dsc$w_length = ccp_nam.nam$b_esl; status = sys$creprc(&pid, &ccp, 0, 0, 0, &prvadr, 0, &proc, baspri, uic, 0, PRC$M_DETACH); sys$setprv(FALSE, &prvprv[0], FALSE, 0); if (status != SS$_NORMAL) { lib$signal(status); return; } util_out_open(0); i2hex(pid, &success[ SIZEOF(success) - 8], 8); util_out_write(&success[0], SIZEOF(success)); util_out_close(); } else lib$signal(status); }
void HEX_encode(const char *strin, char *strout, int cbstr) { const unsigned char *r = (unsigned char *) strin; const unsigned char *e = (unsigned char *) r + cbstr; char *w = strout; while (r < e) { *w++ = i2hex((*r >> 4)); *w++ = i2hex(*r & 0xF); ++r; } #ifdef _DEBUG char *t = (char *) malloc(cbstr * 2); HEX_decode(strout, t, cbstr * 2); assert(!memcmp(strin, t, cbstr)); free(t); #endif }
void op_fngetdvi(mval *device, mval *keyword, mval *ret) { itmlist_struct item_list; short out_len, iosb[4]; uint4 status; char index, slot, last_slot; int4 item_code, out_value; unsigned char buff[MAX_KEY_LENGTH], *upper_case; bool want_secondary; $DESCRIPTOR(device_name,""); error_def(ERR_DVIKEYBAD); error_def(ERR_INVSTRLEN); MV_FORCE_STR(device); MV_FORCE_STR(keyword); if (MAX_DEV_LENGTH < device->str.len) rts_error(VARLSTCNT(1) SS$_IVLOGNAM); if (keyword->str.len > MAX_KEY_LENGTH) rts_error(VARLSTCNT(4) ERR_INVSTRLEN, 2, keyword->str.len, MAX_KEY_LENGTH); if (!keyword->str.len) { rts_error(VARLSTCNT(6) ERR_DVIKEYBAD, 4, device->str.len, device->str.addr, 4, "NULL"); } lower_to_upper(&buff[0], keyword->str.addr, keyword->str.len); upper_case = buff; if ( device->str.len == 0 || (device->str.len == 1 && *device->str.addr == '0')) { device_name.dsc$a_pointer = "SYS$INPUT"; device_name.dsc$w_length = SIZEOF("SYS$INPUT")-1; } else { device_name.dsc$a_pointer = device->str.addr; device_name.dsc$w_length = device->str.len; } item_list.bufflen = VAL_LENGTH; item_list.itmcode = SPL_CODE; item_list.buffaddr = &out_value; item_list.retlen = &out_len; item_list.end = NULL; status = sys$getdvi( efn_immed_wait, 0, &device_name, &item_list, &iosb[0], 0, 0, 0 ); if (status != SS$_NORMAL && status != SS$_NONLOCAL) { rts_error(VARLSTCNT(1) status ) ; } sys$synch(efn_immed_wait, &iosb[0]); if (iosb[0] != SS$_NORMAL && iosb[0] != SS$_NONLOCAL) { rts_error(VARLSTCNT(1) iosb[0] ); } if (out_value != NULL) { want_secondary = TRUE; } else { want_secondary = FALSE; } if ((index = *upper_case - 'A') < MIN_INDEX || index > MAX_INDEX) { rts_error(VARLSTCNT(6) ERR_DVIKEYBAD, 4, device->str.len, device->str.addr, keyword->str.len, keyword->str.addr); } item_code = 0; if ( dvi_index[ index ].len) { slot = dvi_index[ index ].index; last_slot = dvi_index[ index ].len; for ( ; slot < last_slot ; slot++ ) { if (keyword->str.len == dvi_table[ slot ].len && !memcmp(dvi_table[ slot ].name, upper_case, keyword->str.len)) { item_code = dvi_table[ slot ].item_code; break; } } } if (!item_code) { rts_error(VARLSTCNT(6) ERR_DVIKEYBAD, 4, device->str.len, device->str.addr, keyword->str.len, keyword->str.addr); } switch( item_code ) { /* **** the following item codes require a string be returned **** */ case DVI$_ALLDEVNAM: case DVI$_DEVLOCKNAM: case DVI$_DEVNAM: case DVI$_FULLDEVNAM: case DVI$_LOGVOLNAM: case DVI$_NEXTDEVNAM: case DVI$_ROOTDEVNAM: case DVI$_TT_ACCPORNAM: case DVI$_TT_PHYDEVNAM: case DVI$_VOLNAM: if (want_secondary) { if (!((item_code == DVI$_DEVNAM) && (keyword->str.len == 9))) { item_code |= DVI$C_SECONDARY; } } assert(stringpool.free >= stringpool.base); assert(stringpool.top >= stringpool.free); ENSURE_STP_FREE_SPACE(MAX_DVI_STRLEN); item_list.bufflen = MAX_DVI_STRLEN; item_list.itmcode = item_code; item_list.buffaddr = stringpool.free; item_list.retlen = &out_len; item_list.end = NULL; status = sys$getdvi( efn_immed_wait, 0, &device_name, &item_list, &iosb[0], 0, 0, 0 ); if (status != SS$_NORMAL && status != SS$_NONLOCAL) { rts_error(VARLSTCNT(1) status ); } sys$synch(efn_immed_wait, &iosb[0]); if (iosb[0] != SS$_NORMAL && iosb[0] != SS$_NONLOCAL) { rts_error(VARLSTCNT(1) iosb[0] ) ; } ret->str.addr = stringpool.free; ret->str.len = out_len; ret->mvtype = MV_STR; stringpool.free += out_len; assert(stringpool.free >= stringpool.base); assert(stringpool.top >= stringpool.free); return; default: if (want_secondary) item_code |= DVI$C_SECONDARY; item_list.itmcode = item_code; item_list.bufflen = VAL_LENGTH; item_list.buffaddr = &out_value; item_list.retlen = &out_len; item_list.end = NULL; status = sys$getdvi( efn_immed_wait, 0, &device_name, &item_list, &iosb[0], 0, 0, 0 ); if (status != SS$_NORMAL && status != SS$_NONLOCAL) rts_error(VARLSTCNT(1) status ); sys$synch(efn_immed_wait, &iosb[0]); if (iosb[0] != SS$_NORMAL && iosb[0] != SS$_NONLOCAL) rts_error(VARLSTCNT(1) iosb[0] ); if (want_secondary) item_code = item_code - 1; switch(item_code) { case DVI$_LOCKID: case DVI$_ACPPID: case DVI$_OWNUIC: if (out_value) { assert(stringpool.free >= stringpool.base); assert(stringpool.top >= stringpool.free); ENSURE_STP_FREE_SPACE(HEX_LEN); i2hex(out_value, stringpool.free, HEX_LEN); ret->str.addr = stringpool.free; ret->str.len = HEX_LEN; stringpool.free += HEX_LEN; assert(stringpool.free >= stringpool.base); assert(stringpool.top >= stringpool.free); } else { ret->str.addr = ""; ret->str.len = 0; } ret->mvtype = MV_STR; break; case DVI$_ACPTYPE: switch(out_value) { case 0: ret->str.addr = "ILLEGAL"; ret->str.len = 7; break; case 1: ret->str.addr = "F11V1"; ret->str.len = 5; break; case 2: ret->str.addr = "F11V2"; ret->str.len = 5; break; case 3: ret->str.addr = "MTA"; ret->str.len = 3; break; case 4: ret->str.addr = "NET"; ret->str.len = 3; break; case 5: ret->str.addr = "REM"; ret->str.len = 3; } ret->mvtype = MV_STR; break; default: i2mval(ret,out_value) ; } return; } }
static int helper_init(upd_helper_entry_ptr_t helper, recvpool_user helper_type) { int save_errno, save_shutdown; char helper_cmd[UPDHELPER_CMD_MAXLEN]; int status; int4 i4status; mstr helper_log_cmd, helper_trans_cmd; upd_helper_ctl_ptr_t upd_helper_ctl; #ifdef UNIX pid_t helper_pid, waitpid_res; #elif defined(VMS) uint4 helper_pid, cmd_channel; char mbx_suffix[2 + 1]; /* hex representation of numbers 0 through MAX_UPD_HELPERS-1, +1 for '\0' */ $DESCRIPTOR(cmd_desc_reader, UPDHELPER_READER_CMD_STR); $DESCRIPTOR(cmd_desc_writer, UPDHELPER_WRITER_CMD_STR); #endif upd_helper_ctl = recvpool.upd_helper_ctl; save_shutdown = helper->helper_shutdown; helper->helper_shutdown = NO_SHUTDOWN; #ifdef UNIX if (0 > (helper_pid = fork())) /* BYPASSOK: we exec immediately, no FORK_CLEAN needed */ { save_errno = errno; helper->helper_shutdown = save_shutdown; gtm_putmsg(VARLSTCNT(7) ERR_RECVPOOLSETUP, 0, ERR_TEXT, 2, LEN_AND_LIT("Could not fork update process"), save_errno); repl_errno = EREPL_UPDSTART_FORK; return UPDPROC_START_ERR; } if (0 == helper_pid) { /* helper */ getjobnum(); helper->helper_pid_prev = process_id; /* identify owner of slot */ helper_log_cmd.len = STR_LIT_LEN(UPDHELPER_CMD); helper_log_cmd.addr = UPDHELPER_CMD; if (SS_NORMAL != (i4status = TRANS_LOG_NAME(&helper_log_cmd, &helper_trans_cmd, helper_cmd, SIZEOF(helper_cmd), dont_sendmsg_on_log2long))) { helper->helper_shutdown = save_shutdown; gtm_putmsg(VARLSTCNT(6) ERR_RECVPOOLSETUP, 0, ERR_TEXT, 2, LEN_AND_LIT("Could not find path of Helper Process. Check value of $gtm_dist")); if (SS_LOG2LONG == i4status) gtm_putmsg(VARLSTCNT(5) ERR_LOGTOOLONG, 3, LEN_AND_LIT(UPDHELPER_CMD), SIZEOF(helper_cmd) - 1); repl_errno = EREPL_UPDSTART_BADPATH; return UPDPROC_START_ERR; } helper_cmd[helper_trans_cmd.len] = '\0'; if (-1 == EXECL(helper_cmd, helper_cmd, UPDHELPER_CMD_ARG1, UPDHELPER_CMD_ARG2, (UPD_HELPER_READER == helper_type) ? UPDHELPER_READER_CMD_ARG3 : UPDHELPER_WRITER_CMD_ARG3, NULL)) { save_errno = errno; helper->helper_shutdown = save_shutdown; gtm_putmsg(VARLSTCNT(7) ERR_RECVPOOLSETUP, 0, ERR_TEXT, 2, LEN_AND_LIT("Could not exec Helper Process"), save_errno); repl_errno = EREPL_UPDSTART_EXEC; return UPDPROC_START_ERR; } } #elif defined(VMS) /* Create detached server and write startup commands to it */ i2hex(helper - upd_helper_ctl->helper_list, LIT_AND_LEN(mbx_suffix)); mbx_suffix[SIZEOF(mbx_suffix) - 1] = '\0'; /* A mailbox is created per helper, and the mailbox name is assigned to a logical. This logical will persist until the * helper terminates. So, we need to assign a unique logical per helper. Hence the suffix. */ if (SS_NORMAL != (status = repl_create_server((UPD_HELPER_READER == helper_type) ? &cmd_desc_reader : &cmd_desc_writer, UPDHELPER_MBX_PREFIX, mbx_suffix, &cmd_channel, &helper->helper_pid_prev, ERR_RECVPOOLSETUP))) { gtm_putmsg(VARLSTCNT(7) ERR_RECVPOOLSETUP, 0, ERR_TEXT, 2, LEN_AND_LIT("Unable to spawn Helper process"), status); helper->helper_shutdown = save_shutdown; repl_errno = EREPL_UPDSTART_FORK; return UPDPROC_START_ERR; } helper_pid = helper->helper_pid_prev; #endif /* Wait for helper to startup */ while (helper_pid != helper->helper_pid && is_proc_alive(helper_pid, 0)) { SHORT_SLEEP(GTMRECV_WAIT_FOR_SRV_START); UNIX_ONLY(WAITPID(helper_pid, &status, WNOHANG, waitpid_res);) /* Release defunct helper process if dead */ } /* The helper has now gone far enough in the initialization, or died before initialization. Consider startup completed. */ #if defined(VMS) /* Deassign the send-cmd mailbox channel */ if (SS_NORMAL != (status = sys$dassgn(cmd_channel))) { gtm_putmsg(VARLSTCNT(7) ERR_RECVPOOLSETUP, 0, ERR_TEXT, 2, RTS_ERROR_LITERAL("Unable to close upd-send-cmd mbox channel"), status); helper->helper_shutdown = save_shutdown; repl_errno = EREPL_UPDSTART_BADPATH; /* Just to make an auto-shutdown */ return UPDPROC_START_ERR; } #endif repl_log(gtmrecv_log_fp, TRUE, TRUE, "Helper %s started. PID %d [0x%X]\n", (UPD_HELPER_READER == helper_type) ? "reader" : "writer", helper_pid, helper_pid); return UPDPROC_STARTED; }
caddr_t util_format(caddr_t message, va_list fao, caddr_t buff, int4 size, int faocnt) { desc_struct *d; signed char schar; unsigned char type, type2; caddr_t c, outptr, outtop; uchar_ptr_t ret_ptr; unsigned char uchar; short sshort, *s; unsigned short ushort; int i, length, max_chars, field_width, repeat_count, int_val; boolean_t indirect; qw_num_ptr_t val_ptr; unsigned char numa[22]; unsigned char *numptr; VAR_COPY(last_va_list_ptr, fao); outptr = buff; outtop = outptr + size - 5; /* 5 bytes to prevent writing across border */ /* 5 comes from line 268 -- 278 */ while (outptr < outtop) { /* Look for the '!' that starts an FAO directive */ while ((schar = *message++) != '!') { if (schar == '\0') { VAR_COPY(last_va_list_ptr, fao); return outptr; } *outptr++ = schar; if (outptr >= outtop) { VAR_COPY(last_va_list_ptr, fao); return outptr; } } field_width = 0; /* Default values */ repeat_count = 1; /* Look for a field width (or repeat count) */ if (*message == '#') { if (0 < faocnt) field_width = repeat_count = va_arg(fao, int4); ++message; } else { for (c = message; *c >= '0' && *c <= '9'; ++c) ; if ((length = c - message) > 0) { field_width = repeat_count = asc2i((uchar_ptr_t)message, length); message = c; } } if ('@' == *message) /* Indirectly addressed operand */ { indirect = TRUE; message++; } else indirect = FALSE; switch (type = *message++) { case '/': assert(!indirect); *outptr++ = '\n'; continue; case '_': assert(!indirect); *outptr++ = '\t'; continue; case '^': assert(!indirect); *outptr++ = '\f'; continue; case '!': assert(!indirect); *outptr++ = '!'; continue; case '*': assert(!indirect); while ((repeat_count-- > 0) && (outptr < outtop)) *outptr++ = *message; ++message; continue; case 'A': assert(!indirect); switch(type2 = *message++) { case 'C': GETFAOVALDEF(faocnt, fao, caddr_t, c, NULL); length = c ? *c++ : 0; break; case 'D': case 'F': GETFAOVALDEF(faocnt, fao, int4, length, 0); GETFAOVALDEF(faocnt, fao, caddr_t, c, NULL); break; case 'S': if (faocnt) { d = (desc_struct *)va_arg(fao, caddr_t); faocnt--; c = d->addr; length = d->len; } else { c = NULL; length = 0; } break; case 'Z': GETFAOVALDEF(faocnt, fao, caddr_t, c, NULL); length = c ? strlen(c) : 0; } max_chars = MIN((outtop - outptr - 1), (0 == field_width ? length : MIN(field_width, length))); for (i = 0; i < max_chars; ++i, ++c) if (type2 == 'F' && (*c < ' ' || *c > '~')) *outptr++ = '.'; else if (*c == '\0') --i; /* Don't count nul characters */ else *outptr++ = *c; assert(0 <= field_width); assert(0 <= max_chars); for (i = field_width - max_chars; i > 0; --i) *outptr++ = ' '; continue; default: /* Rest of numeric types come here */ assert('S' == type || 'U' == type || 'X' == type || 'Z' == type); numptr = numa; type2 = *message++; if (!indirect) { if ('S' == type) switch(type2) { case 'B': GETFAOVALDEF(faocnt, fao, int4, schar, 0); int_val = schar; break; case 'W': GETFAOVALDEF(faocnt, fao, int4, sshort, 0); int_val = sshort; break; case 'L': GETFAOVALDEF(faocnt, fao, int4, int_val, 0); break; default: assert(FALSE); } else { GETFAOVALDEF(faocnt, fao, int4, int_val, 0); switch(type2) { case 'B': int_val = int_val & 0xFF; break; case 'W': int_val = int_val & 0xFFFF; break; case 'L': int_val = int_val & 0xFFFFFFFF; break; default: assert(FALSE); } } switch (type) { case 'S': /* Signed value. Give sign if need to */ if (0 > int_val) { *numptr++ = '-'; int_val = -(int_val); } /* note fall into unsigned */ case 'U': case 'Z': /* zero filled */ numptr = i2asc(numptr, int_val); break; case 'X': /* Hex */ switch (type2) { /* length is number of ascii hex chars */ case 'B': length = sizeof(short); break; case 'W': length = sizeof(int4); break; case 'L': length = sizeof(int4) + sizeof(int4); break; default: assert(FALSE); } i2hex(int_val, numptr, length); numptr += length; break; default: assert(FALSE); } } else { if ('X' == type) /* Support XH and XJ */ { assert('H' == type2 || 'J' == type2); GETFAOVALDEF(faocnt, fao, qw_num_ptr_t, val_ptr, NULL); /* Addr of long type */ if (val_ptr) { if (0 != field_width) { i2hexl(*val_ptr, numptr, field_width); numptr += field_width; } else { length = i2hexl_nofill(*val_ptr, numptr, HEX16); numptr += length; } } } else /* support ZH and ZJ */ { if ('Z' != type) GTMASSERT; assert('H' == type2 || 'J' == type2); GETFAOVALDEF(faocnt, fao, qw_num_ptr_t, val_ptr, NULL); /* Addr of long type */ if (val_ptr) { ret_ptr = i2ascl(numptr, *val_ptr); length = ret_ptr - (uchar_ptr_t)numptr; if (0 != field_width) numptr += MIN(length, field_width); else numptr += length; } } } length = numptr - numa; /* Length of asciified number */ max_chars = MIN((outtop - outptr - 1), (0 == field_width ? length : MIN(field_width, length))); if (length < field_width) { memset(outptr, (('Z' == type) ? '0' : ' '), field_width - length); outptr += field_width - length; } if ((field_width > 0) && (field_width < length)) { memset(outptr, '*', field_width); outptr += field_width; } else { memcpy(outptr, numa, length); outptr += length; } } } VAR_COPY(last_va_list_ptr, fao); return outptr; }