Module Name:    src
Committed By:   matt
Date:           Sun Jun 30 07:50:54 UTC 2013

Modified Files:
        src/lib/libc/gen: getttyent.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/gen/getttyent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/gen/getttyent.c
diff -u src/lib/libc/gen/getttyent.c:1.24 src/lib/libc/gen/getttyent.c:1.25
--- src/lib/libc/gen/getttyent.c:1.24	Sat Oct 15 23:00:01 2011
+++ src/lib/libc/gen/getttyent.c	Sun Jun 30 07:50:54 2013
@@ -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 @@ __RCSID("$NetBSD: getttyent.c,v 1.24 201
 #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 @@ setttyentpath(const char *path)
 	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;
 }

Reply via email to