Changeset 623 for trunk/user/ksh
- Timestamp:
- Mar 6, 2019, 4:37:15 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/ksh.c
r619 r623 58 58 #define DEBUG_INTER 0 59 59 #define DEBUG_PARSE 0 60 #define DEBUG_CMD_CAT 060 #define DEBUG_CMD_CAT 1 61 61 #define DEBUG_CMD_CP 0 62 62 #define DEBUG_CMD_LOAD 0 … … 122 122 if (argc != 2) 123 123 { 124 fd = -1;125 buf = NULL;126 size = 0;127 124 printf(" usage: cat pathname\n"); 128 goto cmd_cat_exit; 125 126 sem_post( &semaphore ); 127 return; 129 128 } 130 129 … … 135 134 if (fd < 0) 136 135 { 137 buf = NULL;138 size = 0;139 136 printf(" error: cannot open file <%s>\n", path); 140 goto cmd_cat_exit; 137 138 sem_post( &semaphore ); 139 return; 141 140 } 142 141 143 142 #if DEBUG_CMD_CAT 144 snprintf( string , 64 , "[ KSH] %s : file %s open", __FUNCTION__, path );143 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, path ); 145 144 display_string( string ); 146 145 #endif … … 149 148 if ( stat( path , &st ) == -1) 150 149 { 151 buf = NULL;152 size = 0;153 150 printf(" error: cannot stat <%s>\n", path); 154 goto cmd_cat_exit; 151 152 close(fd); 153 sem_post( &semaphore ); 154 return; 155 155 } 156 156 157 157 if ( S_ISDIR(st.st_mode) ) 158 158 { 159 buf = NULL;160 size = 0;161 159 printf(" error: <%s> is a directory\n", path); 162 goto cmd_cat_exit; 160 161 close(fd); 162 sem_post( &semaphore ); 163 return; 163 164 } 164 165 … … 167 168 168 169 #if DEBUG_CMD_CAT 169 snprintf( string , 64 , "[KSH] %s : get size = %d", __FUNCTION__, size ); 170 display_string( string ); 171 #endif 172 173 // MAP_FILE is default type when MAP_ANON and MAP_REMOTE are not specified 170 snprintf( string , 64 , "[ksh] %s : size = %d", __FUNCTION__, size ); 171 display_string( string ); 172 #endif 173 174 if( size == 0 ) 175 { 176 printf(" error: size = 0 for <%s>\n", path); 177 178 close(fd); 179 sem_post( &semaphore ); 180 return; 181 } 182 183 // mapping type is MAP_FILE when MAP_ANON and MAP_REMOTE are not specified 174 184 buf = mmap( NULL , size , PROT_READ|PROT_WRITE , MAP_PRIVATE , fd , 0 ); 175 185 … … 177 187 { 178 188 printf(" error: cannot map file <%s>\n", path ); 179 goto cmd_cat_exit; 189 190 close(fd); 191 sem_post( &semaphore ); 192 return; 180 193 } 181 194 182 195 #if DEBUG_CMD_CAT 183 snprintf( string , 64 , "[KSH] %s : map file %d to buffer %x", __FUNCTION__, fd , buf ); 184 display_string( string ); 185 display_vmm( 0 , getpid() ); 196 snprintf( string , 64 , "[ksh] %s : maped file %d to buffer %x", __FUNCTION__, fd , buf ); 197 display_string( string ); 198 // unsigned int pid = getpid(); 199 // unsigned int cxy = pid >> 16; 200 // display_vmm( cxy , pid ); 186 201 #endif 187 202 … … 189 204 write( 1 , buf , size ); 190 205 191 // release semaphore to get next command 192 sem_post( &semaphore ); 193 194 return; 195 196 cmd_cat_exit: 197 198 if (buf != NULL) munmap(buf, size); 199 if (fd >= 0) close(fd); 206 // unmap te file 207 if( munmap( buf , size ) ) 208 { 209 printf(" error: cannot unmap file <%s>\n", path ); 210 } 211 212 #if DEBUG_CMD_CAT 213 snprintf( string , 64 , "[ksh] %s : unmaped file %d from buffer %x", __FUNCTION__, fd , buf ); 214 display_string( string ); 215 // display_vmm( cxy , pid ); 216 #endif 217 218 // close the file 219 if( close( fd ) ) 220 { 221 printf(" error: cannot close file <%s>\n", path ); 222 } 200 223 201 224 // release semaphore to get next command … … 267 290 268 291 #if DEBUG_CMD_CP 269 snprintf( string , 64 , "[ KSH] %s : file %s open", __FUNCTION__, srcpath );292 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, srcpath ); 270 293 display_string( string ); 271 294 #endif … … 280 303 281 304 #if DEBUG_CMD_CP 282 snprintf( string , 64 , "[ KSH] %s : got stats for %s", __FUNCTION__, srcpath );305 snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, srcpath ); 283 306 display_string( string ); 284 307 #endif … … 304 327 305 328 #if DEBUG_CMD_CP 306 snprintf( string , 64 , "[ KSH] %s : file %s open", __FUNCTION__, dstpath );329 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, dstpath ); 307 330 display_string( string ); 308 331 #endif … … 315 338 316 339 #if DEBUG_CMD_CP 317 snprintf( string , 64 , "[ KSH] %s : got stats for %s", __FUNCTION__, dstpath );340 snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, dstpath ); 318 341 display_string( string ); 319 342 #endif … … 339 362 340 363 #if DEBUG_CMD_CP 341 snprintf( string , 64 , "[ KSH] %s : read %d bytes from %s", __FUNCTION__, len, srcpath );364 snprintf( string , 64 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, srcpath ); 342 365 display_string( string ); 343 366 #endif … … 351 374 352 375 #if DEBUG_CMD_CP 353 snprintf( string , 64 , "[ KSH] %s : write %d bytes to %s", __FUNCTION__, len, dstpath );376 snprintf( string , 64 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, dstpath ); 354 377 display_string( string ); 355 378 #endif … … 381 404 " display dqdt\n" 382 405 " display locks pid trdid\n" 406 " display barrier pid\n" 383 407 " display mapper path page_id nbytes\n"); 384 408 } … … 504 528 { 505 529 printf(" error: illegal arguments pid = %x / trdid = %x\n", pid, trdid ); 530 } 531 } 532 } 533 ///////////////////////////////////////////////// 534 else if( strcmp( argv[1] , "barrier" ) == 0 ) 535 { 536 if( argc != 3 ) 537 { 538 printf(" usage: display barrier pid\n"); 539 } 540 else 541 { 542 unsigned int pid = atoi(argv[2]); 543 544 if( display_barrier( pid ) ) 545 { 546 printf(" error: illegal arguments pid = %x\n", pid ); 506 547 } 507 548 } … … 678 719 679 720 #if DEBUG_CMD_LOAD 680 snprintf( string , 64 , "[ KSH] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n",721 snprintf( string , 64 , "[ksh] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n", 681 722 __FUNCTION__, ksh_pid, argv[1], background, placement, cxy ); 682 723 display_string( string ); … … 697 738 698 739 #if DEBUG_CMD_LOAD 699 snprintf( string , 64 , "[ KSH] %s : child_pid %x after fork, before exec\n",740 snprintf( string , 64 , "[ksh] %s : child_pid %x after fork, before exec\n", 700 741 __FUNCTION__ , getpid() ); 701 742 display_string( string ); … … 706 747 707 748 #if DEBUG_CMD_LOAD 708 snprintf( string , 64 , "[ KSH] %s : child_pid %x after exec / ret_exec %x\n",749 snprintf( string , 64 , "[ksh] %s : child_pid %x after exec / ret_exec %x\n", 709 750 __FUNCTION__ , getpid(), ret_exec ); 710 751 display_string( string ); … … 722 763 723 764 #if DEBUG_CMD_LOAD 724 snprintf( string , 64 , "[ KSH] %s : ksh_pid %x after fork / ret_fork %x\n",765 snprintf( string , 64 , "[ksh] %s : ksh_pid %x after fork / ret_fork %x\n", 725 766 __FUNCTION__, getpid(), ret_fork ); 726 767 display_string( string ); … … 795 836 796 837 #if DEBUG_CMD_LS 797 snprintf( string , 64 , "[ KSH] %s : directory <%s> open / DIR %x\n",838 snprintf( string , 64 , "[ksh] %s : directory <%s> open / DIR %x\n", 798 839 __FUNCTION__, pathname , dir ); 799 840 display_string( string ); … … 803 844 { 804 845 printf(" error : directory <%s> not found\n", pathname ); 805 goto cmd_ls_exit; 846 847 sem_post( &semaphore ); 848 return; 806 849 } 807 850 … … 816 859 817 860 #if DEBUG_CMD_LS 818 snprintf( string , 64 , "[ KSH] %s : directory <%s> closed\n",861 snprintf( string , 64 , "[ksh] %s : directory <%s> closed\n", 819 862 __FUNCTION__, pathname ); 820 863 display_string( string ); … … 822 865 823 866 } 824 825 cmd_ls_exit:826 867 827 868 // release semaphore to get next command … … 908 949 909 950 #if DEBUG_CMD_PS 910 snprintf( string , 64 , "\n[ KSH] %s : call display_cluster_process()", __FUNCTION__ );951 snprintf( string , 64 , "\n[ksh] %s : call display_cluster_process()", __FUNCTION__ ); 911 952 display_string( string ); 912 953 #endif … … 1071 1112 #if DEBUG_PARSE 1072 1113 char string[64]; 1073 snprintf( string , 64 , "\n[ KSH] %s : <%s>", __FUNCTION__ , buf );1114 snprintf( string , 64 , "\n[ksh] %s : <%s>", __FUNCTION__ , buf ); 1074 1115 display_string( string ); 1075 1116 #endif … … 1094 1135 1095 1136 #if DEBUG_PARSE 1096 snprintf( string , 64 , "\n[ KSH] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] );1137 snprintf( string , 64 , "\n[ksh] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] ); 1097 1138 display_string( string ); 1098 1139 #endif … … 1193 1234 #if DEBUG_INTER 1194 1235 unsigned int pid = getpid(); 1195 snprintf( string , 64 , "\n[ KSH] %s : request a new command", __FUNCTION__ );1236 snprintf( string , 64 , "\n[ksh] %s : request a new command", __FUNCTION__ ); 1196 1237 display_string( string ); 1197 1238 #endif … … 1230 1271 1231 1272 #if DEBUG_INTER 1232 snprintf( string , 64 , "[ KSH] %s : parse and execute <%s>", __FUNCTION__, cmd );1273 snprintf( string , 64 , "[ksh] %s : parse and execute <%s>", __FUNCTION__, cmd ); 1233 1274 display_string( string ); 1234 1275 #endif … … 1350 1391 1351 1392 #if DEBUG_INTER 1352 snprintf( string , 64 , "\n[ KSH] %s : complete <%s> command", __FUNCTION__, cmd );1393 snprintf( string , 64 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd ); 1353 1394 display_string( string ); 1354 1395 #endif
Note: See TracChangeset
for help on using the changeset viewer.