Blame SOURCES/cvs-1.11.22-stdinargs.patch

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