• R/O
  • SSH
  • HTTPS

yash: 提交


Commit MetaInfo

修訂4122 (tree)
時間2020-11-02 23:08:14
作者magicant

Log Message

Template of exec_one_command

Change Summary

差異

--- yash/branches/exec/exec.c (revision 4121)
+++ yash/branches/exec/exec.c (revision 4122)
@@ -154,6 +154,9 @@
154154 __attribute__((pure));
155155 static inline void next_pipe(pipeinfo_T *pi, bool next)
156156 __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
157160 static pid_t exec_process(
158161 command_T *restrict c, exec_T type, pipeinfo_T *restrict pi, pid_t pgid)
159162 __attribute__((nonnull));
@@ -574,6 +577,17 @@
574577 /* Executes the commands in a pipeline. */
575578 void exec_commands(command_T *c, exec_T type)
576579 {
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
577591 size_t count;
578592 pid_t pgid;
579593 command_T *cc;
@@ -581,10 +595,6 @@
581595 process_T *ps, *pp;
582596 pipeinfo_T pinfo = PIPEINFO_INIT;
583597
584- /* increment the reference count of `c' to prevent `c' from being freed
585- * during execution. */
586- c = comsdup(c);
587-
588598 /* count the number of the commands */
589599 count = 0;
590600 for (cc = c; cc != NULL; cc = cc->next)
@@ -657,6 +667,7 @@
657667 }
658668 }
659669
670+done:
660671 handle_signals();
661672
662673 apply_errexit_errreturn(c);
@@ -779,6 +790,20 @@
779790 xerror(errno, Ngt("cannot open a pipe"));
780791 }
781792
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+
782807 /* Executes the command.
783808 * If job control is active, the child process's process group ID is set to
784809 * `pgid'. If `pgid' is 0, the child process's process ID is used as the process
Show on old repository browser