Branch: Tag:

2016-12-05

2016-12-05 12:49:06 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Stdio: Survive setsockopt(SO_REUSEPORT) failing with EINVAL.

The Linux emulation layer in MS Windows 10 behaves this way.

Fixes [LysLysKOM 21915643].

289: Inside #if defined(SO_REUSEPORT)
  #ifdef SO_REUSEPORT    if( args > 3 && Pike_sp[3-args].u.integer )    { +  /* FreeBSD 7.x wants this to reuse portnumbers. +  * Linux 2.6.x seems to have reserved a slot for the option, but not +  * enabled it. Survive libc's with the option on kernels without. +  * +  * The emulated Linux runtime on MS Windows 10 fails this with EINVAL. +  */    int o=1; -  if(fd_setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&o, sizeof(int)) < 0) -  { +  if((fd_setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&o, sizeof(int)) < 0) + #ifdef ENOPROTOOPT +  && (errno != ENOPROTOOPT) + #endif + #ifdef EINVAL +  && (errno != EINVAL) + #endif + #ifdef WSAENOPROTOOPT +  && (errno != WSAENOPROTOOPT) + #endif +  ){    p->my_errno=errno;    while (fd_close(fd) && errno == EINTR) {}    errno = p->my_errno;