diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/util/disk.c | 105 | ||||
-rw-r--r-- | src/util/resolver_api.c | 5 |
2 files changed, 39 insertions, 71 deletions
diff --git a/src/util/disk.c b/src/util/disk.c index 6fe2ebe8f..d64bcbafb 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2005, 2006, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2001--2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -1972,6 +1972,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) | |||
1972 | #endif | 1972 | #endif |
1973 | } | 1973 | } |
1974 | 1974 | ||
1975 | |||
1975 | #if WINDOWS | 1976 | #if WINDOWS |
1976 | /* Copyright Bob Byrnes <byrnes <at> curl.com> | 1977 | /* Copyright Bob Byrnes <byrnes <at> curl.com> |
1977 | http://permalink.gmane.org/gmane.os.cygwin.patches/2121 | 1978 | http://permalink.gmane.org/gmane.os.cygwin.patches/2121 |
@@ -2110,6 +2111,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2110 | } | 2111 | } |
2111 | #endif | 2112 | #endif |
2112 | 2113 | ||
2114 | |||
2113 | /** | 2115 | /** |
2114 | * Creates an interprocess channel | 2116 | * Creates an interprocess channel |
2115 | * | 2117 | * |
@@ -2122,18 +2124,9 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr, | |||
2122 | struct GNUNET_DISK_PipeHandle * | 2124 | struct GNUNET_DISK_PipeHandle * |
2123 | GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write) | 2125 | GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write) |
2124 | { | 2126 | { |
2125 | struct GNUNET_DISK_PipeHandle *p; | ||
2126 | struct GNUNET_DISK_FileHandle *fds; | ||
2127 | |||
2128 | p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + | ||
2129 | 2 * sizeof (struct GNUNET_DISK_FileHandle)); | ||
2130 | fds = (struct GNUNET_DISK_FileHandle *) &p[1]; | ||
2131 | p->fd[0] = &fds[0]; | ||
2132 | p->fd[1] = &fds[1]; | ||
2133 | #ifndef MINGW | 2127 | #ifndef MINGW |
2134 | int fd[2]; | 2128 | int fd[2]; |
2135 | int ret; | 2129 | int ret; |
2136 | int flags; | ||
2137 | int eno; | 2130 | int eno; |
2138 | 2131 | ||
2139 | ret = pipe (fd); | 2132 | ret = pipe (fd); |
@@ -2141,58 +2134,14 @@ GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int i | |||
2141 | { | 2134 | { |
2142 | eno = errno; | 2135 | eno = errno; |
2143 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 2136 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); |
2144 | GNUNET_free (p); | ||
2145 | errno = eno; | ||
2146 | return NULL; | ||
2147 | } | ||
2148 | p->fd[0]->fd = fd[0]; | ||
2149 | p->fd[1]->fd = fd[1]; | ||
2150 | ret = 0; | ||
2151 | if (!blocking_read) | ||
2152 | { | ||
2153 | flags = fcntl (fd[0], F_GETFL); | ||
2154 | flags |= O_NONBLOCK; | ||
2155 | if (0 > fcntl (fd[0], F_SETFL, flags)) | ||
2156 | { | ||
2157 | ret = -1; | ||
2158 | eno = errno; | ||
2159 | } | ||
2160 | } | ||
2161 | flags = fcntl (fd[0], F_GETFD); | ||
2162 | flags |= FD_CLOEXEC; | ||
2163 | if (0 > fcntl (fd[0], F_SETFD, flags)) | ||
2164 | { | ||
2165 | ret = -1; | ||
2166 | eno = errno; | ||
2167 | } | ||
2168 | |||
2169 | if (!blocking_write) | ||
2170 | { | ||
2171 | flags = fcntl (fd[1], F_GETFL); | ||
2172 | flags |= O_NONBLOCK; | ||
2173 | if (0 > fcntl (fd[1], F_SETFL, flags)) | ||
2174 | { | ||
2175 | ret = -1; | ||
2176 | eno = errno; | ||
2177 | } | ||
2178 | } | ||
2179 | flags = fcntl (fd[1], F_GETFD); | ||
2180 | flags |= FD_CLOEXEC; | ||
2181 | if (0 > fcntl (fd[1], F_SETFD, flags)) | ||
2182 | { | ||
2183 | ret = -1; | ||
2184 | eno = errno; | ||
2185 | } | ||
2186 | if (ret == -1) | ||
2187 | { | ||
2188 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl"); | ||
2189 | GNUNET_break (0 == close (p->fd[0]->fd)); | ||
2190 | GNUNET_break (0 == close (p->fd[1]->fd)); | ||
2191 | GNUNET_free (p); | ||
2192 | errno = eno; | 2137 | errno = eno; |
2193 | return NULL; | 2138 | return NULL; |
2194 | } | 2139 | } |
2140 | return GNUNET_DISK_pipe_from_fd (blocking_read, | ||
2141 | blocking_write, | ||
2142 | fd); | ||
2195 | #else | 2143 | #else |
2144 | struct GNUNET_DISK_PipeHandle *p; | ||
2196 | BOOL ret; | 2145 | BOOL ret; |
2197 | HANDLE tmp_handle; | 2146 | HANDLE tmp_handle; |
2198 | 2147 | ||
@@ -2249,15 +2198,17 @@ GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int i | |||
2249 | p->fd[1]->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); | 2198 | p->fd[1]->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); |
2250 | p->fd[1]->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); | 2199 | p->fd[1]->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); |
2251 | 2200 | ||
2252 | #endif | ||
2253 | return p; | 2201 | return p; |
2202 | #endif | ||
2254 | } | 2203 | } |
2255 | 2204 | ||
2205 | |||
2256 | /** | 2206 | /** |
2257 | * Creates a pipe object from a couple of file descriptors. | 2207 | * Creates a pipe object from a couple of file descriptors. |
2258 | * Useful for wrapping existing pipe FDs. | 2208 | * Useful for wrapping existing pipe FDs. |
2259 | * | 2209 | * |
2260 | * @param blocking creates an asynchronous pipe if set to GNUNET_NO | 2210 | * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO |
2211 | * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO | ||
2261 | * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes | 2212 | * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes |
2262 | * | 2213 | * |
2263 | * @return handle to the new pipe, NULL on error | 2214 | * @return handle to the new pipe, NULL on error |
@@ -2283,32 +2234,48 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]) | |||
2283 | ret = 0; | 2234 | ret = 0; |
2284 | if (fd[0] >= 0) | 2235 | if (fd[0] >= 0) |
2285 | { | 2236 | { |
2286 | flags = fcntl (fd[0], F_GETFL); | ||
2287 | if (!blocking_read) | 2237 | if (!blocking_read) |
2238 | { | ||
2239 | flags = fcntl (fd[0], F_GETFL); | ||
2288 | flags |= O_NONBLOCK; | 2240 | flags |= O_NONBLOCK; |
2289 | if (0 > fcntl (fd[0], F_SETFL, flags)) | 2241 | if (0 > fcntl (fd[0], F_SETFL, flags)) |
2290 | ret = -1; | 2242 | { |
2243 | ret = -1; | ||
2244 | eno = errno; | ||
2245 | } | ||
2246 | } | ||
2291 | flags = fcntl (fd[0], F_GETFD); | 2247 | flags = fcntl (fd[0], F_GETFD); |
2292 | flags |= FD_CLOEXEC; | 2248 | flags |= FD_CLOEXEC; |
2293 | if (0 > fcntl (fd[0], F_SETFD, flags)) | 2249 | if (0 > fcntl (fd[0], F_SETFD, flags)) |
2250 | { | ||
2294 | ret = -1; | 2251 | ret = -1; |
2252 | eno = errno; | ||
2253 | } | ||
2295 | } | 2254 | } |
2296 | 2255 | ||
2297 | if (fd[1] >= 0) | 2256 | if (fd[1] >= 0) |
2298 | { | 2257 | { |
2299 | flags = fcntl (fd[1], F_GETFL); | ||
2300 | if (!blocking_write) | 2258 | if (!blocking_write) |
2259 | { | ||
2260 | flags = fcntl (fd[1], F_GETFL); | ||
2301 | flags |= O_NONBLOCK; | 2261 | flags |= O_NONBLOCK; |
2302 | if (0 > fcntl (fd[1], F_SETFL, flags)) | 2262 | if (0 > fcntl (fd[1], F_SETFL, flags)) |
2303 | ret = -1; | 2263 | { |
2264 | ret = -1; | ||
2265 | eno = errno; | ||
2266 | } | ||
2267 | } | ||
2304 | flags = fcntl (fd[1], F_GETFD); | 2268 | flags = fcntl (fd[1], F_GETFD); |
2305 | flags |= FD_CLOEXEC; | 2269 | flags |= FD_CLOEXEC; |
2306 | if (0 > fcntl (fd[1], F_SETFD, flags)) | 2270 | if (0 > fcntl (fd[1], F_SETFD, flags)) |
2271 | { | ||
2307 | ret = -1; | 2272 | ret = -1; |
2273 | eno = errno; | ||
2274 | } | ||
2308 | } | 2275 | } |
2309 | if (ret == -1) | 2276 | if (ret == -1) |
2310 | { | 2277 | { |
2311 | eno = errno; | 2278 | errno = eno; |
2312 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl"); | 2279 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl"); |
2313 | if (p->fd[0]->fd >= 0) | 2280 | if (p->fd[0]->fd >= 0) |
2314 | GNUNET_break (0 == close (p->fd[0]->fd)); | 2281 | GNUNET_break (0 == close (p->fd[0]->fd)); |
@@ -2319,8 +2286,6 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]) | |||
2319 | return NULL; | 2286 | return NULL; |
2320 | } | 2287 | } |
2321 | #else | 2288 | #else |
2322 | BOOL ret; | ||
2323 | |||
2324 | if (fd[0] >= 0) | 2289 | if (fd[0] >= 0) |
2325 | p->fd[0]->h = _get_osfhandle (fd[0]); | 2290 | p->fd[0]->h = _get_osfhandle (fd[0]); |
2326 | else | 2291 | else |
@@ -2421,6 +2386,7 @@ GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, | |||
2421 | return ret; | 2386 | return ret; |
2422 | } | 2387 | } |
2423 | 2388 | ||
2389 | |||
2424 | /** | 2390 | /** |
2425 | * Closes an interprocess channel | 2391 | * Closes an interprocess channel |
2426 | * | 2392 | * |
@@ -2663,6 +2629,7 @@ GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, | |||
2663 | #endif | 2629 | #endif |
2664 | } | 2630 | } |
2665 | 2631 | ||
2632 | |||
2666 | /** | 2633 | /** |
2667 | * Closes a named pipe/FIFO | 2634 | * Closes a named pipe/FIFO |
2668 | * @param pipe named pipe | 2635 | * @param pipe named pipe |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index ea9d55d54..9d5ae6c0a 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -272,8 +272,9 @@ GNUNET_RESOLVER_disconnect () | |||
272 | /** | 272 | /** |
273 | * Convert IP address to string without DNS resolution. | 273 | * Convert IP address to string without DNS resolution. |
274 | * | 274 | * |
275 | * @param sa the address | 275 | * @param af address family |
276 | * @param salen number of bytes in sa | 276 | * @param ip the address |
277 | * @param ip_len number of bytes in ip | ||
277 | * @return address as a string, NULL on error | 278 | * @return address as a string, NULL on error |
278 | */ | 279 | */ |
279 | static char * | 280 | static char * |