texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5713] fall back for following links in manpages


From: Gavin D. Smith
Subject: [5713] fall back for following links in manpages
Date: Mon, 21 Jul 2014 22:14:14 +0000

Revision: 5713
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5713
Author:   gavin
Date:     2014-07-21 22:14:13 +0000 (Mon, 21 Jul 2014)
Log Message:
-----------
fall back for following links in manpages

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/man.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-07-18 22:40:50 UTC (rev 5712)
+++ trunk/ChangeLog     2014-07-21 22:14:13 UTC (rev 5713)
@@ -1,3 +1,13 @@
+2014-07-21  Gavin Smith  <address@hidden>
+
+       * info/man.c (get_manpage_contents): Try getting manpage with -a
+       if not found in the section given.
+       (get_manpage_from_formatter): Split out from get_manpage_contents.
+       Don't set a signal handler for SIGCHLD.  Wait for child process to
+       exit before returning.
+       (reap_children): Merged into caller.
+       (read_from_fd): Comment added.
+
 2014-07-18  Gavin Smith  <address@hidden>
 
        * info/t/Init-inter.inc (run_ginfo): Try to get process ID of ginfo

Modified: trunk/info/man.c
===================================================================
--- trunk/info/man.c    2014-07-18 22:40:50 UTC (rev 5712)
+++ trunk/info/man.c    2014-07-21 22:14:13 UTC (rev 5713)
@@ -258,14 +258,6 @@
     }
 }
 
-#if PIPE_USE_FORK
-static void
-reap_children (int sig)
-{
-  wait (NULL);
-}
-#endif
-
 void
 clean_manpage (char *manpage)
 {
@@ -311,15 +303,13 @@
   free (newpage);
 }
 
+static char *get_manpage_from_formatter (char *formatter_args[]);
+
 static char *
 get_manpage_contents (char *pagename)
 {
   static char *formatter_args[4] = { NULL };
-  int pipes[2];
-  pid_t child;
-  RETSIGTYPE (*sigsave) (int signum);
-  char *formatted_page = NULL;
-  int arg_index = 1;
+  char *formatted_page;
 
   if (formatter_args[0] == NULL)
     formatter_args[0] = find_man_formatter ();
@@ -330,21 +320,39 @@
   get_page_and_section (pagename);
 
   if (manpage_section)
-    formatter_args[arg_index++] = manpage_section;
+    formatter_args[1] = manpage_section;
   else
-    formatter_args[arg_index++] = "-a";
+    formatter_args[1] = "-a";
 
-  formatter_args[arg_index++] = manpage_pagename;
-  formatter_args[arg_index] = NULL;
+  formatter_args[2] = manpage_pagename;
+  formatter_args[3] = NULL;
 
+  formatted_page = get_manpage_from_formatter (formatter_args);
+
+  /* If there was a section and the page wasn't found, try again
+     without the section (e.g. "man 3X curses" versus "man -a curses"). */
+  if (!formatted_page && manpage_section)
+    {
+      formatter_args[1] = "-a";
+      formatted_page = get_manpage_from_formatter (formatter_args);
+    }
+
+  return formatted_page;
+}
+
+static char *
+get_manpage_from_formatter (char *formatter_args[])
+{
+  char *formatted_page = NULL;
+  int pipes[2];
+  pid_t child;
+
   /* Open a pipe to this program, read the output, and save it away
      in FORMATTED_PAGE.  The reader end of the pipe is pipes[0]; the
      writer end is pipes[1]. */
 #if PIPE_USE_FORK
   pipe (pipes);
 
-  sigsave = signal (SIGCHLD, reap_children);
-
   child = fork ();
   if (child == -1)
     return NULL;
@@ -356,7 +364,7 @@
       close (pipes[1]);
       formatted_page = read_from_fd (pipes[0]);
       close (pipes[0]);
-      signal (SIGCHLD, sigsave);
+      wait (NULL); /* Wait for child process to exit. */
     }
   else
     { /* In the child, close the read end of the pipe, make the write end
@@ -418,6 +426,8 @@
   return formatted_page;
 }
 
+/* Return pointer to bytes read from file descriptor FD.  Return value to be
+   freed by caller. */
 static char *
 read_from_fd (int fd)
 {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]