shithub: vim

Download patch

ref: e28220f13a086e7283dd4b5285a8c49f5c650399
parent: 2a83ebb7dc6f8f719e2018df7a3a6b090e6541c9
author: phil9 <telephil9@gmail.com>
date: Wed Dec 22 06:15:02 EST 2021

fix command execution

	- replace fork() call with rfork() including RFNOTEG to prevent notes being
	propagated to the parent process and killing unwanted stuff
	- replace call to exit() with _exit() to prevent calling atexit() functions
	and also killing unwanted stuff
	- do not redirect command output ourselves as VIM is actually redirecting
	to temporary files and then using these files

--- a/os_plan9.c
+++ b/os_plan9.c
@@ -1154,38 +1154,27 @@
 }
 #endif
 
-int mch_call_shell(char_u *cmd, int options) {
-    USED(options);
-    int p[2];
-    int pid;
+int
+mch_call_shell(char_u *cmd, int options)
+{
+    pid_t pid;
     int status;
 
-    status = FAIL;
-    if(pipe(p) < 0) {
-	return FAIL;
-    }
-    pid = rfork(RFPROC|RFFDG|RFENVG);
-    switch(pid) {
-    case -1:
-	close(p[0]);
-	close(p[1]);
-	return FAIL;
-    case 0:
-	close(p[0]);
-	dup2(p[1], 1);
-	dup2(2, 1);
-	if (cmd) {
-	    execl("/bin/rc", "rc", "-c", (char*)cmd, NULL);
-	} else {
+    if(options & SHELL_COOKED)
+	settmode(TMODE_COOK);
+
+    pid = rfork(RFPROC|RFFDG|RFENVG|RFNOTEG);
+    if(pid < 0)
+	return -1;
+    if(pid == 0){
+	if (cmd) 
+	    execl("/bin/rc", "rc", "-c", cmd, NULL);
+	 else 
 	    execl("/bin/rc", "rc", NULL);
-	}
-	exit(122);
-	break;
-    case 1:
-	waitpid(pid, &status, 0);
-	close(p[0]);
-	close(p[1]);
-	break;
+	
+	_exit(122);
     }
+    waitpid(pid, &status, 0);
     return status;
 }
+