/* ** Name: CFWriteConf ** ** Description: ** Write out the configuration file. ** ** Inputs: ** loc location to write configuration ** begin starting line of configuration ** ** Outputs: ** none ** ** Returns: ** OK success ** FAIL failure ** ** History: ** 11-Feb-2000 (fanra01) ** Created. */ STATUS CFWriteConf( LOCATION* loc, PRL begin ) { STATUS status = OK; PRL entry = begin; FILE* fptr; i4 count; if ((status=SIfopen( loc, "w", SI_TXT, 0, &fptr )) == OK) { while (entry != NULL) { status = SIwrite( STRLENGTH( entry->text ), entry->text, &count, fptr ); entry = entry->next; } SIclose( fptr ); } else { char* tmp = NULL; LOtos( loc, &tmp ); PRINTF( "Error: %d - Unable to open file %s.\n", status, tmp ); } return (status); }
/*{ ** Name: open_infile - open a template file ** ** Description: ** Opens a template file from a directory. ** ** Inputs: ** directory - template directory ** template_filename - input template file name ** ** Outputs: ** none ** ** Returns: ** NULL - open failed ** FILE * - file pointer */ FILE * open_infile( char *directory, char *template_filename) { FILE *in_file; char *p; char filename[MAX_LOC+1]; LOCATION loc; if (template_filename == NULL || *template_filename == EOS) { IIUGerr(E_RM00EE_Null_empty_arg, UG_ERR_ERROR, 1, ERx("open_infile")); return (NULL); } STcopy(directory, filename); LOfroms(PATH, filename, &loc); LOfstfile(template_filename, &loc); if (SIfopen(&loc, ERx("r"), SI_TXT, SI_MAX_TXT_REC, &in_file) != OK) { LOtos(&loc, &p); IIUGerr(E_RM00F1_Err_open_template, UG_ERR_ERROR, 1, p); return (NULL); } return (in_file); }
/* ** Name: CFCreateConf ** ** Description: ** Create a configuration file. ** ** Inputs: ** path path to configuration file. ** filename filename of configuration file. ** begin Starting line of the confiuration ** ** Outputs: ** loc location structure updated. ** ** Returns: ** OK success ** FAIL failure ** ** History: ** 11-Feb-2000 (fanra01) ** Created. */ STATUS CFCreateConf( char* path, char* filename, LOCATION* loc, PRL begin ) { STATUS status; char* locpath; FILE* fptr; PRL entry = begin; i4 count; /* ** Get the location path */ LOtos( loc, &locpath ); STRCOPY(path, locpath ); if ((status = LOfroms( PATH, locpath, loc )) == OK) { LOfstfile( filename, loc ); if ((status = SIfopen( loc, "w", SI_TXT, 0, &fptr )) == OK) { while ((status == OK) && (entry != NULL)) { status = SIwrite( STRLENGTH(entry->text), entry->text, &count, fptr ); entry = entry->next; } SIclose( fptr ); } else { PRINTF( "Error: %d - Unable to open file %s in %s.\n", status, filename, path ); } } return (status); }
/*{ ** Name: RSblob_gcCallback - IIapi_getColumns callback for blobs ** ** Description: ** If the blob is smaller than DB_MAXTUP-2 bytes, set the blob size and ** return. Otherwise, open a temporary file in II_TEMPORARY and write the ** blob segments to it. ** ** Inputs: ** closure - closure (unused) ** parmBlock - IIAPI_GETCOLPARM parameter block ** ** Outputs: ** RS_BLOB buffer is updated. ** ** Returns: ** none */ II_VOID II_FAR II_CALLBACK RSblob_gcCallback( II_PTR closure, II_PTR parmBlock) { IIAPI_GETCOLPARM *gcolParm = (IIAPI_GETCOLPARM *)parmBlock; RS_BLOB *blob = (RS_BLOB *)gcolParm->gc_columnData[0].dv_value; LOCATION loc; char *p; i4 cnt; if (!blob->fp && !blob->size) { /* ** If this is the only segment, just set the size from the ** length. */ if (!gcolParm->gc_moreSegments) { blob->size = blob->len; return; } /* ** If there are more segments and the file hasn't been opened, ** create a new temporary file. */ NMloc(TEMP, PATH, NULL, &loc); LOuniq(ERx("bl"), ERx("tmp"), &loc); LOtos(&loc, &p); STcopy(p, blob->filename); if (SIfopen(&loc, ERx("w"), SI_VAR, sizeof blob->buf, &blob->fp) != OK) { gcolParm->gc_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY; return; } } /* write the current segment to a file and add to the size */ if (SIwrite((i4)blob->len, blob->buf, &cnt, blob->fp) != OK) { gcolParm->gc_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY; return; } blob->size += blob->len; /* if this is the last segment, close the temporary file */ if (!gcolParm->gc_moreSegments) { if (SIclose(blob->fp) != OK) { gcolParm->gc_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY; return; } blob->fp = NULL; } }
char * xfaddpath(char *filename, i4 in_or_out) { auto char *wholename; if (filename == NULL) { wholename = NULL; } else if (in_or_out == XF_INTOFILE && Xf_into_path != NULL) { STcopy(Xf_into_path, Whole_name); # ifdef UNIX if (Whole_name[STlength(Whole_name)-1] != '/') STcat(Whole_name, ERx("/")); # else # ifdef DESKTOP if (Whole_name[STlength(Whole_name)] != '\\') STcat(Whole_name, ERx("\\")); # endif /* DESKTOP */ # endif wholename = STcat(Whole_name, filename); } else if (in_or_out == XF_FROMFILE && Xf_from_path != NULL) { STcopy(Xf_from_path, Whole_name); # ifdef UNIX if (Whole_name[STlength(Whole_name)-1] != '/') STcat(Whole_name, ERx("/")); # else # ifdef DESKTOP if (Whole_name[STlength(Whole_name)] != '\\') STcat(Whole_name, ERx("\\")); # endif /* DESKTOP */ # endif wholename = STcat(Whole_name, filename); } else { LOcopy(&Xf_dir, Tmppath_buf, &Tmppath); /* add the file name to location */ LOfstfile(filename, &Tmppath); LOtos(&Tmppath, &wholename); } # ifdef NT_GENERIC xlate_backslash(wholename); # endif /* NT_GENERIC */ return (wholename); }
/* ** Name: CFReadConf ** ** Description: ** Read the configuration file a line at a time and build a list. ** ** Inputs: ** path path of file to read ** filename filename of file to read ** ** Outputs: ** loc Location to update with path and filename ** begin Starting line of the confiuration ** end Last line of the configuration ** ** Returns: ** OK success ** FAIL failure ** ** History: ** 11-Feb-2000 (fanra01) ** Created. */ STATUS CFReadConf( char* path, char* filename, LOCATION* loc, PRL* begin ) { STATUS status; char* locpath; FILE* fptr; PRL newline; PRL end; /* ** Get the location path */ LOtos( loc, &locpath ); STRCOPY( path, locpath ); if ((status = LOfroms( PATH, locpath, loc )) == OK) { LOfstfile( filename, loc ); if ((status = SIfopen( loc, "r", SI_TXT, 0, &fptr )) == OK) { do { status = SIgetrec( readbuf, SI_MAX_TXT_REC, fptr ); if (status != ENDFILE) { HALLOC( newline, RL, 1, &status ); if (newline != NULL) { newline->text = STRALLOC( readbuf ); if (*begin == NULL) { *begin = newline; newline->prev = newline; } else { end = (*begin)->prev; end->next = newline; newline->prev = end; (*begin)->prev = newline; } } } }while (status == OK); status = ((status == ENDFILE) || (status == OK)) ? OK : status; SIclose( fptr ); } else { PRINTF( "Error: %d - Unable to open file %s in %s.\n", status, filename, path ); } } return (status); }
/*{ ** Name: ERlog - Send message to the error logger. ** ** Description: ** This procedure sends a message to the system specific error ** logger (currently an error log file). ** ** Inputs: ** message Address of buffer containing the message. ** msg_length Length of the message. ** ** Outputs: ** err_code Operating system error code. ** Returns: ** OK ** ER_BADOPEN ** ER_BADSEND ** ER_BADPARAM ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 29-sep-1992 (pholman) ** First created, taken from original (6.4) version of ERsend ** CL Committee approved, 18-Sep-1992 */ STATUS ERlog(char *message, i4 msg_length, CL_ERR_DESC *err_code) { static int er_ifi = -2; auto LOCATION loc; auto char *fname; #ifdef xCL_074_WRITEV_READV_EXISTS char buf2 = '\n'; struct iovec iov[2]; i4 iovlen = 2; #endif /* Check for bad paramters. */ CL_CLEAR_ERR( err_code ); if (message == 0 || msg_length == 0) return (ER_BADPARAM); if (er_ifi == -2) { if (NMloc(LOG, FILENAME, "errlog.log", &loc) != OK) { er_ifi = -1; return(ER_BADSEND); } LOtos(&loc, &fname); er_ifi = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666); if (er_ifi == -1) { SETCLERR(err_code, 0, ER_open); return(ER_BADSEND); } } #ifdef xCL_074_WRITEV_READV_EXISTS iov[0].iov_base = (caddr_t)message; iov[0].iov_len = msg_length; iov[1].iov_base = (caddr_t)&buf2; iov[1].iov_len = 1; if( writev(er_ifi, iov, iovlen) != (msg_length + 1)) #else if (write(er_ifi, message, msg_length) != msg_length || write(er_ifi, "\n", 1) != 1) #endif { SETCLERR(err_code, 0, ER_write); return(ER_BADSEND); } return(OK); }
/*{ ** Name: open_outfile - creates or appends to an output file ** ** Description: ** Creates or opens (for append) a file in a directory and sets a ** LOCATION structure. ** ** Inputs: ** out_filename - output file name ** out_dir - output directory ** create_or_append - create a new file or append to existing file ** uniq - make a unique filename ** ** Outputs: ** loc_name - output file path ** ** Returns: ** NULL - open failed ** FILE * - file pointer */ FILE * open_outfile( char *out_filename, char *out_dir, char *create_or_append, char *loc_name, bool uniq) { FILE *out_file; char *p; char filename[MAX_LOC+1]; LOCATION loc; if (loc_name == NULL) return (NULL); if (CMcmpcase(create_or_append, ERx("c")) == 0) { STcopy(out_dir, filename); LOfroms(PATH, filename, &loc); /* if uniq is 1, create a unique filename */ if (uniq == 1) LOuniq(out_filename, ERx(""), &loc); else LOfstfile(out_filename, &loc); if (SIfopen(&loc, ERx("w"), SI_TXT, SI_MAX_TXT_REC, &out_file) != OK) { IIUGerr(E_RM00F2_Err_open_outfile, UG_ERR_ERROR, 1, out_filename); return (NULL); } LOtos(&loc, &p); STcopy(p, loc_name); } else { LOfroms(PATH & FILENAME, loc_name, &loc); if (SIfopen(&loc, ERx("a"), SI_TXT, SI_MAX_TXT_REC, &out_file) != OK) { IIUGerr(E_RM00F2_Err_open_outfile, UG_ERR_ERROR, 1, out_filename); return (NULL); } } return (out_file); }
void yyinit( void ) { char *name, *value, *map_path; /* zero the line counter */ yylineno = 0; if( rulemap_path == NULL ) { NMloc( FILES, FILENAME, ERx( "default.rfm" ), &loc ); LOcopy( &loc, file_name, &loc ); LOtos( &loc, &map_path ); } else { STcopy( rulemap_path, file_name ); LOfroms( FILENAME, file_name, &loc ); map_path = rulemap_path; } (void) PMmInit( &rulemap ); if( PMmLoad( rulemap, &loc, PMerror ) != OK ) PCexit( FAIL ); /* initiate scan of rule map */ if( PMmScan( rulemap, ERx( ".*" ), &rfm_scan, NULL, &name, &value ) != OK ) { F_ERROR( "Rule file map %s is empty.", map_path ); } /* set up LOCATION of first rule file */ STcopy( value, file_name ); NMloc( FILES, FILENAME, file_name, &loc ); LOcopy( &loc, file_name, &loc ); /* initialize input pointer */ yyp = &dummy; /* open rule file */ if( SIfopen( &loc, ERx( "r" ), SI_TXT, SI_MAX_TXT_REC, &yyin ) != OK && yywrap() ) { ERROR( "No configuration rule files were found." ); } }
/* ** Name: gipImportInstXML() ** ** Description: ** ** Import generated XML doc containing save set and instance info. ** ** History: ** 05-Sep-2007 (hanje04) ** Created. ** */ STATUS gipImportPkgInfo( LOCATION *xmlfileloc, UGMODE *state, i4 *count ) { char *xmlfilestr = NULL; xmlDocPtr doc; xmlNodePtr cur; /* sanity check */ if ( LOexist( xmlfileloc ) != OK ) return( FAIL ); /* get location string */ LOtos( xmlfileloc, &xmlfilestr ); /* load instance/saveset document */ doc = xmlParseFile( xmlfilestr ); if ( doc == NULL ) return( FAIL ); /* load first element */ cur = xmlDocGetRootElement( doc ); /* basic validation */ /* FIX ME, NEED DTD!!! */ if ( cur == NULL || xmlStrcmp( cur->name, (const xmlChar *) "IngresPackageInfo" ) ) { xmlFreeDoc( doc ); return( FAIL ); } /* walk the tree */ cur = cur->xmlChildrenNode; while ( cur != NULL ) { if ( ! xmlStrcmp( cur->name, (const xmlChar *)"saveset" ) ) gipParseSaveSet( doc, cur ); else if ( ! xmlStrcmp( cur->name, (const xmlChar *)"instances" ) ) gipParseInstances( doc, cur, state, count ); cur = cur->next; } xmlFreeDoc( doc ); return( OK ); }
/* ** Name: setperms - set permissions on a directory ** ** Description: ** Sets specific permissions on a directory. ** ** Inputs: ** loc pointer to LOCATION describing directory ** perms VMS-style permissions mask. ** ** Outputs: ** none ** ** History: ** 03-dec-2003 (abbjo03) ** Created. */ static STATUS setperms( LOCATION *loc, u_i2 perms) { FABDEF fab; XABPRODEF1 xab; char dirfile[MAX_LOC]; char *path; LOtos(loc, &path); /* Convert directory format to file format, if need be */ if ((loc->desc | FILENAME) != FILENAME) LOdir_to_file(path, dirfile); /* Initialize the RMS fab */ MEfill(sizeof(fab), 0, (PTR)&fab); fab.fab$b_bid = FAB$C_BID; fab.fab$b_bln = FAB$C_BLN; fab.fab$b_fac = FAB$M_UPD; fab.fab$l_fna = dirfile; fab.fab$b_fns = STlength(fab.fab$l_fna); fab.fab$l_xab = &xab; /* Initialize the RMS xab */ MEfill(sizeof(xab), 0, (PTR)&xab); xab.xab$b_cod = XAB$C_PRO; xab.xab$b_bln = XAB$C_PROLEN; /* See if we can open it */ if ((sys$open(&fab) & 1) == 0) return FAIL; xab.xab$w_pro = perms; if((sys$close(&fab) & 1) == 0) return FAIL; return OK; }
/* append = nonzero to append to output file. ** rederr = nonzero to redirect stderr to error log. */ STATUS PCdospawn(i4 argc, char **argv, bool wait, LOCATION *in_name, LOCATION *out_name, i4 append, i4 rederr, PID *pid) { char buf[64]; char *in_fname; char *out_fname; STATUS PCwait(); TYPESIG (*old_handler)(); int flags = 0; STATUS status; /* Flush the output buffers to make sure all child output ** follows the parent output. The streams may be buffered ** if, for example, they were redirected to a file. */ SIflush(stdout); SIflush(stderr); TRflush(); /* Don't want to mess up a sub-shell's handling of this by leaving ** it something odd. This might be a problem if something is ** run out of a DBMS server and an iislave happens to die while the ** subprocess spawned here is running. The symptom of this not working ** right is ckpdb failing, because the shell's handling of child death ** was messed up by our redirected handling of SIGCHLD. Frankly, that ** smells odd to me, but what the heck... (daveb). */ old_handler = EXsetsig(SIGCHLD, SIG_DFL); if ( (argc < 1) || (argv[0] == NULL)) { PCstatus = PC_SP_CALL; } /* ** If we are using fork() instead of vfork(), we must check ** to see if argument is executable now, because ** PCstatus from child process won't be available ** to parent. We don't know if we are using fork, so ** always check. */ else if (access(argv[0], 01) == BAD_ACCESS) { switch (errno) { case EACCES: /* error occurred because path was inaccessable. */ PCstatus = PC_SP_PERM; break; case EPERM: PCstatus = PC_SP_OWNER; break; case ENOTDIR: /* error occurred path didn't exist */ PCstatus = PC_SP_PATH; break; case ENOENT: /* error occurred path didn't exist */ PCstatus = PC_SP_SUCH; break; } } else if ( (*pid = (PID)PCfork( &PCstatus )) > 0 ) /* parent */ { /* ** (v)fork returns control to parent after exec. ** Calling process can ask PCspawn() to wait for ** the child, wait itself or choose not to wait. */ /* ** in the case of PC_NO_WAIT, we are only waiting for ** the intermediate process, which will also do fork/exec */ PCstatus = PCwait(*pid); } else if ( *pid == 0 ) /* child */ { if ( !wait ) { #if !defined xCL_086_SETPGRP_0_ARGS /* BSD flavour setpgrp */ if (setpgrp(0, getpid()) == -1 ) { status = errno; SIprintf("Can't change process group for spawned process\n"); PCexit(status); } # ifdef TIOCNOTTY /* say goodbye to our control terminal */ if ( (fd = open("/dev/tty", O_RDWR) ) >= 0 ) { ioctl(fd, TIOCNOTTY, (char *) NULL); close(fd); } # endif /* TIOCNOTTY */ #else /* SYSV flavour setpgrp */ if(setpgrp() == -1) /* create new pgrp, lose control terminal */ { status = errno; SIprintf("Can't change process group for spawned process\n"); PCexit(status); } #endif /* fork again, so we can't reacquire a control terminal */ if ( (*pid = PCfork(&status)) < 0 ) { status = errno; SIprintf("Can't fork again for spawned process\n"); PCexit(status); } else if (*pid > 0) { /* intermediate parent */ _exit(OK); } /* reset all the signal handlers to default */ EXsetsig( SIGCHLD, SIG_DFL ); } if (in_name != NULL) { LOtos(in_name, &in_fname); if ( *in_fname && freopen(in_fname, "r", stdin) != stdin ) PCstatus = PC_SP_REOPEN; } if (PCstatus == OK) { if (out_name != NULL) { char *mode = (append != 0) ? ERx("a") : ERx("w"); LOtos(out_name, &out_fname); if ( *out_fname ) { if (freopen(out_fname, mode, stdout) != stdout) { PCstatus = PC_SP_REOPEN; } else if (rederr != 0) { close(2); dup(1); } } } if (PCstatus == OK) { STcopy(argv[0], buf); argv[argc] = '\0'; /* insure argv set up properly */ execvp(buf, argv); /* should never reach here, because we checked first */ PCno_exec(buf); } } /* Should only reach here we had a PC_SP_REOPEN failure */ _exit( FAIL ); } (void) EXsetsig(SIGCHLD, old_handler); return( PCstatus ); }
/*{ ** Name: CS_des_installation() - destroy shared resources of an installation. ** ** Description: ** Destroy the system shared memory segment, the logging/locking ** shared memory segment, and the system semaphores associated with the ** current installtion. This is called from the logging code as a ** result of "rcpconfig /shutdown". ** ** It assumes that all the shared memory segments have already been ** initialized by the appropriate routines. The order of destruction ** is important as a reverse may cause access violations on some ** implementation of shared memory (where the segment disappears as ** soon as it destroyed). ** ** Any subsequent logging/locking or event routines called after this ** routine will likely fail, so the caller should exit soon after this ** call. ** ** Inputs: ** none. ** ** Outputs: ** none. ** ** ** History: ** 08-sep-88 (anton) ** use LOcations for segments and destroy server segments ** 09-jun-88 (mmm) ** written. ** 12-jun-89 (rogerk) ** Change MEsmdestroy calls to take character string key instead ** of LOCATION pointer. ** 22-dec-92 (mikem) ** Changed a for(;;) to a do..while(FALSE) to shut up stupid acc ** warning. ** 02-feb-92 (sweeney) ** remove orphaned call to MEsmdestroy() on lockseg. ** 26-jul-1993 (bryanp) ** Remove no-longer-needed system semaphores (css_semid sems). ** 03-jun-1996 (canor01) ** Clean up semaphores for operating system threads. ** 16-sep-2002 (somsa01) ** Make sure we run the appropriate "cscleanup" in the case of ** ADD_ON64. ** 22-Jun-2009 (kschendel) SIR 122138 ** VMS doesn't do hybrids, but update the conditional anyway. */ STATUS CS_des_installation(void) { STATUS status; LOCATION loc; char *string; PID pid; char *argv[1]; CL_ERR_DESC err_code; i4 i; char segname[48]; /* stop all servers that are still active, forcing them to exit if ** they have not already exited. */ /* call the cscleanup code to clean up all the server slots still out ** there. */ if ((NMloc(SUBDIR, PATH, "utility", &loc) == OK) && #if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64) (LOfaddpath(&loc, "lp64", &loc) == OK) && #endif (LOfstfile("cscleanup", &loc) == OK)) { /* if everything is successful try and run the cleanup program, ** else just do the rest and make user run "cscleanup" by themselves. */ LOtos(&loc, &string); argv[0] = string; PCspawn(1, argv, TRUE, (LOCATION *) NULL, (LOCATION *) NULL, &pid); } do { /* destroy any left over server segements */ for (i = 0; i < MAXSERVERS; i++) { STcopy("server.", segname); CVna(i, segname+STlength(segname)); #ifdef xCL_NEED_SEM_CLEANUP CS_cp_sem_cleanup(segname, &err_code); #endif (VOID) MEsmdestroy(segname, &err_code); } /* FIX ME */ /* kill off slave processes here or in cscleanup code */ /* destroy the system shared memory segment */ #ifdef xCL_NEED_SEM_CLEANUP CS_cp_sem_cleanup("sysseg.mem", &err_code); #endif status = MEsmdestroy("sysseg.mem", &err_code); if (status) break; } while (FALSE); return(status); }
STATUS getLocation(char *string,char *newstr,LOCTYPE *typeOfLoc) { STATUS ret_val ; LOCATION aLoc ; LOCATION bLoc ; LOCATION *Locptr1 = NULL ; LOCATION *Locptr2 = NULL ; LOCATION *Locptr3 = NULL ; char *cptr = NULL ; char *cptr2 = NULL ; char *next = NULL ; char *start = NULL ; char *tmpBuf = NULL ; char *tmpBuf2 = NULL ; char *gl_dev = NULL ; char *gl_path [128] ; char *gl_file = NULL ; char *resultPtr = NULL ; char *tmpaLocStr = NULL ; char *tmpbLocStr = NULL ; i4 i ; ret_val = OK; for ( i=0; i<128; i++) gl_path[i] = NULL; tmpaLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); tmpbLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); LOfroms(FILENAME & PATH, tmpaLocStr, &aLoc); LOfroms(FILENAME & PATH, tmpbLocStr, &bLoc); if (tracing&TRACE_PARM) { SIfprintf(traceptr, ERx("getLocation00> string = %s\n"), string); SIfprintf(traceptr, ERx("getLocation01> newstr = %s\n"), newstr); } tmpBuf = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); STcopy(string, tmpBuf); if (!(start = STindex(tmpBuf, ERx("("), 0))) { MEtfree(SEP_ME_TAG_GETLOC); return(FAIL); } MEfree(tmpaLocStr); MEfree(tmpbLocStr); aLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); bLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); next = start; CMnext(next); if (typeOfLoc) *typeOfLoc = NULL; if (CMcmpcase(next, ERx(","))) { /* There's a device specification */ cptr = next; if ((next = STindex(cptr, ERx(","), 0)) == NULL) { if ((next = STindex(cptr, ERx(")"), 0)) == NULL) ret_val = FAIL; else { /* ** This is really a file name in the form, @file(filename.type) */ *next = EOS; gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2, TRUE, (STATUS *)NULL); STcopy(cptr, gl_file); if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation02> file = %s\n"), gl_file); if (typeOfLoc) *typeOfLoc = FILENAME; } } else { *next = EOS; gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2, TRUE, (STATUS *)NULL); #ifdef UNIX STpolycat(2,ERx("$"),cptr, gl_dev); cptr2 = gl_dev; SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC); if ((tmpBuf2 == NULL)||(*tmpBuf2 == EOS)) { switch (i = SEP_CMwhatcase(cptr2)) { case 0: break; case 1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2)) CMtolower(cptr2,cptr2); break; case -1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2)) CMtoupper(cptr2,cptr2); break; } if (i != 0) { cptr2 = gl_dev; SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC); } } if (tmpBuf2 != NULL) if (*tmpBuf2 != EOS) { MEfree(gl_dev); gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC, (STlength(tmpBuf2)*2)+2, TRUE,(STATUS *)NULL); STcopy(tmpBuf2,gl_dev); } #else #ifdef MPE STpolycat(2,ERx("!"),cptr, gl_dev); for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2)) CMtoupper(cptr2,cptr2); #else /* Probably VMS */ STcopy(cptr, gl_dev); #endif #endif if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation03> dev = %s\n"), gl_dev); if (typeOfLoc) *typeOfLoc = PATH; } } cptr = CMnext(next); next = STindex(cptr, ERx(","), 0); for (i = 0; next; ) /* do the paths */ { *next = EOS; gl_path[i] = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE, (STATUS *)NULL); STcopy(cptr, gl_path[i]); if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation04> path = %s\n"), gl_path[i]); if (typeOfLoc) *typeOfLoc = PATH; cptr = CMnext(next); next = STindex(cptr, ERx(","), 0); i++; } gl_path[i] = NULL; Locptr1 = &aLoc; Locptr2 = &bLoc; #ifndef MPE if (gl_dev || gl_path[0]) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation05> SEP_LOcompose()\n")); ret_val = SEP_LOcompose(gl_dev, gl_path[0], NULL, NULL, NULL, Locptr1); #ifdef UNIX cptr2 = SEP_CMlastchar(Locptr1->string,0); if (*cptr2 == '/') *cptr2 = EOS; Locptr1->path = Locptr1->string; #endif } for (i=1; (gl_path[i] != NULL)&&(ret_val == OK); i++) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation06> LOfaddpath()\n")); if ((ret_val = LOfaddpath(Locptr1, gl_path[i], Locptr2)) != OK) continue; Locptr3 = Locptr1; Locptr1 = Locptr2; Locptr2 = Locptr3; } #endif if ((gl_file != NULL)&&(ret_val == OK)) { /* ** This first case catches the instance of: @file(filenane.type). ** This was caught above in looking for a device (gl_dev). */ if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation07> LOfroms()\n")); ret_val = LOfroms( FILENAME, gl_file, Locptr1); } else if ((CMcmpcase(cptr, ERx(")")) != 0)&&(ret_val == OK)) { /* There is a filename */ next = STindex(cptr, ERx(")"), 0); *next = EOS; gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE, (STATUS *)NULL); STcopy(cptr, gl_file); if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation08> file = %s\n"), gl_file); if (typeOfLoc) *typeOfLoc = PATH & FILENAME; if (gl_dev || gl_path[0]) { #ifdef MPE if (gl_dev) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation09> MPE's LOfroms ()\n")); char *tmpMPE = NULL ; tmpMPE = SEP_MEalloc(SEP_ME_TAG_GETLOC, (STlength(gl_file)+STlength(gl_dev)+1)*2, TRUE, (STATUS *)NULL); STpolycat(3, gl_file, ERx("."), gl_dev, tmpMPE); LOfroms(FILENAME & PATH, tmpMPE, Locptr1); } #else if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation09> LOfstfile()\n")); LOfstfile(gl_file, Locptr1); #endif } else { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation10> LOfroms()\n")); LOfroms( FILENAME, gl_file, Locptr1); } } if (ret_val == OK) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation11> LOtos()\n")); LOtos(Locptr1, &resultPtr); STcopy(resultPtr, newstr); } MEtfree(SEP_ME_TAG_GETLOC); if (tracing&TRACE_PARM) { if (ret_val != OK) SIfprintf(traceptr,ERx("getLocation12> ret_val = %d\n"),ret_val); else SIfprintf(traceptr,ERx("getLocation13> newstr = %s\n"),newstr); } return(ret_val); }
STATUS xfsetdirs(char *dir, char *frompath, char *intopath) { auto i2 dirflag; auto char *s; char *locbuf; STATUS status; locbuf = XF_REQMEM(MAX_LOC + 1, FALSE); if (dir == NULL || *dir == EOS) { /* Default to current directory. */ status = LOgt(locbuf, &Xf_dir); if(status != OK) { #ifdef UNIX status = LOfakepwd(locbuf, &Xf_dir); #endif if(status != OK) { IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0); return(FAIL); } } dir = NULL; } else { STlcopy(dir, locbuf, MAX_LOC); if (LOfroms(PATH, locbuf, &Xf_dir) != OK) { IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir); return (FAIL); } if (!LOisfull(&Xf_dir)) { auto LOCATION xloc; char xbuf[MAX_LOC + 1]; /* ** path spec. is a relative specification -- we must expand it ** to a full pathname. */ LOcopy(&Xf_dir, xbuf, &xloc); status = LOgt(locbuf, &Xf_dir); if(status != OK) { IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0); return(FAIL); } LOaddpath(&Xf_dir, &xloc, &Xf_dir); } /* LOisdir and LOexist are archaic and should be replaced by LOinfo. */ LOisdir(&Xf_dir, &dirflag); if (dirflag != ISDIR || LOexist(&Xf_dir) != OK) { IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir); return (FAIL); } } LOtos(&Xf_dir, &s); /* the COPY FROM path doesn't have to exist. */ if (frompath != NULL && *frompath != EOS) Xf_from_path = saveloc(frompath); /* the COPY INTO path doesn't have to exist. */ if (intopath != NULL && *intopath != EOS) Xf_into_path = saveloc(intopath); IIUGmsg(ERget(S_XF0064_Unload_Directory_is), FALSE, 1, (PTR)(Xf_into_path == NULL ? s : Xf_into_path)); IIUGmsg(ERget(S_XF0065_Reload_Directory_is), FALSE, 1, (PTR)(Xf_from_path == NULL ? s : Xf_from_path)); return (OK); }
VOID gca_save( GCA_SVC_PARMS *svc_parms ) { GCA_ACB *acb = svc_parms->acb; GCA_SV_PARMS *sv_parms = (GCA_SV_PARMS *)svc_parms->parameter_list; GCA_SAVE_DATA save_data; PTR user_buf = sv_parms->gca_ptr_user_data; i4 user_size = sv_parms->gca_length_user_data; char cl_buf[ GCA_MAX_CL_SAVE_SIZE ]; i4 cl_size; LOCATION file_loc; LOCATION tmp_loc; char loc_buf[ MAX_LOC ]; FILE *save_file; char *save_ptr; char file_id[ MAX_LOC ]; i4 j; /* Initialize status in service invoker's parameter list */ sv_parms->gca_status = E_GCFFFF_IN_PROCESS; /* Get CL save info */ svc_parms->gc_parms.svc_buffer = (PTR)cl_buf; svc_parms->gc_parms.reqd_amount = sizeof( cl_buf ); GCsave( &svc_parms->gc_parms ); if ( svc_parms->gc_parms.status != OK ) goto complete; cl_size = svc_parms->gc_parms.rcv_data_length; /* Format GCA_SAVE_DATA structure */ save_data.save_level_major = GCA_SAVE_LEVEL_MAJOR; save_data.save_level_minor = GCA_SAVE_LEVEL_MINOR; save_data.cl_save_size = cl_size; save_data.user_save_size = user_size; save_data.assoc_id = acb->assoc_id; save_data.size_advise = acb->size_advise; save_data.heterogeneous = acb->flags.heterogeneous; /* Create the save file name. */ file_id[0] = '\0'; (VOID) LOfroms(PATH & FILENAME, file_id, &tmp_loc); (VOID) LOuniq("IIGC", "TMP", &tmp_loc); (VOID) NMloc(TEMP, FILENAME, file_id, &tmp_loc); (VOID) LOcopy( &tmp_loc, loc_buf, &file_loc ); (VOID) LOtos( &file_loc, &save_ptr ); (VOID) STcopy( save_ptr, sv_parms->gca_save_name ); /* Open save file. */ if( SIfopen( &file_loc, "w", SI_VAR, 0, &save_file ) != OK ) { GCA_DEBUG_MACRO(1)( "gca_send bad file open\n" ); svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL; goto complete; } /* Write GCA, CL, and user data to save file. */ if( SIwrite( sizeof( save_data ), (PTR)&save_data, &j, save_file ) != OK || cl_size && SIwrite( cl_size, (PTR)cl_buf, &j, save_file ) != OK || user_size && SIwrite( user_size, user_buf, &j, save_file ) != OK || SIclose( save_file ) != OK ) { GCA_DEBUG_MACRO(1)( "gca_send bad file write/close\n" ); (VOID) SIclose( save_file ); (VOID) LOdelete( &file_loc ); svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL; } complete: return; }
/***************************************************************************** ** Name: ME_makekey() - Make WIN32 file for mapping ** shared memory from user key. ** ** Description: ** Create a file to identify a shared memory segment. The file's inode ** will be used as a shared memory key. The file's existence will be ** used to track shared segments on the system. ** ** Inputs: ** key character key identifying shared segment. ** ** Outputs: ** return value ** ** Returns: ** HANDLE to opened file, or ** -1 file could not be created. ** ** Exceptions: ** none ** ** Side Effects: ** File created in installation's memory directory. ** *****************************************************************************/ HANDLE ME_makekey(char *user_key) { LOCATION location; LOCATION temp_loc; char loc_buf[MAX_LOC + 1]; char *shmemname; STATUS ret_val; HANDLE handle; /* * Build location to file in MEMORY directory. Get location of ME * files for shared memory segments. */ # ifdef MCT gen_Psem(&NM_loc_sem); # endif /* MCT */ ret_val = NMloc(FILES, PATH, (char *) NULL, &temp_loc); if (ret_val) { # ifdef MCT gen_Vsem(&NM_loc_sem); # endif /* MCT */ return (HANDLE) -1; } LOcopy(&temp_loc, loc_buf, &location); # ifdef MCT gen_Vsem(&NM_loc_sem); # endif /* MCT */ LOfaddpath(&location, ME_SHMEM_DIR, &location); LOfstfile(user_key, &location); /* * Create file to identify the shared segment. This will also allow * MEshow_pages to tell what shared segments have been created. */ LOtos(&location, &shmemname); handle = CreateFile(shmemname, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (handle == INVALID_HANDLE_VALUE) { handle = (HANDLE) -1; } return (handle); }
void main(int argc, char *argv[]) { #define MAXBUF 4095 #define MAX_NAME 32 char buf[ MAXBUF+1 ]; char repbuf[ MAXBUF+1 ]; int iarg, ibuf, ichr; char *database = NULL; char username[MAX_NAME] = {""}; LOCATION tloc; LOCATION loc_out; LOCATION loc_in; char loc_buf[MAX_LOC + 1]; char tmp_buf[MAX_LOC + 1]; char otmp_buf[MAX_LOC + 1]; char dev[MAX_LOC + 1]; char path[MAX_LOC + 1]; char fprefix[MAX_LOC + 1]; char fsuffix[MAX_LOC + 1]; char version[MAX_LOC + 1]; char odev[MAX_LOC + 1]; char opath[MAX_LOC + 1]; char ofprefix[MAX_LOC + 1]; char ofsuffix[MAX_LOC + 1]; char oversion[MAX_LOC + 1]; char *new_filename; char *temploc; CL_ERR_DESC err_code; char *p1 = NULL; bool usergiven = FALSE; bool Repmod = FALSE; bool nowait = TRUE; char waitflag[3]; if (argc < 2) { usage(); PCexit(FAIL); } /* Get the temporary path location */ NMloc(TEMP, PATH, NULL, &tloc); LOcopy(&tloc, tmp_buf, &loc_in); LOtos(&tloc, &temploc); LOcopy(&tloc, otmp_buf, &loc_out); /* Get the new filename for path location */ LOuniq(ERx("usrmod"), ERx("sql"), &loc_in); LOtos(&loc_in, &new_filename); LOuniq(ERx("usrmod"), ERx("out"), &loc_out); /* Get just the filename for copydb code */ LOdetail(&loc_in, dev, path, fprefix, fsuffix, version); if ( *fsuffix != '\0' ) { STcat(fprefix, "."); STcat(fprefix, fsuffix); } /* Get just the filename for copydb code */ LOdetail(&loc_out, odev, opath, ofprefix, ofsuffix,oversion); STcat(ofprefix, "."); STcat(ofprefix, ofsuffix); STprintf(buf, ERx("copydb -with_modify -nodependency_check -with_index -with_comments -no_persist -parallel -no_repmod -group_tab_idx -no_warn -d\"%s\" -infile=\"%s\" -outfile=\"%s\"" ), temploc, fprefix,ofprefix); ibuf = STlength(buf); for (iarg = 1; (iarg < argc) && (ibuf < MAXBUF); iarg++) { if( STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) == 0 ) { p1 = argv[ iarg ]; (void) CMnext( p1 ); if ( (STlength(p1) == 0) || !(((STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) || (STscompare( p1, 5, ERx( "noint" ), 5 ) == 0 ) || (STscompare( p1, 6, ERx( "repmod" ), 6 ) == 0 ) || (STscompare( p1, 1, ERx( "w" ), 6 ) == 0 ) || (STscompare( p1, 6, ERx( "online"), 6 ) == 0 )) && ( argc > 2 ) )) { usage(); PCexit(FAIL); } /* ** Get the username if the -u flag is passed in ** with the input */ if (STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) { STcopy(&argv[iarg][2] , (char *)&username); usergiven = TRUE; } else if (STscompare( p1, 1, ERx( "r" ), 1 ) == 0 ) { Repmod = TRUE; continue; } else if (STscompare( p1, 1, ERx( "w"), 1 ) == 0) { nowait = TRUE; continue; } } if( STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) == 0 ) { p1 = argv[ iarg ]; (void) CMnext( p1 ); if (STscompare( p1, 1, ERx( "w" ), 1 ) == 0 ) { nowait = FALSE; continue; } else { usage(); PCexit(FAIL); } } if((database == NULL) && (STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) != 0) && (STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) != 0)) { database = argv[ iarg ]; } buf[ibuf++] = ' '; for (ichr = 0; (argv[iarg][ichr] != '\0') && (ibuf < MAXBUF); ichr++, ibuf++) { buf[ibuf] = argv[iarg][ichr]; } buf[ibuf] = '\0'; } /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) PCexit(FAIL); /* ** we should run the sql script ** sql dbname < new_filename ** if -u flag given then run: ** sql -uusername dbname < new_filename */ if (usergiven) STprintf(buf, ERx( "sql -u%s -s %s <%s" ), username, database, new_filename ); else STprintf(buf, ERx( "sql -s %s <%s" ), database, new_filename ); /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) { STprintf(buf, ERx(" Warning: Non-persistent objects associated with the base table\n in the failed query may have been lost. Please refer to\n %s\n to determine whether any corrective action is required.\n"), new_filename); SIfprintf(stdout, buf); PCexit(FAIL); } /* Now execute the repmod command if the replicator ** modify is also required by the user (-repmod) */ if (Repmod) { if (nowait) STcopy("-w", waitflag) ; else STcopy("+w", waitflag) ; if (usergiven) STprintf(repbuf, ERx( "repmod -u%s %s %s" ), username, database, waitflag ); else STprintf(repbuf, ERx( "repmod %s %s" ), database, waitflag ); if( PCcmdline((LOCATION *) NULL, repbuf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) PCexit(FAIL); } /* ** Delete the location */ LOdelete(&loc_in); LOdelete(&loc_out); PCexit(OK); }
int main( int argc, char **argv ) { CL_ERR_DESC err; PTR handle; PTR handle1; PTR handle2; PTR addr; STATUS status; int (*int_fcn)(); char *(*str_fcn)(); int int_ret; char *cp_ret; LOCATION srcfile; char srcbuf[MAX_LOC+1]; LOCATION objfile; char objbuf[MAX_LOC+1]; bool pristine; LOCATION modloc; char modbuf[MAX_LOC+1]; LOCATION dlloc; char dlbuf[MAX_LOC+1]; LOCATION errloc; char errbuf[MAX_LOC+1]; LOCATION nameloc; char namebuf[MAX_LOC+1]; char *nameptr; char *parms[2]; i4 flags; STATUS mod2status = OK; /* find the working directory */ NMgtAt( "IIDLDIR", &cp_ret ); if ( cp_ret == NULL || *cp_ret == EOS ) { SIprintf( "%sDLDIR not set\n", SystemVarPrefix ); PCexit( 1 ); } /* save the directory name into a larger buffer for LO */ STcopy( cp_ret, srcbuf ); /* initialize a LOCATION with the directory */ LOfroms( PATH, srcbuf, &srcfile ); /* initialize the object file LOCATION with same directory */ LOcopy( &srcfile, objbuf, &objfile ); LOcopy( &srcfile, modbuf, &modloc ); LOcopy( &srcfile, dlbuf, &dlloc ); LOcopy( &srcfile, errbuf, &errloc ); /* add filenames to LOCATION */ LOfstfile( srcs[0], &srcfile ); LOfstfile( objs[0], &objfile ); LOfstfile( erroutput, &errloc ); /* compile with error */ #ifdef NT_GENERIC parms[0] = "-g"; #else NT_GENERIC parms[0] = "-Zi"; #endif NT_GENERIC parms[1] = NULL; status = UTcompile_ex( &srcfile, &objfile, &errloc, parms, FALSE, &pristine, &err ); if ( status != OK ) { SIprintf( "Compile error test returns: " ); if ( status == UT_CO_FILE ) SIprintf( "\n utcom.def file not found or II_COMPILE_DEF not set\n" ); else if ( status == UT_CO_IN_NOT ) SIprintf( "source file not found.\n" ); else SIprintf( "%d\n", status ); SIprintf( "Contents of error file:\n" ); SIprintf( "------------------------------------------------------\n" ); SIcat( &errloc, stdout ); SIprintf( "------------------------------------------------------\n" ); SIprintf( "\n" ); } else { SIprintf( "Test of compile error returned OK.\n" ); SIprintf( "Contents of error file:\n" ); SIprintf( "------------------------------------------------------\n" ); SIcat( &errloc, stdout ); SIprintf( "------------------------------------------------------\n" ); SIprintf( "\n" ); } /* add filenames to LOCATION */ LOfstfile( srcs[0], &srcfile ); LOfstfile( objs[0], &objfile ); /* do a good compile */ #ifdef NT_GENERIC parms[0] = "-Zi"; #else NT_GENERIC parms[0] = "-g"; #endif NT_GENERIC status = UTcompile_ex( &srcfile, &objfile, NULL, parms, FALSE, &pristine, &err ); if ( status != OK ) { SIprintf( "Error compiling module: %d\n", status ); PCexit( 1 ); } LOfstfile( srcs1[0], &srcfile ); LOfstfile( objs1[0], &objfile ); status = UTcompile( &srcfile, &objfile, NULL, &pristine, &err ); if ( status != OK ) { SIprintf( "Error compiling module1\n" ); PCexit( 1 ); } LOfstfile( srcs2[0], &srcfile ); LOfstfile( objs2[0], &objfile ); mod2status = UTcompile( &srcfile, &objfile, NULL, &pristine, &err ); if ( mod2status != OK ) { SIprintf( "Error compiling module2\n" ); SIprintf( "This is not an error if C++ is not installed.\n" ); SIprintf( "Skipping further processing of this module\n\n" ); } /* link first module into shared library */ if ( DLcreate( NULL, NULL, module, objs, NULL, lookups, &err) != OK ) { SIprintf( "Error creating module\n" ); PCexit( 1 ); } if ( DLcreate_loc( NULL, NULL, module1, objs1, NULL, lookups1, &dlloc, NULL, &errloc, FALSE, NULL, &err) != OK ) { SIprintf( "Error creating module1\n" ); PCexit( 1 ); } SIprintf( "Contents of DLcreate_loc() error file for module1:\n" ); SIprintf( "------------------------------------------------------\n" ); SIcat( &errloc, stdout ); SIprintf( "------------------------------------------------------\n" ); SIprintf( "\n" ); if ( mod2status == OK ) { if ( DLcreate_loc( NULL, NULL, module2, objs2, NULL, lookups2, &dlloc, NULL, &errloc, FALSE, "C++", &err) != OK ) { SIprintf( "Error creating module2\n" ); PCexit( 1 ); } SIprintf( "Contents of DLcreate_loc() error file for module2:\n" ); SIprintf( "------------------------------------------------------\n" ); SIcat( &errloc, stdout ); SIprintf( "------------------------------------------------------\n" ); SIprintf( "\n" ); } STcopy( module1, namebuf ); LOfroms( FILENAME, namebuf, &nameloc ); DLconstructloc( &nameloc, namebuf, &nameloc, &err ); LOtos( &nameloc, &nameptr ); SIprintf( "Full path for %s is \"%s\"\n", module1, nameptr ); LOcopy( &dlloc, namebuf, &nameloc ); LOfstfile( module, &nameloc ); DLconstructloc( &nameloc, namebuf, &nameloc, &err); LOtos( &nameloc, &nameptr ); SIprintf( "Full path for %s is \"%s\"\n", module, nameptr ); /* test an error */ SIprintf( "Testing DLprepare of non-existant module.\n" ); if ( DLprepare((char *)NULL, "XXX", lookups, &handle, &err) == OK ) { SIprintf( "Error: returned success, should be failure.\n" ); PCexit( 1 ); } /* load the modules into the executable */ SIprintf( "Now loading the real modules.\n" ); if ( DLprepare((char *)NULL, module, lookups, &handle, &err) != OK ) { SIprintf( "Error loading module\n" ); PCexit( 1 ); } if ( mod2status == OK && DLprepare((char *)NULL, module2, lookups2, &handle2, &err) != OK ) { SIprintf( "Error loading module2\n" ); PCexit( 1 ); } putenv( "IIDLDIR=XXX" ); flags=0; if ( DLprepare_loc((char *)NULL, module1, lookups1, &dlloc, flags, &handle1, &err) != OK ) { SIprintf( "Error loading module1\n" ); PCexit( 1 ); } /* get the address of a function and test it */ if ( DLbind(handle1, "returns_onehundred", &addr, &err) != OK ) { /* "returns_onehundred" function isn't there */ DLunload( handle, &err ); PCexit( 1 ); } int_fcn = (int (*)()) addr; int_ret = (*int_fcn)(); SIprintf( "\"returns_onehundred\" returns %d\n", int_ret ); if ( int_ret != 100 ) { /* function didn't correctly return 100 */ PCexit( 1 ); } if ( mod2status == OK ) { if ( DLbind(handle2, "returns_ninetynine", &addr, &err) != OK ) { SIprintf( "Error binding \"returns_ninetynine\"\n" ); /* "returns_ninetynine" function isn't there */ DLunload( handle2, &err ); PCexit( 1 ); } int_fcn = (int (*)()) addr; int_ret = (*int_fcn)(); SIprintf( "\"returns_ninetynine\" returns %d\n", int_ret ); if ( int_ret != 99 ) { /* function didn't correctly return 99 */ PCexit( 1 ); } } if ( DLbind(handle, "returns_one", &addr, &err) != OK ) { /* "returns_one" function isn't there */ DLunload( handle, &err ); PCexit( 1 ); } int_fcn = (int (*)()) addr; int_ret = (*int_fcn)(); SIprintf( "\"returns_one\" returns %d\n", int_ret ); if ( int_ret != 1 ) { /* function didn't correctly return 1 */ PCexit( 1 ); } if ( DLbind(handle, "returns_zero", &addr, &err) != OK ) { /* "returns_zero" function isn't there */ DLunload( handle, &err ); PCexit( 1 ); } int_fcn = (int (*)()) addr; int_ret = (*int_fcn)(); SIprintf( "\"returns_zero\" returns %d\n", int_ret ); if ( int_ret != 0 ) { /* function didn't correctly return 0 */ PCexit( 1 ); } if ( DLbind(handle, "returns_minus_one", &addr, &err) != OK ) { /* "returns_minus_one" function isn't there */ DLunload( handle, &err ); PCexit( 1 ); } int_fcn = (int (*)()) addr; int_ret = (*int_fcn)(); SIprintf( "\"returns_minus_one\" returns %d\n", int_ret ); if ( int_ret != -1 ) { /* function didn't correctly return -1 */ PCexit( 1 ); } if ( DLbind(handle, "returns_string", &addr, &err) != OK ) { /* "returns_string" function isn't there */ DLunload( handle, &err ); PCexit( 1 ); } str_fcn = (char *(*)()) addr; cp_ret = (*str_fcn)(); SIprintf( "\"returns_string\" returns \"%s\"\n", cp_ret ); if ( STcompare(cp_ret, "String") != OK ) { /* function didn't correctly return "String" */ PCexit( 1 ); } /* functions were called successfully, now unload the modules */ if ( DLunload( handle, &err ) != OK ) { SIprintf( "Error unloading module.\n" ); PCexit( 1 ); } if ( DLunload( handle1, &err ) != OK ) { SIprintf( "Error unloading module.\n" ); PCexit( 1 ); } if ( mod2status == OK && DLunload( handle2, &err ) != OK ) { SIprintf( "Error unloading module2.\n" ); PCexit( 1 ); } if ( DLdelete_loc( module1, &dlloc, &err ) != OK ) { SIprintf( "Error deleting module1.\n" ); PCexit( 1 ); } SIprintf( "Successfully executed.\n" ); PCexit( 0 ); }
/* ** Writes or erases a transaction log and displays a completion thermometer. ** ** 'context' must not be NULL, and defaults for element 0 & 1 of context ** must have been set. */ i4 write_transaction_log(bool create, PM_CONTEXT *context, char *log_dir[], char *log_file[], void (*message)(char *), void (*init_graph)(bool, i4), i4 graph_size, void (*update_graph)()) { # define LG_PAGE_SIZE 2048L # define LG_NUMBER_OF_PAGES 32L /* Number of pages to write at a time */ DI_IO dio[LG_MAX_FILE]; char buf[LG_PAGE_SIZE * LG_NUMBER_OF_PAGES]; char nodename[GL_MAXNAME]; i4 i, j, marker, count, num_logs; i4 num_pages, page, part_size, remainder, loop; CL_ERR_DESC err; char *string; LOCATION loc[LG_MAX_FILE]; char locbuf[MAX_LOC + 1]; char *path[LG_MAX_FILE]; i4 LOinfo_flag; LOINFORMATION loc_info; i8 size; CS_SCB scb; bool size_in_kbytes = FALSE; MEfill( sizeof( scb ), 0, ( PTR ) &scb ); ++graph_size; /* Prepare transaction for log LOCATION(s) */ for (num_logs = 0; num_logs < LG_MAX_FILE; num_logs++) { if (log_dir[num_logs] == 0) break; STcopy( log_dir[num_logs], locbuf ); LOfroms( PATH, locbuf, &loc[num_logs] ); LOfstfile( log_file[num_logs], &loc[num_logs] ); LOtos( &loc[num_logs], &path[num_logs] ); } /* get size (in bytes) of log file to be created or erased */ if( create ) { STATUS status; char *value; bool havevalue = FALSE; status = PMmGet( context, ERx( "$.$.rcp.file.kbytes" ), &value ); if ( status == OK ) { havevalue = TRUE; size_in_kbytes = TRUE; } if ( havevalue == FALSE ) { status = PMmGet( context, ERx( "$.$.rcp.file.size" ), &value ); if ( status == OK ) havevalue = TRUE; } if ( havevalue == FALSE ) { if ( message != NULL ) { char msg[ BIG_ENOUGH ]; STprintf( msg, ERx( "%s %s" ), PMmExpandRequest( context, ERx( "$.$.rcp.file.kbytes" ) ), "not found." ); message( msg ); } return( 0 ); } CVal8( value, &size ); } else { LOinfo_flag = LO_I_SIZE; size = 0; for (i = 0; i < num_logs; i++) { if ( LOinfo( &loc[i], &LOinfo_flag, &loc_info ) != OK ) { if ( message != NULL ) { char msg[ BIG_ENOUGH ]; STprintf( msg, "Unable to get size of transaction log:\n\n\t%s", path[i] ); (*message)( msg ); } return( 0 ); } else size += loc_info.li_size; if ((LOinfo_flag & LO_I_SIZE) == 0) break; } if ( (LOinfo_flag & LO_I_SIZE) == 0 || size == 0L) { STATUS status; char *value; bool havevalue = FALSE; status = PMmGet( context, ERx( "$.$.rcp.file.kbytes" ), &value ); if ( status == OK ) { havevalue = TRUE; size_in_kbytes = TRUE; } if ( havevalue == FALSE ) { status = PMmGet( context, ERx( "$.$.rcp.file.size" ), &value ); if ( status == OK ) havevalue = TRUE; } if ( havevalue == FALSE ) { if ( message != NULL ) { char msg[ BIG_ENOUGH ]; STprintf( msg, ERx( "%s %s." ), PMmExpandRequest( context, ERx( "$.$.rcp.file.kbytes" ) ), "not found." ); message( msg ); } return( 0 ); } CVal8( value, &size ); } } for (i = 0; i < num_logs; i++) { if ( create && LOexist( &loc[i] ) == OK ) { char msg[ BIG_ENOUGH ]; if ( message != NULL ) { STprintf( msg, "%s already exists.", path[i] ); (*message)( msg ); STprintf( msg, "To create a new transaction log, you must first delete all partitions of the old one." ); (*message)( msg ); } return( 0 ); } } if ( CSinitiate( (i4 *) NULL, (char ***) NULL, (CS_CB *) NULL ) != OK ) { if ( message != NULL ) message( "Unable to connect to shared memory" ); return( 0 ); } CSset_sid( &scb ); /* create DI file */ for (i = 0; i < num_logs; i++) { if ( create && DIcreate( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), (i4)LG_PAGE_SIZE, &err) != OK ) { char msg[ BIG_ENOUGH ]; if ( message != NULL ) { STprintf( msg, "Unable to create transaction log:\n\n\t%s", path[i] ); (*message)( msg ); } return( 0 ); } /* open DI file */ if ( DIopen( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), (i4)LG_PAGE_SIZE, DI_IO_WRITE, 0, &err) != OK ) { if ( message != NULL ) { char msg[ BIG_ENOUGH ]; STprintf( msg, "Unable to open transaction log:\n\n\t%s", path[i] ); (*message)( msg ); } return( 0 ); } } if ( size_in_kbytes == FALSE ) size = (size + 1023) / 1024; (*init_graph)( create, (i4) size ); num_pages = size / (LG_PAGE_SIZE/1024); part_size = num_pages / num_logs; /* Readjust num_pages to be a multiple of num_logs */ num_pages = part_size * num_logs; loop = part_size / LG_NUMBER_OF_PAGES; remainder = part_size % LG_NUMBER_OF_PAGES; marker = loop / graph_size; /* Fill buffer with zeroes */ MEfill( sizeof( buf ), 0 , buf); for (i = 0; i < num_logs; i++) { if ( create && DIalloc( &dio[i], part_size, &page, &err ) != OK ) { DIdelete( &dio[i], log_dir[i], (u_i4)STlength( log_dir[i] ), log_file[i], (u_i4)STlength( log_file[i] ), &err ); if ( message != NULL ) (*message)( "Unable to allocate space in transaction log file." ); return( 0 ); } } count = 0; for( j = 0; j < loop; j++ ) { i4 n = LG_NUMBER_OF_PAGES; i4 page_no = j * n; for (i = 0; i < num_logs; i++) { if ( DIwrite( &dio[i], &n, page_no, buf, &err ) != OK ) { DIdelete( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), &err ); if ( message != NULL ) (*message)( "Unable to continue writing transaction log." ); return( 0 ); } } if ( j >= marker && j % marker == 0 && (f4) ((f4) j / (f4) loop) >= ((f4) count + 1) / graph_size ) { ++count; (*update_graph)(); SIflush( stdout ); } } if (remainder) { i4 page_no = loop * LG_NUMBER_OF_PAGES; for (i = 0; i < num_logs; i++) { if ( DIwrite( &dio[i], &remainder, page_no, buf, &err ) != OK ) { DIdelete( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), &err ); if ( message != NULL ) (*message)( "Unable to continue writing transaction log." ); return( 0 ); } } } for (i = 0; i < num_logs; i++) { if ( DIforce( &dio[i], &err ) != OK ) { DIdelete( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), &err ); if ( message != NULL ) (*message)( "Unable to force changes to transaction log." ); return( 0 ); } if ( create && DIflush( &dio[i], &err ) != OK ) { DIdelete( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), &err ); if ( message != NULL ) (*message)( "Unable to flush transaction log to disk." ); return( 0 ); } if( DIclose( &dio[i], &err ) != OK) { DIdelete( &dio[i], log_dir[i], (u_i4)STlength(log_dir[i]), log_file[i], (u_i4)STlength(log_file[i]), &err ); if ( message != NULL ) (*message)( "Unable to finish writing transaction log." ); return( 0 ); } } return( (i4) size ); }
STATUS Run_SED_on_file(SEPFILE **Sep_file,LOCATION *Sep_Loc) { STATUS ret_val ; CL_ERR_DESC cl_err; LOCATION *sedtmploc = NULL ; LOCATION *filtmploc = NULL ; char *SEDbuffer = NULL ; char *sedtmp = NULL ; char *filtmp = NULL ; char *cmd_line = NULL ; char *sed_dev = NULL ; char *sed_path = NULL ; char *sed_name = NULL ; char *sed_type = NULL ; char *sed_vers = NULL ; char *fptr1 = NULL ; char *fptr2 = NULL ; FILE *SEDfptr = NULL ; FILE *fptr = NULL ; bool Sep_file_empty ; sed_dev = SEP_MEalloc(SEP_ME_TAG_SED, LO_DEVNAME_MAX+1, TRUE, NULL); sed_path = SEP_MEalloc(SEP_ME_TAG_SED, LO_PATH_MAX+1, TRUE, NULL); sed_name = SEP_MEalloc(SEP_ME_TAG_SED, LO_FPREFIX_MAX+1, TRUE, NULL); sed_type = SEP_MEalloc(SEP_ME_TAG_SED, LO_FSUFFIX_MAX+1, TRUE, NULL); sed_vers = SEP_MEalloc(SEP_ME_TAG_SED, LO_FVERSION_MAX+1, TRUE, NULL); SEDbuffer = SEP_MEalloc(SEP_ME_TAG_SED, SCR_LINE+1, TRUE, NULL); /* ** Create Sed output file names. */ sedtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION), TRUE, NULL); filtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION), TRUE, NULL); sedtmp = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); filtmp = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); LOtos(Sep_Loc, &fptr2); STcopy(fptr2, sedtmp); STcopy(fptr2, filtmp); LOfroms(FILENAME & PATH, sedtmp, sedtmploc); LOfroms(FILENAME & PATH, filtmp, filtmploc); LOdetail(sedtmploc, sed_dev, sed_path, sed_name, sed_type, sed_vers); STcopy(ERx("sed"),sed_type); SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, sedtmploc); STcopy(ERx("sdr"),sed_type); SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, filtmploc); /* ** Copy Sep SI_RACC file to a SI_TXT file. */ SEPrewind(*Sep_file, FALSE); if ((ret_val = SIfopen(filtmploc,ERx("w"), SI_TXT, SCR_LINE, &fptr)) != OK) return(ret_val); for (Sep_file_empty = TRUE; (ret_val = SEPgetrec(SEDbuffer, *Sep_file)) == OK; SIputrec(SEDbuffer, fptr)) if (Sep_file_empty) Sep_file_empty = FALSE; SIclose(fptr); if (Sep_file_empty == FALSE) { /* ** Create command line for sed command. */ LOtos(SED_loc, &fptr1); LOtos(filtmploc, &fptr2); cmd_line = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); IISTprintf(cmd_line, "sed -f %s %s", fptr1, fptr2); /* ** Close Sep file and run the SED. */ SEPclose(*Sep_file); ret_val = PCcmdline(NULL, cmd_line, PC_WAIT, sedtmploc, &cl_err); if(ret_val != OK) { SEPopen(Sep_Loc, SCR_LINE, Sep_file); del_floc(sedtmploc); del_floc(filtmploc); MEtfree(SEP_ME_TAG_SED); return(1); } /* ** Recreate Sep file. */ #ifdef NT_GENERIC LOdelete(Sep_Loc); #else del_floc(Sep_Loc); #endif if ((ret_val = SIfopen(Sep_Loc, ERx("w"), SI_RACC, SCR_LINE, &fptr)) != OK) return(ret_val); SIclose(fptr); SEPopen(Sep_Loc, SCR_LINE, Sep_file); /* ** Open Sed output file. */ if ((ret_val = SIfopen(sedtmploc, ERx("r"), SI_TXT, SCR_LINE, &SEDfptr)) != OK) return(ret_val); /* ** Copy the Sed output file to the Sep file. */ while((ret_val = SIgetrec(SEDbuffer, SCR_LINE, SEDfptr)) == OK) SEPputrec(SEDbuffer, *Sep_file); SEPclose(*Sep_file); SIclose(SEDfptr); /* ** Reopen the sep file. */ SEPopen(Sep_Loc, SCR_LINE, Sep_file); /* ** Clean up. */ del_floc(sedtmploc); } del_floc(filtmploc); MEtfree(SEP_ME_TAG_SED); return(OK); }
STATUS open_log(char *testPrefix,char *testSufix,char *username,char *errbuff) { SYSTIME atime ; char uname [20] ; char logFileName [MAX_LOC+1] ; char timestr [TEST_LINE] ; char buffer [MAX_LOC+1] ; char *dot = NULL ; char *cptr = NULL ; char year[5]; if (shellMode) STpolycat(3, testPrefix, ERx("."), testSufix, logFileName); else if (updateMode) STpolycat(2, testPrefix, ERx(".upd"), logFileName); else STpolycat(2, testPrefix, ERx(".log"), logFileName); if (outputDir) { if (outputDir_type == PATH) { STcopy(outputDir, buffer); LOfroms(PATH, buffer, &logloc); LOfstfile(logFileName, &logloc); LOtos(&logloc, &cptr); } else { LOtos(&outLoc,&cptr); } STcopy(cptr, logname); } else STcopy(logFileName, logname); if (LOfroms(FILENAME & PATH, logname, &logloc) != OK) { STprintf(errbuff,ERx("ERROR: could not get location for log file")); return(FAIL); } if (SIopen(&logloc,ERx("w"),&logptr) != OK) { STprintf(errbuff,ERx("ERROR: could not open log file")); return(FAIL); } if (!updateMode) { append_line(ERx("/*"),1); copyright_year(&year[0]); STprintf(buffer, ERx("Copyright (c) %s Ingres Corporation"), &year); append_line(buffer, 1); append_line(ERx(" "), 1); STprintf(buffer,ERx("\tTest Name: %s.%s"), testPrefix, testSufix); append_line(buffer,1); TMnow(&atime); TMstr(&atime,timestr); STprintf(buffer,ERx("\tTime: %s"),timestr); append_line(buffer,1); dot = uname; if (username == NULL || *username == '\0') IDname(&dot); else STcopy(username,uname); STprintf(buffer,ERx("\tUser Name: %s"),uname); append_line(buffer,1); STprintf(buffer, ERx("\tTerminal type: %s"), terminalType); append_line(buffer,1); append_line(ERx(" "),1); } return(OK); }
i4 main( i4 argc, char * argv[]) { char c='\0'; char *tz_file=NULL; char *tz_name=NULL; char *tz_def; char tzname[TM_MAX_TZNAME+1]; char tzfile[MAX_LOC+1]; char ioptarg[MAX_LOC + 1]; char tz_pmvalue[MAX_LOC + 1]; char tz_pmname[MAX_LOC + 1]; char *p, *ip, *pm_value; char *tm_tztype; char chr='/'; char *out_file; i4 ioptind=1, i; char *tm_tztime; i4 timecnt, tempi, temptype, temptz; char buf[sizeof(TM_TZ_CB)+TM_MAX_TIMECNT*(sizeof(i4)+1)]; FILE *fid; LOCATION loc_root, tmp_loc; STATUS status=OK; TM_TZ_CB *tm_tz_cb; struct timevect time_v; appname = argv[0]; if( TMtz_getopt(argc, argv, "n:name:f:file", &ioptind, ioptarg, &c) == OK) { switch (c) { case 'f': tz_file = ioptarg; break; case 'n': tz_name = ioptarg; break; default: break; } } else { TMtz_usage(); PCexit(FAIL); } if( tz_file == NULL) { if( tz_name == NULL) { /* Get II_TIMEZONE_NAME value */ NMgtAt(ERx("II_TIMEZONE_NAME"), &tz_def); if (!tz_def || !(*tz_def)) { SIprintf("%s: %s_TIMEZONE_NAME is not set\n", appname, SystemVarPrefix); PCexit(FAIL); } STncpy(tzname, tz_def, TM_MAX_TZNAME); tzname[ TM_MAX_TZNAME ] = EOS; } else { STncpy(tzname, tz_name, TM_MAX_TZNAME); tzname[ TM_MAX_TZNAME ] = EOS; } PMinit(); if( PMload( NULL, (PM_ERR_FUNC *)NULL) != OK) { SIprintf("%s: Error loading PM %s_CONFIG/config.dat file\n", appname, SystemVarPrefix); PCexit(FAIL); } /* Get timezone file name */ STprintf( tz_pmname, ERx("%s.*.tz.%s"), SystemCfgPrefix, tzname); if( PMget( tz_pmname, &pm_value) != OK) { SIprintf("%s: Error locating %s in PM config.dat file\n", appname, tz_pmname); PCexit(FAIL); } do { if((status = NMloc(FILES, PATH, ERx("zoneinfo"), &loc_root)) != OK) break; #if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64) if((status = LOfaddpath(&loc_root, ERx("lp64"), &loc_root)) != OK) break; #endif #if defined(conf_BUILD_ARCH_64_32) && defined(BUILD_ARCH32) { /* ** Reverse hybrid support must be available in ALL ** 32bit binaries */ char *rhbsup; NMgtAt("II_LP32_ENABLED", &rhbsup); if ( (rhbsup && *rhbsup) && ( !(STbcompare(rhbsup, 0, "ON", 0, TRUE)) || !(STbcompare(rhbsup, 0, "TRUE", 0, TRUE)))) status = LOfaddpath(&loc_root, "lp32", &loc_root); } #endif /* reverse hybrid */ STcopy( pm_value, tz_pmvalue); /* ** Compose the directory path */ for( p = tz_pmvalue, ip = tz_pmvalue; (p = STchr(ip, chr)) != NULL;) { *p = EOS; if((status = LOfaddpath(&loc_root, ip, &loc_root)) != OK) break; ip = CMnext(p); } /* ** Add file name to the directory path */ if((status = LOfroms(FILENAME, ip, &tmp_loc)) != OK) break; status = LOstfile( &tmp_loc, &loc_root); } while( FALSE); if( status != OK) { SIprintf("%s: Error composing timezone file name for %s\n", appname, tz_pmvalue); PCexit(FAIL); } } else { STcopy("<unknown>", tzname); STncpy( tzfile, tz_file, MAX_LOC); tzfile[ MAX_LOC ] = EOS; if( LOfroms(FILENAME&PATH, tzfile, &loc_root) != OK) { SIprintf("%s: Error composing timezone file name for %s\n", appname, tz_pmvalue); PCexit(FAIL); } } /* ** Now open the timezone information file */ do { if((status = SIfopen( &loc_root, ERx("r"), SI_VAR, sizeof buf, &fid)) != OK) break; status = SIread(fid, sizeof buf, &i, buf); status = SIclose(fid); } while(FALSE); if( status != OK) { LOtos( &loc_root, &out_file); SIprintf("%s: Error opening %s for timezone %s\n", appname, out_file, tzname); PCexit(FAIL); } tm_tz_cb = (TM_TZ_CB *)&buf; I4ASSIGN_MACRO( tm_tz_cb->timecnt, timecnt); /* Make sure the input file has correct file size */ if( timecnt > TM_MAX_TIMECNT || timecnt < 0 || i != sizeof(TM_TZ_CB) + timecnt*(sizeof(i4)+1)) { LOtos( &loc_root, &out_file); SIprintf( "%s: Invalid file format for timezone file %s for timezone %s\n", appname, out_file, tzname); SIprintf( " File size: %d, Expected file size: %d, time periods: %d\n", i, sizeof(TM_TZ_CB) + timecnt*(sizeof(i4)+1), timecnt); PCexit(FAIL); } /* Now we are all set to display the content of timezone information file */ LOtos( &loc_root, &out_file); SIprintf("\n\n"); SIprintf("timezone name: %s\n", tzname); SIprintf("timezone file: %s\n", out_file); SIprintf("-------------------------------------"); SIprintf("-------------------------------------\n"); if(timecnt == 0) { I4ASSIGN_MACRO( tm_tz_cb->tzinfo[0].gmtoff, tempi); SIprintf(" Fixed GMT offset (secs): %d\n", tempi); } else { SIprintf("\tPeriod Begin"); SIprintf("\t\tGMT offset\n"); SIprintf("\t(YYYY_MM_DD HH:MM)"); SIprintf("\t(Minute)\n\n"); tm_tztype = buf + sizeof(TM_TZ_CB); tm_tztime = tm_tztype + timecnt; i=0; while( i < timecnt) { I4ASSIGN_MACRO( *tm_tztime, tempi); /* Adjust for timezone */ if( i == 0) temptype = (i4)tm_tztype[i+1]; else temptype = (i4)tm_tztype[i-1]; I4ASSIGN_MACRO( tm_tz_cb->tzinfo[temptype].gmtoff, temptz); /* Get real timezone */ tempi += temptz; temptype = (i4)tm_tztype[i]; I4ASSIGN_MACRO( tm_tz_cb->tzinfo[temptype].gmtoff, temptz); TMtz_cvtime( tempi, &time_v); SIprintf("\t%04d_%02d_%02d %02d:%02d\t%d\t%s\n", time_v.tm_year+1900, time_v.tm_mon+1, time_v.tm_mday, time_v.tm_hour, time_v.tm_min, temptz/60, tm_tz_cb->tzlabel + tm_tz_cb->tzinfo[temptype].abbrind); tm_tztime += sizeof(i4); i++; } } PCexit(OK); }
int main(int argc, char *argv[]) { #define MAXBUF 4095 char buf[ MAXBUF+1 ]; int iarg, ibuf, ichr; bool debug = FALSE; CL_ERR_DESC err_code; char *p1 = NULL; char pid[MAXBUF]; char *database = ERx(""); char *user = ERx(""); char *xmlfile = ERx(""); char sql_fname[LO_NM_LEN + 1]; char *work_dir = NULL; char directory[MAX_LOC + 1]; char *tmp_dir = NULL; char tmp_buf[MAX_LOC + 1]; char subdir_buf[MAX_LOC + 1]; char sql_loc_buf[MAX_LOC + 1]; char *progname; LOCATION tmp_dir_loc; LOCATION tmp_subdir_loc; LOCATION tmp_buff_loc; LOCATION curr_loc; LOCATION sql_file_loc; char *password = ERx(""); char *groupid = ERx(""); ARGRET rarg; i4 pos; LOCATION xmlfile_loc; FILE *xmlfile_read; STATUS stat = FAIL; char dbuf[256]; char encode[32]; u_i4 tmppid; TM_STAMP tm_stamp; /* Tell EX this is an ingres tool. */ (void) EXsetclient(EX_INGRES_TOOL); /* Call IIUGinit to initialize character set attribute table */ if ( IIUGinit() != OK) PCexit(FAIL); progname = ERget(F_XM0006_IMPXML); FEcopyright(progname, ERx("2001")); /* ** Get arguments from command line */ /* required parameters */ if (FEutaopen(argc, argv, ERx("xmlimport")) != OK) PCexit(FAIL); /* database name is required */ if (FEutaget(ERx("database"), 0, FARG_PROMPT, &rarg, &pos) != OK) PCexit(FAIL); database = rarg.dat.name; if (FEutaget(ERx("xmlfile"), 0, FARG_PROMPT, &rarg, &pos) != OK) PCexit(FAIL); xmlfile = rarg.dat.name; if (FEutaget(ERx("user"), 0, FARG_FAIL, &rarg, &pos) == OK) user = rarg.dat.name; if (FEutaget(ERx("password"), 0, FARG_FAIL, &rarg, &pos) == OK) { char *IIUIpassword(); if ((password = IIUIpassword(ERx("-P"))) == NULL) { FEutaerr(BADARG, 1, ERx("")); PCexit(FAIL); } } if (FEutaget(ERx("groupid"), 0, FARG_FAIL, &rarg, &pos) == OK) groupid = rarg.dat.name; if (FEutaget(ERx("debug"), 0, FARG_FAIL, &rarg, &pos) == OK) debug = TRUE; ibuf = STlength(buf); /* b121678: pid is no longer based on process id, but it's ** a random number instead. */ PCpid(&tmppid); TMget_stamp(&tm_stamp); MHsrand2(tmppid * tm_stamp.tms_usec); STprintf(pid, "%x", MHrand2()); #ifdef xDEBUG SIprintf(" the pid is: %s \n", pid); #endif /* create the sql file */ /* Avoid a name like "foo.xml.sql" on VMS, use pid.sql instead */ STcopy(pid, sql_fname); STcat(sql_fname, ".sql"); /* ** create in the temp location a directory ** with the name pid. set this directory ** as the working directory for impxml */ NMloc (TEMP, PATH, NULL, &tmp_dir_loc); /* make a location for TMP loc */ /* print location name */ LOcopy (&tmp_dir_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &tmp_dir); #ifdef xDEBUG SIprintf ("temploc: %s \n", tmp_dir); #endif /* make a subdir location with filename, pid */ STcopy (pid, subdir_buf); /* Initialize result loc so that everyone is happy */ LOcopy (&tmp_dir_loc, sql_loc_buf, &sql_file_loc); /* Generate location for temp subdirectory */ if (LOfaddpath (&tmp_dir_loc, subdir_buf, &sql_file_loc) != OK) { IIUGerr(E_XM0007_Locname_Failed, UG_ERR_FATAL, 2, tmp_dir, subdir_buf); /* NOTREACHED */ } /* print the location name */ LOcopy (&sql_file_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &work_dir); #ifdef xDEBUG SIprintf ("work dir loc: %s \n", work_dir); #endif /* create the subdir */ if (LOcreate (&sql_file_loc) != OK) { IIUGerr(E_XM0008_Create_Temp_Dir, UG_ERR_ERROR, 1, work_dir); PCexit(FAIL); } STcopy(work_dir, directory); #ifdef xDEBUG SIprintf ("sql file name: %s \n", sql_fname); SIprintf ("xml file name: %s \n", xmlfile); #endif /* Execute the command impxml */ STprintf (buf, ERx( "impxml -d=\"%s\" -o=\"%s\" " ), directory, sql_fname); /* encoding? */ if ( (LOfroms(PATH & FILENAME, xmlfile, &xmlfile_loc) != OK) || (SIopen(&xmlfile_loc, "r", &xmlfile_read) != OK) || (xmlfile_read == NULL) ) { IIUGerr(E_XM0009_Cannot_Open_File, UG_ERR_ERROR, 1, xmlfile); PCexit(FAIL); } /* scan XML declaration for encoding, if any */ if (stat = SIgetrec(dbuf, sizeof(dbuf) - 1, xmlfile_read) == OK) { char *d = dbuf; i4 i = 0; for (d = dbuf; d != (dbuf + sizeof(dbuf)); d++) { if (MEcmp(d, ERx("encoding="), sizeof(ERx("encoding=")) - 1) == 0) { d += sizeof(ERx("encoding=")); while (MEcmp (d, "\'", sizeof(char)) && MEcmp(d, "\"", sizeof(char))) MEcopy(d++, sizeof(char), &encode[i++]); encode[i++] = MIN_CHAR; encode[i] = EOS; STcat(buf, ERx("-x=")); STcat(buf, encode); break; } } } else if (stat != ENDFILE) { /* unable to read file, report error */ IIUGerr(E_XM000A_Cannot_Read_File, UG_ERR_ERROR, 1, xmlfile); PCexit(FAIL); } stat = SIclose(xmlfile_read); STcat(buf, xmlfile); #ifdef xDEBUG SIprintf ( " query send: %s \n", buf); #endif /* Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *)NULL, &err_code) != OK ) { if (!debug) LOdelete(&sql_file_loc); PCexit(FAIL); } /* ** we should run the sql script ** sql dbname < new_filename */ /* save the current location */ LOcopy(&sql_file_loc, tmp_buf, &curr_loc); /* make a full location path to the location first */ LOfroms(FILENAME, sql_fname, &tmp_buff_loc); LOstfile(&tmp_buff_loc, &curr_loc); LOcopy (&curr_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &tmp_dir); #ifdef xDEBUG SIprintf ("sql file is: %s \n", tmp_dir); #endif /* No space between < and input file for VMS */ STprintf(buf, ERx( "sql -s %s %s %s %s <%s" ), database, user, password, groupid, tmp_dir); #ifdef xDEBUG SIprintf (" query send: %s \n", buf); #endif /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *)NULL, &err_code) != OK ) { if (!debug) LOdelete(&sql_file_loc); PCexit(FAIL); } /* ** Delete the location */ if (!debug) LOdelete(&sql_file_loc); PCexit(OK); }