groff-commit
[Top][All Lists]
Advanced

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

[groff] 26/27: [groff]: Refactor pipeline error handling.


From: G. Branden Robinson
Subject: [groff] 26/27: [groff]: Refactor pipeline error handling.
Date: Sat, 2 Jul 2022 00:43:14 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 016020781be152d79244cf77f2cf6cf1fe1cff2c
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Jul 1 23:27:50 2022 -0500

    [groff]: Refactor pipeline error handling.
    
    * src/roff/groff/pipeline.c: Refactor.  Drop function rename via
      preprocessor macro usage.  Declare and define `c_error` by its correct
      name.
    
      (run_pipeline): Update call sites.  Stop flushing standard error
      stream after calling libgroff's `error` function (which `c_error`
      wraps); libgroff already guarantees this operation.
    
    Also add editor aid comments.
---
 ChangeLog                 |  9 +++++++++
 src/roff/groff/pipeline.c | 42 +++++++++++++++++++++++-------------------
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dbf5321e..5e9f9d00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-07-01  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/groff/pipeline.c: Refactor.  Drop function rename via
+       preprocessor macro usage.  Declare and define `c_error` by its
+       correct name.
+       (run_pipeline): Update call sites.  Stop flushing standard error
+       stream after calling libgroff's `error` function (which
+       `c_error` wraps); libgroff already guarantees this operation.
+
 2022-07-01  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/input.cpp (abort_request): Flush the standard
diff --git a/src/roff/groff/pipeline.c b/src/roff/groff/pipeline.c
index 154918b0..646c84f3 100644
--- a/src/roff/groff/pipeline.c
+++ b/src/roff/groff/pipeline.c
@@ -75,8 +75,6 @@ extern char *strerror();
 
 #include "pipeline.h"
 
-#define error c_error
-
 /* Prototype */
 int run_pipeline(int, char ***, int);
 
@@ -84,8 +82,10 @@ int run_pipeline(int, char ***, int);
 extern "C" {
 #endif
 
-extern void error(const char *, const char *, const char *, const char *);
-extern void c_fatal(const char *, const char *, const char *, const char *);
+extern void c_error(const char *, const char *, const char *,
+                   const char *);
+extern void c_fatal(const char *, const char *, const char *,
+                   const char *);
 extern const char *i_to_a(int);                /* from libgroff */
 
 #ifdef __cplusplus
@@ -305,9 +305,8 @@ int run_pipeline(int ncommands, char ***commands, int 
no_pipe)
       }
     }
     if ((pid = spawnvp(_P_NOWAIT, commands[i][0], commands[i])) < 0) {
-      error("couldn't exec %1: %2",
-           commands[i][0], strerror(errno), (char *)0);
-      fflush(stderr);                  /* just in case error() doesn't */
+      c_error("couldn't exec %1: %2",
+             commands[i][0], strerror(errno), (char *)0);
       _exit(EXEC_FAILED_EXIT_STATUS);
     }
     pids[i] = pid;
@@ -415,13 +414,12 @@ int run_pipeline(int ncommands, char ***commands, int 
no_pipe)
     exit_status = spawnvp(P_WAIT, commands[i][0], commands[i]);
     signal(SIGINT, prev_handler);
     if (child_interrupted) {
-      error("%1: Interrupted", commands[i][0], (char *)0, (char *)0);
+      c_error("%1: Interrupted", commands[i][0], (char *)0, (char *)0);
       ret |= 2;
     }
     else if (exit_status < 0) {
-      error("couldn't exec %1: %2",
-           commands[i][0], strerror(errno), (char *)0);
-      fflush(stderr);                  /* just in case error() doesn't */
+      c_error("couldn't exec %1: %2",
+             commands[i][0], strerror(errno), (char *)0);
       ret |= 4;
     }
     if (exit_status != 0)
@@ -485,9 +483,8 @@ int run_pipeline(int ncommands, char ***commands, int 
no_pipe)
          sys_fatal("close");
       }
       execvp(commands[i][0], commands[i]);
-      error("couldn't exec %1: %2",
-           commands[i][0], strerror(errno), (char *)0);
-      fflush(stderr);                  /* just in case error() doesn't */
+      c_error("couldn't exec %1: %2",
+             commands[i][0], strerror(errno), (char *)0);
       _exit(EXEC_FAILED_EXIT_STATUS);
     }
     /* in the parent */
@@ -535,10 +532,10 @@ int run_pipeline(int ncommands, char ***commands, int 
no_pipe)
          else
 #endif /* SIGPIPE */
          {
-           error("%1: %2%3",
-                 commands[i][0],
-                 xstrsignal(sig),
-                 WCOREDUMP(status) ? " (core dumped)" : "");
+           c_error("%1: %2%3",
+                   commands[i][0],
+                   xstrsignal(sig),
+                   WCOREDUMP(status) ? " (core dumped)" : "");
            ret |= 2;
          }
        }
@@ -551,7 +548,8 @@ int run_pipeline(int ncommands, char ***commands, int 
no_pipe)
            ret |= 1;
        }
        else
-         error("unexpected status %1", i_to_a(status), (char *)0, (char *)0);
+         c_error("unexpected status %1", i_to_a(status), (char *)0,
+                 (char *)0);
        break;
       }
   }
@@ -583,3 +581,9 @@ static const char *xstrsignal(int n)
   sprintf(buf, "Signal %d", n);
   return buf;
 }
+
+// Local Variables:
+// fill-column: 72
+// mode: C
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:



reply via email to

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