Xref: utzoo comp.unix.wizards:20626 comp.lang.perl:389 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!decwrl!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.wizards,comp.lang.perl Subject: Re: Getting tty name without using ttyname(3) Message-ID: <7092@jpl-devvax.JPL.NASA.GOV> Date: 16 Feb 90 20:34:06 GMT References: <673@compel.UUCP> <15137:00:09:24@stealth.acf.nyu.edu> <17954@rpp386.cactus.org> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 75 In article <17954@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes: : How about using DBM? Write a program which takes filenames as arguments : and saves the names away using the device-inode as the index. To find the : name of your tty you would just make a request of the database. You could : then feed all of the tty device names to this program at boot-time to : create the index. You mean a little program like this? #!/usr/bin/perl chdir '/dev' || die "Can't cd to /dev: $!"; unlink 'devices.dir', 'devices.pag'; dbmopen(DEV,'devices',0644) || die "Can't dbmopen /dev/devices: $!"; foreach $file (grep( -c $_ || -b _, <*>)) { ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev) = stat $file; $DEV{sprintf("%d,%d", int($rdev / 256), $rdev % 256)} = $file; } It could also be done with makedbm, if you've got it. In fact, you could write makedbm in perl if you don't have it... In fact, here's a version that does everything but the YP claptrap. #!/usr/bin/perl $usage = <) { chop; while (/\\$/) { chop; $_ .= <>; chop; } ($key,$val) = split(/\s/,$_,2); $DBM{$key} = $val; } } You'd use it like this: ls -l /dev | \ sed -e '/^[^cb]/d' \ -e 's/.*\([0-9][0-9]*,\) *\([0-9][0-9]*\).* \(.*\)/\1\2 \3/' | \ makedbm - /dev/devices To list it out: makedbm -u /dev/devices Larry Wall lwall@jpl-devvax.jpl.nasa.gov