CVS: rdesktop disk.c,1.38,1.39

Peter Åstrand <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30175

Modified Files:
	disk.c 
Log Message:
Support for file systems that cannot handle O_EXCL.


Index: disk.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/disk.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** disk.c	21 Oct 2004 08:28:03 -0000	1.38
--- disk.c	28 Oct 2004 07:46:39 -0000	1.39
***************
*** 192,195 ****
--- 192,245 ----
  }
  
+ /* Just like open(2), but if a open with O_EXCL fails, retry with
+    GUARDED semantics. This might be necessary because some filesystems
+    (such as NFS filesystems mounted from a unfsd server) doesn't
+    support O_EXCL. GUARDED semantics are subject to race conditions,
+    but we can live with that.
+ */
+ static int
+ open_weak_exclusive(const char *pathname, int flags, mode_t mode)
+ {
+ 	int ret;
+ 	struct stat statbuf;
+ 
+ 	ret = open(pathname, flags, mode);
+ 	if (ret != -1 || !(flags & O_EXCL))
+ 	{
+ 		/* Success, or not using O_EXCL */
+ 		return ret;
+ 	}
+ 
+ 	/* An error occured, and we are using O_EXCL. In case the FS
+ 	   doesn't support O_EXCL, some kind of error will be
+ 	   returned. Unfortunately, we don't know which one. Linux
+ 	   2.6.8 seems to return 524, but I cannot find a documented
+ 	   #define for this case. So, we'll return only on errors that
+ 	   we know aren't related to O_EXCL. */
+ 	switch (errno)
+ 	{
+ 		case EACCES:
+ 		case EEXIST:
+ 		case EINTR:
+ 		case EISDIR:
+ 		case ELOOP:
+ 		case ENAMETOOLONG:
+ 		case ENOENT:
+ 		case ENOTDIR:
+ 			return ret;
+ 	}
+ 
+ 	/* Retry with GUARDED semantics */
+ 	if (stat(pathname, &statbuf) != -1)
+ 	{
+ 		/* File exists */
+ 		errno = EEXIST;
+ 		return -1;
+ 	}
+ 	else
+ 	{
+ 		return open(pathname, flags & ~O_EXCL, mode);
+ 	}
+ }
  
  /* Enumeration of devices from rdesktop.c        */
***************
*** 335,339 ****
  		}
  
! 		handle = open(path, flags, mode);
  		if (handle == -1)
  		{
--- 385,389 ----
  		}
  
! 		handle = open_weak_exclusive(path, flags, mode);
  		if (handle == -1)
  		{



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.