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
@ -99,13 +99,6 @@ static int file_lock_normalize(FAR struct file *filep,
|
|||||||
off_t start;
|
off_t start;
|
||||||
off_t end;
|
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 */
|
/* Check that the type brought in the flock is correct */
|
||||||
|
|
||||||
switch (flock->l_type)
|
switch (flock->l_type)
|
||||||
@ -161,8 +154,18 @@ static int file_lock_normalize(FAR struct file *filep,
|
|||||||
}
|
}
|
||||||
|
|
||||||
start += flock->l_start;
|
start += flock->l_start;
|
||||||
|
if (start < 0)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (flock->l_len > 0)
|
if (flock->l_len > 0)
|
||||||
{
|
{
|
||||||
|
if (flock->l_len - 1 > OFFSET_MAX - start)
|
||||||
|
{
|
||||||
|
return -EOVERFLOW;
|
||||||
|
}
|
||||||
|
|
||||||
end = start + flock->l_len - 1;
|
end = start + flock->l_len - 1;
|
||||||
}
|
}
|
||||||
else if (flock->l_len < 0)
|
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_whence = SEEK_SET;
|
||||||
out->l_pid = getpid();
|
|
||||||
out->l_type = flock->l_type;
|
out->l_type = flock->l_type;
|
||||||
out->l_start = start;
|
out->l_start = start;
|
||||||
out->l_end = end;
|
out->l_end = end;
|
||||||
@ -546,8 +548,6 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
flock->l_type = F_UNLCK;
|
|
||||||
|
|
||||||
nxmutex_lock(&g_protect_lock);
|
nxmutex_lock(&g_protect_lock);
|
||||||
|
|
||||||
bucket = file_lock_find_bucket(path);
|
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))
|
if (file_lock_is_conflict(flock, &file_lock->fl_lock))
|
||||||
{
|
{
|
||||||
memcpy(flock, &file_lock->fl_lock, sizeof(*flock));
|
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
|
/* Convert back to flock
|
||||||
* The flock information saved in filelock is used as an offset
|
* 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
|
* l_len should be converted to cover the data quantity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
out:
|
||||||
|
nxmutex_unlock(&g_protect_lock);
|
||||||
if (flock->l_end == OFFSET_MAX)
|
if (flock->l_end == OFFSET_MAX)
|
||||||
{
|
{
|
||||||
flock->l_len = 0;
|
flock->l_len = 0;
|
||||||
@ -625,6 +627,8 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request.l_pid = getpid();
|
||||||
|
|
||||||
nxmutex_lock(&g_protect_lock);
|
nxmutex_lock(&g_protect_lock);
|
||||||
|
|
||||||
bucket = file_lock_find_bucket(path);
|
bucket = file_lock_find_bucket(path);
|
||||||
|
Loading…
Reference in New Issue
Block a user