Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/postinstall Don't rely on stat(1) with format "%SHr...



details:   https://anonhg.NetBSD.org/src/rev/a7ef3f495064
branches:  trunk
changeset: 781015:a7ef3f495064
user:      apb <apb%NetBSD.org@localhost>
date:      Wed Aug 15 12:48:19 2012 +0000

description:
Don't rely on stat(1) with format "%SHr" to print the correct names.
That uses devname(3) internally, which doesn't work at all in a cross
build environment, and doesn't do what I thought even in a native
environment.

Instead, parse the device major numbers for the pty master and slave
devices from the output of "MAKEDEV -s pty0" and check those against the
actual device node that we are thinking of removing.

diffstat:

 usr.sbin/postinstall/postinstall |  40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)

diffs (72 lines):

diff -r b29ac7450d8b -r a7ef3f495064 usr.sbin/postinstall/postinstall
--- a/usr.sbin/postinstall/postinstall  Wed Aug 15 08:09:57 2012 +0000
+++ b/usr.sbin/postinstall/postinstall  Wed Aug 15 12:48:19 2012 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall,v 1.144 2012/08/14 13:11:24 apb Exp $
+# $NetBSD: postinstall,v 1.145 2012/08/15 12:48:19 apb Exp $
 #
 # Copyright (c) 2002-2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -55,6 +55,7 @@
 : ${AWK:=awk}
 : ${DB:=db}
 : ${GREP:=grep}
+: ${HOST_SH:=sh}
 : ${MAKE:=make}
 : ${PWD_MKDB:=/usr/sbin/pwd_mkdb}
 : ${STAT:=stat}
@@ -1739,8 +1740,35 @@
                return 0
        fi
 
+       # Find the device major numbers for the pty master and slave
+       # devices, by parsing the output from "MAKEDEV -s pty0".
+       #
+       # Output from MAKEDEV looks like this:
+       # ./ttyp0 type=char device=netbsd,5,0 mode=666 gid=0 uid=0
+       # ./ptyp0 type=char device=netbsd,6,0 mode=666 gid=0 uid=0
+       #
+       # Output from awk, used in the eval statement, looks like this:
+       # maj_ptym=6; maj_ptys=5;
+       #
+       eval "$(
+           ${HOST_SH} "${DEST_DIR}/dev/MAKEDEV" -s pty0 2>/dev/null \
+           | ${AWK} '\
+           BEGIN { before_re = ".*device=[a-zA-Z]*,"; after_re = ",.*"; }
+           /ptyp0/ { maj_ptym = gensub(before_re, "", 1, $0);
+                     maj_ptym = gensub(after_re, "", 1, maj_ptym); }
+           /ttyp0/ { maj_ptys = gensub(before_re, "", 1, $0);
+                     maj_ptys = gensub(after_re, "", 1, maj_ptys); }
+           END { print "maj_ptym=" maj_ptym "; maj_ptys=" maj_ptys ";"; }
+           '
+           )"
+       #msg "Major numbers are maj_ptym=${maj_ptym} maj_ptys=${maj_ptys}"
+       if [ -z "$maj_ptym" ] || [ -z "$maj_ptys" ]; then
+               msg "Cannot find device major numbers for pty master and slave"
+               return 1
+       fi
+
        # look for /dev/[pt]ty[p-zP-T][0-9a-zA-Z], and check that they
-       # are tty or pty device nodes.  ttyv* is typically not a
+       # have the expected device major numbers.  ttyv* is typically not a
        # pty device, but we check it anyway.
        #
        # The "for d1" loop is intended to avoid overflowing ARG_MAX;
@@ -1753,9 +1781,13 @@
        #
        _ptyfs_tmp="$(mktemp /tmp/postinstall.ptyfs.XXXXXXXX)"
        for d1 in p q r s t u v w x y z P Q R S T; do
-               ${STAT} -f "%SHr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1
+               ${STAT} -f "%Hr %N" "${DEST_DIR}/dev/"[pt]ty${d1}? 2>&1
        done \
-       | ${AWK} '/^[pt]ty/ {print $2}' >"${_ptyfs_tmp}"
+       | while read -r major node ; do
+               case "$major" in
+               ${maj_ptym}|${maj_ptys}) echo "$node" ;;
+               esac
+       done >"${_ptyfs_tmp}"
 
        _desc="legacy device node"
        while read node; do



Home | Main Index | Thread Index | Old Index