• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision4011 (tree)
Time2019-12-22 22:56:00
Authormagicant

Log Message

Fork inside exec_simple_command

Previously the exec_simple_command function required the finally_exit
argument to be true when executed for CT_EXTERNALPROGRAM. I don't think
this implicit precondition very intuitive because it effectively
nullifies the finally_exit parameter.

Starting from this commit we fork inside the exec_simple_command
function to allow the parameter to be false.

Change Summary

Incremental Difference

--- yash/trunk/exec.c (revision 4010)
+++ yash/trunk/exec.c (revision 4011)
@@ -1241,7 +1241,22 @@
12411241 laststatus = Exit_NOTFOUND;
12421242 break;
12431243 case CT_EXTERNALPROGRAM:
1244- assert(finally_exit);
1244+ if (!finally_exit) {
1245+ pid_t cpid = fork_and_reset(0, true, t_leave);
1246+ if (cpid < 0) {
1247+ laststatus = Exit_NOEXEC;
1248+ break;
1249+ } else if (cpid > 0) {
1250+ wchar_t **namep = wait_for_child(
1251+ cpid,
1252+ doing_job_control_now ? cpid : 0,
1253+ doing_job_control_now);
1254+ if (namep != NULL)
1255+ *namep = joinwcsarray(argv, L" ");
1256+ break;
1257+ }
1258+ finally_exit = true;
1259+ }
12451260 exec_external_program(ci->ci_path, argc, argv0, argv, environ);
12461261 break;
12471262 case CT_SPECIALBUILTIN:
@@ -2295,7 +2310,6 @@
22952310 {
22962311 char *argv0 = malloc_wcstombs(argv[0]);
22972312 commandinfo_T ci;
2298- bool finally_exit = false;
22992313
23002314 if (argv0 == NULL) {
23012315 xerror(EILSEQ, NULL);
@@ -2303,24 +2317,7 @@
23032317 }
23042318
23052319 search_command(argv0, argv[0], &ci, type);
2306- if (ci.type == CT_EXTERNALPROGRAM) {
2307- pid_t cpid = fork_and_reset(0, true, t_leave);
2308- if (cpid < 0) {
2309- free(argv0);
2310- return Exit_NOEXEC;
2311- } else if (cpid > 0) {
2312- wchar_t **namep = wait_for_child(
2313- cpid,
2314- doing_job_control_now ? cpid : 0,
2315- doing_job_control_now);
2316- if (namep != NULL)
2317- *namep = joinwcsarray(argv, L" ");
2318- free(argv0);
2319- return laststatus;
2320- }
2321- finally_exit = true;
2322- }
2323- exec_simple_command(&ci, argc, argv0, argv, finally_exit);
2320+ exec_simple_command(&ci, argc, argv0, argv, false);
23242321 free(argv0);
23252322 return laststatus;
23262323 }
Show on old repository browser