gbranden pushed a commit to branch master
in repository groff.
commit 0ae673870c555055eaba7c1ecedaca30ff638acd
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Oct 16 10:35:59 2026 -0500
[mm]: Fix Savannah #68782.
* contrib/mm/mmroff.pl: Decode wait status on pipeline failure, to
better inform the user lacking intimate knowledge of the Unix process
spawning and reaping model. Copy the "abort/autopsy" technique from
groff's "pdfmom.pl".
Fixes <https://savannah.gnu.org/bugs/?68782>. Thanks to Bruno Haible,
John Gardner, Ingo Schwarze, and the mononymous Mike for discussion on
the groff mailing list.
Before:
$ printf '.P\nThis is my\n.I mmroff\ndocument.\n' | ./build/mmroff \
&& echo exit status zero
exit status zero
$ printf '.P\nThis is my\n.I mmroff\ndocument.\n.ab\n' | ./build/mmroff
mmroff: fatal error: "groff -rRef=1 -z -mm " exited with status 1024
Now:
$ printf '.P\nThis is my\n.I mmroff\ndocument.\n' | ./build/mmroff \
&& echo exit status zero
$ printf '.P\nThis is my\n.I mmroff\ndocument.\n.ab\n' | ./build/mmroff
mmroff: fatal error: groff exited with status 4
ANNOUNCE: Acknowledge Mike.
---
ANNOUNCE | 1 +
contrib/mm/ChangeLog | 11 +++++++++++
contrib/mm/mmroff.pl | 45 +++++++++++++++++++++++++++++++++------------
3 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/ANNOUNCE b/ANNOUNCE
index 1676c37dc..498ec0f51 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -254,6 +254,7 @@ Karl Berry
Larry Kollar
Luis Rivera
Martin Simmons
+Mike
Morten Bo Johansen
Nguyễn Gia Phong
Pavol Sloboda
diff --git a/contrib/mm/ChangeLog b/contrib/mm/ChangeLog
index 4bc95c18e..b48b1a2b5 100644
--- a/contrib/mm/ChangeLog
+++ b/contrib/mm/ChangeLog
@@ -1,3 +1,14 @@
+2026-10-16 G. Branden Robinson <[email protected]>
+
+ * mmroff.pl: Fix Savannah #68782. Decode wait status on
+ pipeline failure, to better inform the user lacking intimate
+ knowledge of the Unix process spawning and reaping model. Copy
+ the "abort/autopsy" technique from groff's "pdfmom.pl".
+
+ Fixes <https://savannah.gnu.org/bugs/?68782>. Thanks to Bruno
+ Haible, John Gardner, Ingo Schwarze, and the mononymous Mike for
+ discussion on the groff mailing list.
+
2026-10-16 G. Branden Robinson <[email protected]>
* mmroff.pl: Use Perl more idiomatically. Use `or` as
diff --git a/contrib/mm/mmroff.pl b/contrib/mm/mmroff.pl
index d557193bf..a258b4ff1 100644
--- a/contrib/mm/mmroff.pl
+++ b/contrib/mm/mmroff.pl
@@ -1,6 +1,6 @@
#!@PERL@
-# Copyright 2000 Free Software Foundation, Inc.
-# 2023 G. Branden Robinson
+# Copyright 2000 Free Software Foundation, Inc.
+# 2023-2026 G. Branden Robinson
#
# This file is part of mm, a reimplementation of the Documenter's
# Workbench (DWB) troff memorandum macro package for use with GNU troff.
@@ -30,9 +30,32 @@ use Config;
(my $progname = $0) =~s @.*/@@;
-sub Die {
- print STDERR "$progname: fatal error: @_\n";
- exit 1;
+my $groff; # forward declaration for `autopsy`
+
+sub abort
+{
+ my $message=shift(@_);
+ print STDERR "$progname: fatal error: $message";
+ exit 1;
+}
+
+sub autopsy
+{
+ my $waitstatus=shift(@_);
+ my $finding;
+
+ if ($waitstatus == -1) {
+ $finding = "cannot run groff: $!\n";
+ }
+ elsif ($? & 127) {
+ $finding = sprintf("$groff died with signal %d, %s core dump\n",
+ ($? & 127), ($? & 128) ? 'with' : 'without');
+ }
+ else {
+ $finding = sprintf("$groff exited with status %d\n", $? >> 8);
+ }
+
+ return $finding;
}
# runs groff in safe mode, that seems to be the default
@@ -72,7 +95,6 @@ if (grep(/^-x$/, @ARGV)) {
# Locate groff executable.
my $path = $ENV{'GROFF_BIN_PATH'};
-my $groff;
if ($path) {
for my $dir (split($Config{path_sep}, $path)) {
@@ -95,7 +117,7 @@ my (%cur, $rfilename, $imacro, @out, @indi);
my $max_height = 0;
my $max_width = 0;
open(MACRO, "$first_pass 2>&1 |")
- or Die("cannot run pipeline \"$first_pass\": $!");
+ or abort("cannot run pipeline \"$first_pass\": $!");
while(<MACRO>) {
if (m#^\.\\" Rfilename: (\S+)#) {
# remove all directories just to be more secure
@@ -140,9 +162,8 @@ while(<MACRO>) {
s#\\ \\ $##;
push(@out, $_);
}
-close(MACRO)
- or Die($! ? "error closing pipeline \"$first_pass\": $!"
- : "\"$first_pass\" exited with status $?");
+my $waitstatus = close(MACRO);
+abort(autopsy($?)) unless $waitstatus == 1; # roughly `WIFEXITED()`
# TODO: We should write out references only if there are any; a document
# that uses only `PIC` might lack them.
@@ -152,7 +173,7 @@ if ($rfilename) {
push(@out, ".nr pict*max-width $max_width\n") if defined $max_width;
open(OUT, ">$rfilename")
- or Die("cannot create file \"$rfilename\": $!");
+ or abort("cannot create file \"$rfilename\": $!");
print OUT '.\" references', "\n";
my $i;
for $i (@out) {
@@ -167,7 +188,7 @@ exit system($second_pass);
sub print_index {
my ($f, $ind, $macro) = @_;
- open(OUT, ">$f") or Die("cannot create file \"$f\": $!");
+ open(OUT, ">$f") or abort("cannot create file \"$f\": $!");
my $i;
for $i (sort @$ind) {
if ($macro) {
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit