| 478 | } |
| 479 | |
| 480 | int _msh_exec_lwp(int debug, char *cmd, rt_size_t length) |
| 481 | { |
| 482 | int argc; |
| 483 | int cmd0_size = 0; |
| 484 | char *argv[FINSH_ARG_MAX]; |
| 485 | char *pg_name; |
| 486 | int ret; |
| 487 | |
| 488 | /* find the size of first command */ |
| 489 | while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) |
| 490 | cmd0_size ++; |
| 491 | if (cmd0_size == 0) |
| 492 | return -1; |
| 493 | |
| 494 | /* split arguments */ |
| 495 | rt_memset(argv, 0x00, sizeof(argv)); |
| 496 | argc = msh_split(cmd, length, argv); |
| 497 | if (argc == 0) |
| 498 | return -1; |
| 499 | |
| 500 | /* try to find program in working directory */ |
| 501 | pg_name = _msh_exec_search_path("", argv[0]); |
| 502 | if (pg_name) |
| 503 | { |
| 504 | goto found_program; |
| 505 | } |
| 506 | |
| 507 | /* only check these paths when the first argument doesn't contain path |
| 508 | seperator */ |
| 509 | if (strstr(argv[0], "/")) |
| 510 | { |
| 511 | return -1; |
| 512 | } |
| 513 | |
| 514 | /* try to find program in /bin */ |
| 515 | pg_name = _msh_exec_search_path("/bin", argv[0]); |
| 516 | if (pg_name) |
| 517 | { |
| 518 | goto found_program; |
| 519 | } |
| 520 | |
| 521 | /* try to find program in dirs registered to env path */ |
| 522 | pg_name = _msh_exec_search_env(argv[0]); |
| 523 | if (pg_name) |
| 524 | { |
| 525 | goto found_program; |
| 526 | } |
| 527 | |
| 528 | /* not found in anywhere */ |
| 529 | return -1; |
| 530 | |
| 531 | /* found program */ |
| 532 | found_program: |
| 533 | ret = exec(pg_name, debug, argc, argv); |
| 534 | rt_free(pg_name); |
| 535 | |
| 536 | return ret; |
| 537 | } |
no test coverage detected