Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Dec 1998 14:46:35 +0100 (CET)
From:      Cejka Rudolf <cejkar@dcse.fee.vutbr.cz>
To:        freebsd-current@FreeBSD.ORG (freebsd-current@freebsd.org)
Subject:   mkfifo()/select() & O_RDONLY serious bug?
Message-ID:  <199812101346.OAA12755@kazi.dcse.fee.vutbr.cz>

next in thread | raw e-mail | index | archive | help

I have prepared small testing program (listed at the end) with mkfifo()
and select() calls. Fifo is opened as O_RDONLY or O_RDWR with O_NONBLOCK.
On FreeBSD 3.0-CURRENT, its behavior is different from other systems.
I think it is serious bug: select() returns that there is ready file
descriptor but descriptor is not ready in fact. I'm right?

Tested on systems:
	FreeBSD 3.0-CURRENT
	FreeBSD 2.2.7
	Solaris 2.6
	Unixware 2.1
	Linux Debian 2.0

{
Another bug: On FreeBSD systems I must use "#include <string.h>" for
FD_ZERO() because of bzero() function. Yes? (If not, we need to fix
manual page for select(2) about needed includes.)
}

Results with "#define MODE O_RDWR": (It looks well.)

test: Open...
test: FD = 3
test: Read...
test: read(tst.pipe): Resource temporarily unavailable
test: Select...
test: select(): Not ready			# After timeout

Results with "#define MODE O_RDONLY": (It looks bad for -current.)

test: Open...
test: FD = 3
test: Read...
	# Next line is only on FreeBSD 2.2.7: (So is it bug on FreeBSD 2.2.7?)
test: read(tst.pipe): Resource temporarily unavailable
test: Select...
	# *** Next line on all systems except FreeBSD 3.0-CURRENT:
test: select(): Not ready			# After timeout
	# *** This line is only on FreeBSD 3.0-CURRENT:
	# *** I think, this is next bug, because nothing is ready!
test: select(): Ready 3				# *** Immediate return

=== test.c listing: ===============================================

#define MODE	O_RDONLY /* O_RDWR */

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h> /* Why I need this line on _only_ FreeBSD systems? */
#include <unistd.h>

#define FILE	"tst.pipe"

int main(void)
{
	fd_set set;
	struct timeval t;
	int fd;
	int ret;
	char c;

	unlink(FILE);
	if (mkfifo(FILE, S_IRUSR | S_IWUSR) != 0)
		err(1, "mkfifo(%s)", FILE);
	warnx("Open...");
	if ((fd = open(FILE, MODE | O_NONBLOCK)) < 0)
		err(1, "open(%s)", FILE);
	warnx("FD = %d", fd);
	warnx("Read...");
	if (read(fd, &c, 1) < 0)
		warn("read(%s)", FILE);
	warnx("Select...");
	FD_ZERO(&set);
	FD_SET(fd, &set);
	t.tv_sec = 5; t.tv_usec = 0;
	ret = select(fd + 1, &set, NULL, NULL, &t);
	if (ret < 0)
		err(1, "select(%s)", FILE);
	else if (ret == 0)
		warnx("select(): Not ready");
	else {
		if (FD_ISSET(fd, &set))
			warnx("select(): Ready %d", fd);
		else
			warnx("select(): Ready unknown");
	}

	close(fd);
	return 0;
}
===================================================================

--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--
Rudolf Cejka  (cejkar@dcse.fee.vutbr.cz;  http://www.fee.vutbr.cz/~cejkar)
Technical University of Brno, Faculty of El. Engineering and Comp. Science
Bozetechova 2, 612 66  Brno, Czech Republic

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812101346.OAA12755>