Print this page
6771 end-of-loop code not reached in common/dnssd_clientstub.c

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdns_sd/common/dnssd_clientstub.c
          +++ new/usr/src/lib/libdns_sd/common/dnssd_clientstub.c
↓ open down ↓ 586 lines elided ↑ open up ↑
 587  587              }
 588  588          }
 589  589          //printf("ConnectToServer opened socket %d\n", sdr->sockfd);
 590  590      }
 591  591  
 592  592      *ref = sdr;
 593  593      return kDNSServiceErr_NoError;
 594  594  }
 595  595  
 596  596  #define deliver_request_bailout(MSG) \
 597      -    do { syslog(LOG_WARNING, "dnssd_clientstub deliver_request: %s failed %d (%s)", (MSG), dnssd_errno, dnssd_strerror(dnssd_errno)); goto cleanup; } while(0)
      597 +    syslog(LOG_WARNING, "dnssd_clientstub deliver_request: %s failed %d (%s)", (MSG), dnssd_errno, dnssd_strerror(dnssd_errno)); goto cleanup
 598  598  
 599  599  static DNSServiceErrorType deliver_request(ipc_msg_hdr *hdr, DNSServiceOp *sdr)
 600  600  {
 601  601      uint32_t datalen = hdr->datalen;    // We take a copy here because we're going to convert hdr->datalen to network byte order
 602  602      #if defined(USE_TCP_LOOPBACK) || defined(USE_NAMED_ERROR_RETURN_SOCKET)
 603  603      char *const data = (char *)hdr + sizeof(ipc_msg_hdr);
 604  604      #endif
 605  605      dnssd_sock_t listenfd = dnssd_InvalidSocket, errsd = dnssd_InvalidSocket;
 606  606      DNSServiceErrorType err = kDNSServiceErr_Unknown;   // Default for the "goto cleanup" cases
 607  607      int MakeSeparateReturnSocket = 0;
↓ open down ↓ 21 lines elided ↑ open up ↑
 629  629      }
 630  630  
 631  631      if (MakeSeparateReturnSocket)
 632  632      {
 633  633          #if defined(USE_TCP_LOOPBACK)
 634  634          {
 635  635              union { uint16_t s; u_char b[2]; } port;
 636  636              dnssd_sockaddr_t caddr;
 637  637              dnssd_socklen_t len = (dnssd_socklen_t) sizeof(caddr);
 638  638              listenfd = socket(AF_DNSSD, SOCK_STREAM, 0);
 639      -            if (!dnssd_SocketValid(listenfd)) deliver_request_bailout("TCP socket");
      639 +            if (!dnssd_SocketValid(listenfd)) {
      640 +                                deliver_request_bailout("TCP socket");
      641 +                        }
 640  642  
 641  643              caddr.sin_family      = AF_INET;
 642  644              caddr.sin_port        = 0;
 643  645              caddr.sin_addr.s_addr = inet_addr(MDNS_TCP_SERVERADDR);
 644      -            if (bind(listenfd, (struct sockaddr*) &caddr, sizeof(caddr)) < 0) deliver_request_bailout("TCP bind");
 645      -            if (getsockname(listenfd, (struct sockaddr*) &caddr, &len)   < 0) deliver_request_bailout("TCP getsockname");
 646      -            if (listen(listenfd, 1)                                      < 0) deliver_request_bailout("TCP listen");
      646 +            if (bind(listenfd, (struct sockaddr*) &caddr, sizeof(caddr)) < 0) {
      647 +                                deliver_request_bailout("TCP bind");
      648 +                        }
      649 +            if (getsockname(listenfd, (struct sockaddr*) &caddr, &len)   < 0) {
      650 +                                deliver_request_bailout("TCP getsockname");
      651 +                        }
      652 +                        if (listen(listenfd, 1)                                      < 0) {
      653 +                                deliver_request_bailout("TCP listen");
      654 +                        }
 647  655              port.s = caddr.sin_port;
 648  656              data[0] = port.b[0];  // don't switch the byte order, as the
 649  657              data[1] = port.b[1];  // daemon expects it in network byte order
 650  658          }
 651  659          #elif defined(USE_NAMED_ERROR_RETURN_SOCKET)
 652  660          {
 653  661              mode_t mask;
 654  662              int bindresult;
 655  663              dnssd_sockaddr_t caddr;
 656  664              listenfd = socket(AF_DNSSD, SOCK_STREAM, 0);
 657      -            if (!dnssd_SocketValid(listenfd)) deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET socket");
      665 +            if (!dnssd_SocketValid(listenfd)) {
      666 +                                deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET socket");
      667 +                        }
 658  668  
 659  669              caddr.sun_family = AF_LOCAL;
 660  670              // According to Stevens (section 3.2), there is no portable way to
 661  671              // determine whether sa_len is defined on a particular platform.
 662  672              #ifndef NOT_HAVE_SA_LEN
 663  673              caddr.sun_len = sizeof(struct sockaddr_un);
 664  674              #endif
 665  675              strcpy(caddr.sun_path, data);
 666  676              mask = umask(0);
 667  677              bindresult = bind(listenfd, (struct sockaddr *)&caddr, sizeof(caddr));
 668  678              umask(mask);
 669      -            if (bindresult          < 0) deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET bind");
 670      -            if (listen(listenfd, 1) < 0) deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET listen");
      679 +            if (bindresult          < 0) {
      680 +                                deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET bind");
      681 +                        }
      682 +            if (listen(listenfd, 1) < 0) {
      683 +                                deliver_request_bailout("USE_NAMED_ERROR_RETURN_SOCKET listen");
      684 +                        }
 671  685          }
 672  686          #else
 673  687          {
 674  688              dnssd_sock_t sp[2];
 675      -            if (socketpair(AF_DNSSD, SOCK_STREAM, 0, sp) < 0) deliver_request_bailout("socketpair");
      689 +            if (socketpair(AF_DNSSD, SOCK_STREAM, 0, sp) < 0) {
      690 +                                deliver_request_bailout("socketpair");
      691 +                        }
 676  692              else
 677  693              {
 678  694                  errsd    = sp[0];   // We'll read our four-byte error code from sp[0]
 679  695                  listenfd = sp[1];   // We'll send sp[1] to the daemon
 680  696                  #if !defined(__ppc__) && defined(SO_DEFUNCTOK)
 681  697                  {
 682  698                      int defunct = 1;
 683  699                      if (setsockopt(errsd, SOL_SOCKET, SO_DEFUNCTOK, &defunct, sizeof(defunct)) < 0)
 684  700                          syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: SO_DEFUNCTOK failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno));
 685  701                  }
↓ open down ↓ 45 lines elided ↑ open up ↑
 731  747      {
 732  748  #if defined(USE_TCP_LOOPBACK) || defined(USE_NAMED_ERROR_RETURN_SOCKET)
 733  749          // At this point we may wait in accept for a few milliseconds waiting for the daemon to connect back to us,
 734  750          // but that's okay -- the daemon should not take more than a few milliseconds to respond.
 735  751          // set_waitlimit() ensures we do not block indefinitely just in case something is wrong
 736  752          dnssd_sockaddr_t daddr;
 737  753          dnssd_socklen_t len = sizeof(daddr);
 738  754          if ((err = set_waitlimit(listenfd, DNSSD_CLIENT_TIMEOUT)) != kDNSServiceErr_NoError) 
 739  755              goto cleanup;
 740  756          errsd = accept(listenfd, (struct sockaddr *)&daddr, &len);
 741      -        if (!dnssd_SocketValid(errsd)) 
      757 +        if (!dnssd_SocketValid(errsd)) {
 742  758              deliver_request_bailout("accept");
      759 +                }
 743  760  #else
 744  761  
 745  762          struct iovec vec = { ((char *)hdr) + sizeof(ipc_msg_hdr) + datalen, 1 }; // Send the last byte along with the SCM_RIGHTS
 746  763          struct msghdr msg;
 747  764          struct cmsghdr *cmsg;
 748  765          char cbuf[CMSG_SPACE(4 * sizeof(dnssd_sock_t))];
 749  766  
 750  767          msg.msg_name       = 0;
 751  768          msg.msg_namelen    = 0;
 752  769          msg.msg_iov        = &vec;
↓ open down ↓ 1620 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX