| 408 | } |
| 409 | |
| 410 | static int prepare_cmd(struct strvec *out, const struct child_process *cmd) |
| 411 | { |
| 412 | if (!cmd->args.v[0]) |
| 413 | BUG("command is empty"); |
| 414 | |
| 415 | /* |
| 416 | * Add SHELL_PATH so in the event exec fails with ENOEXEC we can |
| 417 | * attempt to interpret the command with 'sh'. |
| 418 | */ |
| 419 | strvec_push(out, SHELL_PATH); |
| 420 | |
| 421 | if (cmd->git_cmd) { |
| 422 | prepare_git_cmd(out, cmd->args.v); |
| 423 | } else if (cmd->use_shell) { |
| 424 | prepare_shell_cmd(out, cmd->args.v); |
| 425 | } else { |
| 426 | strvec_pushv(out, cmd->args.v); |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * If there are no dir separator characters in the command then perform |
| 431 | * a path lookup and use the resolved path as the command to exec. If |
| 432 | * there are dir separator characters, we have exec attempt to invoke |
| 433 | * the command directly. |
| 434 | */ |
| 435 | if (!has_dir_sep(out->v[1])) { |
| 436 | char *program = locate_in_PATH(out->v[1]); |
| 437 | if (program) { |
| 438 | free((char *)out->v[1]); |
| 439 | out->v[1] = program; |
| 440 | } else { |
| 441 | strvec_clear(out); |
| 442 | errno = ENOENT; |
| 443 | return -1; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static char **prep_childenv(const char *const *deltaenv) |
| 451 | { |
no test coverage detected