mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
generic/484: Need another process to check record locks
According to fcntl(2) manpage, A single process always gets F_UNLCK in the l_type field when using fcntl(F_GETLK) to acquire the existing lock set by itself because it could convert the existing lock to a new lock unconditionally. So we need another process to check if the lock exists. Also remove redundant exit(0). Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> Reviewed-by: Xiong Zhou <xzhou@redhat.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
This commit is contained in:
+13
-1
@@ -8,6 +8,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
static void err_exit(char *op, int errn)
|
static void err_exit(char *op, int errn)
|
||||||
@@ -32,12 +33,24 @@ struct flock fl = {
|
|||||||
|
|
||||||
static void checklock(int fd)
|
static void checklock(int fd)
|
||||||
{
|
{
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0)
|
||||||
|
err_exit("fork", errno);
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
if (fcntl(fd, F_GETLK, &fl) < 0)
|
if (fcntl(fd, F_GETLK, &fl) < 0)
|
||||||
err_exit("getlk", errno);
|
err_exit("getlk", errno);
|
||||||
if (fl.l_type == F_UNLCK) {
|
if (fl.l_type == F_UNLCK) {
|
||||||
printf("record lock is not preserved across execve(2)\n");
|
printf("record lock is not preserved across execve(2)\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
waitpid(pid, NULL, 0);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +65,6 @@ int main(int argc, char **argv)
|
|||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
fd = atoi(argv[2]);
|
fd = atoi(argv[2]);
|
||||||
checklock(fd);
|
checklock(fd);
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open(argv[1], O_WRONLY|O_CREAT, 0755);
|
fd = open(argv[1], O_WRONLY|O_CREAT, 0755);
|
||||||
|
|||||||
Reference in New Issue
Block a user