Changeset 676 for trunk/user/ksh/ksh.c


Ignore:
Timestamp:
Nov 20, 2020, 12:11:35 AM (3 years ago)
Author:
alain
Message:

Introduce chat application to test the named pipes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/ksh/ksh.c

    r659 r676  
    5858
    5959#define DEBUG_MAIN          0
    60 #define DEBUG_INTER         0
    6160#define DEBUG_EXECUTE       0
    6261#define DEBUG_CMD_CAT       0
     
    105104pthread_t       trdid;                      // interactive thread identifier
    106105
     106char            cmd[CMD_MAX_SIZE];                  // buffer for one command
     107
     108char            elf_path[PATH_MAX_SIZE];    // pathname for cmd_load command
     109
    107110char            pathname[PATH_MAX_SIZE];    // pathname for a file
    108111
    109 char            pathnew[PATH_MAX_SIZE];     // used by the rename command
     112char            pathnew[PATH_MAX_SIZE];     // used by the cmd_rename command
    110113 
    111 char            string[128];                // used by snprintf() for debug
     114char            string[256];                // used by snprintf() for debug
    112115
    113116//////////////////////////////////////////////////////////////////////////////////////////
     
    124127
    125128#if DEBUG_CMD_CAT
    126 snprintf( string , 128 , "[ksh] %s enters" , __FUNCTION__);
    127 display_string( string );
     129printf("\n[ksh] %s enters" , __FUNCTION__);
    128130#endif
    129131
     
    139141
    140142#if DEBUG_CMD_CAT
    141 snprintf( string , 128 , "[ksh] %s : after strcpy" , __FUNCTION__ );
    142 display_string( string );
     143printf("\n[ksh] %s : after strcpy" , __FUNCTION__ );
    143144#endif
    144145
     
    154155
    155156#if DEBUG_CMD_CAT
    156 snprintf( string , 128 , "[ksh] %s : file %s open", __FUNCTION__, pathname );
    157 display_string( string );
     157printf("\n[ksh] %s : file %s open", __FUNCTION__, pathname );
    158158#endif
    159159
     
    181181
    182182#if DEBUG_CMD_CAT
    183 snprintf( string , 128 , "[ksh] %s : size = %d",
    184 __FUNCTION__, size );
    185 display_string( string );
     183printf("\n[ksh] %s : size = %d", __FUNCTION__, size );
    186184#endif
    187185
     
    208206
    209207#if DEBUG_CMD_CAT
    210 snprintf( string , 128 , "[ksh] %s : mapped file %d to buffer %x",
    211 __FUNCTION__, fd , buf );
    212 display_string( string );
     208printf("\n[ksh] %s : mapped file %d to buffer %x", __FUNCTION__, fd , buf );
    213209#endif
    214210
     
    223219
    224220#if DEBUG_CMD_CAT
    225 snprintf( string , 128 , "[ksh] %s : unmapped file %d from buffer %x",
    226 __FUNCTION__, fd , buf );
    227 display_string( string );
     221printf("\n[ksh] %s : unmapped file %d from buffer %x", __FUNCTION__, fd , buf );
    228222#endif
    229223
     
    273267
    274268#if DEBUG_CMD_CP
    275 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__);
    276 display_string( string );
     269printf("\n[ksh] enter %s" , __FUNCTION__);
    277270#endif
    278271
     
    297290
    298291#if DEBUG_CMD_CP
    299 snprintf( string , 128 , "[ksh] %s : file %s open", __FUNCTION__, argv[1] );
    300 display_string( string );
     292printf("\n[ksh] %s : file %s open", __FUNCTION__, argv[1] );
    301293#endif
    302294
     
    310302
    311303#if DEBUG_CMD_CP
    312 snprintf( string , 128 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[1] );
    313 display_string( string );
     304printf("\n[ksh] %s : got stats for %s", __FUNCTION__, argv[1] );
    314305#endif
    315306
     
    335326
    336327#if DEBUG_CMD_CP
    337 snprintf( string , 128 , "[ksh] %s : file %s open", __FUNCTION__, argv[2] );
    338 display_string( string );
     328printf("\n[ksh] %s : file %s open", __FUNCTION__, argv[2] );
    339329#endif
    340330
     
    346336
    347337#if DEBUG_CMD_CP
    348 snprintf( string , 128 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[2] );
    349 display_string( string );
     338printf("\n[ksh] %s : got stats for %s", __FUNCTION__, argv[2] );
    350339#endif
    351340
     
    370359
    371360#if DEBUG_CMD_CP
    372 snprintf( string , 128 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, argv[1] );
    373 display_string( string );
     361printf("\n[ksh] %s : read %d bytes from %s", __FUNCTION__, len, argv[1] );
    374362#endif
    375363
     
    382370
    383371#if DEBUG_CMD_CP
    384 snprintf( string , 128 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, argv[2] );
    385 display_string( string );
     372printf("\n[ksh] %s : write %d bytes to %s", __FUNCTION__, len, argv[2] );
    386373#endif
    387374
     
    416403               "         display  fat      min      nslots\n"
    417404               "         display  fat      cxy      0\n"
    418                "         display  socket   pid      fdid\n" );
     405               "         display  socket   pid      fdid\n"
     406               "         display  fd       pid\n"
     407               "         display  fbf      pid\n" );
    419408    }
    420409    ////////////////////////////////////
     
    578567        }
    579568    }
    580     ///////////////////////////////////////////
     569    /////////////////////////////////////////
    581570    else if( strcmp( argv[1] , "fat" ) == 0 )
    582571    {
     
    596585        }
    597586    }
    598     ///////////////////////////////////////////
     587    ////////////////////////////////////////////
    599588    else if( strcmp( argv[1] , "socket" ) == 0 )
    600589    {
     
    614603        }
    615604    }
     605    ////////////////////////////////////////
     606    else if( strcmp( argv[1] , "fd" ) == 0 )
     607    {
     608        if( argc != 3 )
     609        {
     610                    printf("  usage: display fd pid\n");
     611            }
     612        else
     613        {
     614            unsigned int pid = atoi(argv[2]);
     615           
     616            if( display_fd_array( pid ) )
     617            {
     618                printf("  error: cannot found process %x\n", pid );
     619            }
     620        }
     621    }
     622    ////////////////////////////////////////
     623    else if( strcmp( argv[1] , "fbf" ) == 0 )
     624    {
     625        if( argc != 3 )
     626        {
     627                    printf("  usage: display fbf pid\n"
     628                   "         display fbf 0 (all processes)");
     629            }
     630        else
     631        {
     632            unsigned int pid = atoi(argv[2]);
     633           
     634            if( display_fbf_windows( pid ) )
     635            {
     636                printf("  error: cannot found process %x\n", pid );
     637            }
     638        }
     639    }
    616640    ////
    617641    else
     
    632656        if (argc != 2)
    633657    {
    634                 printf("  usage: %s pid\n", argv[0]);
     658                printf("  usage: fg pid\n");
    635659        }
    636660    else
     
    658682        unsigned int i;
    659683
    660         if (argc != 1)
    661     {
    662                 printf("  usage: %s\n", argv[0]);
     684        if( (argc != 1) || (argv[0] == NULL) )
     685    {
     686                printf("  usage: help\n");
    663687        }
    664688    else
     
    676700}   // end cmd_help()
    677701
     702/////////////////////////////////////////////////
     703static void cmd_history( int argc , char **argv )
     704{
     705        unsigned int i;
     706
     707        if( (argc != 1) || (argv[0] == NULL) )
     708    {
     709                printf("  usage: history\n");
     710        }
     711    else
     712    {
     713            printf("--- registered commands ---\n");
     714            for (i = 0; i < LOG_DEPTH; i++)
     715        {
     716                    printf(" - %d\t: %s\n", i, &log_entries[i].buf);
     717            }
     718    }
     719
     720    // release semaphore to get next command
     721    sem_post( &semaphore );
     722
     723} // end cmd_history()
     724
    678725//////////////////////////////////////////////
    679726static void cmd_kill( int argc , char **argv )
     
    683730        if (argc != 2)
    684731    {
    685                 printf("  usage: %s pid\n", argv[0]);
     732                printf("  usage: kill pid\n", argv[0]);
    686733        }
    687734    else
     
    710757        int                  ret_fork;           // return value from fork
    711758        int                  ret_exec;           // return value from exec
    712     unsigned int         ksh_pid;            // KSH process PID
     759    unsigned int         cmd_ok;             // command arguments acceptable
    713760    unsigned int         background;         // background execution if non zero
    714     unsigned int         placement;          // placement specified if non zero
    715     unsigned int         cxy;                // target cluster if placement specified
     761    unsigned int         place;              // user placement if non zero
     762    char               * arg[5];             // array of pointers on main thread arguments
     763    unsigned int         args_nr;            // number of aruments in this array
     764
     765    char                 undef[] = { "undefined" };
     766
     767    // arguments analysis of argv[] array that contains at most 8 strings:
     768    // - the two first arguments ("cmd_type" & "elf_path") are mandatory
     769    // - the six next ("-pcxy","arg0","arg1","arg2","arg3","&") are optional
     770
     771     // analyse the optional arguments
     772    if( argc == 2 )                            // no optional arguments
     773    {
     774        cmd_ok     = 1;
     775        background = 0;
     776        place      = 0;
     777        arg[0]     = undef;
     778        arg[1]     = undef;
     779        arg[2]     = undef;
     780        arg[3]     = undef;
     781        args_nr    = 0;
     782    }
     783    else if( ((argc >= 4) && (argc <= 8)) &&
     784             (argv[2][0] == '-') && (argv[2][1] == 'p') &&           
     785             (strcmp(argv[argc-1] , "&" ) == 0) )     // background, place, 0 to 4 args
     786    {
     787        cmd_ok     = 1;
     788        background = 1;
     789        place      = 0xFF000000 | atoi( argv[2] + 2 );
     790        arg[0]     = (argc > 4) ? argv[3] : undef;
     791        arg[1]     = (argc > 5) ? argv[4] : undef;
     792        arg[2]     = (argc > 6) ? argv[5] : undef;
     793        arg[3]     = (argc > 7) ? argv[6] : undef;
     794        args_nr    = argc - 4;
     795    }
     796    else if( ((argc >= 3) && (argc <= 7)) &&
     797             (argv[2][0] == '-') && (argv[2][1] == 'p') &&
     798             (strcmp(argv[argc-1] , "&" ) != 0) )     // place, no background, 0 to 4 args
     799    {
     800        cmd_ok     = 1;
     801        background = 0;
     802        place      = 0xFF000000 | atoi( argv[2] + 2 );
     803        arg[0]     = (argc > 3) ? argv[3] : undef;
     804        arg[1]     = (argc > 4) ? argv[4] : undef;
     805        arg[2]     = (argc > 5) ? argv[5] : undef;
     806        arg[3]     = (argc > 6) ? argv[6] : undef;
     807        args_nr    = argc - 3;
     808    }
     809    else if( ((argc >=3) && (argc <= 7))  &&       
     810             ((argv[2][0] != '-') || (argv[2][1] != 'p')) &&
     811             (strcmp(argv[argc-1] , "&" ) == 0) )     // no place, background, 0 to 4 args
     812    {
     813        cmd_ok     = 1;
     814        background = 1;
     815        place      = 0;
     816        arg[0]     = (argc > 3) ? argv[2] : undef;
     817        arg[1]     = (argc > 4) ? argv[3] : undef;
     818        arg[2]     = (argc > 5) ? argv[4] : undef;
     819        arg[3]     = (argc > 6) ? argv[5] : undef;
     820        args_nr    = argc - 3;
     821    }
     822    else if( (argc >= 3) && (argc <= 6 ) )     // no place, no background, 0 to 4 args
     823    {
     824        cmd_ok     = 1;
     825        background = 0;
     826        place      = 0;
     827        arg[0]     = (argc > 2) ? argv[2] : undef;
     828        arg[1]     = (argc > 3) ? argv[3] : undef;
     829        arg[2]     = (argc > 4) ? argv[4] : undef;
     830        arg[3]     = (argc > 5) ? argv[5] : undef;
     831        args_nr    = argc - 2;
     832    }
     833    else                                    // illegal optional arguments
     834    {
     835        cmd_ok = 0;
     836        background = 0;
     837        place      = 0;
     838        arg[0]     = undef;
     839        arg[1]     = undef;
     840        arg[2]     = undef;
     841        arg[3]     = undef;
     842        args_nr    = 0;
     843    }
     844
     845    // check syntax errors
     846    if( cmd_ok == 0 )
     847    {
     848        printf("  usage: load elf_path [-pcxy] [arg0] [arg1] [arg2] [arg3] [&]\n");
     849
     850        // release semaphore to get next command
     851        sem_post( &semaphore );
     852
     853        return;
     854    }
     855
     856    // get elf_path
     857    strcpy( elf_path , argv[1] );
    716858
    717859#if DEBUG_CMD_LOAD
    718 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__);
    719 display_string( string );
    720 #endif
    721 
    722         if( (argc < 2) || (argc > 4) ) 
    723     {
    724                 printf("  usage: %s pathname [cxy] [&]\n", argv[0] );
    725         }
    726     else
    727     {
    728             strcpy( pathname , argv[1] );
    729 
    730         if( argc == 2 )
    731         {
    732             background = 0;
    733             placement  = 0;
    734             cxy        = 0;
    735         }
    736         else if( argc == 3 )
    737         {
    738             if( (argv[2][0] == '&') && (argv[2][1] == 0) )
    739             {
    740                 background = 1;
    741                 placement  = 0;
    742                 cxy        = 0;
    743             }
    744             else
    745             {
    746                 background = 0;
    747                 placement  = 1;
    748                 cxy        = atoi( argv[2] );
    749             }
    750         }
    751         else  // argc == 4
    752         {
    753             background = ( (argv[3][0] == '&') && (argv[3][1] == 0) );
    754             placement  = 1;
    755             cxy        = atoi( argv[2] );
    756         }
    757 
    758         // get KSH process PID
    759         ksh_pid = getpid();
     860printf("\n[ksh] %s : path <%s> / place %x / args_nr %d / bg %d\n"
     861"                 arg0 %s / arg1 %s / arg2 %s / arg3 %s\n",
     862__FUNCTION__, elf_path , place , args_nr , background , arg[0] , arg[1] , arg[2] , arg[3] );
     863#endif
     864
     865    // set NULL pointers in args[] array
     866    if     ( arg[0] == undef ) arg[0] = NULL;
     867    else if( arg[1] == undef ) arg[1] = NULL;
     868    else if( arg[2] == undef ) arg[2] = NULL;
     869    else if( arg[3] == undef ) arg[3] = NULL;
     870    else                       arg[4] = NULL;
     871
     872    // set target cluster if required
     873    if( place ) place_fork( place & 0xFFFF );
     874
     875    // KSH process fork CHILD process
     876        ret_fork = fork();
     877
     878    if ( ret_fork < 0 )     // it is a failure reported to KSH
     879    {
     880        printf("  error: ksh process unable to fork\n");
     881    }
     882    else if (ret_fork == 0) // it is the CHILD process
     883    {
    760884
    761885#if DEBUG_CMD_LOAD
    762 snprintf( string , 128 , "[ksh] %s : <%s> / bg %d / place %d / cxy %x",
    763 __FUNCTION__, argv[1], background, placement, cxy );
    764 display_string( string );
    765 #endif
    766 
    767         // set target cluster if required
    768         if( placement ) place_fork( cxy );
    769 
    770         // KSH process fork CHILD process
    771             ret_fork = fork();
    772 
    773         if ( ret_fork < 0 )     // it is a failure reported to KSH
    774         {
    775             printf("  error: ksh process unable to fork\n");
    776         }
    777         else if (ret_fork == 0) // it is the CHILD process
    778         {
     886printf("\n[ksh] %s : child (pid %x) after fork, before exec\n",
     887 __FUNCTION__ , getpid() );
     888#endif
     889
     890        // CHILD process exec NEW process
     891        ret_exec = execve( elf_path , arg , NULL );
    779892
    780893#if DEBUG_CMD_LOAD
    781 snprintf( string , 128 , "[ksh] %s : child (%x) after fork, before exec",
    782 __FUNCTION__ , getpid() );
    783 display_string( string );
    784 #endif
    785 
    786             // CHILD process exec NEW process
    787             ret_exec = execve( pathname , NULL , NULL );
     894printf("\n[ksh] %s : child (pid %x) after exec / ret_exec %x\n",
     895 __FUNCTION__, getpid(), ret_exec );
     896#endif
     897
     898        // this is only executed in case of exec failure
     899        if( ret_exec )
     900        {
     901            printf("  error: child process unable to exec <%s>\n", pathname );
     902            exit( 0 );
     903        }   
     904        }
     905    else                    // it is the KSH process : ret_fork is the new process PID
     906    {
    788907
    789908#if DEBUG_CMD_LOAD
    790 snprintf( string , 128 , "[ksh] %s : child (%x) after exec / ret_exec %x",
    791 __FUNCTION__ , getpid(), ret_exec );
    792 display_string( string );
    793 #endif
    794 
    795             // this is only executed in case of exec failure
    796             if( ret_exec )
    797             {
    798                 printf("  error: child process unable to exec <%s>\n", pathname );
    799                 exit( 0 );
    800             }   
    801             }
    802         else                    // it is the KSH process : ret_fork is the new process PID
    803         {
    804 
    805 #if DEBUG_CMD_LOAD
    806 snprintf( string , 128 , "[ksh] %s : ksh (%x) after fork / ret_fork %x",
    807 __FUNCTION__, getpid(), ret_fork );
    808 display_string( string );
    809 #endif
    810             // when the new process is launched in background, the KSH process
    811             // takes the TXT ownership, and release the semaphore to get the next command.
    812             // Otherwise, the child process keep the TXT ownership, and the semaphore will
    813             // be released by the KSH main thread when the child process exit
    814 
    815             if( background )    //  KSH must keep TXT ownership
    816             {
    817                 // get back the TXT ownership
    818                 fg( ksh_pid );
    819 
    820                 // release semaphore to get next command
    821                 sem_post( &semaphore );
    822             }
     909printf("\n[ksh] %s : ksh (pid %x) after fork / ret_fork %x\n",
     910 __FUNCTION__, getpid(), ret_fork );
     911#endif
     912        // when the new process is launched in background, the KSH process
     913        // takes the TXT ownership, and releases the semaphore to get the next command.
     914        // Otherwise, the child process keep the TXT ownership, and the semaphore will
     915        // be released by the KSH main thread when the child process exit
     916
     917        if( background )    //  KSH must keep TXT ownership
     918        {
     919            // KSH get back the TXT ownership
     920            fg( getpid() );
     921
     922            // release semaphore to get next command
     923            sem_post( &semaphore );
    823924        }
    824925    }
    825926}   // end cmd_load
    826 
    827 /////////////////////////////////////////////
    828 static void cmd_log( int argc , char **argv )
    829 {
    830         unsigned int i;
    831 
    832         if (argc != 1)
    833     {
    834                 printf("  usage: %s\n", argv[0], argc );
    835         }
    836     else
    837     {
    838             printf("--- registered commands ---\n");
    839             for (i = 0; i < LOG_DEPTH; i++)
    840         {
    841                     printf(" - %d\t: %s\n", i, &log_entries[i].buf);
    842             }
    843     }
    844 
    845     // release semaphore to get next command
    846     sem_post( &semaphore );
    847 
    848 } // end cmd_log()
    849 
    850927
    851928////////////////////////////////////////////
     
    856933
    857934#if DEBUG_CMD_LS
    858 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__);
    859 display_string( string );
     935printf("\n[ksh] enter %s" , __FUNCTION__);
    860936#endif
    861937
     
    876952
    877953#if DEBUG_CMD_LS
    878 snprintf( string , 128 , "[ksh] %s : directory <%s> open / DIR %x",
    879 __FUNCTION__, pathname , dir );
    880 display_string( string );
     954printf("\n[ksh] %s : directory <%s> open / DIR %x", __FUNCTION__, pathname , dir );
    881955#endif
    882956
     
    899973
    900974#if DEBUG_CMD_LS
    901 snprintf( string , 128 , "[ksh] %s : directory <%s> closed",
    902 __FUNCTION__, pathname );
    903 display_string( string );
     975printf("\n[ksh] %s : directory <%s> closed", __FUNCTION__, pathname );
    904976#endif
    905977
     
    9641036
    9651037#if DEBUG_CMD_PS
    966 snprintf( string , 128 , "[ksh] enter %s" , __FUNCTION__);
    967 display_string( string );
    968 #endif
    969 
    970         if (argc != 1)
    971     {
    972                 printf("  usage: %s\n", argv[0]);
     1038printf("\n[ksh] enter %s" , __FUNCTION__);
     1039#endif
     1040
     1041        if( (argc != 1) || (argv[0] == NULL) )
     1042    {
     1043                printf("  usage: ps\n");
    9731044        }
    9741045    else
     
    9871058
    9881059#if DEBUG_CMD_PS
    989 snprintf( string , 128 , "\n[ksh] %s : call display_cluster_process()", __FUNCTION__ );
    990 display_string( string );
     1060printf("\n[ksh] %s : call display_cluster_process()", __FUNCTION__ );
    9911061#endif
    9921062
     
    10051075static void cmd_pwd( int argc , char **argv )
    10061076{
    1007         if (argc != 1)
    1008     {
    1009                 printf("  usage: %s\n", argv[0]);
     1077        if( (argc != 1) || (argv[0] == NULL) )
     1078    {
     1079                printf("  usage: pwd\n");
    10101080        }
    10111081    else
     
    10311101        if (argc != 2)
    10321102    {
    1033                 printf("  usage: %s pathname\n", argv[0]);
     1103                printf("  usage: rm pathname\n");
    10341104        }
    10351105    else
     
    10561126        if (argc != 2)
    10571127    {
    1058                 printf("  usage: %s pathname\n", argv[0]);
     1128                printf("  usage: stat pathname\n");
    10591129        }
    10601130    else
     
    10841154static void cmd_rmdir( int argc , char **argv )
    10851155{
    1086     // same as cmd_rm()
    1087         cmd_rm (argc , argv );
    1088 }
     1156        if (argc != 2)
     1157    {
     1158                printf("  usage: rmdir pathname\n");
     1159        }
     1160    else
     1161    {
     1162            strcpy( pathname , argv[1] );
     1163
     1164        if ( unlink( pathname ) )
     1165        {
     1166                    printf("  error: unable to remove <%s>\n", pathname );
     1167            }
     1168    }
     1169
     1170    // release semaphore to get next command
     1171    sem_post( &semaphore );
     1172
     1173}  // end cmd_rmdir()
    10891174
    10901175///////////////////////////////////////////////
     
    11531238        { "load",    "load an user application",                        cmd_load    },
    11541239        { "help",    "list available commands",                         cmd_help    },
     1240        { "history", "list registered commands",                        cmd_history },
    11551241        { "kill",    "kill a process (all threads)",                    cmd_kill    },
    1156         { "log",     "list registered commands",                        cmd_log     },
    11571242        { "ls",      "list directory entries",                          cmd_ls      },
    11581243        { "mkdir",   "create a new directory",                          cmd_mkdir   },
     
    11791264
    11801265#if DEBUG_EXECUTE
    1181 snprintf( string , 128 , "[ksh] enter %s for command <%s>" , __FUNCTION__ , buf );
    1182 display_string( string );
    1183 #endif
    1184 
    1185         // build argc/argv
     1266printf("\n[ksh] enter %s for command <%s>" , __FUNCTION__ , buf );
     1267#endif
     1268
     1269        // build argc/argv :
     1270    // arg[0] is the command type
     1271    // - other arg[i] are the command arguments
     1272
    11861273        for (i = 0; i < len; i++)
    11871274    {
     
    12091296
    12101297#if DEBUG_EXECUTE
    1211 snprintf( string , 128 , "\n[ksh] in %s : argc = %d / arg0 = %s / arg1 = %s",
    1212 __FUNCTION__ , argc , argv[0], argv[1] );
     1298printf("\n[ksh] in %s : argc = %d / type = %s", __FUNCTION__ , argc , argv[0] );
    12131299#endif
    12141300
     
    12451331        unsigned int   state;                   // escape sequence state
    12461332
    1247         char           cmd[CMD_MAX_SIZE];               // buffer for one command
    12481333
    12491334/*  direct command to help debug
    12501335
    1251     int pid = getpid();
    1252 
    1253     if( pid == 3 )
     1336    if( getpid() == 2 )
    12541337    {
    12551338        if( sem_wait( &semaphore ) )
     
    12601343        else
    12611344        {
    1262             strcpy( cmd , "load bin/user/tcp_server.elf" );
     1345            strcpy( cmd , "load bin/user/chat.elf 0" );
    12631346            printf("[ksh] %s\n", cmd );
    12641347            execute( cmd );
    12651348        }
    12661349    }
    1267     else if( getpid() == 4 )
     1350
     1351    else if( getpid() == 3 )
    12681352    {
    12691353        if( sem_wait( &semaphore ) )
     
    12741358        else
    12751359        {
    1276             strcpy( cmd , "load bin/user/tcp_client.elf" );
     1360            strcpy( cmd , "load bin/user/chat.elf 1" );
    12771361            printf("[ksh] %s\n", cmd );
    12781362            execute( cmd );
     
    12811365
    12821366*/
    1283 
    12841367
    12851368        enum fsm_states
     
    13181401            state       = NORMAL;
    13191402        end_command = 0;
    1320 
    1321 #if DEBUG_INTER
    1322 snprintf( string , 128 , "[ksh] %s : request a new command", __FUNCTION__ );
    1323 display_string( string );
    1324 #endif
    13251403
    13261404        // internal loop on characters in one command
     
    13491427                                            cmd[count] = 0;
    13501428                        count++;
    1351 #if DEBUG_INTER
    1352 snprintf( string , 128 , "[ksh] %s : get command <%s>", __FUNCTION__, cmd );
    1353 display_string( string );
    1354 #endif
     1429
    13551430                        // register command in log_entries[] array
    13561431                                            strncpy( log_entries[ptw].buf , cmd , count );
     
    13591434                                            ptr = ptw;
    13601435
    1361 #if DEBUG_INTER
    1362 snprintf( string , 128 , "[ksh] %s : execute <%s>", __FUNCTION__, cmd );
    1363 display_string( string );
    1364 #endif
    13651436                        // echo character
    13661437                        putchar( c );
     
    14791550                }  // end internal while loop on characters
    14801551
    1481 #if DEBUG_INTER
    1482 snprintf( string , 128 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd );
    1483 display_string( string );
    1484 #endif
    1485 
    14861552        // block interactive thread if KSH loose TXT ownership
    14871553        if ( sem_wait( &semaphore ) )
     
    15181584
    15191585#if DEBUG_MAIN
    1520 snprintf( string , 128 , "\n[ksh] main thread started on core[%x,%d]", cxy , lid );
    1521 display_string( string );
     1586printf("\n[ksh] main started on core[%x,%d]", cxy , lid );
    15221587#endif
    15231588   
     
    15301595
    15311596#if DEBUG_MAIN
    1532 snprintf( string , 128 , "\n[ksh] main initialized semaphore" );
    1533 display_string( string );
     1597printf("\n[ksh] main initialized semaphore" );
    15341598#endif
    15351599   
     
    15441608                    NULL );
    15451609#if DEBUG_MAIN
    1546 snprintf( string , 128 , "\n[ksh] main thread launched interactive thread %x", trdid );
    1547 display_string( string );
     1610printf("\n[ksh] main thread launched interactive thread %x", trdid );
    15481611#endif
    15491612
Note: See TracChangeset for help on using the changeset viewer.