int transaction_init() { int pid, currentTime; tr_lock = WA_createLock("transaction lock"); currentTime = time(NULL); #ifndef WIN32 pid = getpid(); #else pid = GetCurrentProcessId(); #endif sprintf(uniqueID_str, "%8.8x%8.8x", currentTime, pid); return tr_lock == NULL; }
ShmemArray *sha_alloc(const char *name, void *arrayBase, size_t elementSize, unsigned int elementCount) { ShmemArray *array; int i; array = WOMALLOC(sizeof(ShmemArray) + sizeof(ShmemArrayElement) * (elementCount-1)); if (array) { array->name = WOSTRDUP(name); array->elementSize = elementSize; array->elementCount = elementCount; for (i=0; i<array->elementCount; i++) { array->elements[i].element = (void *)(arrayBase + elementSize * i); array->elements[i].lock = WA_createLock("array element lock"); array->elements[i].writeLock = WA_createLock("array element write lock"); array->elements[i].lockCount = 0; array->elements[i].lockHandle = NULL; array->elements[i].localData = NULL; array->elements[i].localDataCleanupCallbacks = NULL; } } return array; }
void WOLog_init(const char *logfile, const char *level) { int i; int fd; logMutex = WA_createLock("logMutex"); /* * the file we stat() to see if we should log */ #ifndef ALWAYS_LOG sprintf(logFlag,"%s/%s",tmp(),LOG_FLAG); #endif /* * log to file. we need to make sure it's world writable since * we're likely to fork/exec from root to httpd or something... */ if (logfile != NULL) { strcpy(logPath, logfile); } else { sprintf(logPath,"%s/%s",tmp(),LOG_FILE); } #ifdef WIN32 fd = _lopen(logPath, OF_WRITE| OF_SHARE_COMPAT); _lclose(fd); #else fd = open(logPath, O_WRONLY, 0644); close(fd); /* create the file if needed */ #endif chmod(logPath, 0644); if (level) { for (i = WO_DBG; i <= WO_USER; i++) { if (strcasecmp(WOLogLevel[i], level) == 0) { baselevel = i; break; } } } initialized = 1; }
int WOShmem_init(const char *file, size_t memsize) { int error = 0; char *errMsg = NULL; /* open up the file */ WOShmem_fd = open(file, O_RDWR|O_CREAT, 0600); if (WOShmem_fd > 0) { #ifdef APACHE /* unlink the file so when Apache exits the file is removed */ /* The mmap should still be in effect */ unlink(file); #endif WOShmem_size = ensure_file_size(WOShmem_fd, memsize); if (WOShmem_size != -1) { WOShmem_base_address = (void *)mmap(0, WOShmem_size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED|MAP_INHERIT, WOShmem_fd, 0); if (WOShmem_base_address == MAP_FAILED) { errMsg = WA_errorDescription(WA_error()); WOLog(WO_ERR, "WOShmem_init(): couldn't map file: %s", errMsg); error = 1; } } else error = 1; } else { errMsg = WA_errorDescription(WA_error()); WOLog(WO_ERR,"WOShmem_init(): Couldn't open %s: %s", file, errMsg); error = 1; } if (error) WOShmem_fd = -1; if (errMsg) WA_freeErrorDescription(errMsg); WOShmem_mutex = WA_createLock("WOShmem_lock"); return WOShmem_fd == -1; }