Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen When opening a ttys files, try path.<machine> f...



details:   https://anonhg.NetBSD.org/src/rev/f332058abd3c
branches:  trunk
changeset: 787732:f332058abd3c
user:      matt <matt%NetBSD.org@localhost>
date:      Sun Jun 30 07:50:54 2013 +0000

description:
When opening a ttys files, try path.<machine> first.  This helps
machine archs which have multiple ttys files (arm, mips, powerpc, m68k, sh3)

diffstat:

 lib/libc/gen/getttyent.c |  25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)

diffs (53 lines):

diff -r 7d6589159486 -r f332058abd3c lib/libc/gen/getttyent.c
--- a/lib/libc/gen/getttyent.c  Sun Jun 30 00:00:53 2013 +0000
+++ b/lib/libc/gen/getttyent.c  Sun Jun 30 07:50:54 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getttyent.c,v 1.24 2011/10/15 23:00:01 christos Exp $  */
+/*     $NetBSD: getttyent.c,v 1.25 2013/06/30 07:50:54 matt Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getttyent.c        8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getttyent.c,v 1.24 2011/10/15 23:00:01 christos Exp $");
+__RCSID("$NetBSD: getttyent.c,v 1.25 2013/06/30 07:50:54 matt Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -49,6 +49,9 @@
 #include <err.h>
 #include <stdlib.h>
 
+#include <sys/sysctl.h>
+#include <sys/utsname.h>
+
 #ifdef __weak_alias
 __weak_alias(endttyent,_endttyent)
 __weak_alias(getttyent,_getttyent)
@@ -223,7 +226,23 @@
        if (tf) {
                rewind(tf);
                return 1;
-       } else if ((tf = fopen(path, "re")) != NULL)
+       }
+
+       /*
+        * Try <path>.$MACHINE (e.g. etc/ttys.amd64)
+        */
+       char machine[_SYS_NMLN];
+       const int mib[] = { [0] = CTL_HW, [1] = HW_MACHINE, };
+       size_t len = sizeof(machine);
+
+        if (sysctl(mib, __arraycount(mib), machine, &len, NULL, 0) != -1) {
+               char npath[PATH_MAX];
+               (void)snprintf(npath, sizeof(npath), "%s.%s", path, machine);
+               if ((tf = fopen(npath, "re")) != NULL)
+                       return 1;
+       }
+
+       if ((tf = fopen(path, "re")) != NULL)
                return 1;
        return 0;
 }



Home | Main Index | Thread Index | Old Index