]> git.pld-linux.org Git - packages/apr-compat.git/blob - apr-bug-46425.patch
- initialize flags first
[packages/apr-compat.git] / apr-bug-46425.patch
1 Index: network_io/unix/sockets.c
2 ===================================================================
3 --- network_io/unix/sockets.c   (wersja 746595)
4 +++ network_io/unix/sockets.c   (kopia robocza)
5 @@ -83,7 +83,11 @@
6  apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
7                                 int protocol, apr_pool_t *cont)
8  {
9 -    int family = ofamily;
10 +    int family = ofamily, flags = 0;
11 +
12 +#ifdef SOCK_CLOEXEC
13 +    flags |= SOCK_CLOEXEC;
14 +#endif
15  
16      if (family == APR_UNSPEC) {
17  #if APR_HAVE_IPV6
18 @@ -126,19 +130,19 @@
19      alloc_socket(new, cont);
20  
21  #ifndef BEOS_R5
22 -    (*new)->socketdes = socket(family, type, protocol);
23 +    (*new)->socketdes = socket(family, type|flags, protocol);
24  #else
25      /* For some reason BeOS R5 has an unconventional protocol numbering,
26       * so we need to translate here. */
27      switch (protocol) {
28      case 0:
29 -        (*new)->socketdes = socket(family, type, 0);
30 +        (*new)->socketdes = socket(family, type|flags, 0);
31          break;
32      case APR_PROTO_TCP:
33 -        (*new)->socketdes = socket(family, type, IPPROTO_TCP);
34 +        (*new)->socketdes = socket(family, type|flags, IPPROTO_TCP);
35          break;
36      case APR_PROTO_UDP:
37 -        (*new)->socketdes = socket(family, type, IPPROTO_UDP);
38 +        (*new)->socketdes = socket(family, type|flags, IPPROTO_UDP);
39          break;
40      case APR_PROTO_SCTP:
41      default:
42 @@ -151,7 +155,7 @@
43  #if APR_HAVE_IPV6
44      if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
45          family = APR_INET;
46 -        (*new)->socketdes = socket(family, type, protocol);
47 +        (*new)->socketdes = socket(family, type|flags, protocol);
48      }
49  #endif
50  
51 @@ -160,6 +164,15 @@
52      }
53      set_socket_vars(*new, family, type, oprotocol);
54  
55 +#ifndef SOCK_CLOEXEC
56 +    flags = fcntl((*new)->socketdes, F_GETFD);
57 +    if (flags == -1)
58 +        return errno;
59 +    flags |= FD_CLOEXEC;
60 +    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
61 +        return errno;
62 +#endif
63 +
64      (*new)->timeout = -1;
65      (*new)->inherit = 0;
66      apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
67 @@ -213,12 +226,16 @@
68  apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
69                                 apr_pool_t *connection_context)
70  {
71 -    int s;
72 +    int s, flags;
73      apr_sockaddr_t sa;
74  
75      sa.salen = sizeof(sa.sa);
76  
77 +#ifdef HAVE_ACCEPT4
78 +    s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
79 +#else
80      s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
81 +#endif
82  
83      if (s < 0) {
84          return errno;
85 @@ -300,6 +317,15 @@
86          (*new)->local_interface_unknown = 1;
87      }
88  
89 +#ifndef HAVE_ACCEPT4
90 +    flags = fcntl((*new)->socketdes, F_GETFD);
91 +    if (flags == -1)
92 +        return errno;
93 +    flags |= FD_CLOEXEC;
94 +    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
95 +        return errno;
96 +#endif
97 +
98      (*new)->inherit = 0;
99      apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
100                                socket_cleanup);
101 Index: include/arch/unix/apr_arch_inherit.h
102 ===================================================================
103 --- include/arch/unix/apr_arch_inherit.h        (wersja 746595)
104 +++ include/arch/unix/apr_arch_inherit.h        (kopia robocza)
105 @@ -27,6 +27,12 @@
106      if (the##name->flag & APR_FILE_NOCLEANUP)                       \
107          return APR_EINVAL;                                          \
108      if (!(the##name->flag & APR_INHERIT)) {                         \
109 +        int flags = fcntl(the##name->name##des, F_GETFD);           \
110 +        if (flags == -1)                                            \
111 +            return errno;                                           \
112 +        flags &= ~(FD_CLOEXEC);                                     \
113 +        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
114 +            return errno;                                           \
115          the##name->flag |= APR_INHERIT;                             \
116          apr_pool_child_cleanup_set(the##name->pool,                 \
117                                     (void *)the##name,               \
118 @@ -41,6 +47,12 @@
119      if (the##name->flag & APR_FILE_NOCLEANUP)                       \
120          return APR_EINVAL;                                          \
121      if (the##name->flag & APR_INHERIT) {                            \
122 +        int flags = fcntl(the##name->name##des, F_GETFD);           \
123 +        if (flags == -1)                                            \
124 +            return errno;                                           \
125 +        flags |= FD_CLOEXEC;                                        \
126 +        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
127 +            return errno;                                           \
128          the##name->flag &= ~APR_INHERIT;                            \
129          apr_pool_child_cleanup_set(the##name->pool,                 \
130                                     (void *)the##name,               \
131 Index: configure.in
132 ===================================================================
133 --- configure.in        (wersja 746595)
134 +++ configure.in        (kopia robocza)
135 @@ -782,6 +782,9 @@
136     AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
137  fi
138  
139 +dnl ----------------------------- Checking for extended file descriptor handling
140 +AC_CHECK_FUNCS(dup3 accept4 epoll_create1)
141 +
142  dnl ----------------------------- Checking for missing POSIX thread functions
143  AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
144  
145 Index: poll/unix/epoll.c
146 ===================================================================
147 --- poll/unix/epoll.c   (wersja 746595)
148 +++ poll/unix/epoll.c   (kopia robocza)
149 @@ -95,7 +95,11 @@
150      apr_status_t rv;
151      int fd;
152  
153 +#ifdef HAVE_EPOLL_CREATE1
154 +    fd = epoll_create1(EPOLL_CLOEXEC);
155 +#else
156      fd = epoll_create(size);
157 +#endif
158      if (fd < 0) {
159          pollset->p = NULL;
160          return errno;
161 @@ -338,8 +342,12 @@
162                                         apr_uint32_t flags)
163  {
164      int fd;
165 -    
166 +   
167 +#ifdef HAVE_EPOLL_CREATE1
168 +    fd = epoll_create1(EPOLL_CLOEXEC);
169 +#else
170      fd = epoll_create(size);
171 +#endif
172      
173      if (fd < 0) {
174          return apr_get_netos_error();
175 Index: file_io/unix/open.c
176 ===================================================================
177 --- file_io/unix/open.c (wersja 746595)
178 +++ file_io/unix/open.c (kopia robocza)
179 @@ -127,6 +127,10 @@
180          oflags |= O_BINARY;
181      }
182  #endif
183 +#ifdef O_CLOEXEC
184 +    if (!(flag & APR_FILE_NOCLEANUP))
185 +       oflags |= O_CLOEXEC;
186 +#endif
187      
188  #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
189      oflags |= O_LARGEFILE;
190 @@ -337,6 +341,12 @@
191          return APR_EINVAL;
192      }
193      if (thefile->flags & APR_INHERIT) {
194 +        int flags = fcntl(thefile->filedes, F_GETFD);
195 +        if (flags == -1)
196 +             return errno;
197 +        flags |= FD_CLOEXEC;
198 +        if (fcntl(thefile->filedes, F_SETFD, flags) == -1)
199 +             return errno;
200          thefile->flags &= ~APR_INHERIT;
201          apr_pool_child_cleanup_set(thefile->pool,
202                                     (void *)thefile,
203 Index: file_io/unix/filedup.c
204 ===================================================================
205 --- file_io/unix/filedup.c      (wersja 746595)
206 +++ file_io/unix/filedup.c      (kopia robocza)
207 @@ -24,14 +24,28 @@
208                               apr_file_t *old_file, apr_pool_t *p,
209                               int which_dup)
210  {
211 -    int rv;
212 +    int rv, flags = 0;
213      
214      if (which_dup == 2) {
215          if ((*new_file) == NULL) {
216              /* We can't dup2 unless we have a valid new_file */
217              return APR_EINVAL;
218          }
219 +#ifdef HAVE_DUP3
220 +        if (!(old_file->flags & APR_INHERIT))
221 +            flags |= O_CLOEXEC;
222 +        rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
223 +#else
224 +        if (!(old_file->flags & APR_INHERIT)) {
225 +            flags = fcntl(old_file->filedes, F_GETFD);
226 +            if (flags == -1)
227 +                return errno;
228 +            flags |= FD_CLOEXEC;
229 +            if (fcntl(old_file->filedes, F_SETFD, flags) == -1)
230 +                return errno;
231 +        }
232          rv = dup2(old_file->filedes, (*new_file)->filedes);
233 +#endif
234      } else {
235          rv = dup(old_file->filedes);
236      }
This page took 0.061342 seconds and 3 git commands to generate.