Blame SOURCES/cvs-1.11.22-stdinargs.patch

814382
--- cvs-1.11.22.orig/src/cvs.h	2008-09-09 13:46:07.000000000 -0400
814382
+++ cvs-1.11.22/src/cvs.h	2008-09-09 13:46:13.000000000 -0400
814382
@@ -695,6 +695,8 @@ void sleep_past PROTO ((time_t desttime)
814382
 #define	RUN_STDOUT_APPEND     0x0004    /* append to stdout, don't truncate */
814382
 #define	RUN_STDERR_APPEND     0x0008    /* append to stderr, don't truncate */
814382
 #define	RUN_SIGIGNORE         0x0010    /* ignore interrupts for command */
814382
+#define	RUN_PIPE              0x0020	/* pass the arguments by stdin instead
814382
+                                         * as arguments */
814382
 #define	RUN_TTY               (char *)0 /* for the benefit of lint */
814382
 
814382
 void run_add_arg_p PROTO ((int *, size_t *, char ***, const char *s));
814382
--- cvs-1.11.22.orig/src/run.c	2005-10-03 16:31:12.000000000 -0400
814382
+++ cvs-1.11.22/src/run.c	2008-09-09 13:49:15.000000000 -0400
814382
@@ -123,6 +123,8 @@ run_exec (stin, stout, sterr, flags)
814382
     int rc = -1;
814382
     int rerrno = 0;
814382
     int pid, w;
814382
+    int pipefd[2];
814382
+    char *run_argv2[3] = { NULL, "-", NULL };
814382
 
814382
 #ifdef POSIX_SIGNALS
814382
     sigset_t sigset_mask, sigset_omask;
814382
@@ -163,7 +165,26 @@ run_exec (stin, stout, sterr, flags)
814382
     mode_out |= ((flags & RUN_STDOUT_APPEND) ? O_APPEND : O_TRUNC);
814382
     mode_err |= ((flags & RUN_STDERR_APPEND) ? O_APPEND : O_TRUNC);
814382
 
814382
-    if (stin && (shin = open (stin, O_RDONLY)) == -1)
814382
+    if (*(run_argv[0]) == '|')
814382
+    {
814382
+        char *buf;
814382
+
814382
+        if (pipe(pipefd) == -1) {
814382
+           rerrno = errno;
814382
+           error (0, errno, "unable to open pipe");
814382
+           goto out0;
814382
+        }
814382
+        flags |= RUN_PIPE;
814382
+        shin = pipefd[0];
814382
+        buf = strdup(run_argv[0] + 1); /* skip '|' */
814382
+        if (buf == NULL) {
814382
+            rc = ENOMEM;
814382
+            error (0, errno, "unable to allocate memory");
814382
+            goto out1;
814382
+        }
814382
+        run_argv2[0] = buf;
814382
+    }
814382
+    else if (stin && (shin = open (stin, O_RDONLY)) == -1)
814382
     {
814382
 	rerrno = errno;
814382
 	error (0, errno, "cannot open %s for reading (prog %s)",
814382
@@ -239,8 +260,14 @@ run_exec (stin, stout, sterr, flags)
814382
 #endif
814382
 
814382
 	/* dup'ing is done.  try to run it now */
814382
-	(void) execvp (run_argv[0], run_argv);
814382
-	error (0, errno, "cannot exec %s", run_argv[0]);
814382
+        if (flags & RUN_PIPE) {
814382
+            close(pipefd[1]);
814382
+            (void) execvp (run_argv2[0], run_argv2);
814382
+	    error (0, errno, "cannot exec %s", run_argv2[0]);
814382
+        } else {
814382
+	    (void) execvp (run_argv[0], run_argv);
814382
+	    error (0, errno, "cannot exec %s", run_argv[0]);
814382
+        }
814382
 	_exit (127);
814382
     }
814382
     else if (pid == -1)
814382
@@ -283,6 +310,39 @@ run_exec (stin, stout, sterr, flags)
814382
 #endif
814382
 #endif
814382
 
814382
+    /* write all the arguments in the stdout if requested */
814382
+    if (flags & RUN_PIPE) {
814382
+        int size, s;
814382
+
814382
+	close(pipefd[0]);
814382
+        for (w = 0; run_argv[w] != NULL; w++) {
814382
+             size = strlen(run_argv[w]);
814382
+             s = 0;
814382
+             while (s < size) {
814382
+                 rc = write(pipefd[1], run_argv[w] + s, size - s);
814382
+                 if (rc < 0 && errno != EINTR) {
814382
+                     /* all other cases we'll just fail */
814382
+                     rerrno = errno;
814382
+                     error (0, errno, "unable to write to the application's stdin %s",
814382
+                            run_argv2[0]);
814382
+                     goto wait_for_process;
814382
+                 } else if (rc > 0)
814382
+                     s += rc;
814382
+             }
814382
+             do {
814382
+                 rc = write(pipefd[1], "\n", 1);
814382
+                 if (rc < 0 && errno != EINTR) {
814382
+                     rerrno = errno;
814382
+                     error (0, errno, "unable to write to the application's stdin %s",
814382
+                            run_argv2[0]);
814382
+                     goto wait_for_process;
814382
+                 }
814382
+             } while (rc != 1);
814382
+        }
814382
+wait_for_process:
814382
+        close(pipefd[1]);
814382
+        pipefd[1] = -1;
814382
+    }
814382
     /* wait for our process to die and munge return status */
814382
 #ifdef POSIX_SIGNALS
814382
     while ((w = waitpid (pid, &status, 0)) == -1 && errno == EINTR)
814382
@@ -356,7 +416,14 @@ run_exec (stin, stout, sterr, flags)
814382
 	 * relative to the protocol pipe
814382
 	 */
814382
 	cvs_flushout();
814382
+    if (flags & RUN_PIPE)
814382
+        free(run_argv2[0]);
814382
   out1:
814382
+    if (flags & RUN_PIPE) {
814382
+        shin = -1;
814382
+        if (pipefd[1] != -1)
814382
+            close(pipefd[1]);
814382
+    }
814382
     if (stin)
814382
 	(void) close (shin);