~ubuntu-branches/ubuntu/trusty/eglibc/trusty

« back to all changes in this revision

Viewing changes to sysdeps/unix/sysv/linux/i386/lockf64.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-01-10 18:39:35 UTC
  • mfrom: (1.5.2) (4.4.24 experimental)
  • Revision ID: package-import@ubuntu.com-20130110183935-afsgfxkmg7wk5eaj
Tags: 2.17-0ubuntu1
* Merge with Debian, bringing in a new upstream and many small fixes:
  - patches/any/cvs-malloc-deadlock.diff: Dropped, merged upstream.
  - patches/ubuntu/lddebug-scopes.diff: Rebase for upstream changes.
  - patches/ubuntu/local-CVE-2012-3406.diff: Rebased against upstream.
  - patches/ubuntu/no-asm-mtune-i686.diff: Fixed in recent binutils.
* This upstream merge fixes a nasty hang in pulseaudio (LP: #1085342)
* Bump MIN_KERNEL_SUPPORTED to 2.6.32 on ARM, now that we no longer
  have to support shonky 2.6.31 kernels on imx51 babbage builders.
* Drop patches/ubuntu/local-disable-nscd-host-caching.diff, as these
  issues were apparently resolved upstream a while ago (LP: #613662)
* Fix the compiled-in bug URL to point to launchpad.net, not Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1994,1996,1997,1998,1999,2000,2003,2006
2
 
        Free Software Foundation, Inc.
 
1
/* Copyright (C) 1994-2012 Free Software Foundation, Inc.
3
2
   This file is part of the GNU C Library.
4
3
 
5
4
   The GNU C Library is free software; you can redistribute it and/or
23
22
#include <string.h>
24
23
#include <sysdep.h>
25
24
 
26
 
#include <kernel-features.h>
27
 
 
28
25
/* lockf is a simplified interface to fcntl's locking facilities.  */
29
26
 
30
 
#ifdef __NR_fcntl64
31
 
# if __ASSUME_FCNTL64 == 0
32
 
/* This variable is shared with all files that check for fcntl64. The
33
 
   declaration is in fcntl.c.  */
34
 
extern int __have_no_fcntl64;
35
 
# endif
36
 
#endif
37
 
 
38
27
int
39
28
lockf64 (int fd, int cmd, off64_t len64)
40
29
{
41
 
#if __ASSUME_FCNTL64 == 0
42
 
  struct flock fl;
43
 
  off_t len = (off_t) len64;
44
 
#endif
45
 
#ifdef __NR_fcntl64
46
30
  struct flock64 fl64;
47
31
  int cmd64;
48
 
#endif
49
 
 
50
 
#if __ASSUME_FCNTL64 == 0
51
 
  memset ((char *) &fl, '\0', sizeof (fl));
52
 
 
53
 
  /* lockf is always relative to the current file position.  */
54
 
  fl.l_whence = SEEK_CUR;
55
 
  fl.l_start = 0;
56
 
  fl.l_len = len;
57
 
#endif
58
 
#ifdef __NR_fcntl64
59
 
# if __ASSUME_FCNTL64 == 0
60
 
  if (!__have_no_fcntl64)
61
 
    {
62
 
# endif
63
 
      memset ((char *) &fl64, '\0', sizeof (fl64));
64
 
      fl64.l_whence = SEEK_CUR;
65
 
      fl64.l_start = 0;
66
 
      fl64.l_len = len64;
67
 
# if __ASSUME_FCNTL64 == 0
68
 
    }
69
 
# endif
70
 
#endif
71
 
 
72
 
#if __ASSUME_FCNTL64 == 0 && !defined __NR_fcntl64
73
 
  if (len64 != (off64_t) len)
74
 
    {
75
 
      /* We can't represent the length.  */
76
 
      __set_errno (EOVERFLOW);
77
 
      return -1;
78
 
    }
79
 
#endif
 
32
 
 
33
  memset ((char *) &fl64, '\0', sizeof (fl64));
 
34
  fl64.l_whence = SEEK_CUR;
 
35
  fl64.l_start = 0;
 
36
  fl64.l_len = len64;
 
37
 
80
38
  switch (cmd)
81
39
    {
82
40
    case F_TEST:
83
41
      /* Test the lock: return 0 if FD is unlocked or locked by this process;
84
42
         return -1, set errno to EACCES, if another process holds the lock.  */
85
 
#if __ASSUME_FCNTL64 > 0
86
43
      fl64.l_type = F_RDLCK;
87
44
      if (INLINE_SYSCALL (fcntl64, 3, fd, F_GETLK64, &fl64) < 0)
88
45
        return -1;
90
47
        return 0;
91
48
      __set_errno (EACCES);
92
49
      return -1;
93
 
#else
94
 
# ifdef __NR_fcntl64
95
 
      if (!__have_no_fcntl64)
96
 
        {
97
 
          int res;
98
 
 
99
 
          fl64.l_type = F_RDLCK;
100
 
          res = INLINE_SYSCALL (fcntl64, 3, fd, F_GETLK64, &fl64);
101
 
          /* If errno == ENOSYS try the 32bit interface if len64 can
102
 
             be represented with 32 bits.  */
103
 
 
104
 
          if (res == 0)
105
 
            {
106
 
              if (fl64.l_type == F_UNLCK || fl64.l_pid == __getpid ())
107
 
                return 0;
108
 
              __set_errno (EACCES);
109
 
              return -1;
110
 
            }
111
 
          else if (errno == ENOSYS)
112
 
            __have_no_fcntl64 = 1;
113
 
          else
114
 
            /* res < 0 && errno != ENOSYS.  */
115
 
            return -1;
116
 
          if (len64 != (off64_t) len)
117
 
            {
118
 
              /* We can't represent the length.  */
119
 
              __set_errno (EOVERFLOW);
120
 
              return -1;
121
 
            }
122
 
        }
123
 
# endif
124
 
      fl.l_type = F_RDLCK;
125
 
      if (__fcntl (fd, F_GETLK, &fl) < 0)
126
 
        return -1;
127
 
      if (fl.l_type == F_UNLCK || fl.l_pid == __getpid ())
128
 
        return 0;
129
 
      __set_errno (EACCES);
130
 
      return -1;
131
 
#endif
132
50
    case F_ULOCK:
133
 
#if __ASSUME_FCNTL64 == 0
134
 
      fl.l_type = F_UNLCK;
135
 
      cmd = F_SETLK;
136
 
#endif
137
 
#ifdef __NR_fcntl64
138
51
      fl64.l_type = F_UNLCK;
139
52
      cmd64 = F_SETLK64;
140
 
#endif
141
53
      break;
142
54
    case F_LOCK:
143
 
#if __ASSUME_FCNTL64 == 0
144
 
      fl.l_type = F_WRLCK;
145
 
      cmd = F_SETLKW;
146
 
#endif
147
 
#ifdef __NR_fcntl64
148
55
      fl64.l_type = F_WRLCK;
149
56
      cmd64 = F_SETLKW64;
150
 
#endif
151
57
      break;
152
58
    case F_TLOCK:
153
 
#if __ASSUME_FCNTL64 == 0
154
 
      fl.l_type = F_WRLCK;
155
 
      cmd = F_SETLK;
156
 
#endif
157
 
#ifdef __NR_fcntl64
158
59
      fl64.l_type = F_WRLCK;
159
60
      cmd64 = F_SETLK64;
160
 
#endif
161
61
      break;
162
62
 
163
63
    default:
164
64
      __set_errno (EINVAL);
165
65
      return -1;
166
66
    }
167
 
#if __ASSUME_FCNTL64 > 0
168
67
  return INLINE_SYSCALL (fcntl64, 3, fd, cmd64, &fl64);
169
 
#else
170
 
# ifdef __NR_fcntl64
171
 
 
172
 
  if (!__have_no_fcntl64)
173
 
    {
174
 
      int res = INLINE_SYSCALL (fcntl64, 3, fd, cmd64, &fl64);
175
 
 
176
 
      /* If errno == ENOSYS try the 32bit interface if len64 can
177
 
         be represented with 32 bits.  */
178
 
      if (res == 0 || errno != ENOSYS)
179
 
        return res;
180
 
 
181
 
      __have_no_fcntl64 = 1;
182
 
 
183
 
      if (len64 != (off64_t) len)
184
 
        {
185
 
          /* We can't represent the length.  */
186
 
          __set_errno (EOVERFLOW);
187
 
          return -1;
188
 
        }
189
 
    }
190
 
# endif
191
 
  return __fcntl (fd, cmd, &fl);
192
 
#endif
193
68
}