1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Copyright (c) 2008-2010 Wind River Systems; see
* guts/COPYRIGHT for information.
*
* SPDX-License-Identifier: LGPL-2.1-only
*
* static int
* wrap_fcntl(int fd, int cmd, ...struct flock *lock) {
* int rc = -1;
*/
long arg;
int save_errno;
/* we don't know whether we need lock or arg; grab both, which
* should be safe enough on Linuxy systems. */
va_start(ap, cmd);
arg = va_arg(ap, long);
va_end(ap);
switch (cmd) {
case F_DUPFD:
#ifdef F_DUPFD_CLOEXEC
case F_DUPFD_CLOEXEC:
#endif
/* actually do something */
rc = real_fcntl(fd, cmd, arg);
save_errno = errno;
if (rc != -1) {
pseudo_debug(PDBGF_OP, "fcntl_dup: %d->%d\n", fd, rc);
pseudo_client_op(OP_DUP, 0, fd, rc, 0, 0);
}
errno = save_errno;
break;
/* no argument: */
case F_GETFD:
case F_GETFL:
case F_GETOWN:
case F_GETSIG:
case F_GETLEASE:
rc = real_fcntl(fd, cmd);
break;
/* long argument */
case F_SETFD:
case F_SETFL:
case F_SETOWN:
case F_SETSIG:
case F_SETLEASE:
case F_NOTIFY:
rc = real_fcntl(fd, cmd, arg);
break;
/* struct flock * argument */
case F_GETLK:
case F_SETLK:
case F_SETLKW:
rc = real_fcntl(fd, cmd, lock);
break;
#if defined(F_GETLK64) && (F_GETLK64 != F_GETLK)
/* the cast is safe, all struct pointers must smell the same */
case F_GETLK64:
case F_SETLK64:
case F_SETLKW64:
rc = real_fcntl(fd, cmd, (struct flock64 *) lock);
break;
#endif
default:
pseudo_diag("unknown fcntl argument %d, assuming long argument.\n",
cmd);
rc = real_fcntl(fd, cmd, arg);
break;
}
/* return rc;
* }
*/
|