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


Ignore:
Timestamp:
Jan 3, 2021, 11:32:52 PM (3 years ago)
Author:
alain
Message:

Introduce three new applications:

  • windows : to test the FBF windows kernel manager
  • udp_chat : chat application based on UDP sockets.
  • tcp_chat : chat application based on TCP sockets (including packet loss recovery).
File:
1 edited

Legend:

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

    r676 r682  
    5252#include <shared_syscalls.h>
    5353
     54#define BUF_MAX_SIZE       (4096)   // max number of bytes for k <-> u data transfer
    5455#define CMD_MAX_SIZE       (256)    // max number of characters in one command
    5556#define LOG_DEPTH          (32)     // max number of registered commands
     
    760761    unsigned int         background;         // background execution if non zero
    761762    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" };
     763    char               * arg[5];             // array of pointers on process arguments
     764    unsigned int         args_nr;            // number of arguments in this array
     765
     766    arg[4] = NULL;
    766767
    767768    // arguments analysis of argv[] array that contains at most 8 strings:
    768     // - the two first arguments ("cmd_type" & "elf_path") are mandatory
     769    // - the two first arguments ("cmd_load" & "elf_path") are mandatory
    769770    // - the six next ("-pcxy","arg0","arg1","arg2","arg3","&") are optional
    770771
     
    775776        background = 0;
    776777        place      = 0;
    777         arg[0]     = undef;
    778         arg[1]     = undef;
    779         arg[2]     = undef;
    780         arg[3]     = undef;
     778        arg[0]     = NULL;
     779        arg[1]     = NULL;
     780        arg[2]     = NULL;
     781        arg[3]     = NULL;
    781782        args_nr    = 0;
    782783    }
     
    788789        background = 1;
    789790        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;
     791        arg[0]     = (argc > 4) ? argv[3] : NULL;
     792        arg[1]     = (argc > 5) ? argv[4] : NULL;
     793        arg[2]     = (argc > 6) ? argv[5] : NULL;
     794        arg[3]     = (argc > 7) ? argv[6] : NULL;
    794795        args_nr    = argc - 4;
    795796    }
     
    801802        background = 0;
    802803        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;
     804        arg[0]     = (argc > 3) ? argv[3] : NULL;
     805        arg[1]     = (argc > 4) ? argv[4] : NULL;
     806        arg[2]     = (argc > 5) ? argv[5] : NULL;
     807        arg[3]     = (argc > 6) ? argv[6] : NULL;
    807808        args_nr    = argc - 3;
    808809    }
     
    814815        background = 1;
    815816        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;
     817        arg[0]     = (argc > 3) ? argv[2] : NULL;
     818        arg[1]     = (argc > 4) ? argv[3] : NULL;
     819        arg[2]     = (argc > 5) ? argv[4] : NULL;
     820        arg[3]     = (argc > 6) ? argv[5] : NULL;
    820821        args_nr    = argc - 3;
    821822    }
     
    825826        background = 0;
    826827        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;
     828        arg[0]     = (argc > 2) ? argv[2] : NULL;
     829        arg[1]     = (argc > 3) ? argv[3] : NULL;
     830        arg[2]     = (argc > 4) ? argv[4] : NULL;
     831        arg[3]     = (argc > 5) ? argv[5] : NULL;
    831832        args_nr    = argc - 2;
    832833    }
     
    836837        background = 0;
    837838        place      = 0;
    838         arg[0]     = undef;
    839         arg[1]     = undef;
    840         arg[2]     = undef;
    841         arg[3]     = undef;
     839        arg[0]     = NULL;
     840        arg[1]     = NULL;
     841        arg[2]     = NULL;
     842        arg[3]     = NULL;
    842843        args_nr    = 0;
    843844    }
     
    858859
    859860#if DEBUG_CMD_LOAD
     861if( place )
    860862printf("\n[ksh] %s : path <%s> / place %x / args_nr %d / bg %d\n"
    861863"                 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;
     864__FUNCTION__, elf_path, place & 0xFFFF, args_nr, background, arg[0], arg[1], arg[2], arg[3] );
     865
     866else
     867printf("\n[ksh] %s : path <%s> / args_nr %d / bg %d\n"
     868"                 arg0 %s / arg1 %s / arg2 %s / arg3 %s\n",
     869__FUNCTION__, elf_path, args_nr, background, arg[0], arg[1], arg[2], arg[3] );
     870#endif
    871871
    872872    // set target cluster if required
     
    899899        if( ret_exec )
    900900        {
    901             printf("  error: child process unable to exec <%s>\n", pathname );
     901            printf("  error: child process unable to exec <%s>\n", elf_path );
    902902            exit( 0 );
    903903        }   
     
    952952
    953953#if DEBUG_CMD_LS
    954 printf("\n[ksh] %s : directory <%s> open / DIR %x", __FUNCTION__, pathname , dir );
     954printf("\n[ksh] %s : directory <%s> open / DIR %x\n", __FUNCTION__, pathname , dir );
    955955#endif
    956956
     
    10341034    unsigned int x;
    10351035    unsigned int y;
     1036    unsigned int error;
     1037
     1038    char         u_buf[BUF_MAX_SIZE];
    10361039
    10371040#if DEBUG_CMD_PS
     
    10561059            for( y = 0 ; y < y_size ; y++ )
    10571060            {
     1061                int cxy = HAL_CXY_FROM_XY(x,y);
    10581062
    10591063#if DEBUG_CMD_PS
    1060 printf("\n[ksh] %s : call display_cluster_process()", __FUNCTION__ );
    1061 #endif
    1062 
    1063                 // display only owned processes
    1064                 display_cluster_processes( HAL_CXY_FROM_XY(x,y), 1 );
     1064printf("\n[ksh] %s : call get_processes() in cluster %x", __FUNCTION__ , cxy );
     1065#endif
     1066                // write all owned processes in cxy to u_buf buffer
     1067                // one single NUL terminated string / one line per process)
     1068                error = get_processes( cxy,
     1069                                       1,                      // owned only
     1070                                       u_buf,
     1071                                       BUF_MAX_SIZE );
     1072                if( error )
     1073                {
     1074                   printf(" ... too much processes in cluster %x\n", cxy );
     1075                }
     1076
     1077                // display processes owned by cluster cxy
     1078                printf("%s" , u_buf );
    10651079            }
    10661080        }
     
    12991313#endif
    13001314
    1301     // scan the list of commands to match typed command
     1315    // scan the list of commands to match cmd_type (contained in argv[0]
    13021316    int found = 0;
    13031317    for ( i = 0 ; (command[i].name != NULL) && (found == 0) ; i++ )
     
    13131327        if (!found)
    13141328    {   
    1315         printf("  error : undefined command <%s>\n", argv[0]);
     1329        printf("  error : undefined command type <%s>\n", argv[0]);
    13161330
    13171331        // release semaphore to get next command
     
    13321346
    13331347
    1334 /*  direct command to help debug
    1335 
    1336     if( getpid() == 2 )
     1348//  direct command to help debug
     1349
     1350    if( getpid() == 0x2)
    13371351    {
    13381352        if( sem_wait( &semaphore ) )
     
    13431357        else
    13441358        {
    1345             strcpy( cmd , "load bin/user/chat.elf 0" );
     1359           strcpy( cmd , "load bin/user/tcp_chat.elf 1 0xbbbbbbbb 0xaaaaaaaa 0xcc" );
    13461360            printf("[ksh] %s\n", cmd );
    13471361            execute( cmd );
     
    13491363    }
    13501364
    1351     else if( getpid() == 3 )
     1365    if( getpid() == 0x3 )
    13521366    {
    13531367        if( sem_wait( &semaphore ) )
     
    13581372        else
    13591373        {
    1360             strcpy( cmd , "load bin/user/chat.elf 1" );
     1374            strcpy( cmd , "load bin/user/tcp_chat.elf 0 0xaaaaaaaa 0xbbbbbbbb 0xcc" );
    13611375            printf("[ksh] %s\n", cmd );
    13621376            execute( cmd );
     
    13641378    }
    13651379
    1366 */
     1380//
    13671381
    13681382        enum fsm_states
     
    16111625#endif
    16121626
    1613     // signal INIT process
    1614     kill( 1 , SIGCONT );
    1615    
    1616     // enter infinite loop monitoring children processes termination
     1627    // enter infinite loop monitoring children  termination
    16171628    while( 1 )
    16181629    {
Note: See TracChangeset for help on using the changeset viewer.