tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: [PATCH] Fix "Wait: No Child Process"
Date: Tue, 10 Mar 2015 04:23:41 +0100	[thread overview]
Message-ID: <20150310032341.GB18431@athene.usta.de> (raw)
In-Reply-To: <54FE0AFA.3070909@bsd.lv>

Hi Kristaps,

Kristaps Dzonsons wrote on Mon, Mar 09, 2015 at 10:04:58PM +0100:

> I'm still getting this error on Mac OS X, only for gzip'd files
> when invoked as man(1).  Invoking directly as mandoc(1) does not
> cause the issue.

Gah, there was indeed a second issue causing this symptom, unrelated
to the one reported by bapt@.  It was introduced as a side effect of
main.c rev. 1.212 ("do not spawn a pager when there is no output").

Fixed now...

Thanks for reporting,
  Ingo


Log Message:
-----------
Fix a regression caused in rev. 1.212, reported by kristaps@:

When using a pager and the first manual shown is gzip'ed,
the gunzip(1) process ended up as a child of the pager process
such that the man(1) process couldn't wait for it, preventing
proper display of the manual.

Solve this by making the pager a child of the man(1) process
(instead of the other way round), which requires being a bit
more careful about properly closing file descriptors after use
and waiting for the pager before exiting man(1).

Modified Files:
--------------
    mdocml:
        main.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/main.c,v
retrieving revision 1.223
retrieving revision 1.224
diff -Lmain.c -Lmain.c -u -p -r1.223 -r1.224
--- main.c
+++ main.c
@@ -20,6 +20,7 @@
 
 #include <sys/types.h>
 #include <sys/param.h>	/* MACHINE */
+#include <sys/wait.h>
 
 #include <assert.h>
 #include <ctype.h>
@@ -481,6 +482,21 @@ out:
 
 	free(defos);
 
+	/*
+	 * Flush the output and signal end of file.
+	 * If a pager is attached, it allows browsing to the end.
+	 * Otherwise, it does no harm, we are about to exit anyway.
+	 */
+
+	fclose(stdout);
+
+	/*
+	 * If we spawned a pager, wait for the user to close it.
+	 * Otherwise, this call fails with no adverse effect.
+	 */
+
+	wait(NULL);
+
 	return((int)rc);
 }
 
@@ -951,18 +967,19 @@ spawn_pager(void)
 		    progname, strerror(errno));
 		exit((int)MANDOCLEVEL_SYSERR);
 	case 0:
+		break;
+	default:
 		close(fildes[0]);
 		if (dup2(fildes[1], STDOUT_FILENO) == -1) {
 			fprintf(stderr, "%s: dup output: %s\n",
 			    progname, strerror(errno));
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
+		close(fildes[1]);
 		return;
-	default:
-		break;
 	}
 
-	/* The original process becomes the pager. */
+	/* The child process becomes the pager. */
 
 	close(fildes[1]);
 	if (dup2(fildes[0], STDIN_FILENO) == -1) {
@@ -970,6 +987,7 @@ spawn_pager(void)
 		    progname, strerror(errno));
 		exit((int)MANDOCLEVEL_SYSERR);
 	}
+	close(fildes[0]);
 
 	pager = getenv("MANPAGER");
 	if (pager == NULL || *pager == '\0')
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

      reply	other threads:[~2015-03-10  3:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 10:55 Baptiste Daroussin
2015-03-02 14:56 ` Ingo Schwarze
2015-03-09 21:04   ` Kristaps Dzonsons
2015-03-10  3:23     ` Ingo Schwarze [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150310032341.GB18431@athene.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).