chiark / gitweb /
util: properly identify pty devices by their major
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Mar 2011 01:33:23 +0000 (02:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 Mar 2011 02:12:25 +0000 (03:12 +0100)
src/util.c
src/util.h

index c9366c4..ee6217d 100644 (file)
@@ -2865,7 +2865,7 @@ int getttyname_harder(int fd, char **r) {
 
         if (streq(s, "tty")) {
                 free(s);
 
         if (streq(s, "tty")) {
                 free(s);
-                return get_ctty(r);
+                return get_ctty(r, NULL);
         }
 
         *r = s;
         }
 
         *r = s;
@@ -2907,7 +2907,7 @@ int get_ctty_devnr(dev_t *d) {
         return 0;
 }
 
         return 0;
 }
 
-int get_ctty(char **r) {
+int get_ctty(char **r, dev_t *_devnr) {
         int k;
         char fn[128], *s, *b, *p;
         dev_t devnr;
         int k;
         char fn[128], *s, *b, *p;
         dev_t devnr;
@@ -2925,6 +2925,18 @@ int get_ctty(char **r) {
                 if (k != -ENOENT)
                         return k;
 
                 if (k != -ENOENT)
                         return k;
 
+                /* This is an ugly hack */
+                if (major(devnr) == 136) {
+                        if (asprintf(&b, "pts/%lu", (unsigned long) minor(devnr)) < 0)
+                                return -ENOMEM;
+
+                        *r = b;
+                        if (_devnr)
+                                *_devnr = devnr;
+
+                        return 0;
+                }
+
                 /* Probably something like the ptys which have no
                  * symlink in /dev/char. Let's return something
                  * vaguely useful. */
                 /* Probably something like the ptys which have no
                  * symlink in /dev/char. Let's return something
                  * vaguely useful. */
@@ -2933,6 +2945,9 @@ int get_ctty(char **r) {
                         return -ENOMEM;
 
                 *r = b;
                         return -ENOMEM;
 
                 *r = b;
+                if (_devnr)
+                        *_devnr = devnr;
+
                 return 0;
         }
 
                 return 0;
         }
 
@@ -2950,6 +2965,9 @@ int get_ctty(char **r) {
                 return -ENOMEM;
 
         *r = b;
                 return -ENOMEM;
 
         *r = b;
+        if (_devnr)
+                *_devnr = devnr;
+
         return 0;
 }
 
         return 0;
 }
 
index 13e5f62..320bcd7 100644 (file)
@@ -337,7 +337,7 @@ int getttyname_malloc(int fd, char **r);
 int getttyname_harder(int fd, char **r);
 
 int get_ctty_devnr(dev_t *d);
 int getttyname_harder(int fd, char **r);
 
 int get_ctty_devnr(dev_t *d);
-int get_ctty(char **r);
+int get_ctty(char **r, dev_t *_devnr);
 
 int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
 
 
 int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);