[469] | 1 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 2 | // File : ksh.c |
---|
| 3 | // Date : October 2017 |
---|
| 4 | // Author : Alain Greiner |
---|
[469] | 5 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[457] | 6 | // This application implements a minimal shell for ALMOS-MKH. |
---|
| 7 | // |
---|
| 8 | // This user KSH process contains two POSIX threads: |
---|
[446] | 9 | // - the "main" thread contains the infinite loop implementing |
---|
[574] | 10 | // the children processes termination monitoring, using the wait() syscall. |
---|
[469] | 11 | // - the "interactive" thread contains the infinite loop implementing the command |
---|
| 12 | // interpreter attached to the TXT terminal, and handling one KSH command |
---|
| 13 | // per iteration. |
---|
[457] | 14 | // |
---|
[469] | 15 | // The children processes are created by the <load> command, and are |
---|
[624] | 16 | // attached to the same TXT terminal as the parent KSH process. |
---|
[626] | 17 | // A child process can be launched in foreground or in background: |
---|
[624] | 18 | // . when the child process is launched in foreground, the KSH process loses |
---|
[469] | 19 | // the TXT terminal ownership, that is transfered to the child process. |
---|
[624] | 20 | // . when the child process is launched in background, the KSH process keeps |
---|
[469] | 21 | // the TXT terminal ownership. |
---|
| 22 | // |
---|
[619] | 23 | // We use a semaphore to synchronize the two KSH threads. After each command |
---|
| 24 | // completion, the interactive thread check the TXT ownership (with a sem_wait), |
---|
| 25 | // and blocks, if the KSH process loosed the TXT ownership (after a load, |
---|
| 26 | // or for any other cause). It is unblocked with the following policy: |
---|
[469] | 27 | // . if the command is "not a load", the semaphore is incremented by the |
---|
[619] | 28 | // cmd_***() function when the command is completed, to get the next command |
---|
| 29 | // in the while loop. |
---|
[469] | 30 | // . if the command is a "load without &", the TXT is given to the NEW process by the |
---|
| 31 | // execve() syscall, and is released to the KSH process when NEW process terminates. |
---|
| 32 | // The KSH process is notified and the KSH main() function increments the semahore |
---|
| 33 | // to allow the KSH interactive() function to handle commands. |
---|
| 34 | // . if the command is a "load with &", the cmd_load() function returns the TXT |
---|
| 35 | // to the KSH process and increment the semaphore, when the parent KSH process |
---|
| 36 | // returns from the fork() syscall. |
---|
| 37 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 38 | |
---|
| 39 | #include <stdio.h> |
---|
| 40 | #include <stdlib.h> |
---|
| 41 | #include <string.h> |
---|
[444] | 42 | #include <sys/wait.h> |
---|
| 43 | #include <signal.h> |
---|
| 44 | #include <unistd.h> |
---|
[611] | 45 | #include <dirent.h> |
---|
[445] | 46 | #include <almosmkh.h> |
---|
[457] | 47 | #include <semaphore.h> |
---|
[588] | 48 | #include <hal_macros.h> |
---|
[596] | 49 | #include <sys/stat.h> |
---|
| 50 | #include <sys/mman.h> |
---|
| 51 | #include <fcntl.h> |
---|
[230] | 52 | |
---|
[407] | 53 | #define CMD_MAX_SIZE (256) // max number of characters in one command |
---|
[436] | 54 | #define LOG_DEPTH (32) // max number of registered commands |
---|
[407] | 55 | #define MAX_ARGS (32) // max number of arguments in a command |
---|
[625] | 56 | #define PATH_MAX_SIZE (256) // max number of characters in a pathname |
---|
[230] | 57 | |
---|
[611] | 58 | #define DEBUG_MAIN 0 |
---|
[619] | 59 | #define DEBUG_INTER 0 |
---|
[625] | 60 | #define DEBUG_EXECUTE 0 |
---|
[624] | 61 | #define DEBUG_CMD_CAT 0 |
---|
[611] | 62 | #define DEBUG_CMD_CP 0 |
---|
| 63 | #define DEBUG_CMD_LOAD 0 |
---|
| 64 | #define DEBUG_CMD_LS 0 |
---|
[619] | 65 | #define DEBUG_CMD_PS 0 |
---|
[457] | 66 | |
---|
[469] | 67 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 68 | // Structures |
---|
[469] | 69 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 70 | |
---|
[407] | 71 | // one entry in the registered commands array |
---|
| 72 | typedef struct log_entry_s |
---|
| 73 | { |
---|
| 74 | char buf[CMD_MAX_SIZE]; |
---|
| 75 | unsigned int count; |
---|
| 76 | } |
---|
| 77 | log_entry_t; |
---|
[230] | 78 | |
---|
[407] | 79 | // one entry in the supported command types array |
---|
| 80 | typedef struct ksh_cmd_s |
---|
| 81 | { |
---|
| 82 | char * name; |
---|
| 83 | char * desc; |
---|
| 84 | void (*fn)( int , char ** ); |
---|
| 85 | } |
---|
| 86 | ksh_cmd_t; |
---|
| 87 | |
---|
| 88 | |
---|
[469] | 89 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 90 | // Global Variables |
---|
[469] | 91 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 92 | |
---|
[625] | 93 | ksh_cmd_t command[]; // array of supported commands |
---|
[230] | 94 | |
---|
[625] | 95 | log_entry_t log_entries[LOG_DEPTH]; // array of registered commands |
---|
[230] | 96 | |
---|
[625] | 97 | unsigned int ptw; // write pointer in log_entries[] |
---|
| 98 | unsigned int ptr; // read pointer in log_entries[] |
---|
[230] | 99 | |
---|
[625] | 100 | pthread_attr_t attr; // interactive thread attributes |
---|
[446] | 101 | |
---|
[625] | 102 | sem_t semaphore; // block interactive thread when zero |
---|
[457] | 103 | |
---|
[625] | 104 | pthread_t trdid; // interactive thread identifier |
---|
| 105 | |
---|
| 106 | char pathname[PATH_MAX_SIZE]; // pathname for a file |
---|
| 107 | |
---|
| 108 | char pathnew[PATH_MAX_SIZE]; // used by the rename command |
---|
[619] | 109 | |
---|
[469] | 110 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 111 | // Shell Commands |
---|
[469] | 112 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 113 | |
---|
[407] | 114 | ///////////////////////////////////////////// |
---|
| 115 | static void cmd_cat( int argc , char **argv ) |
---|
[230] | 116 | { |
---|
[611] | 117 | struct stat st; |
---|
[596] | 118 | int fd; |
---|
| 119 | int size; |
---|
| 120 | char * buf; |
---|
[230] | 121 | |
---|
[619] | 122 | #if DEBUG_CMD_CAT |
---|
| 123 | char string[64]; |
---|
| 124 | #endif |
---|
| 125 | |
---|
[407] | 126 | if (argc != 2) |
---|
| 127 | { |
---|
[409] | 128 | printf(" usage: cat pathname\n"); |
---|
[623] | 129 | |
---|
| 130 | sem_post( &semaphore ); |
---|
| 131 | return; |
---|
[596] | 132 | } |
---|
[407] | 133 | |
---|
[625] | 134 | strcpy( pathname , argv[1] ); |
---|
[230] | 135 | |
---|
[596] | 136 | // open the file |
---|
[625] | 137 | fd = open( pathname , O_RDONLY , 0 ); |
---|
[596] | 138 | if (fd < 0) |
---|
| 139 | { |
---|
[625] | 140 | printf(" error: cannot open file <%s>\n", pathname ); |
---|
[623] | 141 | |
---|
| 142 | sem_post( &semaphore ); |
---|
| 143 | return; |
---|
[596] | 144 | } |
---|
[407] | 145 | |
---|
[611] | 146 | #if DEBUG_CMD_CAT |
---|
[625] | 147 | snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, pathname ); |
---|
[619] | 148 | display_string( string ); |
---|
[596] | 149 | #endif |
---|
| 150 | |
---|
| 151 | // get file stats |
---|
[625] | 152 | if ( stat( pathname , &st ) == -1) |
---|
[407] | 153 | { |
---|
[625] | 154 | printf(" error: cannot stat <%s>\n", pathname ); |
---|
[623] | 155 | |
---|
| 156 | close(fd); |
---|
| 157 | sem_post( &semaphore ); |
---|
| 158 | return; |
---|
[596] | 159 | } |
---|
[230] | 160 | |
---|
[596] | 161 | if ( S_ISDIR(st.st_mode) ) |
---|
[407] | 162 | { |
---|
[625] | 163 | printf(" error: <%s> is a directory\n", pathname ); |
---|
[623] | 164 | |
---|
| 165 | close(fd); |
---|
| 166 | sem_post( &semaphore ); |
---|
| 167 | return; |
---|
[596] | 168 | } |
---|
[230] | 169 | |
---|
[596] | 170 | // get file size |
---|
| 171 | size = st.st_size; |
---|
[230] | 172 | |
---|
[611] | 173 | #if DEBUG_CMD_CAT |
---|
[623] | 174 | snprintf( string , 64 , "[ksh] %s : size = %d", __FUNCTION__, size ); |
---|
[619] | 175 | display_string( string ); |
---|
[596] | 176 | #endif |
---|
[230] | 177 | |
---|
[623] | 178 | if( size == 0 ) |
---|
| 179 | { |
---|
[625] | 180 | printf(" error: size = 0 for <%s>\n", pathname ); |
---|
[623] | 181 | |
---|
| 182 | close(fd); |
---|
| 183 | sem_post( &semaphore ); |
---|
| 184 | return; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | // mapping type is MAP_FILE when MAP_ANON and MAP_REMOTE are not specified |
---|
[596] | 188 | buf = mmap( NULL , size , PROT_READ|PROT_WRITE , MAP_PRIVATE , fd , 0 ); |
---|
[230] | 189 | |
---|
[596] | 190 | if ( buf == NULL ) |
---|
| 191 | { |
---|
[625] | 192 | printf(" error: cannot map file <%s>\n", pathname ); |
---|
[623] | 193 | |
---|
| 194 | close(fd); |
---|
| 195 | sem_post( &semaphore ); |
---|
| 196 | return; |
---|
[596] | 197 | } |
---|
| 198 | |
---|
[611] | 199 | #if DEBUG_CMD_CAT |
---|
[623] | 200 | snprintf( string , 64 , "[ksh] %s : maped file %d to buffer %x", __FUNCTION__, fd , buf ); |
---|
[619] | 201 | display_string( string ); |
---|
[596] | 202 | #endif |
---|
| 203 | |
---|
| 204 | // display the file content on TXT terminal |
---|
| 205 | write( 1 , buf , size ); |
---|
| 206 | |
---|
[623] | 207 | // unmap te file |
---|
| 208 | if( munmap( buf , size ) ) |
---|
| 209 | { |
---|
[625] | 210 | printf(" error: cannot unmap file <%s>\n", pathname ); |
---|
[623] | 211 | } |
---|
[596] | 212 | |
---|
[623] | 213 | #if DEBUG_CMD_CAT |
---|
| 214 | snprintf( string , 64 , "[ksh] %s : unmaped file %d from buffer %x", __FUNCTION__, fd , buf ); |
---|
| 215 | display_string( string ); |
---|
| 216 | #endif |
---|
[596] | 217 | |
---|
[623] | 218 | // close the file |
---|
| 219 | if( close( fd ) ) |
---|
| 220 | { |
---|
[625] | 221 | printf(" error: cannot close file <%s>\n", pathname ); |
---|
[623] | 222 | } |
---|
[596] | 223 | |
---|
[457] | 224 | // release semaphore to get next command |
---|
| 225 | sem_post( &semaphore ); |
---|
| 226 | |
---|
[407] | 227 | } // end cmd_cat() |
---|
| 228 | |
---|
| 229 | //////////////////////////////////////////// |
---|
| 230 | static void cmd_cd( int argc , char **argv ) |
---|
| 231 | { |
---|
| 232 | if (argc != 2) |
---|
| 233 | { |
---|
[409] | 234 | printf(" usage: cd pathname\n"); |
---|
[407] | 235 | } |
---|
[596] | 236 | else |
---|
| 237 | { |
---|
[625] | 238 | strcpy( pathname , argv[1] ); |
---|
[407] | 239 | |
---|
[610] | 240 | // call the relevant syscall |
---|
[625] | 241 | if( chdir( pathname ) ) |
---|
[610] | 242 | { |
---|
[625] | 243 | printf(" error: cannot found <%s> directory\n", pathname ); |
---|
[610] | 244 | } |
---|
[596] | 245 | } |
---|
[407] | 246 | |
---|
[457] | 247 | // release semaphore to get next command |
---|
| 248 | sem_post( &semaphore ); |
---|
[407] | 249 | |
---|
| 250 | } // end cmd_cd() |
---|
| 251 | |
---|
| 252 | ///////////////////////////////////////// |
---|
[230] | 253 | static void cmd_cp(int argc, char **argv) |
---|
| 254 | { |
---|
[611] | 255 | int src_fd; |
---|
| 256 | int dst_fd; |
---|
| 257 | int size; // source file size |
---|
| 258 | int bytes; // number of transfered bytes |
---|
| 259 | char buf[4096]; |
---|
| 260 | struct stat st; |
---|
[230] | 261 | |
---|
[619] | 262 | #if DEBUG_CMD_CP |
---|
| 263 | char string[64]; |
---|
| 264 | #endif |
---|
| 265 | |
---|
[407] | 266 | if (argc != 3) |
---|
| 267 | { |
---|
[596] | 268 | src_fd = -1; |
---|
| 269 | dst_fd = -1; |
---|
[409] | 270 | printf(" usage: cp src_pathname dst_pathname\n"); |
---|
[611] | 271 | goto cmd_cp_exit; |
---|
[230] | 272 | } |
---|
| 273 | |
---|
[596] | 274 | // open the src file |
---|
[625] | 275 | strcpy( pathname , argv[1] ); |
---|
| 276 | src_fd = open( pathname , O_RDONLY , 0 ); |
---|
[230] | 277 | |
---|
[596] | 278 | if ( src_fd < 0 ) |
---|
| 279 | { |
---|
| 280 | dst_fd = -1; |
---|
[625] | 281 | printf(" error: cannot open <%s>\n", argv[1] ); |
---|
[611] | 282 | goto cmd_cp_exit; |
---|
[596] | 283 | } |
---|
[230] | 284 | |
---|
[611] | 285 | #if DEBUG_CMD_CP |
---|
[625] | 286 | snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, argv[1] ); |
---|
[619] | 287 | display_string( string ); |
---|
[610] | 288 | #endif |
---|
| 289 | |
---|
[596] | 290 | // get file stats |
---|
[625] | 291 | if ( stat( pathname , &st ) ) |
---|
[596] | 292 | { |
---|
| 293 | dst_fd = -1; |
---|
[625] | 294 | printf(" error: cannot stat <%s>\n", argv[1] ); |
---|
[611] | 295 | goto cmd_cp_exit; |
---|
[596] | 296 | } |
---|
| 297 | |
---|
[611] | 298 | #if DEBUG_CMD_CP |
---|
[625] | 299 | snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[1] ); |
---|
[619] | 300 | display_string( string ); |
---|
[610] | 301 | #endif |
---|
| 302 | |
---|
[596] | 303 | if ( S_ISDIR(st.st_mode) ) |
---|
| 304 | { |
---|
| 305 | dst_fd = -1; |
---|
[625] | 306 | printf(" error: <%s> is a directory\n", argv[1] ); |
---|
[611] | 307 | goto cmd_cp_exit; |
---|
[230] | 308 | } |
---|
[596] | 309 | |
---|
| 310 | // get src file size |
---|
[230] | 311 | size = st.st_size; |
---|
| 312 | |
---|
[407] | 313 | // open the dst file |
---|
[625] | 314 | strcpy( pathname , argv[2] ); |
---|
| 315 | dst_fd = open( pathname , O_CREAT|O_TRUNC|O_RDWR , 0 ); |
---|
[596] | 316 | |
---|
| 317 | if ( dst_fd < 0 ) |
---|
| 318 | { |
---|
[625] | 319 | printf(" error: cannot open <%s>\n", argv[2] ); |
---|
[611] | 320 | goto cmd_cp_exit; |
---|
[230] | 321 | } |
---|
[596] | 322 | |
---|
[611] | 323 | #if DEBUG_CMD_CP |
---|
[625] | 324 | snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, argv[2] ); |
---|
[619] | 325 | display_string( string ); |
---|
[610] | 326 | #endif |
---|
| 327 | |
---|
[625] | 328 | if ( stat( pathname , &st ) ) |
---|
[596] | 329 | { |
---|
[625] | 330 | printf(" error: cannot stat <%s>\n", argv[2] ); |
---|
[611] | 331 | goto cmd_cp_exit; |
---|
[230] | 332 | } |
---|
[596] | 333 | |
---|
[611] | 334 | #if DEBUG_CMD_CP |
---|
[625] | 335 | snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[2] ); |
---|
[619] | 336 | display_string( string ); |
---|
[610] | 337 | #endif |
---|
| 338 | |
---|
[596] | 339 | if ( S_ISDIR(st.st_mode ) ) |
---|
| 340 | { |
---|
[625] | 341 | printf(" error: <%s> is a directory\n", argv[2] ); |
---|
[611] | 342 | goto cmd_cp_exit; |
---|
[230] | 343 | } |
---|
| 344 | |
---|
[596] | 345 | bytes = 0; |
---|
| 346 | |
---|
| 347 | while (bytes < size) |
---|
[230] | 348 | { |
---|
[608] | 349 | int len = ((size - bytes) < 4096) ? (size - bytes) : 4096; |
---|
[230] | 350 | |
---|
[407] | 351 | // read the source |
---|
[608] | 352 | if ( read( src_fd , buf , len ) != len ) |
---|
[596] | 353 | { |
---|
[625] | 354 | printf(" error: cannot read from file <%s>\n", argv[1] ); |
---|
[611] | 355 | goto cmd_cp_exit; |
---|
[230] | 356 | } |
---|
| 357 | |
---|
[611] | 358 | #if DEBUG_CMD_CP |
---|
[625] | 359 | snprintf( string , 64 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, argv[1] ); |
---|
[619] | 360 | display_string( string ); |
---|
[610] | 361 | #endif |
---|
| 362 | |
---|
[407] | 363 | // write to the destination |
---|
[608] | 364 | if ( write( dst_fd , buf , len ) != len ) |
---|
[596] | 365 | { |
---|
[625] | 366 | printf(" error: cannot write to file <%s>\n", argv[2] ); |
---|
[611] | 367 | goto cmd_cp_exit; |
---|
[230] | 368 | } |
---|
| 369 | |
---|
[611] | 370 | #if DEBUG_CMD_CP |
---|
[625] | 371 | snprintf( string , 64 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, argv[2] ); |
---|
[619] | 372 | display_string( string ); |
---|
[610] | 373 | #endif |
---|
| 374 | |
---|
[608] | 375 | bytes += len; |
---|
[230] | 376 | } |
---|
| 377 | |
---|
[611] | 378 | cmd_cp_exit: |
---|
[596] | 379 | |
---|
[407] | 380 | if (src_fd >= 0) close(src_fd); |
---|
| 381 | if (dst_fd >= 0) close(dst_fd); |
---|
[230] | 382 | |
---|
[457] | 383 | // release semaphore to get next command |
---|
| 384 | sem_post( &semaphore ); |
---|
| 385 | |
---|
[407] | 386 | } // end cmd_cp() |
---|
| 387 | |
---|
[436] | 388 | ///////////////////////////////////////////////// |
---|
| 389 | static void cmd_display( int argc , char **argv ) |
---|
| 390 | { |
---|
[596] | 391 | if( argc < 2 ) |
---|
[436] | 392 | { |
---|
[626] | 393 | printf(" usage: display vmm cxy pid\n" |
---|
| 394 | " display sched cxy lid\n" |
---|
[611] | 395 | " display process cxy\n" |
---|
| 396 | " display txt txtid\n" |
---|
| 397 | " display vfs\n" |
---|
| 398 | " display chdev\n" |
---|
| 399 | " display dqdt\n" |
---|
[626] | 400 | " display locks pid trdid\n" |
---|
[623] | 401 | " display barrier pid\n" |
---|
[626] | 402 | " display mapper path page nbytes\n" |
---|
| 403 | " display fat page entries\n" |
---|
| 404 | " display fat cxy 0\n"); |
---|
[596] | 405 | } |
---|
| 406 | //////////////////////////////////// |
---|
| 407 | else if( strcmp( argv[1] , "vmm" ) == 0 ) |
---|
| 408 | { |
---|
[442] | 409 | if( argc != 4 ) |
---|
[436] | 410 | { |
---|
[442] | 411 | printf(" usage: display vmm cxy pid\n"); |
---|
[436] | 412 | } |
---|
[596] | 413 | else |
---|
| 414 | { |
---|
| 415 | unsigned int cxy = atoi(argv[2]); |
---|
| 416 | unsigned int pid = atoi(argv[3]); |
---|
[436] | 417 | |
---|
[596] | 418 | if( display_vmm( cxy , pid ) ) |
---|
| 419 | { |
---|
| 420 | printf(" error: no process %x in cluster %x\n", pid , cxy ); |
---|
| 421 | } |
---|
[436] | 422 | } |
---|
| 423 | } |
---|
[596] | 424 | /////////////////////////////////////////// |
---|
[436] | 425 | else if( strcmp( argv[1] , "sched" ) == 0 ) |
---|
| 426 | { |
---|
| 427 | if( argc != 4 ) |
---|
| 428 | { |
---|
| 429 | printf(" usage: display sched cxy lid\n"); |
---|
| 430 | } |
---|
[596] | 431 | else |
---|
| 432 | { |
---|
| 433 | unsigned int cxy = atoi(argv[2]); |
---|
| 434 | unsigned int lid = atoi(argv[3]); |
---|
[436] | 435 | |
---|
[596] | 436 | if( display_sched( cxy , lid ) ) |
---|
| 437 | { |
---|
| 438 | printf(" error: illegal arguments cxy = %x / lid = %d\n", cxy, lid ); |
---|
| 439 | } |
---|
[436] | 440 | } |
---|
| 441 | } |
---|
[596] | 442 | ///////////////////////////////////////////// |
---|
[436] | 443 | else if( strcmp( argv[1] , "process" ) == 0 ) |
---|
| 444 | { |
---|
| 445 | if( argc != 3 ) |
---|
| 446 | { |
---|
| 447 | printf(" usage: display process cxy\n"); |
---|
| 448 | } |
---|
[596] | 449 | else |
---|
| 450 | { |
---|
| 451 | unsigned int cxy = atoi(argv[2]); |
---|
[436] | 452 | |
---|
[596] | 453 | if( display_cluster_processes( cxy , 0 ) ) |
---|
| 454 | { |
---|
| 455 | printf(" error: illegal argument cxy = %x\n", cxy ); |
---|
| 456 | } |
---|
[436] | 457 | } |
---|
| 458 | } |
---|
[596] | 459 | ///////////////////////////////////////// |
---|
[436] | 460 | else if( strcmp( argv[1] , "txt" ) == 0 ) |
---|
| 461 | { |
---|
| 462 | if( argc != 3 ) |
---|
| 463 | { |
---|
| 464 | printf(" usage: display txt txt_id\n"); |
---|
| 465 | } |
---|
[596] | 466 | else |
---|
| 467 | { |
---|
| 468 | unsigned int txtid = atoi(argv[2]); |
---|
[436] | 469 | |
---|
[596] | 470 | if( display_txt_processes( txtid ) ) |
---|
| 471 | { |
---|
| 472 | printf(" error: illegal argument txtid = %d\n", txtid ); |
---|
| 473 | } |
---|
[436] | 474 | } |
---|
| 475 | } |
---|
[596] | 476 | ///////////////////////////////////////// |
---|
[436] | 477 | else if( strcmp( argv[1] , "vfs" ) == 0 ) |
---|
| 478 | { |
---|
| 479 | if( argc != 2 ) |
---|
| 480 | { |
---|
| 481 | printf(" usage: display vfs\n"); |
---|
| 482 | } |
---|
[596] | 483 | else |
---|
| 484 | { |
---|
| 485 | display_vfs(); |
---|
| 486 | } |
---|
[436] | 487 | } |
---|
[596] | 488 | ////////////////////////////////////////// |
---|
[436] | 489 | else if( strcmp( argv[1] , "chdev" ) == 0 ) |
---|
| 490 | { |
---|
| 491 | if( argc != 2 ) |
---|
| 492 | { |
---|
| 493 | printf(" usage: display chdev\n"); |
---|
| 494 | } |
---|
[596] | 495 | else |
---|
| 496 | { |
---|
| 497 | display_chdev(); |
---|
| 498 | } |
---|
[436] | 499 | } |
---|
[596] | 500 | ////////////////////////////////////////// |
---|
[445] | 501 | else if( strcmp( argv[1] , "dqdt" ) == 0 ) |
---|
| 502 | { |
---|
| 503 | if( argc != 2 ) |
---|
| 504 | { |
---|
| 505 | printf(" usage: display dqdt\n"); |
---|
| 506 | } |
---|
[596] | 507 | else |
---|
| 508 | { |
---|
| 509 | display_dqdt(); |
---|
| 510 | } |
---|
| 511 | } |
---|
| 512 | /////////////////////////////////////////// |
---|
| 513 | else if( strcmp( argv[1] , "locks" ) == 0 ) |
---|
| 514 | { |
---|
| 515 | if( argc != 4 ) |
---|
| 516 | { |
---|
| 517 | printf(" usage: display locks pid trdid\n"); |
---|
| 518 | } |
---|
| 519 | else |
---|
| 520 | { |
---|
| 521 | unsigned int pid = atoi(argv[2]); |
---|
| 522 | unsigned int trdid = atoi(argv[3]); |
---|
[445] | 523 | |
---|
[596] | 524 | if( display_busylocks( pid , trdid ) ) |
---|
| 525 | { |
---|
| 526 | printf(" error: illegal arguments pid = %x / trdid = %x\n", pid, trdid ); |
---|
| 527 | } |
---|
| 528 | } |
---|
[445] | 529 | } |
---|
[623] | 530 | ///////////////////////////////////////////////// |
---|
| 531 | else if( strcmp( argv[1] , "barrier" ) == 0 ) |
---|
| 532 | { |
---|
| 533 | if( argc != 3 ) |
---|
| 534 | { |
---|
| 535 | printf(" usage: display barrier pid\n"); |
---|
| 536 | } |
---|
| 537 | else |
---|
| 538 | { |
---|
| 539 | unsigned int pid = atoi(argv[2]); |
---|
| 540 | |
---|
| 541 | if( display_barrier( pid ) ) |
---|
| 542 | { |
---|
| 543 | printf(" error: illegal arguments pid = %x\n", pid ); |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } |
---|
[611] | 547 | /////////////////////////////////////////// |
---|
| 548 | else if( strcmp( argv[1] , "mapper" ) == 0 ) |
---|
| 549 | { |
---|
| 550 | if( argc != 5 ) |
---|
| 551 | { |
---|
| 552 | printf(" usage: display mapper path page_id nbytes\n"); |
---|
| 553 | } |
---|
| 554 | else |
---|
| 555 | { |
---|
| 556 | unsigned int page_id = atoi(argv[3]); |
---|
| 557 | unsigned int nbytes = atoi(argv[4]); |
---|
| 558 | |
---|
| 559 | if( display_mapper( argv[2] , page_id, nbytes ) ) |
---|
| 560 | { |
---|
| 561 | printf(" error: cannot display page %d of mapper %s\n", page_id, argv[2] ); |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | } |
---|
[626] | 565 | /////////////////////////////////////////// |
---|
| 566 | else if( strcmp( argv[1] , "fat" ) == 0 ) |
---|
| 567 | { |
---|
| 568 | if( argc != 4 ) |
---|
| 569 | { |
---|
| 570 | printf(" usage: display fat page_id nb_entries\n"); |
---|
| 571 | } |
---|
| 572 | else |
---|
| 573 | { |
---|
| 574 | unsigned int page_id = atoi(argv[2]); |
---|
| 575 | unsigned int nb_entries = atoi(argv[3]); |
---|
| 576 | |
---|
| 577 | if( display_fat( page_id, nb_entries ) ) |
---|
| 578 | { |
---|
| 579 | printf(" error: cannot display page %d of fat\n", page_id ); |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | } |
---|
[436] | 583 | else |
---|
| 584 | { |
---|
[596] | 585 | printf(" error: undefined display request : %s\n", argv[1] ); |
---|
| 586 | } |
---|
[457] | 587 | |
---|
| 588 | // release semaphore to get next command |
---|
| 589 | sem_post( &semaphore ); |
---|
| 590 | |
---|
[436] | 591 | } // end cmd_display() |
---|
| 592 | |
---|
[427] | 593 | ///////////////////////////////////////// |
---|
| 594 | static void cmd_fg(int argc, char **argv) |
---|
| 595 | { |
---|
| 596 | unsigned int pid; |
---|
| 597 | |
---|
| 598 | if (argc != 2) |
---|
| 599 | { |
---|
| 600 | printf(" usage: %s pid\n", argv[0]); |
---|
| 601 | } |
---|
[596] | 602 | else |
---|
[427] | 603 | { |
---|
[596] | 604 | pid = atoi( argv[1] ); |
---|
[427] | 605 | |
---|
[596] | 606 | if( pid == 0 ) |
---|
| 607 | { |
---|
| 608 | printf(" error: PID cannot be 0\n" ); |
---|
| 609 | } |
---|
| 610 | else if( fg( pid ) ) |
---|
| 611 | { |
---|
| 612 | printf(" error: cannot find process %x\n", pid ); |
---|
| 613 | } |
---|
| 614 | } |
---|
[457] | 615 | |
---|
| 616 | // release semaphore to get next command |
---|
| 617 | sem_post( &semaphore ); |
---|
| 618 | |
---|
[436] | 619 | } // end cmd_fg() |
---|
[427] | 620 | |
---|
[407] | 621 | ////////////////////////////////////////////// |
---|
| 622 | static void cmd_help( int argc , char **argv ) |
---|
[230] | 623 | { |
---|
[407] | 624 | unsigned int i; |
---|
[230] | 625 | |
---|
[407] | 626 | if (argc != 1) |
---|
| 627 | { |
---|
[409] | 628 | printf(" usage: %s\n", argv[0]); |
---|
[230] | 629 | } |
---|
[596] | 630 | else |
---|
[407] | 631 | { |
---|
[619] | 632 | printf("available commands:\n"); |
---|
| 633 | for (i = 0 ; command[i].name ; i++) |
---|
[596] | 634 | { |
---|
[619] | 635 | printf("\t%s\t : %s\n", command[i].name , command[i].desc); |
---|
[596] | 636 | } |
---|
| 637 | } |
---|
[457] | 638 | |
---|
| 639 | // release semaphore to get next command |
---|
| 640 | sem_post( &semaphore ); |
---|
| 641 | |
---|
[407] | 642 | } // end cmd_help() |
---|
[230] | 643 | |
---|
[407] | 644 | ////////////////////////////////////////////// |
---|
| 645 | static void cmd_kill( int argc , char **argv ) |
---|
[230] | 646 | { |
---|
[407] | 647 | unsigned int pid; |
---|
[230] | 648 | |
---|
[407] | 649 | if (argc != 2) |
---|
| 650 | { |
---|
[409] | 651 | printf(" usage: %s pid\n", argv[0]); |
---|
[230] | 652 | } |
---|
[596] | 653 | else |
---|
| 654 | { |
---|
| 655 | pid = atoi( argv[1] ); |
---|
[230] | 656 | |
---|
[596] | 657 | if( pid == 0 ) |
---|
| 658 | { |
---|
| 659 | printf(" error: kernel process 0 cannot be killed\n" ); |
---|
| 660 | } |
---|
[230] | 661 | |
---|
[596] | 662 | else if( kill( pid , SIGKILL ) ) |
---|
| 663 | { |
---|
| 664 | printf(" error: process %x cannot be killed\n", pid ); |
---|
| 665 | } |
---|
| 666 | } |
---|
[427] | 667 | |
---|
[457] | 668 | // release semaphore to get next command |
---|
| 669 | sem_post( &semaphore ); |
---|
| 670 | |
---|
[407] | 671 | } // end cmd_kill() |
---|
[230] | 672 | |
---|
[407] | 673 | ////////////////////////////////////////////// |
---|
| 674 | static void cmd_load( int argc , char **argv ) |
---|
[230] | 675 | { |
---|
[436] | 676 | int ret_fork; // return value from fork |
---|
| 677 | int ret_exec; // return value from exec |
---|
| 678 | unsigned int ksh_pid; // KSH process PID |
---|
| 679 | unsigned int background; // background execution if non zero |
---|
[588] | 680 | unsigned int placement; // placement specified if non zero |
---|
| 681 | unsigned int cxy; // target cluster if placement specified |
---|
[407] | 682 | |
---|
[619] | 683 | #if DEBUG_CMD_LOAD |
---|
| 684 | char string[64]; |
---|
| 685 | #endif |
---|
| 686 | |
---|
[588] | 687 | if( (argc < 2) || (argc > 4) ) |
---|
[407] | 688 | { |
---|
[588] | 689 | printf(" usage: %s pathname [cxy] [&]\n", argv[0] ); |
---|
[407] | 690 | } |
---|
[596] | 691 | else |
---|
| 692 | { |
---|
[625] | 693 | strcpy( pathname , argv[1] ); |
---|
[407] | 694 | |
---|
[596] | 695 | if( argc == 2 ) |
---|
[588] | 696 | { |
---|
[596] | 697 | background = 0; |
---|
[588] | 698 | placement = 0; |
---|
| 699 | cxy = 0; |
---|
| 700 | } |
---|
[596] | 701 | else if( argc == 3 ) |
---|
[588] | 702 | { |
---|
[596] | 703 | if( (argv[2][0] == '&') && (argv[2][1] == 0) ) |
---|
| 704 | { |
---|
| 705 | background = 1; |
---|
| 706 | placement = 0; |
---|
| 707 | cxy = 0; |
---|
| 708 | } |
---|
| 709 | else |
---|
| 710 | { |
---|
| 711 | background = 0; |
---|
| 712 | placement = 1; |
---|
| 713 | cxy = atoi( argv[2] ); |
---|
| 714 | } |
---|
| 715 | } |
---|
| 716 | else // argc == 4 |
---|
| 717 | { |
---|
| 718 | background = ( (argv[3][0] == '&') && (argv[3][1] == 0) ); |
---|
[588] | 719 | placement = 1; |
---|
| 720 | cxy = atoi( argv[2] ); |
---|
| 721 | } |
---|
[427] | 722 | |
---|
[596] | 723 | // get KSH process PID |
---|
| 724 | ksh_pid = getpid(); |
---|
[407] | 725 | |
---|
[611] | 726 | #if DEBUG_CMD_LOAD |
---|
[623] | 727 | snprintf( string , 64 , "[ksh] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n", |
---|
[619] | 728 | __FUNCTION__, ksh_pid, argv[1], background, placement, cxy ); |
---|
| 729 | display_string( string ); |
---|
[457] | 730 | #endif |
---|
| 731 | |
---|
[596] | 732 | // set target cluster if required |
---|
| 733 | if( placement ) place_fork( cxy ); |
---|
[588] | 734 | |
---|
[596] | 735 | // KSH process fork CHILD process |
---|
| 736 | ret_fork = fork(); |
---|
[434] | 737 | |
---|
[596] | 738 | if ( ret_fork < 0 ) // it is a failure reported to KSH |
---|
| 739 | { |
---|
| 740 | printf(" error: ksh process unable to fork\n"); |
---|
| 741 | } |
---|
| 742 | else if (ret_fork == 0) // it is the CHILD process |
---|
| 743 | { |
---|
[469] | 744 | |
---|
[611] | 745 | #if DEBUG_CMD_LOAD |
---|
[623] | 746 | snprintf( string , 64 , "[ksh] %s : child_pid %x after fork, before exec\n", |
---|
[619] | 747 | __FUNCTION__ , getpid() ); |
---|
| 748 | display_string( string ); |
---|
[469] | 749 | #endif |
---|
| 750 | |
---|
[596] | 751 | // CHILD process exec NEW process |
---|
| 752 | ret_exec = execve( pathname , NULL , NULL ); |
---|
[434] | 753 | |
---|
[611] | 754 | #if DEBUG_CMD_LOAD |
---|
[623] | 755 | snprintf( string , 64 , "[ksh] %s : child_pid %x after exec / ret_exec %x\n", |
---|
[619] | 756 | __FUNCTION__ , getpid(), ret_exec ); |
---|
| 757 | display_string( string ); |
---|
[469] | 758 | #endif |
---|
| 759 | |
---|
[596] | 760 | // this is only executed in case of exec failure |
---|
| 761 | if( ret_exec ) |
---|
| 762 | { |
---|
| 763 | printf(" error: child process unable to exec <%s>\n", pathname ); |
---|
| 764 | exit( 0 ); |
---|
| 765 | } |
---|
| 766 | } |
---|
| 767 | else // it is the KSH process : ret_fork is the new process PID |
---|
[409] | 768 | { |
---|
[436] | 769 | |
---|
[611] | 770 | #if DEBUG_CMD_LOAD |
---|
[623] | 771 | snprintf( string , 64 , "[ksh] %s : ksh_pid %x after fork / ret_fork %x\n", |
---|
[619] | 772 | __FUNCTION__, getpid(), ret_fork ); |
---|
| 773 | display_string( string ); |
---|
[457] | 774 | #endif |
---|
[625] | 775 | // when the new process is launched in background, the KSH process |
---|
| 776 | // takes the TXT ownership, and release the semaphore to get the next command. |
---|
| 777 | // Otherwise, the child process keep the TXT ownership, and the semaphore will |
---|
| 778 | // be released by the KSH main thread when the child process exit |
---|
[457] | 779 | |
---|
[619] | 780 | if( background ) // KSH must keep TXT ownership |
---|
[596] | 781 | { |
---|
[619] | 782 | // get back the TXT ownership |
---|
[596] | 783 | fg( ksh_pid ); |
---|
[619] | 784 | |
---|
| 785 | // release semaphore to get next command |
---|
| 786 | sem_post( &semaphore ); |
---|
[596] | 787 | } |
---|
[457] | 788 | } |
---|
[436] | 789 | } |
---|
[407] | 790 | } // end cmd_load |
---|
| 791 | |
---|
| 792 | ///////////////////////////////////////////// |
---|
| 793 | static void cmd_log( int argc , char **argv ) |
---|
| 794 | { |
---|
| 795 | unsigned int i; |
---|
| 796 | |
---|
[473] | 797 | if (argc != 1) |
---|
| 798 | { |
---|
| 799 | printf(" usage: %s\n", argv[0], argc ); |
---|
| 800 | } |
---|
[596] | 801 | else |
---|
[407] | 802 | { |
---|
[596] | 803 | printf("--- registered commands ---\n"); |
---|
| 804 | for (i = 0; i < LOG_DEPTH; i++) |
---|
| 805 | { |
---|
| 806 | printf(" - %d\t: %s\n", i, &log_entries[i].buf); |
---|
| 807 | } |
---|
| 808 | } |
---|
[230] | 809 | |
---|
[457] | 810 | // release semaphore to get next command |
---|
| 811 | sem_post( &semaphore ); |
---|
| 812 | |
---|
| 813 | } // end cmd_log() |
---|
| 814 | |
---|
| 815 | |
---|
[407] | 816 | //////////////////////////////////////////// |
---|
| 817 | static void cmd_ls( int argc , char **argv ) |
---|
[230] | 818 | { |
---|
[611] | 819 | struct dirent * entry; |
---|
| 820 | DIR * dir; |
---|
[230] | 821 | |
---|
[619] | 822 | #if DEBUG_CMD_LS |
---|
| 823 | char string[64]; |
---|
| 824 | #endif |
---|
| 825 | |
---|
[612] | 826 | if (argc > 2 ) |
---|
[407] | 827 | { |
---|
[596] | 828 | printf(" usage: ls [path]\n"); |
---|
[407] | 829 | } |
---|
[596] | 830 | else |
---|
[407] | 831 | { |
---|
[612] | 832 | // handle case with no argument |
---|
[230] | 833 | |
---|
[611] | 834 | // get target directory path |
---|
[612] | 835 | if ( argc == 1 ) strcpy( pathname , "." ); |
---|
[625] | 836 | else strcpy( pathname , argv[1] ); |
---|
[611] | 837 | |
---|
| 838 | // open target directory |
---|
| 839 | dir = opendir( pathname ); |
---|
| 840 | |
---|
| 841 | #if DEBUG_CMD_LS |
---|
[623] | 842 | snprintf( string , 64 , "[ksh] %s : directory <%s> open / DIR %x\n", |
---|
[611] | 843 | __FUNCTION__, pathname , dir ); |
---|
[619] | 844 | display_string( string ); |
---|
[611] | 845 | #endif |
---|
| 846 | |
---|
| 847 | if( dir == NULL) |
---|
| 848 | { |
---|
| 849 | printf(" error : directory <%s> not found\n", pathname ); |
---|
[623] | 850 | |
---|
| 851 | sem_post( &semaphore ); |
---|
| 852 | return; |
---|
[611] | 853 | } |
---|
| 854 | |
---|
| 855 | // loop on directory entries |
---|
| 856 | while ( (entry = readdir(dir)) != NULL ) |
---|
| 857 | { |
---|
[612] | 858 | printf("%s\n", entry->d_name); |
---|
[611] | 859 | } |
---|
| 860 | |
---|
| 861 | // close target directory |
---|
| 862 | closedir( dir ); |
---|
| 863 | |
---|
| 864 | #if DEBUG_CMD_LS |
---|
[623] | 865 | snprintf( string , 64 , "[ksh] %s : directory <%s> closed\n", |
---|
[611] | 866 | __FUNCTION__, pathname ); |
---|
[619] | 867 | display_string( string ); |
---|
[611] | 868 | #endif |
---|
| 869 | |
---|
[596] | 870 | } |
---|
[230] | 871 | |
---|
[457] | 872 | // release semaphore to get next command |
---|
| 873 | sem_post( &semaphore ); |
---|
| 874 | |
---|
| 875 | } // end cmd_ls() |
---|
| 876 | |
---|
[407] | 877 | /////////////////////////////////////////////// |
---|
| 878 | static void cmd_mkdir( int argc , char **argv ) |
---|
[230] | 879 | { |
---|
[407] | 880 | if (argc != 2) |
---|
| 881 | { |
---|
[409] | 882 | printf(" usage: mkdir pathname\n"); |
---|
[230] | 883 | } |
---|
[596] | 884 | else |
---|
| 885 | { |
---|
[625] | 886 | strcpy( pathname , argv[1] ); |
---|
[230] | 887 | |
---|
[610] | 888 | mkdir( pathname , 0x777 ); |
---|
[596] | 889 | } |
---|
[230] | 890 | |
---|
[457] | 891 | // release semaphore to get next command |
---|
| 892 | sem_post( &semaphore ); |
---|
| 893 | |
---|
| 894 | } // end cmd_mkdir() |
---|
| 895 | |
---|
[407] | 896 | //////////////////////////////////////////// |
---|
| 897 | static void cmd_mv( int argc , char **argv ) |
---|
[230] | 898 | { |
---|
[610] | 899 | if (argc != 3) |
---|
| 900 | { |
---|
| 901 | printf(" usage: mv old_pathname new_pathname\n"); |
---|
[230] | 902 | } |
---|
[596] | 903 | else |
---|
| 904 | { |
---|
[625] | 905 | strcpy( pathname , argv[1] ); |
---|
| 906 | strcpy( pathnew , argv[2] ); |
---|
[610] | 907 | |
---|
| 908 | // call the relevant syscall |
---|
[625] | 909 | if( rename( pathname , pathnew ) ) |
---|
[610] | 910 | { |
---|
[625] | 911 | printf(" error: unable to rename <%s> to <%s>\n", pathname , pathnew ); |
---|
[610] | 912 | } |
---|
[596] | 913 | } |
---|
[610] | 914 | |
---|
[457] | 915 | // release semaphore to get next command |
---|
| 916 | sem_post( &semaphore ); |
---|
[407] | 917 | |
---|
[457] | 918 | } // end cmd_mv |
---|
[230] | 919 | |
---|
[588] | 920 | |
---|
| 921 | //////////////////////////////////////////// |
---|
| 922 | static void cmd_ps( int argc , char **argv ) |
---|
| 923 | { |
---|
| 924 | unsigned int x_size; |
---|
| 925 | unsigned int y_size; |
---|
| 926 | unsigned int ncores; |
---|
| 927 | unsigned int x; |
---|
| 928 | unsigned int y; |
---|
| 929 | |
---|
[619] | 930 | #if DEBUG_CMD_PS |
---|
| 931 | char string[64]; |
---|
| 932 | #endif |
---|
| 933 | |
---|
[588] | 934 | if (argc != 1) |
---|
| 935 | { |
---|
| 936 | printf(" usage: %s\n", argv[0]); |
---|
| 937 | } |
---|
[596] | 938 | else |
---|
| 939 | { |
---|
| 940 | // get platform config |
---|
| 941 | get_config( &x_size , &y_size , &ncores ); |
---|
[588] | 942 | |
---|
[596] | 943 | // scan all clusters |
---|
| 944 | for( x = 0 ; x < x_size ; x++ ) |
---|
[588] | 945 | { |
---|
[596] | 946 | for( y = 0 ; y < y_size ; y++ ) |
---|
| 947 | { |
---|
[619] | 948 | |
---|
| 949 | #if DEBUG_CMD_PS |
---|
[623] | 950 | snprintf( string , 64 , "\n[ksh] %s : call display_cluster_process()", __FUNCTION__ ); |
---|
[619] | 951 | display_string( string ); |
---|
| 952 | #endif |
---|
| 953 | |
---|
[596] | 954 | // display only owned processes |
---|
| 955 | display_cluster_processes( HAL_CXY_FROM_XY(x,y), 1 ); |
---|
| 956 | } |
---|
[588] | 957 | } |
---|
| 958 | } |
---|
| 959 | |
---|
| 960 | // release semaphore to get next command |
---|
| 961 | sem_post( &semaphore ); |
---|
| 962 | |
---|
| 963 | } // end cmd_ps() |
---|
| 964 | |
---|
[407] | 965 | ///////////////////////////////////////////// |
---|
| 966 | static void cmd_pwd( int argc , char **argv ) |
---|
[230] | 967 | { |
---|
[407] | 968 | if (argc != 1) |
---|
| 969 | { |
---|
[473] | 970 | printf(" usage: %s\n", argv[0]); |
---|
[407] | 971 | } |
---|
| 972 | else |
---|
| 973 | { |
---|
[625] | 974 | if ( getcwd( pathname , PATH_MAX_SIZE ) ) |
---|
[596] | 975 | { |
---|
| 976 | printf(" error: unable to get current directory\n"); |
---|
| 977 | } |
---|
| 978 | else |
---|
| 979 | { |
---|
[625] | 980 | printf("%s\n", pathname ); |
---|
[596] | 981 | } |
---|
| 982 | } |
---|
[407] | 983 | |
---|
[457] | 984 | // release semaphore to get next command |
---|
| 985 | sem_post( &semaphore ); |
---|
| 986 | |
---|
| 987 | } // end cmd_pwd() |
---|
| 988 | |
---|
[407] | 989 | //////////////////////////////////////////// |
---|
| 990 | static void cmd_rm( int argc , char **argv ) |
---|
| 991 | { |
---|
| 992 | if (argc != 2) |
---|
| 993 | { |
---|
[473] | 994 | printf(" usage: %s pathname\n", argv[0]); |
---|
[230] | 995 | } |
---|
[596] | 996 | else |
---|
| 997 | { |
---|
[625] | 998 | strcpy( pathname , argv[1] ); |
---|
[230] | 999 | |
---|
[608] | 1000 | if ( unlink( pathname ) ) |
---|
| 1001 | { |
---|
[611] | 1002 | printf(" error: unable to remove <%s>\n", pathname ); |
---|
[608] | 1003 | } |
---|
[596] | 1004 | } |
---|
[230] | 1005 | |
---|
[457] | 1006 | // release semaphore to get next command |
---|
| 1007 | sem_post( &semaphore ); |
---|
[230] | 1008 | |
---|
[457] | 1009 | } // end_cmd_rm() |
---|
| 1010 | |
---|
[407] | 1011 | /////////////////////////////////////////////// |
---|
| 1012 | static void cmd_rmdir( int argc , char **argv ) |
---|
[230] | 1013 | { |
---|
[457] | 1014 | // same as cmd_rm() |
---|
[625] | 1015 | cmd_rm (argc , argv ); |
---|
[230] | 1016 | } |
---|
| 1017 | |
---|
[442] | 1018 | /////////////////////////////////////////////// |
---|
| 1019 | static void cmd_trace( int argc , char **argv ) |
---|
| 1020 | { |
---|
| 1021 | unsigned int cxy; |
---|
| 1022 | unsigned int lid; |
---|
| 1023 | |
---|
| 1024 | if (argc != 3) |
---|
| 1025 | { |
---|
| 1026 | printf(" usage: trace cxy lid \n"); |
---|
| 1027 | } |
---|
[596] | 1028 | else |
---|
| 1029 | { |
---|
| 1030 | cxy = atoi(argv[1]); |
---|
| 1031 | lid = atoi(argv[2]); |
---|
[442] | 1032 | |
---|
[596] | 1033 | if( trace( 1 , cxy , lid ) ) |
---|
| 1034 | { |
---|
| 1035 | printf(" error: core[%x,%d] not found\n", cxy, lid ); |
---|
| 1036 | } |
---|
[442] | 1037 | } |
---|
| 1038 | |
---|
[457] | 1039 | // release semaphore to get next command |
---|
| 1040 | sem_post( &semaphore ); |
---|
| 1041 | |
---|
| 1042 | } // end cmd_trace |
---|
| 1043 | |
---|
[442] | 1044 | /////////////////////////////////////////////// |
---|
| 1045 | static void cmd_untrace( int argc , char **argv ) |
---|
| 1046 | { |
---|
| 1047 | unsigned int cxy; |
---|
| 1048 | unsigned int lid; |
---|
| 1049 | |
---|
| 1050 | if (argc != 3) |
---|
| 1051 | { |
---|
| 1052 | printf(" usage: untrace cxy lid \n"); |
---|
| 1053 | } |
---|
[596] | 1054 | else |
---|
| 1055 | { |
---|
| 1056 | cxy = atoi(argv[1]); |
---|
| 1057 | lid = atoi(argv[2]); |
---|
[442] | 1058 | |
---|
[596] | 1059 | if( trace( 0 , cxy , lid ) ) |
---|
| 1060 | { |
---|
| 1061 | printf(" error: core[%x,%d] not found\n", cxy, lid ); |
---|
| 1062 | } |
---|
[442] | 1063 | } |
---|
| 1064 | |
---|
[457] | 1065 | // release semaphore to get next command |
---|
| 1066 | sem_post( &semaphore ); |
---|
| 1067 | |
---|
| 1068 | } // end cmd_untrace() |
---|
| 1069 | |
---|
| 1070 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 1071 | // Array of commands |
---|
[457] | 1072 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[230] | 1073 | |
---|
[619] | 1074 | ksh_cmd_t command[] = |
---|
[230] | 1075 | { |
---|
[435] | 1076 | { "cat", "display file content", cmd_cat }, |
---|
| 1077 | { "cd", "change current directory", cmd_cd }, |
---|
| 1078 | { "cp", "replicate a file in file system", cmd_cp }, |
---|
| 1079 | { "fg", "put a process in foreground", cmd_fg }, |
---|
| 1080 | { "display", "display vmm/sched/process/vfs/chdev/txt", cmd_display }, |
---|
| 1081 | { "load", "load an user application", cmd_load }, |
---|
| 1082 | { "help", "list available commands", cmd_help }, |
---|
[457] | 1083 | { "kill", "kill a process (all threads)", cmd_kill }, |
---|
[435] | 1084 | { "log", "list registered commands", cmd_log }, |
---|
| 1085 | { "ls", "list directory entries", cmd_ls }, |
---|
| 1086 | { "mkdir", "create a new directory", cmd_mkdir }, |
---|
| 1087 | { "mv", "move a file in file system", cmd_mv }, |
---|
| 1088 | { "pwd", "print current working directory", cmd_pwd }, |
---|
[588] | 1089 | { "ps", "display all processes", cmd_ps }, |
---|
[435] | 1090 | { "rm", "remove a file from file system", cmd_rm }, |
---|
| 1091 | { "rmdir", "remove a directory from file system", cmd_rmdir }, |
---|
[442] | 1092 | { "trace", "activate trace for a given core", cmd_trace }, |
---|
| 1093 | { "untrace", "desactivate trace for a given core", cmd_untrace }, |
---|
[435] | 1094 | { NULL, NULL, NULL } |
---|
[230] | 1095 | }; |
---|
| 1096 | |
---|
[407] | 1097 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[457] | 1098 | // This function analyses one command (with arguments), executes it, and returns. |
---|
[407] | 1099 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[625] | 1100 | static void __attribute__ ((noinline)) execute( char * buf ) |
---|
[230] | 1101 | { |
---|
[619] | 1102 | int argc = 0; |
---|
| 1103 | char * argv[MAX_ARGS]; |
---|
| 1104 | int i; |
---|
| 1105 | int len = strlen(buf); |
---|
[230] | 1106 | |
---|
[625] | 1107 | #if DEBUG_EXECUTE |
---|
| 1108 | printf("\n[ksh] %s : command <%s>\n", |
---|
| 1109 | __FUNCTION__ , buf ); |
---|
[619] | 1110 | #endif |
---|
| 1111 | |
---|
[230] | 1112 | // build argc/argv |
---|
[407] | 1113 | for (i = 0; i < len; i++) |
---|
| 1114 | { |
---|
[619] | 1115 | // convert SPACE to NUL |
---|
[407] | 1116 | if (buf[i] == ' ') |
---|
| 1117 | { |
---|
[230] | 1118 | buf[i] = '\0'; |
---|
[407] | 1119 | } |
---|
| 1120 | else if (i == 0 || buf[i - 1] == '\0') |
---|
| 1121 | { |
---|
| 1122 | if (argc < MAX_ARGS) |
---|
| 1123 | { |
---|
[230] | 1124 | argv[argc] = &buf[i]; |
---|
| 1125 | argc++; |
---|
| 1126 | } |
---|
| 1127 | } |
---|
| 1128 | } |
---|
| 1129 | |
---|
[625] | 1130 | // check command |
---|
| 1131 | if (argc == 0) |
---|
| 1132 | { |
---|
| 1133 | // release semaphore to get next command |
---|
| 1134 | sem_post( &semaphore ); |
---|
| 1135 | } |
---|
| 1136 | |
---|
| 1137 | #if DEBUG_EXECUTE |
---|
| 1138 | printf("\n[ksh] %s : argc %d / arg0 %s / arg1 %s\n", |
---|
| 1139 | __FUNCTION__ , argc , argv[0], argv[1] ); |
---|
[619] | 1140 | #endif |
---|
| 1141 | |
---|
[625] | 1142 | // scan the list of commands to match typed command |
---|
| 1143 | int found = 0; |
---|
| 1144 | for ( i = 0 ; (command[i].name != NULL) && (found == 0) ; i++ ) |
---|
[407] | 1145 | { |
---|
[625] | 1146 | if (strcmp(argv[0], command[i].name) == 0) |
---|
[407] | 1147 | { |
---|
[625] | 1148 | command[i].fn(argc, argv); |
---|
| 1149 | found = 1; |
---|
[230] | 1150 | } |
---|
[625] | 1151 | } |
---|
[230] | 1152 | |
---|
[625] | 1153 | // check undefined command |
---|
| 1154 | if (!found) |
---|
| 1155 | { |
---|
| 1156 | printf(" error : undefined command <%s>\n", argv[0]); |
---|
[457] | 1157 | |
---|
[625] | 1158 | // release semaphore to get next command |
---|
| 1159 | sem_post( &semaphore ); |
---|
[230] | 1160 | } |
---|
[625] | 1161 | } // end execute() |
---|
[230] | 1162 | |
---|
[626] | 1163 | |
---|
| 1164 | |
---|
[574] | 1165 | /////////////////////////////// |
---|
[503] | 1166 | static void interactive( void ) |
---|
[230] | 1167 | { |
---|
[469] | 1168 | char c; // read character |
---|
| 1169 | unsigned int end_command; // last character found in a command |
---|
| 1170 | unsigned int count; // pointer in command buffer |
---|
| 1171 | unsigned int i; // index for loops |
---|
| 1172 | unsigned int state; // escape sequence state |
---|
[230] | 1173 | |
---|
[619] | 1174 | char cmd[CMD_MAX_SIZE]; // buffer for one command |
---|
[457] | 1175 | |
---|
[619] | 1176 | #if DEBUG_INTER |
---|
[625] | 1177 | char string[128]; |
---|
[619] | 1178 | #endif |
---|
| 1179 | |
---|
[626] | 1180 | /* |
---|
| 1181 | // Lauch one or several commands without interactive mode |
---|
[625] | 1182 | |
---|
| 1183 | // 1. first command |
---|
[588] | 1184 | if( sem_wait( &semaphore ) ) |
---|
[469] | 1185 | { |
---|
[588] | 1186 | printf("\n[ksh error] cannot found semafore\n" ); |
---|
| 1187 | exit( 1 ); |
---|
[469] | 1188 | } |
---|
[588] | 1189 | else |
---|
| 1190 | { |
---|
[626] | 1191 | printf("\n[ksh] display fat 0 32\n"); |
---|
[588] | 1192 | } |
---|
[469] | 1193 | |
---|
[626] | 1194 | strcpy( cmd , "display fat 0 32" ); |
---|
[625] | 1195 | execute( cmd ); |
---|
| 1196 | |
---|
| 1197 | // 2. second command |
---|
| 1198 | if( sem_wait( &semaphore ) ) |
---|
| 1199 | { |
---|
| 1200 | printf("\n[ksh error] cannot found semafore\n" ); |
---|
| 1201 | exit( 1 ); |
---|
| 1202 | } |
---|
| 1203 | else |
---|
| 1204 | { |
---|
[626] | 1205 | printf("\n[ksh] load bin/user/pgcd.elf\n"); |
---|
[625] | 1206 | } |
---|
| 1207 | |
---|
[626] | 1208 | strcpy( cmd , "load bin/user/pgcd.elf" ); |
---|
[625] | 1209 | execute( cmd ); |
---|
| 1210 | |
---|
| 1211 | // end non-interactive mode |
---|
[611] | 1212 | */ |
---|
[469] | 1213 | |
---|
[407] | 1214 | enum fsm_states |
---|
| 1215 | { |
---|
[457] | 1216 | NORMAL = 0, |
---|
| 1217 | ESCAPE = 1, |
---|
| 1218 | BRAKET = 2, |
---|
[230] | 1219 | }; |
---|
| 1220 | |
---|
[457] | 1221 | // This lexical analyser writes one command line in the command buffer. |
---|
| 1222 | // It is implemented as a 3 states FSM to handle the following escape sequences: |
---|
[230] | 1223 | // - ESC [ A : up arrow |
---|
| 1224 | // - ESC [ B : down arrow |
---|
| 1225 | // - ESC [ C : right arrow |
---|
| 1226 | // - ESC [ D : left arrow |
---|
[407] | 1227 | // The three states have the following semantic: |
---|
[230] | 1228 | // - NORMAL : no (ESC) character has been found |
---|
| 1229 | // - ESCAPE : the character (ESC) has been found |
---|
| 1230 | // - BRAKET : the wo characters (ESC,[) have been found |
---|
[436] | 1231 | |
---|
[619] | 1232 | // take the semaphore for the first command |
---|
| 1233 | if ( sem_wait( &semaphore ) ) |
---|
| 1234 | { |
---|
| 1235 | printf("\n[ksh error] cannot found semafore\n" ); |
---|
| 1236 | exit( 1 ); |
---|
| 1237 | } |
---|
| 1238 | |
---|
| 1239 | // display prompt for the first command |
---|
| 1240 | printf("\n[ksh] "); |
---|
| 1241 | |
---|
| 1242 | // external loop on the commands / the interactive thread do not exit this loop |
---|
[230] | 1243 | while (1) |
---|
| 1244 | { |
---|
[457] | 1245 | // initialize command buffer |
---|
[625] | 1246 | // memset( cmd , 0x20 , sizeof(cmd) ); // TODO useful ? |
---|
[619] | 1247 | count = 0; |
---|
| 1248 | state = NORMAL; |
---|
| 1249 | end_command = 0; |
---|
[230] | 1250 | |
---|
[619] | 1251 | #if DEBUG_INTER |
---|
| 1252 | unsigned int pid = getpid(); |
---|
[625] | 1253 | snprintf( string , 128 , "\n[ksh] %s : request a new command", __FUNCTION__ ); |
---|
[619] | 1254 | display_string( string ); |
---|
| 1255 | #endif |
---|
[407] | 1256 | |
---|
[457] | 1257 | // internal loop on characters in one command |
---|
| 1258 | while( end_command == 0 ) |
---|
| 1259 | { |
---|
| 1260 | // get one character from TXT_RX |
---|
| 1261 | c = (char)getchar(); |
---|
| 1262 | |
---|
| 1263 | if( c == 0 ) continue; |
---|
| 1264 | |
---|
| 1265 | if( state == NORMAL ) // we are not in an escape sequence |
---|
| 1266 | { |
---|
[230] | 1267 | if ((c == '\b') || (c == 0x7F)) // backspace => remove one character |
---|
| 1268 | { |
---|
[457] | 1269 | if (count > 0) |
---|
| 1270 | { |
---|
| 1271 | printf("\b \b"); |
---|
| 1272 | count--; |
---|
| 1273 | } |
---|
[230] | 1274 | } |
---|
[457] | 1275 | else if (c == '\n') // new line => end of command |
---|
[230] | 1276 | { |
---|
[457] | 1277 | if (count > 0) // analyse & execute command |
---|
| 1278 | { |
---|
| 1279 | // complete command with NUL character |
---|
[619] | 1280 | cmd[count] = 0; |
---|
[457] | 1281 | count++; |
---|
[625] | 1282 | #if DEBUG_INTER |
---|
| 1283 | snprintf( string , 128 , "[ksh] %s : get command <%s> / &log = %x / ptw = %d / &ptw = %x", |
---|
| 1284 | __FUNCTION__, cmd , log_entries[ptw].buf , ptw , &ptw ); |
---|
| 1285 | display_string( string ); |
---|
| 1286 | display_vmm( 0 , 2 ); |
---|
| 1287 | #endif |
---|
| 1288 | // register command in log_entries[] array |
---|
[619] | 1289 | strncpy( log_entries[ptw].buf , cmd , count ); |
---|
[457] | 1290 | log_entries[ptw].count = count; |
---|
| 1291 | ptw = (ptw + 1) % LOG_DEPTH; |
---|
| 1292 | ptr = ptw; |
---|
[230] | 1293 | |
---|
[619] | 1294 | #if DEBUG_INTER |
---|
[625] | 1295 | snprintf( string , 128 , "[ksh] %s : execute <%s>", __FUNCTION__, cmd ); |
---|
[619] | 1296 | display_string( string ); |
---|
| 1297 | #endif |
---|
[457] | 1298 | // echo character |
---|
| 1299 | putchar( c ); |
---|
[230] | 1300 | |
---|
[625] | 1301 | // execute command |
---|
| 1302 | execute( cmd ); |
---|
[457] | 1303 | } |
---|
| 1304 | else // no command registered |
---|
[441] | 1305 | { |
---|
[457] | 1306 | // release semaphore to get next command |
---|
| 1307 | sem_post( &semaphore ); |
---|
[441] | 1308 | } |
---|
[457] | 1309 | |
---|
| 1310 | // exit internal loop on characters |
---|
| 1311 | end_command = 1; |
---|
| 1312 | } |
---|
| 1313 | else if (c == '\t') // tabulation => do nothing |
---|
| 1314 | { |
---|
| 1315 | } |
---|
| 1316 | else if (c == (char)0x1B) // ESC => start an escape sequence |
---|
| 1317 | { |
---|
| 1318 | state = ESCAPE; |
---|
| 1319 | } |
---|
| 1320 | else // normal character |
---|
[230] | 1321 | { |
---|
[619] | 1322 | if (count < (sizeof(cmd) - 1) ) |
---|
[457] | 1323 | { |
---|
| 1324 | // register character in command buffer |
---|
[619] | 1325 | cmd[count] = c; |
---|
[457] | 1326 | count++; |
---|
| 1327 | |
---|
| 1328 | // echo character |
---|
| 1329 | putchar( c ); |
---|
[230] | 1330 | } |
---|
[619] | 1331 | else |
---|
| 1332 | { |
---|
| 1333 | printf("\none command cannot exceed %d characters\n", sizeof(cmd) ); |
---|
| 1334 | } |
---|
[230] | 1335 | } |
---|
| 1336 | } |
---|
[457] | 1337 | else if( state == ESCAPE ) |
---|
[230] | 1338 | { |
---|
| 1339 | if (c == '[') // valid sequence => continue |
---|
| 1340 | { |
---|
| 1341 | state = BRAKET; |
---|
| 1342 | } |
---|
| 1343 | else // invalid sequence => do nothing |
---|
| 1344 | { |
---|
| 1345 | state = NORMAL; |
---|
| 1346 | } |
---|
| 1347 | } |
---|
[457] | 1348 | else if( state == BRAKET ) |
---|
[230] | 1349 | { |
---|
[619] | 1350 | if (c == 'D') // valid LEFT sequence => move cmd pointer left |
---|
[230] | 1351 | { |
---|
| 1352 | if (count > 0) |
---|
| 1353 | { |
---|
| 1354 | printf("\b"); |
---|
| 1355 | count--; |
---|
| 1356 | } |
---|
| 1357 | |
---|
| 1358 | // get next user char |
---|
| 1359 | state = NORMAL; |
---|
| 1360 | } |
---|
[619] | 1361 | else if (c == 'C') // valid RIGHT sequence => move cmd pointer right |
---|
[230] | 1362 | { |
---|
[619] | 1363 | if (count < sizeof(cmd) - 1) |
---|
[230] | 1364 | { |
---|
[619] | 1365 | printf("%c", cmd[count]); |
---|
[230] | 1366 | count++; |
---|
| 1367 | } |
---|
| 1368 | |
---|
| 1369 | // get next user char |
---|
| 1370 | state = NORMAL; |
---|
| 1371 | } |
---|
| 1372 | else if (c == 'A') // valid UP sequence => move log pointer backward |
---|
| 1373 | { |
---|
| 1374 | // cancel current command |
---|
| 1375 | for (i = 0; i < count; i++) printf("\b \b"); |
---|
| 1376 | count = 0; |
---|
| 1377 | |
---|
[619] | 1378 | // copy log command into cmd |
---|
[230] | 1379 | ptr = (ptr - 1) % LOG_DEPTH; |
---|
[619] | 1380 | strcpy(cmd, log_entries[ptr].buf); |
---|
[458] | 1381 | count = log_entries[ptr].count - 1; |
---|
[230] | 1382 | |
---|
| 1383 | // display log command |
---|
[619] | 1384 | printf("%s", cmd); |
---|
[230] | 1385 | |
---|
| 1386 | // get next user char |
---|
| 1387 | state = NORMAL; |
---|
| 1388 | } |
---|
| 1389 | else if (c == 'B') // valid DOWN sequence => move log pointer forward |
---|
| 1390 | { |
---|
| 1391 | // cancel current command |
---|
| 1392 | for (i = 0 ; i < count; i++) printf("\b \b"); |
---|
| 1393 | count = 0; |
---|
| 1394 | |
---|
[619] | 1395 | // copy log command into cmd |
---|
[230] | 1396 | ptr = (ptr + 1) % LOG_DEPTH; |
---|
[619] | 1397 | strcpy(cmd, log_entries[ptr].buf); |
---|
[230] | 1398 | count = log_entries[ptr].count; |
---|
| 1399 | |
---|
| 1400 | // display log command |
---|
[619] | 1401 | printf("%s", cmd); |
---|
[230] | 1402 | |
---|
| 1403 | // get next user char |
---|
| 1404 | state = NORMAL; |
---|
| 1405 | } |
---|
| 1406 | else // other character => do nothing |
---|
| 1407 | { |
---|
| 1408 | // get next user char |
---|
| 1409 | state = NORMAL; |
---|
| 1410 | } |
---|
| 1411 | } |
---|
[457] | 1412 | } // end internal while loop on characters |
---|
[619] | 1413 | |
---|
| 1414 | #if DEBUG_INTER |
---|
[625] | 1415 | snprintf( string , 128 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd ); |
---|
[619] | 1416 | display_string( string ); |
---|
| 1417 | #endif |
---|
| 1418 | |
---|
| 1419 | // block interactive thread if KSH loose TXT ownership |
---|
| 1420 | if ( sem_wait( &semaphore ) ) |
---|
| 1421 | { |
---|
| 1422 | printf("\n[ksh error] cannot found semafore\n" ); |
---|
| 1423 | exit( 1 ); |
---|
| 1424 | } |
---|
| 1425 | |
---|
| 1426 | // display prompt for next command |
---|
| 1427 | printf("\n[ksh] "); |
---|
| 1428 | |
---|
[457] | 1429 | } // end external while loop on commands |
---|
[619] | 1430 | |
---|
[446] | 1431 | } // end interactive() |
---|
| 1432 | |
---|
[574] | 1433 | //////////////// |
---|
[503] | 1434 | int main( void ) |
---|
[446] | 1435 | { |
---|
| 1436 | unsigned int cxy; // owner cluster identifier for this KSH process |
---|
| 1437 | unsigned int lid; // core identifier for this KSH main thread |
---|
| 1438 | int status; // child process termination status |
---|
[457] | 1439 | int child_pid; // child process identifier |
---|
[469] | 1440 | int parent_pid; // parent process identifier (i.e. this process) |
---|
[457] | 1441 | unsigned int is_owner; // non-zero if KSH process is TXT owner |
---|
[446] | 1442 | |
---|
| 1443 | // initialize log buffer |
---|
| 1444 | memset( &log_entries , 0, sizeof(log_entries)); |
---|
| 1445 | ptw = 0; |
---|
| 1446 | ptr = 0; |
---|
| 1447 | |
---|
[457] | 1448 | // get KSH process pid and core |
---|
| 1449 | parent_pid = getpid(); |
---|
[459] | 1450 | get_core( &cxy , &lid ); |
---|
[457] | 1451 | |
---|
[611] | 1452 | #if DEBUG_MAIN |
---|
[619] | 1453 | printf("\n[ksh] main thread started on core[%x,%d]\n", cxy , lid ); |
---|
[574] | 1454 | #endif |
---|
| 1455 | |
---|
| 1456 | // initializes the semaphore used to synchronize with interactive thread |
---|
[469] | 1457 | if ( sem_init( &semaphore , 0 , 1 ) ) |
---|
| 1458 | { |
---|
| 1459 | printf("\n[KSH ERROR] cannot initialize semaphore\n" ); |
---|
| 1460 | exit( 1 ); |
---|
| 1461 | } |
---|
[457] | 1462 | |
---|
[611] | 1463 | #if DEBUG_MAIN |
---|
[574] | 1464 | printf("\n[ksh] main initialized semaphore\n" ); |
---|
| 1465 | #endif |
---|
| 1466 | |
---|
[446] | 1467 | // initialize interactive thread attributes |
---|
| 1468 | attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED; |
---|
| 1469 | attr.cxy = cxy; |
---|
| 1470 | |
---|
| 1471 | // lauch the interactive thread |
---|
| 1472 | pthread_create( &trdid, |
---|
| 1473 | &attr, |
---|
| 1474 | &interactive, // entry function |
---|
| 1475 | NULL ); |
---|
[611] | 1476 | #if DEBUG_MAIN |
---|
[619] | 1477 | printf("\n[ksh] main thread launched interactive thread %x\n", trdid ); |
---|
[574] | 1478 | #endif |
---|
[588] | 1479 | |
---|
| 1480 | // signal INIT process |
---|
| 1481 | kill( 1 , SIGCONT ); |
---|
[446] | 1482 | |
---|
| 1483 | // enter infinite loop monitoring children processes termination |
---|
| 1484 | while( 1 ) |
---|
| 1485 | { |
---|
[457] | 1486 | // wait children termination |
---|
| 1487 | child_pid = wait( &status ); |
---|
[446] | 1488 | |
---|
[611] | 1489 | #if DEBUG_MAIN |
---|
[574] | 1490 | if( WIFEXITED (status) ) printf("\n[ksh] child process %x exit\n" , child_pid ); |
---|
| 1491 | if( WIFSIGNALED(status) ) printf("\n[ksh] child process %x killed\n" , child_pid ); |
---|
| 1492 | if( WIFSTOPPED (status) ) printf("\n[ksh] child process %x stopped\n", child_pid ); |
---|
[446] | 1493 | #endif |
---|
| 1494 | |
---|
[457] | 1495 | // release semaphore if KSH process is TXT owner, to unblock interactive thread |
---|
| 1496 | is_fg( parent_pid , &is_owner ); |
---|
| 1497 | if( is_owner ) sem_post( &semaphore ); |
---|
[446] | 1498 | } |
---|
[436] | 1499 | } // end main() |
---|
[230] | 1500 | |
---|
[446] | 1501 | |
---|