Index: cvsapi/RunFile.h =================================================================== RCS file: /usr/local/cvs/cvsnt/cvsapi/RunFile.h,v retrieving revision 1.1.2.19.4.5 diff -c -r1.1.2.19.4.5 RunFile.h *** cvsapi/RunFile.h 14 Nov 2011 04:42:22 -0000 1.1.2.19.4.5 --- cvsapi/RunFile.h 28 Aug 2012 02:50:14 -0000 *************** *** 42,48 **** CVSAPI_EXPORT bool setOutput(int (*outputFn)(const char *,size_t,void *), void *userData); CVSAPI_EXPORT bool setError(int (*outputFn)(const char *,size_t,void *), void *userData); CVSAPI_EXPORT bool setDebug(int (*debugFn)(int type, const char *,size_t, void *), void *userData); ! CVSAPI_EXPORT bool run(const char *path, bool bShow = false, bool bSuspend = false); CVSAPI_EXPORT bool wait(int& result, int timeout = -1); CVSAPI_EXPORT bool terminate(); CVSAPI_EXPORT unsigned long processid(); --- 42,48 ---- CVSAPI_EXPORT bool setOutput(int (*outputFn)(const char *,size_t,void *), void *userData); CVSAPI_EXPORT bool setError(int (*outputFn)(const char *,size_t,void *), void *userData); CVSAPI_EXPORT bool setDebug(int (*debugFn)(int type, const char *,size_t, void *), void *userData); ! CVSAPI_EXPORT bool run(const char *path, bool bShow = false, bool bSuspend = false, bool bNoPipe = false); CVSAPI_EXPORT bool wait(int& result, int timeout = -1); CVSAPI_EXPORT bool terminate(); CVSAPI_EXPORT unsigned long processid(); Index: cvsapi/unix/RunFile.cpp =================================================================== RCS file: /usr/local/cvs/cvsnt/cvsapi/unix/RunFile.cpp,v retrieving revision 1.1.2.20.4.9 diff -c -r1.1.2.20.4.9 RunFile.cpp *** cvsapi/unix/RunFile.cpp 14 Nov 2011 04:42:22 -0000 1.1.2.20.4.9 --- cvsapi/unix/RunFile.cpp 28 Aug 2012 02:53:13 -0000 *************** *** 136,142 **** } /* On Unix, the bShow parameter does nothing */ ! bool CRunFile::run(const char *path, bool bShow /* = false */, bool bSuspend /* = false */) { int pid; int fd1[2],fd2[2],fd3[2]; --- 136,142 ---- } /* On Unix, the bShow parameter does nothing */ ! bool CRunFile::run(const char *path, bool bShow /* = false */, bool bSuspend /* = false */, bool bNoPipe /* = false */) { int pid; int fd1[2],fd2[2],fd3[2]; *************** *** 144,149 **** --- 144,151 ---- char * args=(char *)m_args->toString(); CServerIo::trace(3,"CreateProcess(%s,%s)",path?path:"",args?args:""); + if (!bNoPipe) + { if(m_inputFn && m_inputFn != StandardInput) { pipe(fd1); *************** *** 170,175 **** --- 172,187 ---- } else m_errFd=-1; + } + else { + pipe(fd1); + pipe(fd1); + pipe(fd2); + m_inFd=-1; + m_outFd=-1; + m_errFd=-1; + } + if(path) m_args->insertArg(0,path); *************** *** 183,188 **** --- 195,202 ---- { int nullfd = open("/dev/null",O_RDWR); + if (!bNoPipe) + { if(m_inFd>=0) { close(fd1[PIPE_WRITE]); *************** *** 204,215 **** } else if(!m_errorFn) dup2(nullfd,2); close(nullfd); char **myargv = (char**)m_args->toArgv(); execvp (myargv[0], myargv); ! perror("Exec failed"); exit(-1); } --- 218,242 ---- } else if(!m_errorFn) dup2(nullfd,2); + } close(nullfd); char **myargv = (char**)m_args->toArgv(); execvp (myargv[0], myargv); ! int execvp_res = execvp (myargv[0], myargv); ! if (execvp_res==-1) ! { ! int execvp_errno=errno; ! CServerIo::trace(3,"unable to execute \"%s\" err %d \"%s\".",myargv[0],execvp_errno,strerror(execvp_errno)); ! ! /* ! int image_list_count = _dyld_image_count(); ! for (int i = 0; i < image_list_count; ++i) ! { ! printf("dyld: %p: name = %s\n", _dyld_get_image_header(i),_dyld_get_image_name(i) ); ! }*/ ! } exit(-1); } Index: cvsapi/unix/SocketIO.cpp =================================================================== RCS file: /usr/local/cvs/cvsnt/cvsapi/unix/SocketIO.cpp,v retrieving revision 1.1.2.24.4.15 diff -c -r1.1.2.24.4.15 SocketIO.cpp *** cvsapi/unix/SocketIO.cpp 4 Jul 2012 04:10:20 -0000 1.1.2.24.4.15 --- cvsapi/unix/SocketIO.cpp 28 Aug 2012 06:17:04 -0000 *************** *** 228,233 **** --- 228,234 ---- { if(timeout && !blocking(false)) return false; + CServerIo::trace(4,"connect %lu",(unsigned long)n); int res = ::connect(m_sockets[n],addr->ai_addr,(int)addr->ai_addrlen); if(!res) { *************** *** 241,251 **** { int select_tries=0; fd_set fds; ! struct timeval tv = { timeout/1000, (timeout%1000)*1000 }; while (!do_retry_select) { FD_ZERO(&fds); FD_SET(m_sockets[n],&fds); res = ::select(((int)m_sockets[n])+1,NULL,&fds,NULL,&tv); if ((select_tries>=timtries)||(res!=0)) { --- 242,255 ---- { int select_tries=0; fd_set fds; ! struct timeval tv; ! tv.tv_sec = timeout/1000; ! tv.tv_usec = (timeout%1000)*1000; while (!do_retry_select) { FD_ZERO(&fds); FD_SET(m_sockets[n],&fds); + CServerIo::trace(4,"select %lu sec=%d usec=%d try=%d",(unsigned long)n,(int)tv.tv_sec,(int)tv.tv_usec,select_tries); res = ::select(((int)m_sockets[n])+1,NULL,&fds,NULL,&tv); if ((select_tries>=timtries)||(res!=0)) { Index: cvsapi/win32/RunFile.cpp =================================================================== RCS file: /usr/local/cvs/cvsnt/cvsapi/win32/RunFile.cpp,v retrieving revision 1.1.2.28.4.4 diff -c -r1.1.2.28.4.4 RunFile.cpp *** cvsapi/win32/RunFile.cpp 14 Nov 2011 04:42:22 -0000 1.1.2.28.4.4 --- cvsapi/win32/RunFile.cpp 28 Aug 2012 04:23:07 -0000 *************** *** 149,156 **** return true; } ! bool CRunFile::run(const char *path, bool bShow /* = false */, bool bSuspend /* = false */) { STARTUPINFOW si = { sizeof(STARTUPINFO) }; PROCESS_INFORMATION pi; BOOL status; --- 149,158 ---- return true; } ! bool CRunFile::run(const char *path, bool bShow /* = false */, bool bSuspend /* = false */, bool bNoPipe /* = false */) { + // bNoPipe is not implemented on windows + STARTUPINFOW si = { sizeof(STARTUPINFO) }; PROCESS_INFORMATION pi; BOOL status; Index: src/main.cpp =================================================================== RCS file: /usr/local/cvs/cvsnt/src/main.c,v retrieving revision 1.71.2.151.6.76 diff -c -r1.71.2.151.6.76 main.cpp *** src/main.cpp 3 Aug 2012 04:01:49 -0000 1.71.2.151.6.76 --- src/main.cpp 28 Aug 2012 09:22:16 -0000 *************** *** 19,24 **** --- 19,46 ---- #include #endif + #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) + #include // _NSGetExecutablePath() + //#include /* PATH_MAX */ + #include /* ftok */ + #endif + #if defined( __HP_aCC ) + #include + #define _PSTAT64 + #include + #include + //#include + #endif + #if (defined (sun) || defined (__sun__)) + //#include + #include + #include + #endif + #define USHORT ushort + #include /* strerror */ + #include /* semget and semop */ + #include /* dirname */ + #ifndef HAVE_GETADDRINFO #include "socket.h" #include "getnameinfo.h" *************** *** 1493,1499 **** --- 1515,1584 ---- TRACE(1,"Tracelevel set to %d. PID is %d",trace,(int)getpid()); TRACE(1,"Session ID is %s",PATCH_NULL(global_session_id)); TRACE(1,"Session time is %s",PATCH_NULL(global_session_time)); + + + #ifndef _WIN32 + wchar_t semnamew[2048]; + union semun + { + int val; + struct semid_ds *buf; + USHORT *array; + } ignored_argument; + int sem_errno; + const char *sem_err; + char base_pathbuf[PATH_MAX + 1], pathbuf[PATH_MAX + 1], real_pathbuf[PATH_MAX + 1]; + uint32_t pathbufsize = sizeof(pathbuf); + key_t key=0; + int semid=-1; + + wcscpy(semnamew,L"\0"); + real_pathbuf[0]='\0'; + #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) + _NSGetExecutablePath( pathbuf, &pathbufsize); + realpath(pathbuf,real_pathbuf); + #else + #if (defined (sun) || defined (__sun__)) + strcpy(real_pathbuf,getexecname()); + #else + #if defined( __HP_aCC ) + struct pst_status ps; + if (pstat_getproc( &ps, sizeof( ps ), 0, getpid() ) >= 0) + pstat_getpathname( real_pathbuf, PATH_MAX, &ps.pst_fid_text ); + #else + // must be linux + readlink( "/proc/self/exe", result, PATH_MAX ); + #endif // HPUX + #endif // SUN + #endif // APPLE + if (strlen(real_pathbuf)>0) + { + char *bundle_id; + pid_t myppid = getppid(); + bundle_id = dirname(real_pathbuf); + strcpy(base_pathbuf, bundle_id); + strcat(base_pathbuf, "/"); + strcat(base_pathbuf, "cvsproxy"); + key = ftok(base_pathbuf,myppid); + if (key>=0) + semid = semget(key,1,0666); + else + CServerIo::trace(3,"ftok failed - no path %s",base_pathbuf); + swprintf(semnamew,2048,L"%s_%d(%lu)",base_pathbuf,myppid,(unsigned long)key); + } + if(semid < 0) + { + sem_errno = errno; + sem_err = strerror(sem_errno); + CServerIo::log(CServerIo::logError,"Open Semaphore failed - cannot ensure that client terminates ok: %s\nThis may be caused by a person trying to run 'cvsnt' rather than 'cvs'.",sem_err); + CServerIo::trace(3,"Open Semaphore failed - cannot ensure client terminates OK: %s",sem_err); + error (1, 0, "Please run \"cvs\" not \"cvsnt\".\nError cannot continue.\n"); + } + else + CServerIo::trace(3,"Opened Semaphore OK [%ls].",semnamew); + #endif // UNIX/LINUX/MAC + /* Look up the command name. */ command_name = argv[0]; *************** *** 2109,2114 **** --- 2194,2204 ---- // free_names(&argc,argv); } /* end of stuff that gets done if the user DOESN'T ask for help */ + + #ifndef _WIN32 + if(semid >= 0) + semctl(semid, 1, IPC_RMID , ignored_argument); + #endif TRACE(1,"Process %d exiting",(int)getpid()); Index: CvsProxyUnix.cpp =================================================================== RCS file: /scotty/cvsproxy/CvsProxyUnix.cpp,v retrieving revision 1.11 diff -c -r1.11 CvsProxyUnix.cpp *** CvsProxyUnix.cpp 30 Jun 2012 01:10:22 -0000 1.11 --- CvsProxyUnix.cpp 28 Aug 2012 09:18:21 -0000 *************** *** 12,23 **** #include #include #include #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) - #include /* dirname */ #include // _NSGetExecutablePath() //#include /* PATH_MAX */ ! #include /* dirname */ #endif #include "../licenselib/MHLicense.h" --- 12,40 ---- #include #include #include + #include + #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) #include // _NSGetExecutablePath() //#include /* PATH_MAX */ ! #include /* ftok */ ! #endif ! #if defined( __HP_aCC ) ! #include ! #define _PSTAT64 ! #include ! #include ! //#include #endif + #if (defined (sun) || defined (__sun__)) + //#include + #include + #include + #endif + #define USHORT ushort + #include /* strerror */ + #include /* semget and semop */ + #include /* dirname */ #include "../licenselib/MHLicense.h" *************** *** 25,30 **** --- 42,68 ---- #include #endif + #define DISPLAY_NAME L"CVS Suite Proxy" + #define DISPLAY_NAMEA "CVS Suite Proxy" + + #ifndef MAX_PATH + #ifdef PATH_MAX + #define MAX_PATH PATH_MAX + #elif defined(_MAX_PATH) + #define MAX_PATH _MAX_PATH + #else + #define MAX_PATH 1024 + #endif + #endif + + #define BUFFER_SIZE (BUFSIZ*10) + #define GLOBAL_SESSION_ID_LENGTH 64 + char g_session_id[GLOBAL_SESSION_ID_LENGTH]; /* Random session ID */ + const char *g_session_time; + time_t g_session_time_t; + char *g_trace_file; + FILE *g_trace_file_fp; + static bool g_bStop; static unsigned int g_wait_count=0; static int g_wrwait=120, g_wswait=120; *************** *** 98,114 **** --- 136,281 ---- #endif } + #ifdef __cplusplus + extern "C" { + #endif + + void prx_trace(int level, const char *fmt, ...) + { + if(g_trace_file) + { + va_list va; + char str[1536]; + time_t t = time(NULL); + + va_start(va, fmt); + vsnprintf(str, 1024, fmt, va); + va_end(va); + + if(g_trace_file) + { + if(!g_trace_file_fp) + g_trace_file_fp = fopen(g_trace_file,"w"); + if(!g_trace_file_fp) + { + free(g_trace_file); + g_trace_file=NULL; + } + else + { + fprintf(g_trace_file_fp,"%-8.8s: %c -> ", ctime(&t)+11, 'P'); + fprintf(g_trace_file_fp,"%s\n",str); + fflush(g_trace_file_fp); + } + } + } + } + + static int prx_main_trace(int lvl, const char *out) + { + prx_trace(lvl,"%s",out); + return 0; + } + + int prx_output (const char *str, size_t len) + { + return (int)len; + } + + int prx_outerr (const char *str, size_t len) + { + return (int)len; + } + + #ifdef __cplusplus + } + #endif + + void doClientTraceFile(void) + { + // if we want to enable trace in the control panel... + if (1) + { + char buffer[MAX_PATH]; + + if(!CGlobalSettings::GetGlobalValue("cvsnt","PServer","ClientTraceFile",buffer,sizeof(buffer))) + g_trace_file = strdup(buffer); + if(g_trace_file && !*g_trace_file) + { + free(g_trace_file); + g_trace_file=NULL; + } + if(g_trace_file) + { + cvs::string trace_file_str; + char process_id_str[50]; + size_t foundpos; + + trace_file_str = g_trace_file; + free(g_trace_file); + g_trace_file=NULL; + sprintf(process_id_str,"%d",(int)getpid()); + + sprintf(g_session_id,"%x%08lx%04x",(int)getpid(),(long)time(NULL),rand()&0xFFFF); + time (&g_session_time_t); + g_session_time = strdup(asctime (gmtime(&g_session_time_t))); + ((char*)g_session_time)[24] = '\0'; + // use %g - global_session_id + // use %p - process id + // use %t - global session time + if ((foundpos=trace_file_str.rfind("%g"))!=cvs::string::npos) + trace_file_str.replace(foundpos,2,PATCH_NULL(g_session_id)); + if ((foundpos=trace_file_str.rfind("%t"))!=cvs::string::npos) + trace_file_str.replace(foundpos,2,PATCH_NULL(g_session_time)); + if ((foundpos=trace_file_str.rfind("%p"))!=cvs::string::npos) + trace_file_str.replace(foundpos,2,process_id_str); + + g_trace_file = strdup(trace_file_str.c_str()); + CServerIo::loglevel(99); + } + CServerIo::init(prx_output,prx_outerr,prx_outerr,prx_main_trace); + CServerIo::trace(3,"CVSPROXY trace started pid=%d ppid=%d.",getpid(),getppid()); + } + return; + } + int main(int argc, char *argv[]) { + doClientTraceFile(); + CServerIo::trace(3,"started"); + + CServerIo::trace(3,"command is: %s %s",argv[0],(argc>=2)?argv[1]:"** none **"); + uid_t uid; + uid = getuid (); + if (uid != (uid_t) 0) + { + struct passwd *pw; + if ((pw = (struct passwd *) getpwuid (uid)) != NULL) + { + char *userName = strdup (pw->pw_name); + CServerIo::trace(3,"user is: %s",userName); + free(userName); + userName=NULL; + } + } + g_wait_count=0; License_t lic; if(!CheckLicense(lic)) { if(lic.type==licExpired) + { + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" Startup failed - %s license","Expired"); + CServerIo::trace(3," Startup failed - %s license","Expired"); printf("License for this product has expired\n"); + } else + { + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" Startup failed - %s license","Invalid"); + CServerIo::trace(3," Startup failed - %s license","Invalid"); printf("Invalid license key\n"); + } return -1; } #if ((CVSNT_PRODUCT_MAJOR==2) && (CVSNT_PRODUCT_MINOR==8) && (CVSNT_PRODUCT_PATCHLEVEL>=2) && (CVSNT_PRODUCT_BUILD>4135)) *************** *** 123,134 **** --- 290,305 ---- } if((lic.type==licTrial)&&(lic.daysLeft<0)) { + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" Startup failed - %s license","Expired"); + CServerIo::trace(3," Startup failed - %s license","Expired"); printf("License for this product has expired\n"); return -1; } #if ((CVSNT_PRODUCT_MAJOR==2) && (CVSNT_PRODUCT_MINOR==8) && (CVSNT_PRODUCT_PATCHLEVEL>=2) && (CVSNT_PRODUCT_BUILD>4135)) if((lic.type==licMulti)&&(lic.daysLeft<0)&&(lic.activateId==0)) { + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" Startup failed - %s license","Not Activated"); + CServerIo::trace(3,"Activation period has expired - you must activate this license now."); printf("Activation period has expired - you must activate this license now.\n"); return -1; } *************** *** 143,205 **** else { int n; ! char real_executable[PATH_MAX + 1]; ! #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) ! char pathbuf[PATH_MAX + 1], real_pathbuf[PATH_MAX + 1]; uint32_t pathbufsize = sizeof(pathbuf); ! ! if(!CGlobalSettings::GetGlobalValue("cvsnt","PServer","InstallPath",pathbuf,sizeof(pathbuf))) ! { ! strcpy(real_executable, pathbuf); ! } ! else ! { //int32_t cvstools_id; //cvstools_id = NSVersionOfRunTimeLibrary("cvstools"); //cvstools supplies GlobalSettings - char *bundle_id; _NSGetExecutablePath( pathbuf, &pathbufsize); - realpath(pathbuf,real_pathbuf); bundle_id = dirname(real_pathbuf); ! ! strcpy(real_executable, bundle_id); } ! strcat(real_executable, "/"); ! strcat(real_executable, "cvsnt"); - #else - - strcpy(real_executable, "cvsnt"); - - #endif // Can't guarantee argv is null terminated so we duplicate it char **nargv = (char**)malloc(sizeof(char*)*argc+1); nargv[0]=(char*)"cvsnt"; for(n=1; n 7) ! if (execvp_res==-1) { ! int execvp_errno=errno; ! printf("unable to execute \"%s\" err %d \"%s\".\n",real_executable,execvp_errno,strerror(execvp_errno)); ! ! /* ! int image_list_count = _dyld_image_count(); ! for (int i = 0; i < image_list_count; ++i) ! { ! printf("dyld: %p: name = %s\n", _dyld_get_image_header(i),_dyld_get_image_name(i) ); ! }*/ return -1; - } #endif ! return execvp_res; } } --- 314,472 ---- else { int n; ! //char real_executable[PATH_MAX + 1]; ! char real_filename[PATH_MAX + 1]; ! char base_pathbuf[PATH_MAX + 1], pathbuf[PATH_MAX + 1], real_pathbuf[PATH_MAX + 1]; uint32_t pathbufsize = sizeof(pathbuf); ! key_t key=0; ! int semid=-1; ! wchar_t semnamew[2048]; ! ! wcscpy(semnamew,L"\0"); ! real_pathbuf[0]='\0'; ! #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) ! //if(!CGlobalSettings::GetGlobalValue("cvsnt","PServer","InstallPath",pathbuf,sizeof(pathbuf))) ! //{ ! // strcpy(real_executable, pathbuf); ! //} ! //else ! //{ //int32_t cvstools_id; //cvstools_id = NSVersionOfRunTimeLibrary("cvstools"); //cvstools supplies GlobalSettings _NSGetExecutablePath( pathbuf, &pathbufsize); realpath(pathbuf,real_pathbuf); + //} + #else + #if (defined (sun) || defined (__sun__)) + strcpy(real_pathbuf,getexecname()); + #else + #if defined( __HP_aCC ) + struct pst_status ps; + if (pstat_getproc( &ps, sizeof( ps ), 0, getpid() ) >= 0) + pstat_getpathname( real_pathbuf, PATH_MAX, &ps.pst_fid_text ); + #else + // must be linux + readlink( "/proc/self/exe", result, PATH_MAX ); + #endif // HPUX + #endif // SUN + #endif // APPLE + + wcscpy(semnamew,L"\0"); + + if (strlen(real_pathbuf)>0) + { + char *bundle_id; + pid_t mypid = getpid(); bundle_id = dirname(real_pathbuf); ! strcpy(base_pathbuf, bundle_id); ! strcpy(real_filename, bundle_id); ! strcat(base_pathbuf, "/"); ! strcat(base_pathbuf, "cvsproxy"); ! strcat(real_filename, "/"); ! strcat(real_filename, "cvsnt"); ! key = ftok(base_pathbuf,mypid); ! semid = semget(key,1,0666 | IPC_CREAT); ! swprintf(semnamew,2048,L"%s_%d(%lu)",base_pathbuf,(int)mypid,(unsigned long)key); } + int sem_errno; + const char *sem_err; ! if(semid < 0) ! { ! if (strlen(base_pathbuf)>0) ! { ! sem_errno = errno; ! sem_err = strerror(sem_errno); ! } ! else ! sem_err=strdup("** no real path **"); ! ! CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" Create Semaphore failed - cannot ensure that accept() is not raced: %s\n",sem_err); ! CServerIo::trace(3,"Create Semaphore (%S) failed - cannot ensure that accept() is not raced (%s): %s",semnamew,sem_err); ! printf("Create Semaphore failed - cannot ensure that accept() is not raced: %s\n",sem_err); ! } ! CServerIo::trace(3,"Create Semaphore (%S) OK",semnamew); ! ! union semun ! { ! int val; ! struct semid_ds *buf; ! USHORT *array; ! } semctl_arg,ignored_argument; ! ! //Set Initial value for the resource - initially not owned ! semctl_arg.val = 0; //Setting semval to 0 ! if (semctl(semid, 0, SETVAL, semctl_arg)<0) ! CServerIo::trace(3,"Set Semaphore value to zero FAIL."); ! CServerIo::trace(3,"Set Semaphore value to zero OK."); + // this is the old (before Suite 2010) method of starting the 'real' cvsnt process. + if (0) + { // Can't guarantee argv is null terminated so we duplicate it char **nargv = (char**)malloc(sizeof(char*)*argc+1); nargv[0]=(char*)"cvsnt"; for(n=1; n=2)?argv[1]:"** none **"); int execvp_res; ! execvp_res = execvp(real_filename,argv); ! } ! ! CRunFile rf; ! ! ! rf.resetArgs(); ! rf.addArg(real_filename); ! for(n=1; n=2)?argv[1]:"** none **"); ! if(!rf.run(NULL,false,false,true)) { ! #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) ! CServerIo::trace(3,"unable to execute \"%s\".",real_filename); return -1; #endif ! } ! ! unsigned long rfpid = (unsigned long)rf.processid(); ! ! CServerIo::trace(3,"Cvsnt process %lu started at %-8.8s", rfpid, ctime(&rft)+11); ! CServerIo::trace(3,"%s", rf.toString()); ! ! // don't want two processes both connected to stdin (0) so close the cvsproxy stdin... ! int nullfd = open("/dev/null",O_RDWR); ! int fd1[2] = {-1, -1}; ! pipe(fd1); ! CServerIo::trace(3,"Pipe fd1[0]=%d fd1[1]=%d",fd1[0],fd1[1]); ! dup2(nullfd,fd1[0]); ! close(nullfd); ! CServerIo::trace(3,"Deleted stdin"); ! ! int rf_res=-1; ! if(!rf.wait(rf_res)) ! { ! CServerIo::trace(3,"unable to wait on run"); ! return false; ! } ! CServerIo::trace(3,"the client process exited status is %d.",rf_res); ! ! if(semid >= 0) ! { ! int semclosed; ! semclosed=semctl(semid, 1, IPC_RMID , ignored_argument); ! if (semclosed!=-1) ! CServerIo::trace(3,"Closed Semaphore OK."); ! } ! ! CServerIo::trace(3,"finished simple proxy"); ! return rf_res; } } *************** *** 227,237 **** --- 494,506 ---- if(!sock.create(NULL,"32999",true,true,g_wrwait,g_wswait)) { + CServerIo::trace(3,"error 0 Couldn't connect to server - is it running?"); printf("error 0 Couldn't connect to server - is it running?\n"); return -1; } if(!sock.connect()) { + CServerIo::trace(3,"error 0 Couldn't connect to server - is it running?"); printf("error 0 Couldn't connect to server - is it running?\n"); return -1; } *************** *** 256,266 **** --- 525,539 ---- // Endianness doesn't matter here because we always proxy to localhost if(sock.send((const char *)&len,sizeof(len))!=sizeof(len)) { + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" error 0 Failed writing to server"); + CServerIo::trace(3,"error 0 Failed writing to server"); printf("error 0 Failed writing to server\n"); return -1; } if(sock.send(encbuf,len)!=len) { + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" error 0 Failed writing to server"); + CServerIo::trace(3,"error 0 Failed writing to server"); printf("error 0 Failed writing to server\n"); return -1; } Index: CvsManager.cpp =================================================================== RCS file: /scotty/cvsmanager/CvsManager.cpp,v retrieving revision 1.77 diff -c -r1.77 CvsManager.cpp *** CvsManager.cpp 17 Jul 2012 06:22:53 -0000 1.77 --- CvsManager.cpp 28 Aug 2012 09:18:48 -0000 *************** *** 29,34 **** --- 29,35 ---- #define USHORT ushort #include /* strerror */ #include /* semget and semop */ + #include /* dirname */ #endif *************** *** 1226,1232 **** --- 1227,1327 ---- rf.addArg(license.rspline.c_str()); } #endif + time_t rft = time(NULL); + + #ifndef _WIN32 + char base_pathbuf[PATH_MAX + 1], pathbuf[PATH_MAX + 1], real_pathbuf[PATH_MAX + 1]; + uint32_t pathbufsize = sizeof(pathbuf); + key_t key=0; + int semid=-1; + wchar_t semnamew[2048]; + + wcscpy(semnamew,L"\0"); + real_pathbuf[0]='\0'; + #if (__APPLE__) && (!defined(__DARWIN_OS__) || __DARWIN_OS__ > 7) + //if(!CGlobalSettings::GetGlobalValue("cvsnt","PServer","InstallPath",pathbuf,sizeof(pathbuf))) + //{ + // strcpy(real_executable, pathbuf); + //} + //else + //{ + //int32_t cvstools_id; + //cvstools_id = NSVersionOfRunTimeLibrary("cvstools"); //cvstools supplies GlobalSettings + _NSGetExecutablePath( pathbuf, &pathbufsize); + realpath(pathbuf,real_pathbuf); + //} + #else + #if (defined (sun) || defined (__sun__)) + strcpy(real_pathbuf,getexecname()); + #else + #if defined( __HP_aCC ) + struct pst_status ps; + if (pstat_getproc( &ps, sizeof( ps ), 0, getpid() ) >= 0) + pstat_getpathname( real_pathbuf, PATH_MAX, &ps.pst_fid_text ); + #else + // must be linux + readlink( "/proc/self/exe", result, PATH_MAX ); + #endif // HPUX + #endif // SUN + #endif // APPLE + + wcscpy(semnamew,L"\0"); + + if (strlen(real_pathbuf)>0) + { + char *bundle_id; + pid_t mypid = getpid(); + bundle_id = dirname(real_pathbuf); + strcpy(base_pathbuf, bundle_id); + strcat(base_pathbuf, "/"); + strcat(base_pathbuf, "cvsproxy"); + key = ftok(base_pathbuf,mypid); + semid = semget(key,1,0666 | IPC_CREAT); + swprintf(semnamew,2048,L"%s_%d(%lu)",base_pathbuf,mypid,(unsigned long)key); + } + + int sem_errno; + const char *sem_err; + + if(semid < 0) + { + if (strlen(base_pathbuf)>0) + { + sem_errno = errno; + sem_err = strerror(sem_errno); + } + else + sem_err=strdup("** no real path **"); + + CServerIo::log(CServerIo::logError,DISPLAY_NAMEA" Create Semaphore failed - cannot ensure that accept() is not raced: %s\n",sem_err); + CServerIo::trace(3,"Create Semaphore (%s) failed - cannot ensure that accept() is not raced (%s): %s","Global\\CVSNT_MgrAccept",sem_err); + printf("Create Semaphore failed - cannot ensure that accept() is not raced: %s\n",sem_err); + } + + CServerIo::trace(3,"Created Semaphore OK [%ls].",semnamew); + #endif // UNIX/LINUX/MAC + + #ifndef _WIN32 + union semun + { + int val; + struct semid_ds *buf; + USHORT *array; + } semctl_arg,ignored_argument; + + //Set Initial value for the resource - initially not owned + semctl_arg.val = 0; //Setting semval to 0 + if (semctl(semid, 0, SETVAL, semctl_arg)<0) + { + if(g_bTestMode) + printf("Set Semaphore value to zero OK.\n"); + CServerIo::trace(3,"Set Semaphore value to zero OK."); + } + + #endif // NOT WINDOWS + + if(!rf.run(NULL,false,true)) { #ifdef _WIN32 *************** *** 1273,1280 **** --- 1368,1377 ---- LocalFree( errbuf ); errbuf = NULL;*/ } + #endif if (rf.resume()==0) { + #ifdef _WIN32 if(g_bTestMode) printf("Failed to resume client thread\n"); CServerIo::trace(3,"Failed to resume client thread"); *************** *** 1282,1295 **** g_crit.enter(); g_running_servers--; g_crit.leave(); ! CloseHandle(hSemClnt); return; } CServerIo::trace(3,"Cvsnt process %lu started at %-8.8s (%d servers, status %d)", rfpid, ctime(&rft)+11, g_running_servers, g_crit.status); CServerIo::trace(3,"%s\n", rf.toString()); - #endif if(g_bTestMode) { printf("Cvsnt process %lu started at %-8.8s (%d servers, status %d)\n %s\n", --- 1379,1404 ---- g_crit.enter(); g_running_servers--; g_crit.leave(); ! #ifdef _WIN32 ! if (hSemClnt!=NULL) ! CloseHandle(hSemClnt); ! #else ! if(semid >= 0) ! semctl(semid, 1, IPC_RMID , ignored_argument); ! #endif return; + #else + if(g_bTestMode) + { + CServerIo::trace(4,"Failed to resume because it's not implemented on linux/unix/mac"); + printf("Failed to resume because it's not implemented on linux/unix/mac\n"); + } + #endif } CServerIo::trace(3,"Cvsnt process %lu started at %-8.8s (%d servers, status %d)", rfpid, ctime(&rft)+11, g_running_servers, g_crit.status); CServerIo::trace(3,"%s\n", rf.toString()); if(g_bTestMode) { printf("Cvsnt process %lu started at %-8.8s (%d servers, status %d)\n %s\n", *************** *** 1311,1320 **** g_crit.leave(); #ifdef _WIN32 ! CloseHandle(hSemClnt); ! CServerIo::trace(3,"Cvsnt process %lu terminated at %-8.8s (%d servers left, status %d)", ! rfpid, ctime(&rft)+11, g_running_servers, g_crit.status); #endif if(g_bTestMode) { printf("Cvsnt process %lu terminated at %-8.8s (%d servers left, status %d)\n", --- 1420,1438 ---- g_crit.leave(); #ifdef _WIN32 ! if (hSemClnt!=NULL) ! CloseHandle(hSemClnt); ! #else ! if(semid >= 0) ! { ! int semclosed; ! semclosed=semctl(semid, 1, IPC_RMID , ignored_argument); ! if (semclosed!=-1) ! CServerIo::trace(3,"Closed Semaphore OK."); ! } #endif + CServerIo::trace(3,"Cvsnt process %lu terminated at %-8.8s (%d servers left, status %d)", + rfpid, ctime(&rft)+11, g_running_servers, g_crit.status); if(g_bTestMode) { printf("Cvsnt process %lu terminated at %-8.8s (%d servers left, status %d)\n",