* fhandler.cc (fhandler_base::lock): Move to flock.cc.

(fhandler_base::fixup_after_exec): Reset mandatory_locking.
	* fhandler.h (class fhandler_base): Add mandatory_locking status flag.
	Add mandatory_locking accessor methods.  Accommodate change throughout.
	(fhandler_base::mand_lock): Declare.
	(class fhandler_disk_file): Drop in favor of new status flag.
	* (fhandler_disk_file::fcntl): Call need_fork_fixup if mandatory_locking
	flag gets set.
	* flock.cc (fhandler_base::lock): Define here.
	(flock): Handle mandatory_locking.
	(lockf): Ditto.
	(fhandler_base::mand_lock): Define.
This commit is contained in:
Corinna Vinschen 2013-06-04 10:24:43 +00:00
parent ca1dd3a9b5
commit edd73646f3
6 changed files with 51 additions and 22 deletions

View File

@ -1,3 +1,18 @@
2013-06-04 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::lock): Move to flock.cc.
(fhandler_base::fixup_after_exec): Reset mandatory_locking.
* fhandler.h (class fhandler_base): Add mandatory_locking status flag.
Add mandatory_locking accessor methods. Accommodate change throughout.
(fhandler_base::mand_lock): Declare.
(class fhandler_disk_file): Drop in favor of new status flag.
* (fhandler_disk_file::fcntl): Call need_fork_fixup if mandatory_locking
flag gets set.
* flock.cc (fhandler_base::lock): Define here.
(flock): Handle mandatory_locking.
(lockf): Ditto.
(fhandler_base::mand_lock): Define.
2013-06-03 Corinna Vinschen <corinna@vinschen.de> 2013-06-03 Corinna Vinschen <corinna@vinschen.de>
* sigproc.cc (exit_thread): Allow to exit the thread while running * sigproc.cc (exit_thread): Allow to exit the thread while running

View File

@ -1230,13 +1230,6 @@ fhandler_base::ioctl (unsigned int cmd, void *buf)
return res; return res;
} }
int
fhandler_base::lock (int, struct flock *)
{
set_errno (EINVAL);
return -1;
}
int __reg2 int __reg2
fhandler_base::fstat (struct stat *buf) fhandler_base::fstat (struct stat *buf)
{ {
@ -1553,6 +1546,7 @@ fhandler_base::fixup_after_exec ()
debug_printf ("here for '%s'", get_name ()); debug_printf ("here for '%s'", get_name ());
if (unique_id && close_on_exec ()) if (unique_id && close_on_exec ())
del_my_locks (after_exec); del_my_locks (after_exec);
mandatory_locking (false);
} }
void void
fhandler_base_overlapped::fixup_after_exec () fhandler_base_overlapped::fixup_after_exec ()

View File

@ -147,12 +147,13 @@ class fhandler_base
unsigned close_on_exec : 1; /* close-on-exec */ unsigned close_on_exec : 1; /* close-on-exec */
unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */ unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */
unsigned isclosed : 1; /* Set when fhandler is closed. */ unsigned isclosed : 1; /* Set when fhandler is closed. */
unsigned mandatory_locking : 1; /* Windows mandatory locking */
public: public:
status_flags () : status_flags () :
rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0), rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0),
did_lseek (0), query_open (no_query), close_on_exec (0), did_lseek (0), query_open (no_query), close_on_exec (0),
need_fork_fixup (0), isclosed (0) need_fork_fixup (0), isclosed (0), mandatory_locking (0)
{} {}
} status, open_status; } status, open_status;
@ -247,6 +248,7 @@ class fhandler_base
IMPLEMENT_STATUS_FLAG (bool, close_on_exec) IMPLEMENT_STATUS_FLAG (bool, close_on_exec)
IMPLEMENT_STATUS_FLAG (bool, need_fork_fixup) IMPLEMENT_STATUS_FLAG (bool, need_fork_fixup)
IMPLEMENT_STATUS_FLAG (bool, isclosed) IMPLEMENT_STATUS_FLAG (bool, isclosed)
IMPLEMENT_STATUS_FLAG (bool, mandatory_locking)
int get_default_fmode (int flags); int get_default_fmode (int flags);
@ -360,6 +362,7 @@ public:
virtual ssize_t __reg3 pwrite (void *, size_t, off_t); virtual ssize_t __reg3 pwrite (void *, size_t, off_t);
virtual off_t lseek (off_t offset, int whence); virtual off_t lseek (off_t offset, int whence);
virtual int lock (int, struct flock *); virtual int lock (int, struct flock *);
virtual int mand_lock (int, struct flock *);
virtual int dup (fhandler_base *child, int flags); virtual int dup (fhandler_base *child, int flags);
virtual int fpathconf (int); virtual int fpathconf (int);
@ -963,7 +966,6 @@ class fhandler_dev_tape: public fhandler_dev_raw
class fhandler_disk_file: public fhandler_base class fhandler_disk_file: public fhandler_base
{ {
HANDLE prw_handle; HANDLE prw_handle;
bool mandatory_locking;
int __reg3 readdir_helper (DIR *, dirent *, DWORD, DWORD, PUNICODE_STRING fname); int __reg3 readdir_helper (DIR *, dirent *, DWORD, DWORD, PUNICODE_STRING fname);
int prw_open (bool); int prw_open (bool);

View File

@ -1379,12 +1379,12 @@ fhandler_base::utimens_fs (const struct timespec *tvp)
} }
fhandler_disk_file::fhandler_disk_file () : fhandler_disk_file::fhandler_disk_file () :
fhandler_base (), prw_handle (NULL), mandatory_locking (false) fhandler_base (), prw_handle (NULL)
{ {
} }
fhandler_disk_file::fhandler_disk_file (path_conv &pc) : fhandler_disk_file::fhandler_disk_file (path_conv &pc) :
fhandler_base (), prw_handle (NULL), mandatory_locking (false) fhandler_base (), prw_handle (NULL)
{ {
set_name (pc); set_name (pc);
} }
@ -1415,7 +1415,8 @@ fhandler_disk_file::fcntl (int cmd, intptr_t arg)
switch (cmd) switch (cmd)
{ {
case F_LCK_MANDATORY: case F_LCK_MANDATORY:
mandatory_locking = !!arg; mandatory_locking (!!arg);
need_fork_fixup (true);
res = 0; res = 0;
break; break;
case F_GETLK: case F_GETLK:
@ -1424,7 +1425,7 @@ fhandler_disk_file::fcntl (int cmd, intptr_t arg)
{ {
struct flock *fl = (struct flock *) arg; struct flock *fl = (struct flock *) arg;
fl->l_type &= F_RDLCK | F_WRLCK | F_UNLCK; fl->l_type &= F_RDLCK | F_WRLCK | F_UNLCK;
res = mandatory_locking ? mand_lock (cmd, fl) : lock (cmd, fl); res = mandatory_locking () ? mand_lock (cmd, fl) : lock (cmd, fl);
} }
break; break;
default: default:
@ -1445,7 +1446,6 @@ fhandler_disk_file::dup (fhandler_base *child, int flags)
GetCurrentProcess (), &fhc->prw_handle, GetCurrentProcess (), &fhc->prw_handle,
0, TRUE, DUPLICATE_SAME_ACCESS)) 0, TRUE, DUPLICATE_SAME_ACCESS))
fhc->prw_handle = NULL; fhc->prw_handle = NULL;
fhc->mandatory_locking = mandatory_locking;
return ret; return ret;
} }
@ -1453,7 +1453,7 @@ void
fhandler_disk_file::fixup_after_fork (HANDLE parent) fhandler_disk_file::fixup_after_fork (HANDLE parent)
{ {
prw_handle = NULL; prw_handle = NULL;
mandatory_locking = false; mandatory_locking (false);
fhandler_base::fixup_after_fork (parent); fhandler_base::fixup_after_fork (parent);
} }

View File

@ -918,6 +918,13 @@ static void lf_wakelock (lockf_t *, HANDLE);
/* This is the fcntl advisory lock implementation. For the implementation /* This is the fcntl advisory lock implementation. For the implementation
of mandatory locks using the Windows mandatory locking functions, see the of mandatory locks using the Windows mandatory locking functions, see the
fhandler_disk_file::mand_lock method at the end of this file. */ fhandler_disk_file::mand_lock method at the end of this file. */
int
fhandler_base::lock (int, struct flock *)
{
set_errno (EINVAL);
return -1;
}
int int
fhandler_disk_file::lock (int a_op, struct flock *fl) fhandler_disk_file::lock (int a_op, struct flock *fl)
{ {
@ -1733,19 +1740,22 @@ flock (int fd, int operation)
switch (operation & (~LOCK_NB)) switch (operation & (~LOCK_NB))
{ {
case LOCK_EX: case LOCK_EX:
fl.l_type = F_WRLCK | F_FLOCK; fl.l_type = F_WRLCK;
break; break;
case LOCK_SH: case LOCK_SH:
fl.l_type = F_RDLCK | F_FLOCK; fl.l_type = F_RDLCK;
break; break;
case LOCK_UN: case LOCK_UN:
fl.l_type = F_UNLCK | F_FLOCK; fl.l_type = F_UNLCK;
break; break;
default: default:
set_errno (EINVAL); set_errno (EINVAL);
goto done; goto done;
} }
res = cfd->lock (cmd, &fl); if (!cfd->mandatory_locking ())
fl.l_type |= F_FLOCK;
res = cfd->mandatory_locking () ? cfd->mand_lock (cmd, &fl)
: cfd->lock (cmd, &fl);
if ((res == -1) && ((get_errno () == EAGAIN) || (get_errno () == EACCES))) if ((res == -1) && ((get_errno () == EAGAIN) || (get_errno () == EACCES)))
set_errno (EWOULDBLOCK); set_errno (EWOULDBLOCK);
done: done:
@ -1803,7 +1813,8 @@ lockf (int filedes, int function, off_t size)
goto done; goto done;
/* NOTREACHED */ /* NOTREACHED */
} }
res = cfd->lock (cmd, &fl); res = cfd->mandatory_locking () ? cfd->mand_lock (cmd, &fl)
: cfd->lock (cmd, &fl);
done: done:
syscall_printf ("%R = lockf(%d, %d, %D)", res, filedes, function, size); syscall_printf ("%R = lockf(%d, %d, %D)", res, filedes, function, size);
return res; return res;
@ -1831,6 +1842,13 @@ blocking_lock_thr (LPVOID param)
return 0; return 0;
} }
int
fhandler_base::mand_lock (int, struct flock *)
{
set_errno (EINVAL);
return -1;
}
int int
fhandler_disk_file::mand_lock (int a_op, struct flock *fl) fhandler_disk_file::mand_lock (int a_op, struct flock *fl)
{ {

View File

@ -10,8 +10,8 @@ What's new:
- Add support for the AFS filesystem. - Add support for the AFS filesystem.
- Preliminary support for mandatory locking via fcntl, using Windows - Support for mandatory locking via fcntl/flock/lockf, using Windows locking
locking semantics. New F_LCK_MANDATORY fcntl command. semantics. New F_LCK_MANDATORY fcntl command.
- New APIs: __b64_ntop, __b64_pton, arc4random, arc4random_addrandom, - New APIs: __b64_ntop, __b64_pton, arc4random, arc4random_addrandom,
arc4random_buf, arc4random_stir, arc4random_uniform. arc4random_buf, arc4random_stir, arc4random_uniform.