]> git.pld-linux.org Git - packages/apr.git/blob - apr-bug-46425.patch
- update from bug report
[packages/apr.git] / apr-bug-46425.patch
1 diff -ur apr-1.3.3.org/configure.in apr-1.3.3/configure.in
2 --- apr-1.3.3.org/configure.in  2009-02-22 15:55:36.340196167 +0100
3 +++ apr-1.3.3/configure.in      2009-02-22 15:56:09.198943991 +0100
4 @@ -771,6 +771,9 @@
5     AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
6  fi
7  
8 +dnl ----------------------------- Checking for extended file descriptor handling
9 +AC_CHECK_FUNCS(dup3 accept4 epoll_create1)
10 +
11  dnl ----------------------------- Checking for missing POSIX thread functions
12  AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
13  
14 diff -ur apr-1.3.3.org/file_io/netware/mktemp.c apr-1.3.3/file_io/netware/mktemp.c
15 --- apr-1.3.3.org/file_io/netware/mktemp.c      2007-06-01 19:58:04.000000000 +0200
16 +++ apr-1.3.3/file_io/netware/mktemp.c  2009-02-22 15:56:09.402572969 +0100
17 @@ -43,9 +43,12 @@
18  
19  
20         if (!(flags & APR_FILE_NOCLEANUP)) {
21 +            int fdflags = fcntl(fd, F_GETFD);
22 +            fdflags |= FD_CLOEXEC;
23 +            fcntl(fd, F_SETFD, fdflags);
24             apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
25                                       apr_unix_file_cleanup,
26 -                                     apr_unix_child_file_cleanup);
27 +                                     apr_pool_cleanup_null);
28         }
29      }
30  
31 diff -ur apr-1.3.3.org/file_io/unix/filedup.c apr-1.3.3/file_io/unix/filedup.c
32 --- apr-1.3.3.org/file_io/unix/filedup.c        2007-05-15 04:37:16.000000000 +0200
33 +++ apr-1.3.3/file_io/unix/filedup.c    2009-02-22 15:56:09.402572969 +0100
34 @@ -24,14 +24,28 @@
35                               apr_file_t *old_file, apr_pool_t *p,
36                               int which_dup)
37  {
38 -    int rv;
39 +    int rv, flags = 0;
40      
41      if (which_dup == 2) {
42          if ((*new_file) == NULL) {
43              /* We can't dup2 unless we have a valid new_file */
44              return APR_EINVAL;
45          }
46 +#ifdef HAVE_DUP3
47 +        if (!(old_file->flags & APR_INHERIT))
48 +            flags |= O_CLOEXEC;
49 +        rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
50 +#else
51          rv = dup2(old_file->filedes, (*new_file)->filedes);
52 +        if (!(old_file->flags & APR_INHERIT)) {
53 +            flags = fcntl((*new_file)->filedes, F_GETFD);
54 +            if (flags == -1)
55 +                return errno;
56 +            flags |= FD_CLOEXEC;
57 +            if (fcntl((*new_file)->filedes, F_SETFD, flags) == -1)
58 +                return errno;
59 +        }
60 +#endif
61      } else {
62          rv = dup(old_file->filedes);
63      }
64 @@ -78,9 +92,8 @@
65       * already closed with apr_file_close, because the expected
66       * cleanup was already killed.
67       */
68 -    if (which_dup == 2) {
69 +    if (which_dup == 2)
70          return APR_SUCCESS;
71 -    }
72  
73      /* apr_file_dup() retains all old_file flags with the exceptions
74       * of APR_INHERIT and APR_FILE_NOCLEANUP.
75 @@ -92,7 +105,7 @@
76  
77      apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
78                                apr_unix_file_cleanup, 
79 -                              apr_unix_child_file_cleanup);
80 +                              apr_pool_cleanup_null);
81  #ifndef WAITIO_USES_POLL
82      /* Start out with no pollset.  apr_wait_for_io_or_timeout() will
83       * initialize the pollset if needed.
84 @@ -144,9 +157,7 @@
85      if (!(old_file->flags & APR_FILE_NOCLEANUP)) {
86          apr_pool_cleanup_register(p, (void *)(*new_file), 
87                                    apr_unix_file_cleanup,
88 -                                  ((*new_file)->flags & APR_INHERIT)
89 -                                     ? apr_pool_cleanup_null
90 -                                     : apr_unix_child_file_cleanup);
91 +                                  apr_pool_cleanup_null);
92      }
93  
94      old_file->filedes = -1;
95 diff -ur apr-1.3.3.org/file_io/unix/mktemp.c apr-1.3.3/file_io/unix/mktemp.c
96 --- apr-1.3.3.org/file_io/unix/mktemp.c 2007-06-01 19:58:04.000000000 +0200
97 +++ apr-1.3.3/file_io/unix/mktemp.c     2009-02-22 15:56:09.402572969 +0100
98 @@ -203,9 +203,12 @@
99      (*fp)->fname = apr_pstrdup(p, template);
100  
101      if (!(flags & APR_FILE_NOCLEANUP)) {
102 +        int fdflags = fcntl(fd, F_GETFD);
103 +        fdflags |= FD_CLOEXEC;
104 +        fcntl(fd, F_SETFD, fdflags);
105          apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
106                                    apr_unix_file_cleanup,
107 -                                  apr_unix_child_file_cleanup);
108 +                                  apr_pool_cleanup_null);
109      }
110  #endif
111      return APR_SUCCESS;
112 diff -ur apr-1.3.3.org/file_io/unix/open.c apr-1.3.3/file_io/unix/open.c
113 --- apr-1.3.3.org/file_io/unix/open.c   2007-05-15 04:37:16.000000000 +0200
114 +++ apr-1.3.3/file_io/unix/open.c       2009-02-22 15:56:09.402572969 +0100
115 @@ -125,7 +125,15 @@
116          oflags |= O_BINARY;
117      }
118  #endif
119 -    
120 +
121 +#ifdef O_CLOEXEC
122 +    /* Introduced in Linux 2.6.23. Silently ignored on earlier Linux kernels.
123 +     */
124 +    if (!(flag & APR_FILE_NOCLEANUP)) {
125 +        oflags |= O_CLOEXEC;
126 +}
127 +#endif
128
129  #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
130      oflags |= O_LARGEFILE;
131  #elif defined(O_LARGEFILE)
132 @@ -153,6 +161,11 @@
133      if (fd < 0) {
134         return errno;
135      }
136 +    if (!(flag & APR_FILE_NOCLEANUP)) {
137 +        int fdflags = fcntl(fd, F_GETFD);
138 +        fdflags |= FD_CLOEXEC;
139 +        fcntl(fd, F_SETFD, fdflags);
140 +    }
141  
142      (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
143      (*new)->pool = pool;
144 @@ -194,7 +207,7 @@
145      if (!(flag & APR_FILE_NOCLEANUP)) {
146          apr_pool_cleanup_register((*new)->pool, (void *)(*new), 
147                                    apr_unix_file_cleanup, 
148 -                                  apr_unix_child_file_cleanup);
149 +                                  apr_pool_cleanup_null);
150      }
151      return APR_SUCCESS;
152  }
153 @@ -325,23 +338,6 @@
154  }
155  
156  APR_IMPLEMENT_INHERIT_SET(file, flags, pool, apr_unix_file_cleanup)
157 -
158 -/* We need to do this by hand instead of using APR_IMPLEMENT_INHERIT_UNSET
159 - * because the macro sets both cleanups to the same function, which is not
160 - * suitable on Unix (see PR 41119). */
161 -APR_DECLARE(apr_status_t) apr_file_inherit_unset(apr_file_t *thefile)
162 -{
163 -    if (thefile->flags & APR_FILE_NOCLEANUP) {
164 -        return APR_EINVAL;
165 -    }
166 -    if (thefile->flags & APR_INHERIT) {
167 -        thefile->flags &= ~APR_INHERIT;
168 -        apr_pool_child_cleanup_set(thefile->pool,
169 -                                   (void *)thefile,
170 -                                   apr_unix_file_cleanup,
171 -                                   apr_unix_child_file_cleanup);
172 -    }
173 -    return APR_SUCCESS;
174 -}
175 +APR_IMPLEMENT_INHERIT_UNSET(file, flags, pool, apr_unix_file_cleanup)
176  
177  APR_POOL_IMPLEMENT_ACCESSOR(file)
178 Tylko w apr-1.3.3/file_io/unix: open.c.orig
179 diff -ur apr-1.3.3.org/include/arch/unix/apr_arch_inherit.h apr-1.3.3/include/arch/unix/apr_arch_inherit.h
180 --- apr-1.3.3.org/include/arch/unix/apr_arch_inherit.h  2006-08-03 12:55:31.000000000 +0200
181 +++ apr-1.3.3/include/arch/unix/apr_arch_inherit.h      2009-02-22 15:56:09.402572969 +0100
182 @@ -27,10 +27,13 @@
183      if (the##name->flag & APR_FILE_NOCLEANUP)                       \
184          return APR_EINVAL;                                          \
185      if (!(the##name->flag & APR_INHERIT)) {                         \
186 +        int flags = fcntl(the##name->name##des, F_GETFD);           \
187 +        if (flags == -1)                                            \
188 +            return errno;                                           \
189 +        flags &= ~(FD_CLOEXEC);                                     \
190 +        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
191 +            return errno;                                           \
192          the##name->flag |= APR_INHERIT;                             \
193 -        apr_pool_child_cleanup_set(the##name->pool,                 \
194 -                                   (void *)the##name,               \
195 -                                   cleanup, apr_pool_cleanup_null); \
196      }                                                               \
197      return APR_SUCCESS;                                             \
198  }
199 @@ -41,10 +44,13 @@
200      if (the##name->flag & APR_FILE_NOCLEANUP)                       \
201          return APR_EINVAL;                                          \
202      if (the##name->flag & APR_INHERIT) {                            \
203 +        int flags = fcntl(the##name->name##des, F_GETFD);           \
204 +        if (flags == -1)                                            \
205 +            return errno;                                           \
206 +        flags |= FD_CLOEXEC;                                        \
207 +        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
208 +            return errno;                                           \
209          the##name->flag &= ~APR_INHERIT;                            \
210 -        apr_pool_child_cleanup_set(the##name->pool,                 \
211 -                                   (void *)the##name,               \
212 -                                   cleanup, cleanup);               \
213      }                                                               \
214      return APR_SUCCESS;                                             \
215  }
216 diff -ur apr-1.3.3.org/network_io/unix/sockets.c apr-1.3.3/network_io/unix/sockets.c
217 --- apr-1.3.3.org/network_io/unix/sockets.c     2009-02-22 15:55:36.179428770 +0100
218 +++ apr-1.3.3/network_io/unix/sockets.c 2009-02-22 16:09:42.820111487 +0100
219 @@ -83,7 +83,11 @@
220  apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
221                                 int protocol, apr_pool_t *cont)
222  {
223 -    int family = ofamily;
224 +    int family = ofamily, flags = 0;
225 +
226 +#ifdef SOCK_CLOEXEC
227 +    flags |= SOCK_CLOEXEC;
228 +#endif
229  
230      if (family == APR_UNSPEC) {
231  #if APR_HAVE_IPV6
232 @@ -96,19 +100,19 @@
233      alloc_socket(new, cont);
234  
235  #ifndef BEOS_R5
236 -    (*new)->socketdes = socket(family, type, protocol);
237 +    (*new)->socketdes = socket(family, type|flags, protocol);
238  #else
239      /* For some reason BeOS R5 has an unconventional protocol numbering,
240       * so we need to translate here. */
241      switch (protocol) {
242      case 0:
243 -        (*new)->socketdes = socket(family, type, 0);
244 +        (*new)->socketdes = socket(family, type|flags, 0);
245          break;
246      case APR_PROTO_TCP:
247 -        (*new)->socketdes = socket(family, type, IPPROTO_TCP);
248 +        (*new)->socketdes = socket(family, type|flags, IPPROTO_TCP);
249          break;
250      case APR_PROTO_UDP:
251 -        (*new)->socketdes = socket(family, type, IPPROTO_UDP);
252 +        (*new)->socketdes = socket(family, type|flags, IPPROTO_UDP);
253          break;
254      case APR_PROTO_SCTP:
255      default:
256 @@ -121,7 +125,7 @@
257  #if APR_HAVE_IPV6
258      if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
259          family = APR_INET;
260 -        (*new)->socketdes = socket(family, type, protocol);
261 +        (*new)->socketdes = socket(family, type|flags, protocol);
262      }
263  #endif
264  
265 @@ -130,6 +134,15 @@
266      }
267      set_socket_vars(*new, family, type, protocol);
268  
269 +#ifndef SOCK_CLOEXEC
270 +    flags = fcntl((*new)->socketdes, F_GETFD);
271 +    if (flags == -1)
272 +        return errno;
273 +    flags |= FD_CLOEXEC;
274 +    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
275 +        return errno;
276 +#endif
277 +
278      (*new)->timeout = -1;
279      (*new)->inherit = 0;
280      apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
281 @@ -176,12 +189,16 @@
282  apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
283                                 apr_pool_t *connection_context)
284  {
285 -    int s;
286 +    int s, flags;
287      apr_sockaddr_t sa;
288  
289      sa.salen = sizeof(sa.sa);
290  
291 +#ifdef HAVE_ACCEPT4
292 +    s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
293 +#else
294      s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
295 +#endif
296  
297      if (s < 0) {
298          return errno;
299 @@ -255,6 +272,15 @@
300          (*new)->local_interface_unknown = 1;
301      }
302  
303 +#ifndef HAVE_ACCEPT4
304 +    flags = fcntl((*new)->socketdes, F_GETFD);
305 +    if (flags == -1)
306 +        return errno;
307 +    flags |= FD_CLOEXEC;
308 +    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
309 +        return errno;
310 +#endif
311 +
312      (*new)->inherit = 0;
313      apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
314                                socket_cleanup);
315 diff -ur apr-1.3.3.org/poll/unix/epoll.c apr-1.3.3/poll/unix/epoll.c
316 --- apr-1.3.3.org/poll/unix/epoll.c     2008-04-13 13:37:52.000000000 +0200
317 +++ apr-1.3.3/poll/unix/epoll.c 2009-02-22 16:01:22.005735200 +0100
318 @@ -91,14 +91,24 @@
319                                               apr_uint32_t flags)
320  {
321      apr_status_t rv;
322 -    int fd;
323 +    int fd, fdflags;
324  
325 +#ifdef HAVE_EPOLL_CREATE1
326 +    fd = epoll_create1(EPOLL_CLOEXEC);
327 +#else
328      fd = epoll_create(size);
329 +#endif
330      if (fd < 0) {
331          *pollset = NULL;
332          return errno;
333      }
334  
335 +#ifndef HAVE_EPOLL_CREATE1
336 +    fdflags = fcntl(fd, F_GETFD);
337 +    fdflags |= FD_CLOEXEC;
338 +    fcntl(fd, F_SETFD, fdflags);
339 +#endif
340 +
341      *pollset = apr_palloc(p, sizeof(**pollset));
342  #if APR_HAS_THREADS
343      if ((flags & APR_POLLSET_THREADSAFE) &&
344 @@ -315,14 +325,24 @@
345                                              apr_pool_t *p,
346                                              apr_uint32_t flags)
347  {
348 -    int fd;
349 -    
350 +    int fd, fdflags;
351 +   
352 +#ifdef HAVE_EPOLL_CREATE1
353 +    fd = epoll_create1(EPOLL_CLOEXEC);
354 +#else
355      fd = epoll_create(size);
356 +#endif
357      
358      if (fd < 0) {
359          *pollcb = NULL;
360          return apr_get_netos_error();
361      }
362 +
363 +#ifndef HAVE_EPOLL_CREATE1
364 +    fdflags = fcntl(fd, F_GETFD);
365 +    fdflags |= FD_CLOEXEC;
366 +    fcntl(fd, F_SETFD, fdflags);
367 +#endif
368      
369      *pollcb = apr_palloc(p, sizeof(**pollcb));
370      (*pollcb)->nalloc = size;
371
This page took 0.064458 seconds and 4 git commands to generate.