void ccs_rpc_request( const long rpcmsg, /* Message type */ const char tspHandle[], /* Client's tspdata* */ const char* pszUUID, /* Where client will listen for the reply */ const long lenRequest, /* Length of buffer */ const char pbRequest[], /* Data buffer */ const long serverStartTime, /* Which server session we're talking to */ long* return_status ) { /* Return code */ cc_int32 status = 0; k5_ipc_stream stream; DWORD* p = (DWORD*)(tspHandle); WIN_PIPE* pipe = NULL; #if 0 cci_debug_printf("%s rpcmsg:%d; UUID:<%s> SST:<%s>", __FUNCTION__, rpcmsg, pszUUID, serverStartTime); #endif status = (rpcmsg != CCMSG_REQUEST) && (rpcmsg != CCMSG_PING); if (!status) { status = k5_ipc_stream_new (&stream); /* Create a stream for the request data */ } if (!status) { /* Put the data into the stream */ status = k5_ipc_stream_write (stream, pbRequest, lenRequest); } pipe = ccs_win_pipe_new(pszUUID, *p); worklist_add(rpcmsg, pipe, stream, serverStartTime); *return_status = status; }
void cvs_repository_lock(const char *repo, int wantlock) { int i; uid_t myuid; struct stat st; char fpath[MAXPATHLEN]; struct passwd *pw; if (cvs_noexec == 1 || cvs_readonlyfs == 1) return; cvs_log(LP_TRACE, "cvs_repository_lock(%s, %d)", repo, wantlock); (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", repo, CVS_LOCK); myuid = getuid(); for (i = 0; i < CVS_LOCK_TRIES; i++) { if (cvs_quit) fatal("received signal %d", sig_received); if (stat(fpath, &st) == -1) break; if (st.st_uid == myuid) return; if ((pw = getpwuid(st.st_uid)) == NULL) fatal("cvs_repository_lock: %s", strerror(errno)); cvs_log(LP_NOTICE, "waiting for %s's lock in '%s'", pw->pw_name, repo); sleep(CVS_LOCK_SLEEP); } if (i == CVS_LOCK_TRIES) fatal("maximum wait time for lock inside '%s' reached", repo); if (wantlock == 0) return; if ((i = open(fpath, O_WRONLY|O_CREAT|O_TRUNC, 0755)) < 0) { if (errno == EEXIST) fatal("cvs_repository_lock: somebody beat us"); else fatal("cvs_repository_lock: %s: %s", fpath, strerror(errno)); } (void)close(i); worklist_add(fpath, &repo_locks); }
/* futex post & wait */ void wait_futex_sem(struct lockinfo *l) { int ret; l->data = 1; worklist_add(l); while(l->data == 1) { ret = futex_wait(&l->data, 1, NULL, 0); if (ret && ret == EWOULDBLOCK) { perror("futex wait"); exit(1); } } }
/* futex post & wait */ void wait_futex_sem(struct lockinfo *l) { int ret; l->data = 1; worklist_add(l); while(l->data == 1) { ret = futex(&l->data, FUTEX_WAIT, 1, NULL, NULL, 0); /* if (ret && ret != EWOULDBLOCK) { perror("futex wait"); exit(1); }*/ } }
void ccs_rpc_connect( const long rpcmsg, /* Message type */ const char tspHandle[], /* Client's tspdata* */ const char* pszUUID, /* Data buffer */ long* return_status ) { /* Return code */ DWORD* p = (DWORD*)(tspHandle); WIN_PIPE* pipe = ccs_win_pipe_new(pszUUID, *p); #if 0 cci_debug_printf("%s; rpcmsg:%d; UUID: <%s>", __FUNCTION__, rpcmsg, pszUUID); #endif worklist_add( rpcmsg, pipe, NULL, /* No payload with connect request */ (const time_t)0 ); /* No server session number with connect request */ }
/* nanosleep sems here */ void wait_nanosleep_sem(struct lockinfo *l) { int ret; struct timespec tv = { 0, 1000000 }; int count = 0; l->data = 1; worklist_add(l); while(l->data) { ret = nanosleep(&tv, NULL); if (ret) { perror("nanosleep"); exit(1); } count++; } }
/* ipc semaphore post& wait */ void wait_ipc_sem(struct lockinfo *l) { struct sembuf sb; int ret; struct timespec *tvp = NULL; struct timespec tv = { 0, 1 }; sb.sem_num = l->index; sb.sem_flg = 0; sb.sem_op = -1; l->data = 1; if (timeout_test && (l->id % 5) == 0) tvp = &tv; worklist_add(l); ret = semtimedop(semid_lookup[l->id], &sb, 1, tvp); while(l->data != 0 && tvp) { struct timespec tv2 = { 0, 500 }; nanosleep(&tv2, NULL); } if (l->data != 0) { if (tvp) return; fprintf(stderr, "wakeup without data update\n"); exit(1); } if (ret) { if (errno == EAGAIN && tvp) return; perror("semtimed op"); exit(1); } }