*BSD News Article 30161


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!arundel.vthrc.uq.oz.au!D.Thomas
From: Danny Thomas <D.Thomas@vthrc.uq.edu.au>
Newsgroups: comp.os.386bsd.bugs
Subject: crash doing readdir of /dev: bug?
Date: 5 May 1994 08:09:18 GMT
Organization: Vision, Touch & Hearing Research Centre
Lines: 39
Distribution: world
Message-ID: <2qa9je$nhh@dingo.cc.uq.oz.au>
NNTP-Posting-Host: arundel.vthrc.uq.oz.au
X-Newsreader: Nuntius Version 1.2
X-XXMessage-ID: <A9EEE99EF7010415@arundel.vthrc.uq.oz.au>
X-XXDate: Thu, 5 May 1994 02:21:18 GMT

the following code core dumps under (PC) NetBSD 0.9 in traversing the
/dev directory. I added a syslog as the first part of the while{} body,
and the last file it reports is rsd1h. Actually it doesn't seem to crash
at the same point - tty00 fd1b etc (doing ls -lf). Is this a known
problem, or is the code bad?

cheers,
Danny Thomas

PS it's not my code, but I guess you could get around it by explicitly
opening the possible /dev/pty?? files.
PPS I also added a check for the opendir returning a NULL (it wasn't) but
it doesn't seem this is necessary.


findpty (slave)
char **slave;
{
   int master;
   static char *line = "/dev/ptyXX";
   DIR *dirp;
   struct dirent *dp;

   dirp = opendir("/dev");
   while ((dp = readdir(dirp)) != NULL) {
      if (strncmp(dp->d_name, "pty", 3) == 0 && strlen(dp->d_name) == 5) {
         line[8] = dp->d_name[3];
         line[9] = dp->d_name[4];
         if ((master = open(line, O_RDWR)) >= 0) {
            line[5] = 't';
            *slave = line;
            closedir(dirp);
            return (master);
         }
      }
   }
   closedir(dirp);
   return (-1);
}