[newlib-cygwin] Cygwin: introduce virt_fdsymlink to simplify /proc/PID/fd symlink handling

Corinna Vinschen corinna@sourceware.org
Sun Jan 6 19:41:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a3a5d52b398887a5ee1ca75b23915d17a60ac10a

commit a3a5d52b398887a5ee1ca75b23915d17a60ac10a
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sat Jan 5 21:41:01 2019 +0100

    Cygwin: introduce virt_fdsymlink to simplify /proc/PID/fd symlink handling
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler.h          | 1 +
 winsup/cygwin/fhandler_process.cc | 3 ++-
 winsup/cygwin/path.cc             | 4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 07e8a18..0ead0d9 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -126,6 +126,7 @@ enum del_lock_called_from {
 };
 
 enum virtual_ftype_t {
+  virt_fdsymlink = -8,	/* Fd symlink (e.g. /proc/<PID>/fd/0) */
   virt_blk = -7,	/* Block special */
   virt_chr = -6,	/* Character special */
   virt_fsfile = -5,	/* FS-based file via /proc/sys */
diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
index b0fae4c..24ef7d0 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -175,6 +175,7 @@ fhandler_process::fstat (struct stat *buf)
 	buf->st_nlink = 3;
       return 0;
     case virt_symlink:
+    case virt_fdsymlink:
       buf->st_uid = p->uid;
       buf->st_gid = p->gid;
       buf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
@@ -397,7 +398,7 @@ format_process_fd (void *data, char *&destbuf)
 	  return 0;
 	}
       if (*e == '\0')
-	*((process_fd_t *) data)->fd_type = virt_symlink;
+	*((process_fd_t *) data)->fd_type = virt_fdsymlink;
       else /* trailing path */
 	{
 	  char *newbuf = (char *) cmalloc_abort (HEAP_STR, strlen (destbuf)
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 3324395..563ba0e 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -801,7 +801,8 @@ path_conv::check (const char *src, unsigned opt,
 		  else
 		    {
 		      file_type = fh->exists ();
-		      if (file_type == virt_symlink)
+		      if (file_type == virt_symlink
+			  || file_type == virt_fdsymlink)
 			{
 			  fh->fill_filebuf ();
 			  symlen = sym.set (fh->get_filebuf ());
@@ -842,6 +843,7 @@ path_conv::check (const char *src, unsigned opt,
 			if (component == 0)
 			  fileattr = 0;
 			break;
+		      case virt_fdsymlink:
 		      case virt_symlink:
 			goto is_virtual_symlink;
 		      case virt_pipe:



More information about the Cygwin-cvs mailing list