~andreserl/ubuntu/lucid/bind9/bind9-apport-533601

« back to all changes in this revision

Viewing changes to lib/isc/unix/socket.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2006-01-05 12:29:28 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060105122928-oih7ttkkmpb90q8q
Tags: 1:9.3.2-1
* New upstream
* use lsb-base for start/stop messages in init.d.
* switch to debhelper 4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
 
2
 * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
3
3
 * Copyright (C) 1998-2003  Internet Software Consortium.
4
4
 *
5
5
 * Permission to use, copy, modify, and distribute this software for any
15
15
 * PERFORMANCE OF THIS SOFTWARE.
16
16
 */
17
17
 
18
 
/* $Id: socket.c,v 1.207.2.19.2.15 2004/11/18 21:31:16 marka Exp $ */
 
18
/* $Id: socket.c,v 1.207.2.19.2.22 2005/11/03 23:08:42 marka Exp $ */
19
19
 
20
20
#include <config.h>
21
21
 
280
280
           const char *fmt, ...)
281
281
{
282
282
        char msgbuf[2048];
283
 
        char peerbuf[256];
 
283
        char peerbuf[ISC_SOCKADDR_FORMATSIZE];
284
284
        va_list ap;
285
285
 
286
286
        if (! isc_log_wouldlog(isc_lctx, level))
363
363
                }
364
364
#endif
365
365
        } while (cc < 0 && SOFT_ERROR(errno));
366
 
                                
 
366
 
367
367
        if (cc < 0) {
368
368
                isc__strerror(errno, strbuf, sizeof(strbuf));
369
369
                FATAL_ERROR(__FILE__, __LINE__,
389
389
        cc = read(mgr->pipe_fds[0], buf, sizeof(buf));
390
390
        if (cc < 0) {
391
391
                *msg = SELECT_POKE_NOTHING;
 
392
                *fd = -1;       /* Silence compiler. */
392
393
                if (SOFT_ERROR(errno))
393
394
                        return;
394
395
 
429
430
        int ret;
430
431
        int flags;
431
432
        char strbuf[ISC_STRERRORSIZE];
 
433
#ifdef USE_FIONBIO_IOCTL
 
434
        int on = 1;
432
435
 
 
436
        ret = ioctl(fd, FIONBIO, (char *)&on);
 
437
#else
433
438
        flags = fcntl(fd, F_GETFL, 0);
434
 
        flags |= O_NONBLOCK;
 
439
        flags |= PORT_NONBLOCK;
435
440
        ret = fcntl(fd, F_SETFL, flags);
 
441
#endif
436
442
 
437
443
        if (ret == -1) {
438
444
                isc__strerror(errno, strbuf, sizeof(strbuf));
439
445
                UNEXPECTED_ERROR(__FILE__, __LINE__,
440
 
                                 "fcntl(%d, F_SETFL, %d): %s",
441
 
                                 fd, flags, strbuf);
 
446
#ifdef USE_FIONBIO_IOCTL
 
447
                                 "ioctl(%d, FIONBIO, &on): %s", fd,
 
448
#else
 
449
                                 "fcntl(%d, F_SETFL, %d): %s", fd, flags,
 
450
#endif
 
451
                                 strbuf);
442
452
 
443
453
                return (ISC_R_UNEXPECTED);
444
454
        }
461
471
#else
462
472
        ISC_SOCKADDR_LEN_T hdrlen;
463
473
 
464
 
        hdrlen = (ISC_SOCKADDR_LEN_T)CMSG_DATA(NULL); /* XXX */
 
474
        /*
 
475
         * Cast NULL so that any pointer arithmetic performed by CMSG_DATA
 
476
         * is correct.
 
477
         */
 
478
        hdrlen = (ISC_SOCKADDR_LEN_T)CMSG_DATA(((struct cmsghdr *)NULL));
465
479
        return (hdrlen + len);
466
480
#endif
467
481
}
1222
1236
        cmsgbuflen += cmsg_space(sizeof(struct timeval));
1223
1237
#endif
1224
1238
        sock->recvcmsgbuflen = cmsgbuflen;
1225
 
        if (sock->recvcmsgbuflen != 0) {
 
1239
        if (sock->recvcmsgbuflen != 0U) {
1226
1240
                sock->recvcmsgbuf = isc_mem_get(manager->mctx, cmsgbuflen);
1227
1241
                if (sock->recvcmsgbuf == NULL)
1228
1242
                        goto error;
1233
1247
        cmsgbuflen = cmsg_space(sizeof(struct in6_pktinfo));
1234
1248
#endif
1235
1249
        sock->sendcmsgbuflen = cmsgbuflen;
1236
 
        if (sock->sendcmsgbuflen != 0) {
 
1250
        if (sock->sendcmsgbuflen != 0U) {
1237
1251
                sock->sendcmsgbuf = isc_mem_get(manager->mctx, cmsgbuflen);
1238
1252
                if (sock->sendcmsgbuf == NULL)
1239
1253
                        goto error;
1348
1362
        int on = 1;
1349
1363
#endif
1350
1364
        char strbuf[ISC_STRERRORSIZE];
 
1365
        const char *err = "socket";
1351
1366
 
1352
1367
        REQUIRE(VALID_MANAGER(manager));
1353
1368
        REQUIRE(socketp != NULL && *socketp == NULL);
1367
1382
        }
1368
1383
 
1369
1384
#ifdef F_DUPFD
1370
 
        /*
1371
 
         * Leave a space for stdio to work in.
1372
 
         */
1373
 
        if (sock->fd >= 0 && sock->fd < 20) {
1374
 
                int new, tmp;
1375
 
                new = fcntl(sock->fd, F_DUPFD, 20);
1376
 
                tmp = errno;
1377
 
                (void)close(sock->fd);
1378
 
                errno = tmp;
1379
 
                sock->fd = new;
1380
 
        }
 
1385
        /*
 
1386
         * Leave a space for stdio to work in.
 
1387
         */
 
1388
        if (sock->fd >= 0 && sock->fd < 20) {
 
1389
                int new, tmp;
 
1390
                new = fcntl(sock->fd, F_DUPFD, 20);
 
1391
                tmp = errno;
 
1392
                (void)close(sock->fd);
 
1393
                errno = tmp;
 
1394
                sock->fd = new;
 
1395
                err = "isc_socket_create: fcntl";
 
1396
        }
1381
1397
#endif
1382
1398
 
1383
1399
        if (sock->fd >= (int)FD_SETSIZE) {
1384
1400
                (void)close(sock->fd);
1385
1401
                isc_log_iwrite(isc_lctx, ISC_LOGCATEGORY_GENERAL,
1386
 
                              ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
 
1402
                               ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
1387
1403
                               isc_msgcat, ISC_MSGSET_SOCKET,
1388
1404
                               ISC_MSG_TOOMANYFDS,
1389
1405
                               "%s: too many open file descriptors", "socket");
1413
1429
                default:
1414
1430
                        isc__strerror(errno, strbuf, sizeof(strbuf));
1415
1431
                        UNEXPECTED_ERROR(__FILE__, __LINE__,
1416
 
                                         "socket() %s: %s",
 
1432
                                         "%s() %s: %s", err,
1417
1433
                                         isc_msgcat_get(isc_msgcat,
1418
1434
                                                        ISC_MSGSET_GENERAL,
1419
1435
                                                        ISC_MSG_FAILED,
1464
1480
#endif /* SO_TIMESTAMP */
1465
1481
 
1466
1482
#if defined(ISC_PLATFORM_HAVEIPV6)
1467
 
                if (pf == AF_INET6 && sock->recvcmsgbuflen == 0) {
 
1483
                if (pf == AF_INET6 && sock->recvcmsgbuflen == 0U) {
1468
1484
                        /*
1469
1485
                         * Warn explicitly because this anomaly can be hidden
1470
1486
                         * in usual operation (and unexpectedly appear later).
1764
1780
        int fd;
1765
1781
        isc_result_t result = ISC_R_SUCCESS;
1766
1782
        char strbuf[ISC_STRERRORSIZE];
 
1783
        const char *err = "accept";
1767
1784
 
1768
1785
        UNUSED(me);
1769
1786
 
1817
1834
                    (void *)&addrlen);
1818
1835
 
1819
1836
#ifdef F_DUPFD
1820
 
        /*
1821
 
         * Leave a space for stdio to work in.
1822
 
         */
1823
 
        if (fd >= 0 && fd < 20) {
1824
 
                int new, tmp;
1825
 
                new = fcntl(fd, F_DUPFD, 20);
1826
 
                tmp = errno;
1827
 
                (void)close(fd);
1828
 
                errno = tmp;
1829
 
                fd = new;
1830
 
        }
 
1837
        /*
 
1838
         * Leave a space for stdio to work in.
 
1839
         */
 
1840
        if (fd >= 0 && fd < 20) {
 
1841
                int new, tmp;
 
1842
                new = fcntl(fd, F_DUPFD, 20);
 
1843
                tmp = errno;
 
1844
                (void)close(fd);
 
1845
                errno = tmp;
 
1846
                fd = new;
 
1847
                err = "fcntl";
 
1848
        }
1831
1849
#endif
1832
1850
 
1833
1851
        if (fd < 0) {
1856
1874
                }
1857
1875
                isc__strerror(errno, strbuf, sizeof(strbuf));
1858
1876
                UNEXPECTED_ERROR(__FILE__, __LINE__,
1859
 
                                 "internal_accept: accept() %s: %s",
 
1877
                                 "internal_accept: %s() %s: %s", err,
1860
1878
                                 isc_msgcat_get(isc_msgcat,
1861
1879
                                                ISC_MSGSET_GENERAL,
1862
1880
                                                ISC_MSG_FAILED,
1865
1883
                fd = -1;
1866
1884
                result = ISC_R_UNEXPECTED;
1867
1885
        } else {
1868
 
                if (addrlen == 0) {
 
1886
                if (addrlen == 0U) {
1869
1887
                        UNEXPECTED_ERROR(__FILE__, __LINE__,
1870
1888
                                         "internal_accept(): "
1871
1889
                                         "accept() failed to return "
2197
2215
                        cc = select(maxfd, &readfds, &writefds, NULL, NULL);
2198
2216
                        if (cc < 0) {
2199
2217
                                if (!SOFT_ERROR(errno)) {
2200
 
                                        isc__strerror(errno, strbuf,
 
2218
                                        isc__strerror(errno, strbuf,
2201
2219
                                                      sizeof(strbuf));
2202
2220
                                        FATAL_ERROR(__FILE__, __LINE__,
2203
2221
                                                    "select() %s: %s",
3094
3112
                        ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES);
3095
3113
                        ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH);
3096
3114
                        ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED);
 
3115
                        ERROR_MATCH(ECONNRESET, ISC_R_CONNECTIONRESET);
3097
3116
#undef ERROR_MATCH
3098
3117
                }
3099
3118
 
3163
3182
        int cc;
3164
3183
        ISC_SOCKADDR_LEN_T optlen;
3165
3184
        char strbuf[ISC_STRERRORSIZE];
 
3185
        char peerbuf[ISC_SOCKADDR_FORMATSIZE];
3166
3186
 
3167
3187
        UNUSED(me);
3168
3188
        INSIST(ev->ev_type == ISC_SOCKEVENT_INTW);
3239
3259
                        ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH);
3240
3260
                        ERROR_MATCH(EPIPE, ISC_R_NOTCONNECTED);
3241
3261
                        ERROR_MATCH(ETIMEDOUT, ISC_R_TIMEDOUT);
 
3262
                        ERROR_MATCH(ECONNRESET, ISC_R_CONNECTIONRESET);
3242
3263
#undef ERROR_MATCH
3243
3264
                default:
3244
3265
                        dev->result = ISC_R_UNEXPECTED;
 
3266
                        isc_sockaddr_format(&sock->address, peerbuf,
 
3267
                                            sizeof(peerbuf));
3245
3268
                        isc__strerror(errno, strbuf, sizeof(strbuf));
3246
3269
                        UNEXPECTED_ERROR(__FILE__, __LINE__,
3247
 
                                         "internal_connect: connect() %s",
3248
 
                                         strbuf);
 
3270
                                         "internal_connect: connect(%s) %s",
 
3271
                                         peerbuf, strbuf);
3249
3272
                }
3250
3273
        } else {
3251
3274
                dev->result = ISC_R_SUCCESS;
3407
3430
                                dev->result = ISC_R_CANCELED;
3408
3431
                                dev->ev_sender = sock;
3409
3432
                                isc_task_sendanddetach(&current_task,
3410
 
                                                ISC_EVENT_PTR(&dev));
 
3433
                                                       ISC_EVENT_PTR(&dev));
3411
3434
                        }
3412
3435
 
3413
3436
                        dev = next;