Ignore:
Timestamp:
Jul 14, 2010, 3:54:10 PM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/packages/vizservers/pymolproxy/pymolproxy.c

    r1719 r1807  
    10381038}
    10391039
     1040/*
     1041 * LoadPDBCmd --
     1042 *
     1043 *      Load a PDB file into pymol.  There is no good way to load PDB data
     1044 *      into pymol without using a file.  This causes problems in that we
     1045 *      don't know when pymol is done with the file.  So there's always
     1046 *      a bit of mess left around. We use the same file for every file
     1047 *      so there's a chance that pymol is still using a file while we're
     1048 *      overwriting it. 
     1049 *
     1050 *      The command expects the number of bytes in the pdb data, the
     1051 *      name, and the state.
     1052 */
    10401053static int
    10411054LoadPDBCmd(ClientData clientData, Tcl_Interp *interp, int argc,
     
    10461059    int state = 1;
    10471060    int i, defer = 0, push = 0, varg = 1;
    1048    
     1061    int nBytes;
     1062
    10491063    if (proxyPtr == NULL)
    10501064        return TCL_ERROR;
    10511065    clear_error(proxyPtr);
    1052     pdbdata = name = NULL;      /* Suppress compiler warning. */
     1066    pdbdata = name = NULL;              /* Suppress compiler warning. */
     1067    nBytes = 0;                         /* Suppress compiler warning. */
    10531068    for(i = 1; i < argc; i++) {
    10541069        if ( strcmp(argv[i],"-defer") == 0 )
     
    10571072            push = 1;
    10581073        else if (varg == 1) {
    1059             pdbdata = argv[i];
     1074            nBytes = atoi(argv[i]);
    10601075            varg++;
    10611076        } else if (varg == 2) {
     
    10671082        }
    10681083    }
    1069    
    10701084    if (!defer || push) {
    10711085        proxyPtr->flags |= UPDATE_PENDING;
     
    10801094        char fileName[200];
    10811095        FILE *f;
    1082         size_t nBytes;
    10831096        ssize_t nWritten;
    1084 
     1097        char *data;
     1098
     1099        data = malloc(sizeof(char) * nBytes);
     1100        if (data == NULL) {
     1101            trace("can't allocate %d bytes for \"pdbdata\" buffer", nBytes);
     1102            return  TCL_ERROR;
     1103        }
     1104        if (GetBytes(&proxyPtr->client, data, nBytes) != BUFFER_OK) {
     1105            trace("can't read %d bytes for \"pdbdata\" buffer", nBytes);
     1106            return  TCL_ERROR;
     1107        }
    10851108        sprintf(fileName, "/tmp/pymol%d.pdb", getpid());
    10861109        f = fopen(fileName, "w");
     
    10891112            perror("pymolproxy");
    10901113        }
    1091         nBytes = strlen(pdbdata);
    1092         nWritten = fwrite(pdbdata, sizeof(char), nBytes, f);
     1114        nWritten = fwrite(data, sizeof(char), nBytes, f);
    10931115        if (nBytes != nWritten) {
    10941116            trace("short write %d wanted %d bytes", nWritten, nBytes);
     
    18441866
    18451867    child = fork();
    1846        
    18471868    if (child < 0) {
    18481869        fprintf(stderr, "can't fork process: %s\n", strerror(errno));
     
    19431964    } else if (status == 0) {
    19441965        trace("attempting to signal (SIGTERM) pymol server.");
    1945         kill(-child, SIGTERM); // kill process group
     1966        kill(-child, SIGTERM);          // Kill process group
    19461967        alarm(5);
    19471968        status = waitpid(child, &result, 0);
     
    19501971        while ((status == -1) && (errno == EINTR)) {
    19511972            trace("Attempting to signal (SIGKILL) pymol server.");
    1952             kill(-child, SIGKILL); // kill process group
     1973            kill(-child, SIGKILL);      // Kill process group
    19531974            alarm(10);
    19541975            status = waitpid(child, &result, 0);
Note: See TracChangeset for help on using the changeset viewer.