[PATCH] tty: Improve error handling and reporting

Juergen Hoetzel juergen at hoetzel.info
Sun May 3 16:34:00 CEST 2020


From: Juergen Hoetzel <juergen at archlinux.org>

* tty/pinentry-tty.c (tty_cmd_handler): Set specific_err,
specific_err_loc and return early if opening the ttyname fails.

Signed-off-by: Juergen Hoetzel <juergen at archlinux.org>
---
 tty/pinentry-tty.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tty/pinentry-tty.c b/tty/pinentry-tty.c
index 403dd60..fdffa0d 100644
--- a/tty/pinentry-tty.c
+++ b/tty/pinentry-tty.c
@@ -545,16 +545,20 @@ tty_cmd_handler (pinentry_t pinentry)
     {
       ttyfi = fopen (pinentry->ttyname, "r");
       if (!ttyfi)
-        rc = -1;
+        {
+          pinentry->specific_err = gpg_error_from_syserror ();
+          pinentry->specific_err_loc = "open_tty_for_read";
+          return -1;
+        }
       else
         {
           ttyfo = fopen (pinentry->ttyname, "w");
           if (!ttyfo)
             {
-              int err = errno;
+              pinentry->specific_err = gpg_error_from_syserror ();
+              pinentry->specific_err_loc = "open_tty_for_write";
               fclose (ttyfi);
-              errno = err;
-              rc = -1;
+              return -1;
             }
         }
     }
-- 
2.26.2




More information about the Gnupg-devel mailing list