forked from nuttx/nuttx-update
fs_locks:Fix getlk's l pid return
When there is no conflicting lock, getlk should not tamper with the l_pid content from the upper layer Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
parent
5c6bd833ed
commit
8cdec83adb
1 changed files with 16 additions and 12 deletions
|
@ -99,13 +99,6 @@ static int file_lock_normalize(FAR struct file *filep,
|
|||
off_t start;
|
||||
off_t end;
|
||||
|
||||
/* Check the legality of incoming flocks */
|
||||
|
||||
if (flock->l_len - 1 > OFFSET_MAX - flock->l_start)
|
||||
{
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
/* Check that the type brought in the flock is correct */
|
||||
|
||||
switch (flock->l_type)
|
||||
|
@ -161,8 +154,18 @@ static int file_lock_normalize(FAR struct file *filep,
|
|||
}
|
||||
|
||||
start += flock->l_start;
|
||||
if (start < 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (flock->l_len > 0)
|
||||
{
|
||||
if (flock->l_len - 1 > OFFSET_MAX - start)
|
||||
{
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
end = start + flock->l_len - 1;
|
||||
}
|
||||
else if (flock->l_len < 0)
|
||||
|
@ -181,7 +184,6 @@ static int file_lock_normalize(FAR struct file *filep,
|
|||
}
|
||||
|
||||
out->l_whence = SEEK_SET;
|
||||
out->l_pid = getpid();
|
||||
out->l_type = flock->l_type;
|
||||
out->l_start = start;
|
||||
out->l_end = end;
|
||||
|
@ -546,8 +548,6 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
|
|||
return ret;
|
||||
}
|
||||
|
||||
flock->l_type = F_UNLCK;
|
||||
|
||||
nxmutex_lock(&g_protect_lock);
|
||||
|
||||
bucket = file_lock_find_bucket(path);
|
||||
|
@ -559,12 +559,12 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
|
|||
if (file_lock_is_conflict(flock, &file_lock->fl_lock))
|
||||
{
|
||||
memcpy(flock, &file_lock->fl_lock, sizeof(*flock));
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_protect_lock);
|
||||
flock->l_type = F_UNLCK;
|
||||
|
||||
/* Convert back to flock
|
||||
* The flock information saved in filelock is used as an offset
|
||||
|
@ -572,6 +572,8 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
|
|||
* l_len should be converted to cover the data quantity
|
||||
*/
|
||||
|
||||
out:
|
||||
nxmutex_unlock(&g_protect_lock);
|
||||
if (flock->l_end == OFFSET_MAX)
|
||||
{
|
||||
flock->l_len = 0;
|
||||
|
@ -625,6 +627,8 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
|
|||
return ret;
|
||||
}
|
||||
|
||||
request.l_pid = getpid();
|
||||
|
||||
nxmutex_lock(&g_protect_lock);
|
||||
|
||||
bucket = file_lock_find_bucket(path);
|
||||
|
|
Loading…
Reference in a new issue