DragonFly submit List (threaded) for 2009-07
DragonFly BSD
DragonFly submit List (threaded) for 2009-07
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: dma(8): Fix race condition in multi-recipient delivery


From: "Simon 'corecode' Schubert" <corecode@xxxxxxxxxxxx>
Date: Fri, 10 Jul 2009 10:48:53 +0200

Matthew Dillon wrote:
    dup() doesn't solve the problem.  A dup()'d descriptor still
    points to a common file pointer and thus a common seek position.

    Only open() will generate a new file pointer backing the file
    descriptor.

That's not true.


cheers
  simon

--
  <3 the future  +++  RENT this banner advert  +++   ASCII Ribbon   /"\
  rock the past  +++  space for low CHF NOW!1  +++     Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \
#include <stdio.h>

int
main(void)
{
	FILE *f = fopen("duptmp", "w");
	FILE *f1, *f2;
	char line[100];

	if (f == NULL)
		return (1);

	fputs("1\n2\n3\n", f);
	fclose(f);

	f1 = fopen("duptmp", "r");
	if (f1 == NULL)
		return (1);
	f2 = fdopen(dup(fileno(f1)), "r");
	if (f2 == NULL)
		return (2);
	fgets(line, sizeof(line), f1);
	printf("read1: %s", line);
	fgets(line, sizeof(line), f2);
	printf("read2: %s", line);
	return (0);
}


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