]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Unix Pageant: factor out have_controlling_tty().
authorSimon Tatham <anakin@pobox.com>
Wed, 13 May 2015 12:54:15 +0000 (13:54 +0100)
committerSimon Tatham <anakin@pobox.com>
Wed, 13 May 2015 13:00:29 +0000 (14:00 +0100)
I'm going to want to reuse it when deciding on a passphrase-prompting
strategy.

unix/uxpgnt.c

index 0329f6b9359dd54f2e553267cf96df087db9953a..a641a2e5cf035972422805dfd22acae80afe27e4 100644 (file)
@@ -269,6 +269,21 @@ void add_keyact(keyact action, const char *filename)
     keyact_tail = a;
 }
 
+int have_controlling_tty(void)
+{
+    int fd = open("/dev/tty", O_RDONLY);
+    if (fd < 0) {
+        if (errno != ENXIO) {
+            perror("/dev/tty: open");
+            exit(1);
+        }
+        return FALSE;
+    } else {
+        close(fd);
+        return TRUE;
+    }
+}
+
 char **exec_args = NULL;
 enum {
     LIFE_UNSPEC, LIFE_X11, LIFE_TTY, LIFE_DEBUG, LIFE_PERM, LIFE_EXEC
@@ -840,16 +855,9 @@ void run_agent(void)
              * our containing tty session has ended, so it's time to
              * clean up and leave.
              */
-            int fd = open("/dev/tty", O_RDONLY);
-            if (fd < 0) {
-                if (errno != ENXIO) {
-                    perror("/dev/tty: open");
-                    exit(1);
-                }
+            if (!have_controlling_tty()) {
                 time_to_die = TRUE;
                 break;
-            } else {
-                close(fd);
             }
         }