OSDN Git Service

Don't chmod /dev/ptmx when allocating a pty on Android.
authorGreg Hartman <ghartman@google.com>
Wed, 29 Jul 2015 22:38:15 +0000 (15:38 -0700)
committerGreg Hartman <ghartman@google.com>
Thu, 30 Jul 2015 17:59:13 +0000 (10:59 -0700)
This resolves an incompatibility with non-root adb.
BUG=22803455

Change-Id: I908923e9ddc04e0ec8de0122eb79486c8b1ae03e

sshpty.c

index af85259..5816922 100644 (file)
--- a/sshpty.c
+++ b/sshpty.c
@@ -73,16 +73,21 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
                return 0;
        }
 #ifdef ANDROID
-       /* Android does not have a working ttyname() */
-       name = "/dev/ptmx";
+       if (ptsname_r(*ptyfd, namebuf, namebuflen)) {
+               fatal("openpty ptsname failed.");
+               close(*ptyfd);
+               *ptyfd = -1;
+               return -1;
+       }
+       return 1;
 #else
        name = ttyname(*ttyfd);
        if (!name)
                fatal("openpty returns device for which ttyname fails.");
-#endif
 
        strlcpy(namebuf, name, namebuflen);     /* possible truncation */
        return 1;
+#endif
 }
 
 /* Releases the tty.  Its ownership is returned to root, and permissions to 0666. */