Return to BSD News archive
Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!ames!pacbell.com!amdahl!amdahl.uts.amdahl.com!agc
From: agc@uts.amdahl.com (Alistair G. Crooks)
Subject: Re: crash doing readdir of /dev: bug?
Message-ID: <1994May5.124147.3110@uts.amdahl.com>
Organization: Amdahl Corporation, Sunnyvale CA
References: <2qa9je$nhh@dingo.cc.uq.oz.au>
Date: Thu, 5 May 1994 12:41:47 GMT
Lines: 42
In article <2qa9je$nhh@dingo.cc.uq.oz.au> Danny Thomas <D.Thomas@vthrc.uq.edu.au> writes:
> 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?
Neither - you'll have to compile the code with -fwritable-strings, or
-traditional. Or use the code as modified below:
int
findpty (slave)
char **slave;
{
int master;
static char line[100];
DIR *dirp;
struct dirent *dp;
(void) strcpy(line, "/dev/ptyXX");
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);
}
Alistair
--
Alistair G. Crooks (agc@uts.amdahl.com) +44 252 346377
Amdahl European HQ, Dogmersfield Park, Hartley Wintney, Hants RG27 8TE, UK.
[These are only my opinions, and certainly not those of Amdahl Corporation]