Changeset 682 for trunk/user/ksh
- Timestamp:
- Jan 3, 2021, 11:32:52 PM (4 years ago)
- Location:
- trunk/user/ksh
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/ksh.c
r676 r682 52 52 #include <shared_syscalls.h> 53 53 54 #define BUF_MAX_SIZE (4096) // max number of bytes for k <-> u data transfer 54 55 #define CMD_MAX_SIZE (256) // max number of characters in one command 55 56 #define LOG_DEPTH (32) // max number of registered commands … … 760 761 unsigned int background; // background execution if non zero 761 762 unsigned int place; // user placement if non zero 762 char * arg[5]; // array of pointers on main threadarguments763 unsigned int args_nr; // number of ar uments in this array764 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; 766 767 767 768 // arguments analysis of argv[] array that contains at most 8 strings: 768 // - the two first arguments ("cmd_ type" & "elf_path") are mandatory769 // - the two first arguments ("cmd_load" & "elf_path") are mandatory 769 770 // - the six next ("-pcxy","arg0","arg1","arg2","arg3","&") are optional 770 771 … … 775 776 background = 0; 776 777 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; 781 782 args_nr = 0; 782 783 } … … 788 789 background = 1; 789 790 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; 794 795 args_nr = argc - 4; 795 796 } … … 801 802 background = 0; 802 803 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; 807 808 args_nr = argc - 3; 808 809 } … … 814 815 background = 1; 815 816 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; 820 821 args_nr = argc - 3; 821 822 } … … 825 826 background = 0; 826 827 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; 831 832 args_nr = argc - 2; 832 833 } … … 836 837 background = 0; 837 838 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; 842 843 args_nr = 0; 843 844 } … … 858 859 859 860 #if DEBUG_CMD_LOAD 861 if( place ) 860 862 printf("\n[ksh] %s : path <%s> / place %x / args_nr %d / bg %d\n" 861 863 " 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 866 else 867 printf("\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 871 871 872 872 // set target cluster if required … … 899 899 if( ret_exec ) 900 900 { 901 printf(" error: child process unable to exec <%s>\n", pathname);901 printf(" error: child process unable to exec <%s>\n", elf_path ); 902 902 exit( 0 ); 903 903 } … … 952 952 953 953 #if DEBUG_CMD_LS 954 printf("\n[ksh] %s : directory <%s> open / DIR %x ", __FUNCTION__, pathname , dir );954 printf("\n[ksh] %s : directory <%s> open / DIR %x\n", __FUNCTION__, pathname , dir ); 955 955 #endif 956 956 … … 1034 1034 unsigned int x; 1035 1035 unsigned int y; 1036 unsigned int error; 1037 1038 char u_buf[BUF_MAX_SIZE]; 1036 1039 1037 1040 #if DEBUG_CMD_PS … … 1056 1059 for( y = 0 ; y < y_size ; y++ ) 1057 1060 { 1061 int cxy = HAL_CXY_FROM_XY(x,y); 1058 1062 1059 1063 #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 ); 1064 printf("\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 ); 1065 1079 } 1066 1080 } … … 1299 1313 #endif 1300 1314 1301 // scan the list of commands to match typed command1315 // scan the list of commands to match cmd_type (contained in argv[0] 1302 1316 int found = 0; 1303 1317 for ( i = 0 ; (command[i].name != NULL) && (found == 0) ; i++ ) … … 1313 1327 if (!found) 1314 1328 { 1315 printf(" error : undefined command <%s>\n", argv[0]);1329 printf(" error : undefined command type <%s>\n", argv[0]); 1316 1330 1317 1331 // release semaphore to get next command … … 1332 1346 1333 1347 1334 / *direct command to help debug1335 1336 if( getpid() == 2 )1348 // direct command to help debug 1349 1350 if( getpid() == 0x2) 1337 1351 { 1338 1352 if( sem_wait( &semaphore ) ) … … 1343 1357 else 1344 1358 { 1345 strcpy( cmd , "load bin/user/chat.elf 0" );1359 strcpy( cmd , "load bin/user/tcp_chat.elf 1 0xbbbbbbbb 0xaaaaaaaa 0xcc" ); 1346 1360 printf("[ksh] %s\n", cmd ); 1347 1361 execute( cmd ); … … 1349 1363 } 1350 1364 1351 else if( getpid() ==3 )1365 if( getpid() == 0x3 ) 1352 1366 { 1353 1367 if( sem_wait( &semaphore ) ) … … 1358 1372 else 1359 1373 { 1360 strcpy( cmd , "load bin/user/ chat.elf 1" );1374 strcpy( cmd , "load bin/user/tcp_chat.elf 0 0xaaaaaaaa 0xbbbbbbbb 0xcc" ); 1361 1375 printf("[ksh] %s\n", cmd ); 1362 1376 execute( cmd ); … … 1364 1378 } 1365 1379 1366 */1380 // 1367 1381 1368 1382 enum fsm_states … … 1611 1625 #endif 1612 1626 1613 // signal INIT process 1614 kill( 1 , SIGCONT ); 1615 1616 // enter infinite loop monitoring children processes termination 1627 // enter infinite loop monitoring children termination 1617 1628 while( 1 ) 1618 1629 {
Note: See TracChangeset
for help on using the changeset viewer.