]> granicus.if.org Git - sudo/commitdiff
Add debug warning if KERN_PROC sysctl fails or devname() can't
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 11 Jan 2012 19:09:16 +0000 (14:09 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 11 Jan 2012 19:09:16 +0000 (14:09 -0500)
resolve the tty device to a name.

src/sudo.c

index 025edb98063224035d021c65aae454abe3e33018..4124e8ffec0942fe8aea526c93be305f7b5c770f 100644 (file)
@@ -472,8 +472,18 @@ get_process_tty(void)
            ki_proc = erealloc(ki_proc, size);
            rc = sysctl(mib, sudo_kp_namelen, ki_proc, &size, NULL, 0);
        } while (rc == -1 && errno == ENOMEM);
-       if (rc != -1)
+       if (rc != -1) {
            tty = devname(ki_proc->sudo_kp_tdev, S_IFCHR);
+           if (*tty != '/') {
+               sudo_debug_printf(SUDO_DEBUG_WARN,
+                   "unable to map device number %u to name: %s",
+                   ki_proc->sudo_kp_tdev, tty);
+               tty = NULL;
+           }
+       } else {
+           sudo_debug_printf(SUDO_DEBUG_WARN,
+               "unable to resolve tty via KERN_PROC: %s", strerror(errno));
+       }
     }
 
     /* If all else fails, fall back on ttyname(). */
@@ -518,7 +528,7 @@ get_process_tty(void)
 
     debug_return_str(tty);
 }
-#endif /* HAVE_STRUCT_KINFO_PROC_KI_TDEV */
+#endif /* sudo_kp_tdev */
 
 /*
  * Return user information as an array of name=value pairs.