]> granicus.if.org Git - procps-ng/commitdiff
library: find tty device name of process quicker
authorSimon Tatham <anakin@pobox.com>
Sun, 3 Jul 2016 00:08:18 +0000 (10:08 +1000)
committerCraig Small <csmall@enc.com.au>
Sun, 3 Jul 2016 00:47:25 +0000 (10:47 +1000)
The procps library attempts to work out the tty of a process
through several methods. For things like /dev/tty123 or
/dev/foo it works fine.

For tty devices that put the minor number in a directory
of the major name this fails. So then we have to fallback
to stating things like the processes STDERR and try again.

Considering a lot of processes sit on ttys such as
/dev/pts/3 this is a lot of wasted time. At the point of
entering driver_name we know "/dev/pts" and we know "3"
we just didn't join them up the right way as this is old
code.

This change now looks for /dev/pts/3 as well. It does it
after looking for /dev/pts3 so the behaviour is the same.

References:
 https://bugs.debian.org/770215

Signed-off-by: Craig Small <csmall@enc.com.au>
NEWS
proc/devname.c

diff --git a/NEWS b/NEWS
index c884b15f3afd85d0d4d6a773fb7ac932764f71d5..c160a4a7d9a2bf76dc0cf44b73b23cf3a693ef98 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,8 +5,9 @@ procps-ng-NEXT
   * ps: Fallback to attr/current for context Debian #786956
   * tests: Conditionally add prctl Debian #816237
   * pidof: check cmd if space in argv0. GitLab #4
-  * kill: report error if cannot kill process #733172
+  * kill: report error if cannot kill process Debian #733172
   * watch: Add hostname to header
+  * library: Find tty quicker Debian #770215
 
 procps-ng-3.3.11
 ----------------
index e6d0b554c00f15f62ca5d2d4a0b9c3e5ebfc55e6..10b7845dc7341bce3ce654105e15f4f0f479ee1a 100644 (file)
@@ -132,9 +132,12 @@ static int driver_name(char *restrict const buf, unsigned maj, unsigned min){
   }
   sprintf(buf, "/dev/%s%d", tmn->name, min);  /* like "/dev/ttyZZ255" */
   if(stat(buf, &sbuf) < 0){
-    if(tmn->devfs_type) return 0;
-    sprintf(buf, "/dev/%s", tmn->name);  /* like "/dev/ttyZZ255" */
-    if(stat(buf, &sbuf) < 0) return 0;
+    sprintf(buf, "/dev/%s/%d", tmn->name, min);  /* like "/dev/pts/255" */
+    if(stat(buf, &sbuf) < 0){
+      if(tmn->devfs_type) return 0;
+      sprintf(buf, "/dev/%s", tmn->name);  /* like "/dev/ttyZZ255" */
+      if(stat(buf, &sbuf) < 0) return 0;
+    }
   }
   if(min != MINOR_OF(sbuf.st_rdev)) return 0;
   if(maj != MAJOR_OF(sbuf.st_rdev)) return 0;