Template of exec_one_command
@@ -154,6 +154,9 @@ | ||
154 | 154 | __attribute__((pure)); |
155 | 155 | static inline void next_pipe(pipeinfo_T *pi, bool next) |
156 | 156 | __attribute__((nonnull)); |
157 | +static void exec_one_command(command_T *c, exec_T type) | |
158 | + __attribute__((nonnull)); | |
159 | +// TODO Reconsider order of functions around here | |
157 | 160 | static pid_t exec_process( |
158 | 161 | command_T *restrict c, exec_T type, pipeinfo_T *restrict pi, pid_t pgid) |
159 | 162 | __attribute__((nonnull)); |
@@ -574,6 +577,17 @@ | ||
574 | 577 | /* Executes the commands in a pipeline. */ |
575 | 578 | void exec_commands(command_T *c, exec_T type) |
576 | 579 | { |
580 | + // TODO Probably should do this in exec_one_command | |
581 | + /* increment the reference count of `c' to prevent `c' from being freed | |
582 | + * during execution. */ | |
583 | + c = comsdup(c); | |
584 | + | |
585 | + if (c->next == NULL) { | |
586 | + exec_one_command(c, type); | |
587 | + goto done; | |
588 | + } | |
589 | + | |
590 | + // TODO rewrite below | |
577 | 591 | size_t count; |
578 | 592 | pid_t pgid; |
579 | 593 | command_T *cc; |
@@ -581,10 +595,6 @@ | ||
581 | 595 | process_T *ps, *pp; |
582 | 596 | pipeinfo_T pinfo = PIPEINFO_INIT; |
583 | 597 | |
584 | - /* increment the reference count of `c' to prevent `c' from being freed | |
585 | - * during execution. */ | |
586 | - c = comsdup(c); | |
587 | - | |
588 | 598 | /* count the number of the commands */ |
589 | 599 | count = 0; |
590 | 600 | for (cc = c; cc != NULL; cc = cc->next) |
@@ -657,6 +667,7 @@ | ||
657 | 667 | } |
658 | 668 | } |
659 | 669 | |
670 | +done: | |
660 | 671 | handle_signals(); |
661 | 672 | |
662 | 673 | apply_errexit_errreturn(c); |
@@ -779,6 +790,20 @@ | ||
779 | 790 | xerror(errno, Ngt("cannot open a pipe")); |
780 | 791 | } |
781 | 792 | |
793 | +void exec_one_command(command_T *c, exec_T type) | |
794 | +{ | |
795 | + /* prevent the command data from being freed in case the command is part of | |
796 | + * a function that is unset during execution. */ | |
797 | + c = comsdup(c); | |
798 | + | |
799 | + if (c->c_type == CT_SIMPLE) { | |
800 | + } else { | |
801 | + } | |
802 | + // TODO implement exec_one_command | |
803 | + | |
804 | + comsfree(c); | |
805 | +} | |
806 | + | |
782 | 807 | /* Executes the command. |
783 | 808 | * If job control is active, the child process's process group ID is set to |
784 | 809 | * `pgid'. If `pgid' is 0, the child process's process ID is used as the process |