]> granicus.if.org Git - procps-ng/commitdiff
library: cygwin fixes for devname
authorCraig Small <csmall@dropbear.xyz>
Tue, 3 May 2022 10:33:44 +0000 (20:33 +1000)
committerCraig Small <csmall@dropbear.xyz>
Tue, 3 May 2022 10:33:44 +0000 (20:33 +1000)
Change the default name to cons%d

ctty can be used by other systems not just Cygwin so create a define
separate to cygwin for using the ctty function. The autoconf will need
to be updated to check for these specific systems in future.

Thanks to Achim of the Cygwin project for the patches.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
proc/devname.c

index 13b1b8a48a5d321ce4920b029338654a58ed0c94..1cc6bc78c8c0b6aa4d9c40ab09c7ab36e8a85d13 100644 (file)
@@ -207,7 +207,7 @@ static int guess_name(char *restrict const buf, unsigned maj, unsigned min){
   case   3:      /* /dev/[pt]ty[p-za-o][0-9a-z] is 936 */
     if(tmpmin > 255) return 0;   // should never happen; array index protection
 #ifdef __CYGWIN__
-    sprintf(buf, "dev/cons%d", tmpmin);
+    sprintf(buf, "cons%d", tmpmin);
     /* Skip stat call.  The reason is that cons devices are local to
      * the processes running in that console.  Calling stat from another
      * console or pty will return -1. */
@@ -295,7 +295,7 @@ static int link_name(char *restrict const buf, unsigned maj, unsigned min, int p
   return 1;
 }
 
-#ifdef __CYGWIN__
+#ifdef USE_PROC_CTTY
 /* Cygwin keeps the name to the controlling tty in a virtual file called
    /proc/PID/ctty, including a trailing LF (sigh). */
 static int ctty_name(char *restrict const buf, int pid) {
@@ -326,7 +326,7 @@ unsigned dev_to_tty(char *restrict ret, unsigned chop, dev_t dev_t_dev, int pid,
   unsigned dev = dev_t_dev;
   unsigned i = 0;
   int c;
-#ifdef __CYGWIN__
+#ifdef USE_PROC_CTTY
   if(  ctty_name(tmp, pid                                        )) goto abbrev;
 #endif
   if(dev == 0u) goto no_tty;