char * Utilities::strtok(char * str, char delim, int pos) { int totalTokens = qtytoken(str,delim), count = 1, posStr = 0, posToken = 0; int len = stlen(str, posStr, delim); char * token; if(len==0) return '\0'; //token = (char*)mallocFS(len); token = new char[len]; while(str[posStr]!='\0') { if(str[posStr]==delim) { int len = stlen(str, posStr, delim); count++; //token =((count<pos)) ? (char*)mallocFS(len) : token; if(count<pos)token = new char[len]; } else if(count==pos){ token[posToken] = str[posStr]; posToken++; } posStr++; } return token; }
void write_file(t_file *f) { int fd; t_tim time; t_stt sb; time.modtime = gtnb(f->time); if (f->name[stlen(f->name) - 1] == '/') { if (mkdir(f->name, strtol(f->right, NULL, 8)) < 0 && stat(f->name, &sb)) my_puterror("mkdir", 1); } else if ((fd = open(f->name, O_CREAT | O_WRONLY, strtol(f->right, NULL, 8))) < 0) { my_puterror("open", 1); } else if (write(fd, f->content, f->size) < 0) my_puterror("write", 1); if (utime(f->name, &time) < 0) my_puterror("utime", 1); if (f->name[stlen(f->name) - 1] != '/') close(fd); }
char *str_dup(char *str) { char *returner; int i; if (!(returner = malloc(stlen(str) + 1))) my_puterror("malloc", 1); i = -1; while (++i <= stlen(str)) returner[i] = str[i]; return (returner); }
DSMVOID uttrace() { int fd; /* file descriptor to print on */ int ret; LONG clock; TEXT *pdate; int syserror; TEXT fileName[MAXNAM]; /* get a unique name by using the pid to generate a filename */ stnclr(fileName, sizeof(fileName)); sprintf((psc_rtlchar_t *)fileName, "%s.%d","gemtrace",getpid()); fd = open(fileName, CREATE_RW_APPEND, DEFLT_PERM); if (fd < 0) { /* if the open failed, put a message out to the screen * and we will dump the stack to the screen */ printf("Failed to open file %s errno %d", fileName, syserror); fd = 1; } /* we should have a valid fileHandle, even though it might be stdout. * Time to call the routine to print the stack trace */ ret = write(fd, UT_TRACE_HEADING,stlen(UT_TRACE_HEADING)); if (ret != stlen(UT_TRACE_HEADING)) { /* write failed, revert to stdout */ fd = 1; } /* get the date and time so we can put it into the file */ time(&clock); pdate = (TEXT *)ctime(&clock); ret = write(fd, pdate, stlen(pdate)); uttraceback(fd); if (fd != 1) { /* cleanup */ close(fd); } } /* end uttrace */
/* PROGRAM: utpwd - copy the path name of the current working directory * into a buffer, truncating if necessary. * * Arguments identify buffer location and length. * * RETURNS: the length of the pathname. */ int utpwd (TEXT *pdir, /* answer goes here */ int len _UNUSED_, /* length of answer area */ int drvno _UNUSED_) /* drive number */ { TEXT *ptxt = pdir; /* terminate string, if any errors encountered, leave it null */ *pdir = '\0'; #if OPSYS==UNIX getcwd((char *)pdir,MAXUTFLEN); #else /* !UNIX */ #if OPSYS==WIN32API /* if no drive number specified use current */ if(drvno == 0) { drvno = utgetdrv(); utgetdir(drvno,pdir); utdrvstr(drvno,pdir); /* add drive specification for directory path */ } else utgetdir(drvno,pdir); #endif #endif /* #else !UNIX */ /* get rid of trailing newline, if any */ ptxt = (TEXT *)(term(pdir) - 1); if ( *ptxt == '\n' && ptxt != pdir ) *ptxt = '\0'; /* return length of path name */ return stlen( pdir ); }
char *mystrtok(char * str, char delim, int pos) { int tokenPosition = 0; int totalTokens = qtytoken(str, delim), count = 1, posStr = 0; int len = stlen(str, posStr, delim); char * token = (char*)mallocFS(len); if (len == 1) return str; while (str[posStr] != '\0') { if (str[posStr] == delim) { count++; if (count < pos)token = (char*)mallocFS(len); } else if (count == pos){ token[tokenPosition] = str[posStr]; tokenPosition++; } posStr++; } return token; }
/* PROGRAM: utMakePathname - concat 2 strings together and print a message if * the result is too big for the buffer * NOTE WELL: The scope of this routine has been narrowed to include only * its standard use to append a type suffix onto a file name. * Using it for any other purpose may not work on VRX or for that * matter anywhere else. - gb - 9/30/87 * * RETURNS: -1 string too large for buffer to new string * 0 strings concat'd */ LONG utMakePathname(TEXT *buffer, int buflen, TEXT *pstr1, TEXT *pstr2) { TEXT *nbuffer; if ( stlen(pstr1) + stlen(pstr2) + 1 > buflen ) { return DBUT_S_NAME_TOO_LONG; } nbuffer = (TEXT *)stcopy(stcopy(buffer, pstr1), pstr2); return 0; }
char *Utilities::mystrtok(char * str, char delim, int pos) { int totalTokens = qtytoken(str,delim), count = 1, posStr = 0; int len = stlen(str, posStr, delim); char * token = new char[len]; if(len == 1) return str; int posToken = 0; while(str[posStr]!='\0') { if(str[posStr]==delim) { count++; //token =((count<pos)) ? (char*)malloc(stlen(str, posStr, delim)) : token; if(count<pos)token = new char[len]; } else if(count==pos){ token[posToken] = str[posStr]; posToken++; } posStr++; } //printstring(token); return token; }
/*?????????????????? ix format cann't hold large keys - this proc is used for VST small keys only */ keyStatus_t keyConvertCxToIx( TEXT *pt, /* OUT - target area - old format (v6, ix) */ int keysize, /* IN - Size of source area (incl 3 bytes info */ TEXT *ps) /* IN - source area - new format (v7, cx) */ { int ix_key_len = 2; int ix_comp_len; int cx_key_len; int cx_comp_len; TEXT *pCx = ps; TEXT *pIx = pt; keyStatus_t rc = KEY_SUCCESS; /* CX --> IX */ /* pCx += 7; Skip CS,KS,IS, 2 nulls & the index number */ pCx += FULLKEYHDRSZ + 4; /* Skip CS,KS,IS, 2 nulls & the index number */ /* cx_key_len = (int) keysize - 7; */ cx_key_len = (int) keysize - (FULLKEYHDRSZ + 4); /* Save space for the length [byte] at the beginning */ pIx++; while (cx_key_len > 0) { cx_comp_len = stlen (pCx) + 1; /* Use cx_comp_len to estimate space required for the IX length * byte and the IX component value. CX value + null byte will * always be >= sizeof (IX value) + IX length byte. IX value may * take less space because several two byte escape sequences become * a single byte. */ if ( (rc = keyConvertCxToIxComponent(pIx, pCx)) != KEYSUCCESS) return rc; pCx += cx_comp_len; ix_comp_len = *pIx + 1; /* +1 for the length [byte] */ pIx += ix_comp_len; ix_key_len += ix_comp_len; cx_key_len -= cx_comp_len; } if (ix_key_len > KEYSIZE) return KEY_EXCEEDS_MAX_SIZE; *pt = (TEXT) ix_key_len; /* fill in the length byte at the beginning */ *pIx = (TEXT) ix_key_len; /* ...and the end */ return KEY_SUCCESS; } /* end keyConvertCxToIx */
DSMVOID bkioRemoveLkFile ( dsmContext_t *pcontext, TEXT *dbname) /* name of database */ { TEXT namebuf[MAXPATHN+1]; LONG retMakePath = 0; int lockret; UCOUNT nameCrc; int i; dbcontext_t *pdbcontext = pcontext->pdbcontext; /* delete the dbname.lk file */ if(pdbcontext->pdatadir) utmypath(namebuf,pdbcontext->pdatadir,dbname, (TEXT *)".lk"); else retMakePath = utMakePathname(namebuf, sizeof(namebuf), dbname, (TEXT *)".lk"); if (retMakePath != DBUT_S_SUCCESS) { /* Report error */ dbUserError(pcontext, retMakePath, errno, 0, (DSMVOID *)NULL, (DSMVOID *)NULL); } nameCrc = calc_crc((UCOUNT)0, namebuf, (COUNT)stlen(namebuf)); for (i = 0; i < 240; i++) { if ((lkstr[i].nameCrc == nameCrc) && (lkstr[i].lkHandle != (fileHandle_t)0) && (lkstr[i].lkHandle != INVALID_FILE_HANDLE) ) { /* we found the handle */ lockret = utUnlockLkFile(&lkstr[i].lkHandle); lkstr[i].nameCrc = 0; break; } } #if OPSYS==UNIX unlink((const char *)namebuf); #endif #if OPSYS==WIN32API lockret = DeleteFile(namebuf); #endif }
char * strtok(char * str, char delim, int pos) { int totalTokens = qtytoken(str,delim), count = 1, posStr = 0; char * token = (char*)malloc(stlen(str, posStr, delim)); int posToken = 0; while(str[posStr]!='\0') { if(str[posStr]==delim) { int len = stlen(str, posStr, delim); count++; token =((count<pos)) ? (char*)malloc(stlen(str, posStr, delim)) : token; } else if(count==pos){ token[posToken] = str[posStr]; posToken++; } posStr++; } return token; }
/* PROGRAM: utmypath - Creates a full path using the input components * */ DLLEXPORT TEXT * utmypath(TEXT *pfullpath, TEXT *pdatadir,TEXT *prelname,TEXT *psuffix) { int i = 0; TEXT dirsep; #if OPSYS == WIN32API dirsep = '\\'; #else dirsep = '/'; #endif if (prelname[0] != dirsep #if OPSYS == WIN32API && prelname[1] != ':' #endif ) { stncop(pfullpath, pdatadir, MAXUTFLEN); i = stlen(pdatadir); pfullpath[i] = dirsep; i++; } stncop(&pfullpath[i],prelname,MAXUTFLEN); i+= stlen(prelname); if(psuffix) { stncop(&pfullpath[i],psuffix,MAXUTFLEN); i += stlen(psuffix); } pfullpath[i] = '\0'; i++; return &pfullpath[i]; }
void add_car_to_str(char **str, char car) { char *cpy; int i; if (!(cpy = malloc(stlen(*str) + 2))) my_puterror("malloc", 1); i = -1; while (str[0][++i] != 0) cpy[i] = str[0][i]; cpy[i] = car; cpy[i + 1] = 0; free(*str); *str = cpy; }
DSMVOID utmkosnm( TEXT *prefix, TEXT *pname, TEXT *buf, int len, int id) { TEXT *p, *pch; stnclr(buf, len); pch = buf; pch = stcopy(pch, prefix); #if OPSYS==WIN32API /* [johnls] */ for (p = pname; *p && (int)(pch - buf) != len; pch++, p++) { if (*p == ':' && (*(p+1) == '\\' || *(p+1) == '/')) p++; if (*p == '/' || *p == '\\' || *p == ':') *pch = '.'; else *pch = tolower(*p); } *pch = 0; #else pch = stncop(pch, pname, MIN(8, len-11-stlen(prefix))); #endif if (id >= 0) { pch = stcopy(pch, "."); utitoa(id, pch); } }
/* PROGRAM: bkioVerifyLkFile - verify that the .lk file is valid with the * passed in pid. * * * RETURNS: 0 - lk is valid * -1 - lk is invalid */ int bkioVerifyLkFile( dsmContext_t *pcontext, int pid, /* .lk creators pid */ TEXT *dbname) /* basename for the .lk file */ { LONG ret; /* return for utReadFromFile() */ int status =0; /* value returned */ int errorStatus = 0; TEXT namebuf[MAXPATHN+1]; TEXT nodebuf[BKIO_NODESZ]; TEXT snodebuf[BKIO_NODESZ]; int spid = 0; LONG retMakePath = 0; int bytesRead; int lockret = 0; int needopen = 0; UCOUNT nameCrc; fileHandle_t lkhandle = (fileHandle_t) -1; int i; dbcontext_t *pdbcontext = pcontext->pdbcontext; if(pdbcontext->pdatadir) utmypath(namebuf,pdbcontext->pdatadir,dbname, (TEXT *)".lk"); else retMakePath = utMakePathname(namebuf, sizeof(namebuf), dbname, (TEXT *)".lk"); if (retMakePath != DBUT_S_SUCCESS) { /* Report Error */ dbUserError(pcontext, retMakePath, errno, 0, (DSMVOID *)NULL, (DSMVOID *)NULL); } nameCrc = calc_crc((UCOUNT)0, namebuf, (COUNT)stlen(namebuf)); /* find the handle for the lkfile */ for (i = 0; i < 240; i++) { if ((lkstr[i].nameCrc == nameCrc) && (lkstr[i].lkHandle != (fileHandle_t)0)) { lkhandle = lkstr[i].lkHandle; break; } } /* if we don't have a valid file handle, open the lock file and get one */ if (lkhandle == (fileHandle_t) -1) { /* note that we needed to open the lock file */ needopen = 1; /* get the absolute path of the .lk file */ lkhandle = utOsOpen((TEXT *)namebuf, OPEN_R, DEFLT_PERM, OPEN_SEQL, &errorStatus); if (lkhandle == INVALID_FILE_HANDLE) { /* failed to open the .lk file, return the failure */ MSGN_CALLBACK(pcontext, bkMSG100,namebuf,errorStatus); return -1; } } /* Try to lock the lock file - if we get a lock, then the .lk file * is not valid. */ /* Remove this conditional once file locking is implemented for UNIX */ #if OPSYS == WIN32API lockret = utLockLkFile(lkhandle); #endif if (lockret) { /* we got the lock so the old .lk file must have been invalid */ MSGN_CALLBACK(pcontext, bkMSG132, namebuf, errorStatus); return -1; } /* now lets read the .lk file */ /* read the past the mode from the .lk file */ ret = utReadFromFile(lkhandle, 0, (TEXT *)&spid, sizeof(int), &bytesRead, &errorStatus); if (bytesRead != sizeof(int)) { /* read failed. Either the file is too short, or read gave an error. Regardless, we need to shutdown */ MSGN_CALLBACK(pcontext, bkMSG101,"MODE",namebuf,errorStatus); utOsClose(lkhandle,OPEN_SEQL); return -1; } /* read the pid from the .lk file */ ret = utReadFromFile(lkhandle, sizeof(int), (TEXT *)&spid,sizeof(int), &bytesRead, &errorStatus); if (bytesRead != sizeof(int)) { /* read failed. Either the file is too short, or read gave an error. Regardless, we need to shutdown */ MSGN_CALLBACK(pcontext, bkMSG101,"PID",namebuf,errorStatus); utOsClose(lkhandle,OPEN_SEQL); return -1; } /* read the hostname from the .lk file */ ret = utReadFromFile(lkhandle, 2 * sizeof(int), snodebuf,BKIO_NODESZ, &bytesRead, &errorStatus); if (bytesRead != BKIO_NODESZ) { /* read failed. Either the file is too short, or read gave an error. Regardless, we need to shutdown */ MSGN_CALLBACK(pcontext, bkMSG101,"HOSTNAME",namebuf,errorStatus); utOsClose(lkhandle,OPEN_SEQL); return -1; } /* get the systems hostname don't worry about failures, the stpcmp will verify the host for us later */ ret = utgethostname((TEXT *)nodebuf,BKIO_NODESZ - 1); /* now that we have read the .lk file, verify it's a valid one */ if (pid == spid) { /* pids match, now check the hostname */ if (stpcmp(nodebuf,snodebuf) != 0) { /* hostnames don't match. .lk file is invalid for this server */ MSGN_CALLBACK(pcontext, bkMSG102,namebuf,snodebuf,nodebuf); status = -1; } } else { /* pids don't match. .lk file is invalid for this server */ MSGN_CALLBACK(pcontext, bkMSG103,namebuf,spid,pid); status = -1; } if (needopen) { utOsClose (lkhandle, OPEN_SEQL); lkhandle = (fileHandle_t) -1; } return(status); }
/* PROGRAM: bkioUpdateLkFile - update the .lk file * * Update the .lk file with the NON-NULL parameters passed to the * routine. This is used to revalidate the .lk file incase it's * creator has disappeared. An example of this is during Emergency * Shutdown, the first thing that happens is that the broker dies * hence the .lk is now "stale". * * RETURNS: 0 - success * -1 - failure */ int bkioUpdateLkFile( dsmContext_t *pcontext, int mode, /* mode database is opened in */ int pid, /* pid of the owner */ TEXT *phost, /* hostname */ TEXT *dbname) /* name of database */ { LONG ret; LONG retMakePath = 0; int errorStatus = 0; int bytesWritten; TEXT namebuf[MAXPATHN+1]; int lockret; UCOUNT nameCrc; fileHandle_t lkhandle = (fileHandle_t) -1; int i; /* get the absolute path of the .lk file */ if(pcontext->pdbcontext->pdatadir) utmypath(namebuf,pcontext->pdbcontext->pdatadir, pcontext->pdbcontext->pdbname, (TEXT *)".lk"); else retMakePath = utMakePathname(namebuf, sizeof(namebuf), dbname, (TEXT *)".lk"); if (retMakePath != DBUT_S_SUCCESS) { /* Report error */ dbUserError(pcontext, retMakePath, errno, 0, (DSMVOID *)NULL, (DSMVOID *)NULL); } nameCrc = calc_crc((UCOUNT)0, namebuf, (COUNT)stlen(namebuf)); /* find the handle for the lkfile */ for (i = 0; i < 240; i++) { if ((lkstr[i].nameCrc == nameCrc) && (lkstr[i].lkHandle != (fileHandle_t)0)) { lkhandle = lkstr[i].lkHandle; break; } } /* If we were not called from a process that knew the lock file * handle, go get it. */ if (lkhandle == (fileHandle_t) -1) { lkhandle = utOsOpen((TEXT *)namebuf, OPEN_RW, DEFLT_PERM, OPEN_SEQL, &errorStatus); if (lkhandle == INVALID_FILE_HANDLE) { /* failed to open the .lk file, return the failure */ MSGN_CALLBACK(pcontext, bkMSG100, namebuf, errorStatus); return -1; } /* we are going to end up owning this lk file, save the handle for future use. */ for (i = 0; i < 240; i++) { if (lkstr[i].lkHandle == (fileHandle_t)0) { /* we found an empty slot, populate it */ lkstr[i].lkHandle = lkhandle; lkstr[i].nameCrc = calc_crc((UCOUNT)0, namebuf, (COUNT)stlen(namebuf)); break; } } } #if OPSYS==UNIX else { /* we are going to close this file at the end so we need to make sure every knows that */ lkstr[i].lkHandle = (fileHandle_t) -1; } #endif /* If we get the lock, then we were called by brkillall, watchdog, * or wdogLkFileCheck (after it was determined that the broker was gone). * If we don't get a lock, then we were called by nsaloop during startup * and we need to change the mode from DBLKSTARTUP to DBLKMULT. */ lockret = utLockLkFile(lkhandle); if (mode) { /* update the mode with the passed one */ ret = utWriteToFile(lkhandle, 0, (TEXT *)&mode,sizeof(int), &bytesWritten, &errorStatus); if (ret < 0) { /* failed to write mode to the .lk file, return the failure */ MSGN_CALLBACK(pcontext, bkMSG099,namebuf,errorStatus); return -1; } } if (pid) { /* update the pid with the passed one */ ret = utWriteToFile(lkhandle, sizeof(int), (TEXT *)&pid,sizeof(int), &bytesWritten, &errorStatus); if (ret < 0) { /* failed to seek to pid in the .lk file, return the failure */ MSGN_CALLBACK(pcontext, bkMSG099,namebuf,errorStatus); return -1; } } if (phost) { /* update the hostname with the passed one */ ret = utWriteToFile(lkhandle,2 * sizeof(int), phost,stlen(phost), &bytesWritten, &errorStatus); if (ret < 0) { /* failed to write hostname to the .lk file, return the failure */ MSGN_CALLBACK(pcontext, bkMSG099, namebuf, errorStatus); return -1; } } /* if we got here, time to close up shop and return success */ #if OPSYS == UNIX utOsClose (lkhandle, OPEN_SEQL); #endif return 0; }
/* PROGRAM: utapath - given a file name, possibly fully qualified, * an optional suffix, a target buffer, and the length * of the target buffer, put the pieces of the file name * together into the output buffer. If the pathname is * not fully qualified, prepend the current working * directory. * * Needs work for MSDOS. * * RETURNS: the output buffer updated, truncated if the result is * too long * */ TEXT * utapath (TEXT *fullpath, /* fully qualified path name */ int pathlen, /* length of answer buffer */ TEXT *filename, /* file name, possibly qualified */ TEXT *suffix) /* suffix for file name */ { TEXT *ptxt; /* current location */ int used = 0; /* amount used */ int drvno = 0; #if OPSYS==WIN32API int i, j; #endif /* if file name not fully qualified, get pathname of current working directory into answer buffer */ #if OPSYS==UNIX if (*filename != '/') #endif #if OPSYS==WIN32API /* handle drive specfier, if any */ j = stlen(filename); for (i = 1, ptxt = filename; i <= j; i++, ptxt++) if (*ptxt == ':') break; if (i < j && i != 2) { /* file server volume name is specified */ bufcop(fullpath, filename, i); used += i; filename += i; } if ((i == 2) && (filename[1] == ':')) { bufcop(fullpath, filename, 2); used += 2; drvno = toupper(*filename) - 64; /* A = 1 B = 2 ..etc */ filename += 2; } else drvno = 0; /* means use current drive */ if ((*filename != '/') && (*filename != '\\')) #endif /* OPSYS == WIN32API */ { used += utpwd (fullpath+used, pathlen ,drvno); if (*filename) { if((*(fullpath+used-1) != '\\') && (*(fullpath+used-1) != '/')) { ptxt = (TEXT *)stcopy ( (TEXT *)fullpath+used, (TEXT *)"/" ); ++used; } } } ptxt = fullpath + used; /* move in filename and suffix */ used += stncop ( ptxt, filename, (pathlen - used) ); ptxt = fullpath + used; used += stncop ( ptxt, suffix, (pathlen - used) ); used = utfCompressPath(fullpath); /* return pointer to null terminator */ return (fullpath + used); }
/* PROGRAM: bkioCreateLkFile -- lock the database in desired mode. * * Create a .lk file holding the following information: * a.) The mode the db is in BKIO_LKSNGL | BKIO_LKMULT * b.) The process ID of the starter of the db * c.) The hostname of the machine where the db was started * * * RETURNS: * 0 database locked in requested mode. * BKIO_LKSNGL database currently locked in single-user mode, * request denied. * BKIO_LKMULT database currently locked in multi-user mode, * request denied. * BKIO_LKSTARTUP database is in the process of starting up * request denied. * */ int bkioCreateLkFile ( dsmContext_t *pcontext, int mode, /* desired usage mode, either BKIO_LKSNGL or BKIO_LKMULT */ TEXT *dbname, /* name of database */ int dispmsg) /* if true, then display a message */ { TEXT namebuf[MAXPATHN+1]; TEXT dbnamebuf[MAXPATHN+1]; TEXT nodebuf[BKIO_NODESZ]; int ret = 0; ULONG spid = 0; int errorStatus = 0; int bytesWritten; LONG retWrite; LONG retMakePath = 0; int lockret = 1; int wmode = mode; fileHandle_t lkhandle; int i; int local = 0; dbcontext_t *pdbcontext = pcontext->pdbcontext; /* see if the *.lk file already exists and is valid */ if(pdbcontext->pdatadir) utmypath(namebuf,pdbcontext->pdatadir,dbname, (TEXT *)".lk"); else retMakePath = utMakePathname(namebuf, sizeof(namebuf), dbname, (TEXT *)".lk"); if (retMakePath != DBUT_S_SUCCESS) { /* Report error */ dbUserError(pcontext, retMakePath, errno, 0, (DSMVOID *)NULL, (DSMVOID *)NULL); } if(pdbcontext->pdatadir) utmypath(dbnamebuf,pdbcontext->pdatadir,dbname, (TEXT *)".db"); else retMakePath = utMakePathname(dbnamebuf, sizeof(dbnamebuf), dbname, (TEXT *)".db"); if (retMakePath != DBUT_S_SUCCESS) { /* Report error */ dbUserError(pcontext, retMakePath, errno, 0, (DSMVOID *)NULL, (DSMVOID *)NULL); } ret = bkioTestLkFile(pcontext, dbname); if (ret) { switch(ret) { case BKIO_LKSNGL: if(dispmsg) MSGN_CALLBACK(pcontext, bkMSG005, dbname); break; /* db in use single-user */ case BKIO_LKMULT: case BKIO_LKSTARTUP: if(dispmsg) MSGN_CALLBACK(pcontext, bkMSG006, dbname); break; /* db in use multi-user */ case BKIO_LKNOHOST: MSGN_CALLBACK(pcontext, bkMSG007, namebuf); MSGN_CALLBACK(pcontext, bkMSG008); MSGN_CALLBACK(pcontext, bkMSG009); MSGN_CALLBACK(pcontext, bkMSG010); MSGN_CALLBACK(pcontext, bkMSG011, namebuf); break; case BKIO_LKTRUNC: break; /* message was put out by bkioTestLkFile */ default: FATAL_MSGN_CALLBACK(pcontext, bkFTL009, dbname); break; } } else { /* open failed, try to creat it */ /* 19990525-028 - small window of opportunity for two brokers */ /* to start on same database. Replace utOsCreat call with */ /* utOsOpen. */ /* lkhandle = utOsCreat((TEXT *)namebuf, 0444, 0, &errorStatus); */ /* 19990525-028 second try. Can only call utOsOpen if not on NFS */ /* See bug for details. */ local = bkioIsLocalFile(pcontext,dbnamebuf); /* if .lk file is on NFS drive */ if (local == 0) { lkhandle = utOsCreat((TEXT *)namebuf, 0444, 0, &errorStatus); } else { #if OPSYS == WIN32API lkhandle = utOsOpen((TEXT *)namebuf, (O_CREAT | O_EXCL | O_WRONLY), CREATE_DATA_FILE, 0, &errorStatus); #else lkhandle = utOsOpen((TEXT *)namebuf, (O_CREAT | O_EXCL | O_WRONLY), 0444, 0, &errorStatus); #endif } if (lkhandle == INVALID_FILE_HANDLE) { /* cant open */ MSGN_CALLBACK(pcontext, bkMSG002, namebuf, errorStatus); return -1; } /* Remove this conditional once file locking is implemented for UNIX */ #if OPSYS == WIN32API /* attempt to get a lock in the .lk file itself */ lockret = utLockLkFile(lkhandle); #endif /* if we got the lock, write out the mode, pid and nodename */ if (lockret) { if (mode == BKIO_LKMULT) { wmode = BKIO_LKSTARTUP; } /* write out the mode the database is in */ retWrite = utWriteToFile(lkhandle, 0, (TEXT *)&wmode, sizeof(int), &bytesWritten, &errorStatus); /* get the process id and put that into the file */ spid = utgetpid (); retWrite = utWriteToFile(lkhandle, sizeof(int), (TEXT *)&spid, sizeof(int), &bytesWritten, &errorStatus); stnclr(nodebuf,BKIO_NODESZ); /*fill with nulls*/ /* get the hostname and put it into the file */ ret = utgethostname((TEXT *)nodebuf,BKIO_NODESZ - 1); if (ret < 0) { /* if the utgethostname call failed, write out an ampty hostname, that will cause the .lk file checking to be more strict */ stnclr(nodebuf,BKIO_NODESZ); /*fill with nulls*/ } retWrite = utWriteToFile(lkhandle,2*(sizeof(int)),nodebuf, BKIO_NODESZ, &bytesWritten, &errorStatus); /* Save the handle in the lkstr structure */ for (i = 0; i < 240; i++) { if (lkstr[i].lkHandle == (fileHandle_t)0) { /* we found an empty slot, populate it */ lkstr[i].lkHandle = lkhandle; lkstr[i].nameCrc = calc_crc((UCOUNT)0, namebuf, (COUNT)stlen(namebuf)); break; } } } else { /* we did no succeed in locking the .lk file */ utOsClose(lkhandle,0); MSGN_CALLBACK(pcontext, bkMSG131, namebuf, errorStatus); return -1; } } return(ret); }