• R/O
  • SSH
  • HTTPS

yash: 提交


Commit MetaInfo

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

Log Message

Run subshell in child process

Change Summary

差異

--- yash/branches/exec/exec.c (revision 4126)
+++ yash/branches/exec/exec.c (revision 4127)
@@ -1170,16 +1170,38 @@
11701170 }
11711171
11721172 /* Executes the specified command whose type is not `CT_SIMPLE'.
1173- * The redirections for the command is not performed in this function.
1174- * For CT_SUBSHELL, this function must be called in an already-forked subshell.
1175- */
1173+ * The redirections for the command is not performed in this function. */
11761174 void exec_nonsimple_command(command_T *c, bool finally_exit)
11771175 {
1178- // TODO fork or become_child(0) if CT_GROUP
11791176 switch (c->c_type) {
11801177 case CT_SIMPLE:
11811178 assert(false);
11821179 case CT_SUBSHELL:
1180+ if (finally_exit) {
1181+ /* This is the last command to execute in the current shell, hence
1182+ * no need to make a new child. */
1183+ become_child(0);
1184+ } else {
1185+ /* make a child process to execute the command */
1186+ pid_t cpid = fork_and_reset(0, true, 0);
1187+ if (cpid < 0) {
1188+ /* parent process: fork failed */
1189+ laststatus = Exit_NOEXEC;
1190+ break;
1191+ } else if (cpid > 0) {
1192+ /* parent process: fork succeeded */
1193+ wchar_t **namep = wait_for_child(
1194+ cpid,
1195+ doing_job_control_now ? cpid : 0,
1196+ doing_job_control_now);
1197+ if (namep != NULL)
1198+ *namep = command_to_wcs(c, false);
1199+ break;
1200+ }
1201+ /* child process */
1202+ finally_exit = true;
1203+ }
1204+ // falls thru!
11831205 case CT_GROUP:
11841206 exec_and_or_lists(c->c_subcmds, finally_exit);
11851207 break;
Show on old repository browser