if (launch_psm(executable) != CMTSuccess) {
rc = launch_psm(executable);  setWorkingDir(oldWorkingDir);  if (rc != CMTSuccess) {
PCMT_CONTROL CMT_EstablishControlConnection(char            *inPath,                                             CMT_SocketFuncs *sockFuncs,                                            CMT_MUTEX       *mutex){    PCMT_CONTROL control;#ifndef XP_MAC    char *executable;    char *newWorkingDir;    char oldWorkingDir[MAX_PATH_LEN];    size_t stringLen;#endif        int i;    char *path = NULL;    /*	On the Mac, we do special magic in the Seamonkey PSM component, so    	if PSM isn't launched by the time we reach this point, we're not doing well. */#ifndef XP_MAC    struct stat stbuf;        /*     * Create our own copy of path.     * I'd like to do a straight strdup here, but that caused problems     * for https.     */    stringLen = strlen(inPath);    path = (char*) malloc(stringLen+1);    memcpy(path, inPath, stringLen);    path[stringLen] = '\0';    control = CMT_ControlConnect(mutex, sockFuncs);    if (control != NULL) {        return control;    }    /*     * We have to try to launch it now, so it better be a valid      * path.     */    if (stat(path, &stbuf) == -1) {        goto loser;    }    /*     * Now we have to parse the path and launch the psm server.     */    executable = strrchr(path, DIRECTORY_SEPARATOR);    if (executable != NULL) {        *executable = '\0';        executable ++;        newWorkingDir = path;    } else {        executable = path;        newWorkingDir = NULL;    }    if (getCurrWorkDir(oldWorkingDir, MAX_PATH_LEN) == NULL) {        goto loser;    }    setWorkingDir(newWorkingDir);    if (launch_psm(executable) != CMTSuccess) {        goto loser;    }    setWorkingDir(oldWorkingDir);#endif    /*     * Now try to connect to the psm server.  We will try to connect     * a maximum of 30 times and then give up.     */#ifdef WIN32    for (i=0; i<30; i++) {        Sleep(1000);        control = CMT_ControlConnect(mutex, sockFuncs);        if (control != NULL) {            break;        }    }#elif defined(XP_UNIX) || defined(XP_BEOS)    i = 0;    while (i<1000) {        i += sleep(10);	control = CMT_ControlConnect(mutex, sockFuncs);	if (control != NULL) {	  break;	}    }#elif defined(XP_MAC)	for (i=0; i<30; i++) 	{		EventRecord theEvent;		WaitNextEvent(0, &theEvent, 30, NULL);		control = CMT_ControlConnect(mutex, sockFuncs);		if (control != NULL) 			break;	}#else    /*     * Figure out how to sleep for a while first     */    for (i=0; i<30; i++) {      control = CMT_ControlConnect(mutex, sockFuncs);      if (control!= NULL) {	break;      }    }#endif    if (control == NULL) {        goto loser;    }    if (path) {        free (path);    }    return control; loser:    if (control != NULL) {        CMT_CloseControlConnection(control);    }    if (path) {        free(path);    }    return NULL;}