https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=1188d308bf254a85c2cdfca86453bd684cffb7ef
commit 1188d308bf254a85c2cdfca86453bd684cffb7ef Author: Corinna Vinschen <cori...@vinschen.de> Date: Wed Feb 14 10:20:42 2018 +0100 Cygwin: fix file-related functions on unix sockets * Fix an incorrect condition to recognize AF_LOCAL sockets in file-related functions (fchmod, fchown, fstat, fsttavfs, facl, link). * Return successfully when called on unnamed or abstract AF_LOCAL sockets, except link, just as on Linux. Signed-off-by: Corinna Vinschen <cori...@vinschen.de> Diff: --- winsup/cygwin/fhandler_socket.cc | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index fa2bdf3..2d043bd 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -39,6 +39,7 @@ #include "wininfo.h" #include <unistd.h> #include <sys/param.h> +#include <sys/statvfs.h> #include <cygwin/acl.h> #include "cygtls.h" #include <sys/un.h> @@ -947,8 +948,21 @@ int __reg2 fhandler_socket::fstat (struct stat *buf) { int res; - if (get_device () == FH_UNIX) + if (get_addr_family () == AF_LOCAL) { + if (!get_sun_path () || get_sun_path ()[0] == '\0') + { + memset (buf, 0, sizeof *buf); + buf->st_dev = FH_UNIX; + buf->st_ino = get_plain_ino (); + buf->st_mode = S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO; + buf->st_nlink = 1; + buf->st_uid = myself->uid; + buf->st_gid = myself->gid; + time_as_timestruc_t (&buf->st_ctim); + buf->st_blksize = 4096; + return 0; + } res = fhandler_base::fstat_fs (buf); if (!res) { @@ -975,8 +989,15 @@ fhandler_socket::fstat (struct stat *buf) int __reg2 fhandler_socket::fstatvfs (struct statvfs *sfs) { - if (get_device () == FH_UNIX) + if (get_addr_family () == AF_LOCAL) { + if (!get_sun_path () || get_sun_path ()[0] == '\0') + { + memset (sfs, 0, sizeof (*sfs)); + sfs->f_bsize = sfs->f_frsize = 4096; + sfs->f_namemax = NAME_MAX; + return 0; + } fhandler_disk_file fh (pc); fh.get_device () = FH_FS; return fh.fstatvfs (sfs); @@ -988,8 +1009,10 @@ fhandler_socket::fstatvfs (struct statvfs *sfs) int fhandler_socket::fchmod (mode_t mode) { - if (get_device () == FH_UNIX) + if (get_addr_family () == AF_LOCAL) { + if (!get_sun_path () || get_sun_path ()[0] == '\0') + return 0; fhandler_disk_file fh (pc); fh.get_device () = FH_FS; int ret = fh.fchmod (S_IFSOCK | adjust_socket_file_mode (mode)); @@ -1002,8 +1025,10 @@ fhandler_socket::fchmod (mode_t mode) int fhandler_socket::fchown (uid_t uid, gid_t gid) { - if (get_device () == FH_UNIX) + if (get_addr_family () == AF_LOCAL) { + if (!get_sun_path () || get_sun_path ()[0] == '\0') + return 0; fhandler_disk_file fh (pc); return fh.fchown (uid, gid); } @@ -1014,8 +1039,10 @@ fhandler_socket::fchown (uid_t uid, gid_t gid) int fhandler_socket::facl (int cmd, int nentries, aclent_t *aclbufp) { - if (get_device () == FH_UNIX) + if (get_addr_family () == AF_LOCAL) { + if (!get_sun_path () || get_sun_path ()[0] == '\0') + return fhandler_base::facl (cmd, nentries, aclbufp); fhandler_disk_file fh (pc); return fh.facl (cmd, nentries, aclbufp); } @@ -1026,7 +1053,7 @@ fhandler_socket::facl (int cmd, int nentries, aclent_t *aclbufp) int fhandler_socket::link (const char *newpath) { - if (get_device () == FH_UNIX) + if (get_addr_family () == AF_LOCAL) { fhandler_disk_file fh (pc); return fh.link (newpath);