Show
Ignore:
Timestamp:
02/17/12 17:05:04 (16 months ago)
Author:
denton
Message:

Corrected bugs related to piped info between the ucache daemon and its client.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/apps/ucache/ucached.c

    r9190 r9197  
    4848    else 
    4949    { 
    50         strcpy(buffer, "FAILURE: check log:" UCACHED_LOG_FILE); 
     50        strcpy(buffer, "FAILURE: check log: " UCACHED_LOG_FILE); 
    5151    } 
    5252} 
     
    8080 * handled.  
    8181 * Returns -1 when 1 or more  hung locks are detected and couldn't 
    82  * be handled properly. (error)  
     82* be handled properly. (error)  
    8383 */ 
    8484static int ucached_lockchk(void) 
     
    179179            break; 
    180180        case 'i': 
    181             rc = ucache_info(stdout, "sav"); 
     181        { 
     182            char info_options[6]; 
     183            memset(info_options, 0, 6); 
     184 
     185            /* Open FILE * to output ucache_info */ 
     186            FILE * info_out = fopen(UCACHED_INFO_FILE, "w"); 
     187            //FILE * info_out = fdopen(writefd, "w"); 
     188 
     189            int howmany = sscanf(&buffer[1], "%s", info_options); 
     190            if(howmany > 0) 
     191            { 
     192                rc = ucache_info(info_out, info_options); 
     193            } 
     194            else 
     195            { 
     196                fprintf(info_out, "No display options specified. "  
     197                    "Showing all ucache contents.\n"); 
     198                rc = ucache_info(info_out, "a"); 
     199            } 
     200            rc = 1; 
     201            fclose(info_out); 
     202            //shmdt(ucache); 
     203            //shmdt(ucache_aux); 
    182204            break; 
     205        } 
    183206        /* Close Daemon */ 
    184207        case 'x':  
     
    190213            } 
    191214            close(writefd); 
     215            close(readfd); 
    192216            exit(EXIT_SUCCESS); 
    193217            break; 
    194218        default: 
    195219            strcpy(buffer, "FAILURE\tInvalid command character"); 
    196             break; 
    197      } 
     220            return -1; 
     221    } 
    198222    return rc; 
    199223} 
     
    475499    if(dest_ucache) 
    476500    { 
     501//        printf("dest_ucache\n"); 
    477502        gossip_debug(GOSSIP_UCACHED_DEBUG, 
    478503            "INFO: destroying ucache shmem\n"); 
     
    499524    if(dest_locks) 
    500525    { 
     526//        printf("dest_locks\n"); 
    501527        gossip_debug(GOSSIP_UCACHED_DEBUG, 
    502528            "INFO: destroying locks' shmem\n"); 
     
    523549    gossip_debug(GOSSIP_UCACHED_DEBUG, 
    524550        "INFO: both shmem segments marked for destruction.\n"); 
    525  
    526551    return rc; 
    527552} 
     
    576601 
    577602    /* Daemonize! */ 
    578     rc = daemon(0, 0); 
     603    //rc = daemon( 0, 0); 
     604    rc = daemon( 1, 1); 
    579605 
    580606    if(rc != 0) 
     
    645671                char c = buffer[0]; 
    646672                /* Valid Command? */ 
    647                 if(c == 'c' || c == 'd' || c == 'x' || 'i') 
     673                if(c == 'c' || c == 'd' || c == 'x' || c == 'i') 
    648674                { 
    649675                    gossip_debug(GOSSIP_UCACHED_DEBUG, 
    650676                        "INFO: Command Received: %c\n", c); 
    651                     /* Run creation in child process */ 
    652                     if(c == 'c') 
     677                    if(c == 'c' || c == 'i') 
    653678                    { 
     679                        /* Run creation in child process */ 
    654680                        run_as_child(c); 
    655681                    } 
    656682                    else 
    657683                    { 
    658                         rc = execute_cmd(c); 
     684                        execute_cmd(c); 
    659685                    } 
    660                     check_rc(rc);                   
     686                    check_rc(rc); 
    661687                } 
    662688                /* Invalid Command */ 
     
    670696 
    671697                /* Data can be written, not guaranteed anything to write */ 
    672                 int responseLength = 0; 
    673                 if((responseLength = strlen(buffer)) != 0) 
     698                int responseLength = strlen(buffer); 
     699                if(responseLength != 0) 
    674700                { 
    675701                    writefd = open(FIFO2, O_WRONLY); 
    676702                    if(writefd == -1) 
    677                     { 
     703                    {   perror("Error Opening File"); 
    678704                        gossip_debug(GOSSIP_UCACHED_DEBUG, 
    679705                           "ERROR: opening write FIFO: errno = %d\n", errno); 
     
    681707                    rc = write(writefd, buffer, BUFF_SIZE); 
    682708                    while(rc <= 0) 
    683                     { 
     709                    {   printf("rc = %d\n", rc); 
    684710                        rc = write(writefd, buffer, BUFF_SIZE); 
    685711                    } 
    686712                    memset(buffer, 0, BUFF_SIZE); 
    687                     close(writefd); 
    688713                } 
     714                else 
     715                { 
     716                    printf("no response\n"); 
     717                } 
    689718            } 
    690719        } 
     
    693722        if(ucache_avail) 
    694723        { 
    695             /* Gather stats */ 
    696             /* TODO: which stats? */ 
     724            /* TODO: write some stats to file periodically */ 
    697725 
    698726            /* Write some dirty blocks out */ 
    699             /* TODO: create function to do this or do i already have one that will suffice? */ 
     727            /* TODO: create function to do this. */ 
    700728 
    701729            /* Check for hung locks */