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: Sat, 19 May 2018 17:25:15 +0200

 Hello Martin,
 
 Martin Husemann writes:
 >
 >  https://bugs.python.org/issue33384
 >  
 
 JFTR (and to include a possible patch for lang/python36!), it seems
 that also NetBSD is affected by bpo-30225
 (<https://bugs.python.org/issue30225>).
 
 Extracting is_valid_fd() (from Python/pylifecycle.c) in an
 is_valid_fd.c to ease the reproduction (in python-3.6.5 USE_FSTAT
 logic is only honored by __APPLE__ and dup(2) is used on all the
 the other platforms):
 
  | % cat is_valid_fd.c
  | #include <stdio.h>
  | #include <sys/stat.h>
  | #include <unistd.h>
  | 
  | /* Check if a file descriptor is valid or not.
  |    Return 0 if the file descriptor is invalid, return
  |    non-zero otherwise. */
  | static int
  | is_valid_fd(int fd)
  | {
  | #ifdef USE_FSTAT 
  |     /* bpo-30225: On macOS Tiger, when stdout is redirected
  |        to a pipe and the other side of the pipe is closed,
  |        dup(1) succeed, whereas fstat(1, &st) fails with EBADF.
  |        Prefer fstat() over dup() to detect such error. */
  |     struct stat st;
  |     return (fstat(fd, &st) == 0);
  | #else
  |     int fd2;
  |     if (fd < 0)
  |         return 0;
  |     /* Prefer dup() over fstat(). fstat() can require
  |        input/output whereas dup() doesn't, there is a low
  |        risk of EMFILE/ENFILE at Python startup. */
  |     fd2 = dup(fd);
  |     if (fd2 >= 0)
  |         close(fd2);
  |     return fd2 >= 0;
  | #endif
  | }
  | 
  | 
  | int
  | main(void)
  | {
  | 
  |     printf("0: %d\n", is_valid_fd(0));
  |     printf("1: %d\n", is_valid_fd(1));
  |     printf("2: %d\n", is_valid_fd(2));
  | 
  |     return 0;
  | }
 
 We can see (this is on NetBSD/amd64 8.99.15) that using dup(2):
 
  | % cc -o ivf is_valid_fd.c
  | % sleep 5 && ./ivf > /tmp/log & exit
  | [... the terminal is closed via ^D ...]
  | % cat /tmp/log
  | 0: 1
  | 1: 1
  | 2: 1
 
 ...and using fstat(2):
 
  | % cc -DUSE_FSTAT -o ivf is_valid_fd.c
  | % sleep 5 && ./ivf > /tmp/log & exit
  | [... the terminal is closed via ^D ...]
  | % cat /tmp/log
  | 0: 0
  | 1: 1
  | 2: 0
 
 The attached patch seems to fix that problem:
 
  <https://www.NetBSD.org/~leot/pkgsrc-patches/python36-3.6.5-bpo-33384.patch>
 


Home | Main Index | Thread Index | Old Index