man command not working in lynxcgi script

Bug #992271 reported by Owen Leibman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libpipeline (Ubuntu)
Fix Released
Medium
Colin Watson
man-db (Ubuntu)
Fix Released
Medium
Colin Watson

Bug Description

I have made slight tweaks to the w3mman2html.cgi script supplied with w3m so that it is usable by other browsers, in particular lynx and firefox (I also use the script with lynx under windows/cygwin). However, an un-tweaked version will demonstrate this problem. Through Ubuntu 11.10, I was able to execute the script in lynx using the lynxcgi protocol. In Ubuntu 12.04, the script still works for w3m, of course, and for firefox; however, it no longer works for lynx. In order to try to narrow down the source of the problem, I altered the cgi script so that the command it issued wound up as:
/usr/bin/man -d apropos 2>temp.mand
(Note that this problem is not restricted to the apropos man page; all pages show the same results.)
Comparing the temp.mand files, which I am attaching to this report, the successful w3m run produces a 389-line log. The unsuccesful lynx version produces a 388-line log; the first 379 are identical to w3m, followed by an insertion:
gzip: standard input: Bad file descriptor
They then compare equal on the next line, but then 4 lines of w3m (indicating success) are replaced with 2 lines for lynx (indicating failure). The final 5 lines of each file then compare equal. Here are the differences reported by diff:

380d379
< gzip: standard input: Bad file descriptor
382,383c381,384
< cat-saver exited with status 1
< unlinking temporary cat
---
> cat-saver exited with status 0
> fixing temporary cat's mode
> renaming temporary cat to /var/cache/man/cat1/apropos.1.gz
> setting modtime on cat file /var/cache/man/cat1/apropos.1.gz

To get to this situation, the lynx.cfg file needs the following:
TRUSTED_LYNXCGI: /usr/lib/w3m/cgi-bin
LYNXCGI_ENVIRONMENT:PATH
LYNXCGI_ENVIRONMENT:LANG

The command to demonstrate the problem would then be:
lynx lynxcgi:/usr/lib/w3m/cgi-bin/w3mman2html.cgi?apropos

The command for w3m is: w3mman apropos

It is, of course, possible that the problem lies not with man-db but with lynx (it seems very unlikely to be with the cgi script). However, since man debug clearly shows a difference between the results of the script when run under one vs. the other, I am starting by reporting it as a man-db bug.

Revision history for this message
Owen Leibman (eclipsechasers2) wrote :
Revision history for this message
Colin Watson (cjwatson) wrote :

Thanks for your report, and sorry for my delay!

The distinguishing feature here is that lynx closes the CGI script's standard input. As a result, at some point man does roughly:

  last_input = open (filename, O_RDONLY);
  dup2 (last_input, 0);
  close (last_input);

But the "open" returns 0, since that's the first available file descriptor, so everything is now very confused. libpipeline needs to tolerate this situation.

affects: man-db (Ubuntu) → libpipeline (Ubuntu)
Changed in libpipeline (Ubuntu):
assignee: nobody → Colin Watson (cjwatson)
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Colin Watson (cjwatson) wrote :

On the man-db side, this is no longer an issue as of man-db 2.8.6 (Ubuntu 19.10 and newer), which ensures that the standard file descriptors are open.

It would probably still be helpful (if cumbersome) for libpipeline to tolerate this situation.

Changed in man-db (Ubuntu):
assignee: nobody → Colin Watson (cjwatson)
importance: Undecided → Medium
status: New → Fix Released
Revision history for this message
Colin Watson (cjwatson) wrote :

In fact, upon trying to do this in libpipeline, I've changed my mind: tolerating this situation there is far too fiddly and fragile. I've therefore decided to document this restriction instead, given that it's already fixed in man-db:

  https://git.savannah.gnu.org/cgit/libpipeline.git/commit/?id=f42a4472eefe730d5fc17a16af202eb30ed78795

Changed in libpipeline (Ubuntu):
status: Triaged → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libpipeline - 1.5.2-1ubuntu1

---------------
libpipeline (1.5.2-1ubuntu1) focal; urgency=medium

  * Make autopkgtests cross-test-friendly.

 -- Steve Langasek <email address hidden> Thu, 09 Jan 2020 08:45:21 -0800

Changed in libpipeline (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.