pkgsrc-Bugs archive

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

Re: pkg/53229: textproc/py-expat does not build w/o terminal session



The following reply was made to PR pkg/53229; it has been noted by GNATS.

From: Leonardo Taccari <leot%NetBSD.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: pkg/53229: textproc/py-expat does not build w/o terminal session
Date: Mon, 21 May 2018 13:13:24 +0200

 And for completeness here the behaviours of just dup(2) and fstat(2)
 (please note that they can be safely ignored, but if you're
 curious...):
 
  | % cat sleep-and-dup.c
  | #include <errno.h>
  | #include <stdio.h>
  | #include <string.h>
  | #include <unistd.h>
  | =
 
  | =
 
  | int
  | main(void)
  | {
  | 	int fd;
  | =
 
  | 	if ((fd =3D dup(STDIN_FILENO)) !=3D -1)
  | 		printf("Before: %d\n", fd);
  | 	else
  | 		printf("%s\n", strerror(errno));
  | 	sleep(5);
  | 	if ((fd =3D dup(STDIN_FILENO)) !=3D -1)
  | 		printf("After: %d\n", fd);
  | 	else
  | 		printf("%s\n", strerror(errno));
  | 	return 0;
  | }
  | % cat sleep-and-fstat.c
  | #include <errno.h>
  | #include <sys/stat.h>
  | #include <stdio.h>
  | #include <string.h>
  | #include <unistd.h>
  | =
 
  | =
 
  | int
  | main(void)
  | {
  | 	struct stat st;
  | =
 
  | 	if (fstat(STDIN_FILENO, &st) !=3D -1)
  | 		printf("Before: %d\n", fstat(STDIN_FILENO, &st));
  | 	else
  | 		printf("%s\n", strerror(errno));
  | 	sleep(5);
  | 	if (fstat(STDIN_FILENO, &st) !=3D -1)
  | 		printf("Before: %d\n", fstat(STDIN_FILENO, &st));
  | 	else
  | 		printf("%s\n", strerror(errno));
  | 	return 0;
  | }
  | % cc sleep-and-dup.c -o dup
  | % cc sleep-and-fstat.c -o fstat
  | % ( ./dup > dup.log & ) && sleep 1 && exit
  | [... the terminal is closed ...]
  | % ( ./fstat > fstat.log & ) && sleep 1 && exit
  | [... the terminal is closed ...]
  | % cat dup.log
  | Before: 3
  | After: 4
  | % cat fstat.log
  | Before: 0
  | Bad file descriptor
 
 And according both 1003.1-2004 and 1003.1-2008, respectively for
 dup[0][1] in the ERRORS section we can read:
 
 > The dup() function shall fail if:
 > =
 
 > [EBADF]
 >     The fildes [oldfd in dup(2)] pargument is not a valid open file desc=
 riptor.
 > [...]
 
 In dup(2) regarding EBADF we have `oldfd is not a valid active descriptor'=
 .
 
 For fstat[2][3]:
 
 > The fstat() function shall fail if:
 > =
 
 > [EBADF]
 >     The fildes argument is not a valid file descriptor.
 > [...]
 
 In fstat(2) regarding EBADF we have `fd is not a valid open file descripto=
 r'.
 
 
 (So I guess that in the example above stdin is a valid /active/
 descriptor, while it is not a valid /open/ file descriptor!)
 
 
 [0]: <http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html>
 [1]: <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html>
 [2]: <http://pubs.opengroup.org/onlinepubs/009695399/functions/fstat.html>
 [3]: <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fstat.html=
 >
 


Home | Main Index | Thread Index | Old Index