Print this page
10108 libstmfproxy needs smatch fixes

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libstmfproxy/common/stmftransport.c
          +++ new/usr/src/lib/libstmfproxy/common/stmftransport.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
       26 +/*
       27 + * Copyright (c) 2018, Joyent, Inc.
       28 + */
       29 +
  26   30  #include <stdio.h>
  27   31  #include <stdlib.h>
  28   32  #include <string.h>
  29   33  #include <strings.h>
  30   34  #include <sys/types.h>
  31   35  #include <errno.h>
  32   36  #include <syslog.h>
  33   37  #include <unistd.h>
  34   38  #include <sys/types.h>
  35   39  #include <sys/socket.h>
↓ open down ↓ 78 lines elided ↑ open up ↑
 114  118                  new_sfd = accept(sfd, (struct sockaddr *)&cli_addr, &cliLen);
 115  119  
 116  120                  if (new_sfd < 0) {
 117  121                          syslog(LOG_DAEMON|LOG_WARNING, "accept failed: %d",
 118  122                              errno);
 119  123                          goto serv_out;
 120  124                  }
 121  125                  sh = malloc(sizeof (*sh));
 122  126                  sh->sockfd = new_sfd;
 123  127  serv_out:
 124      -                close(sfd);
      128 +                (void) close(sfd);
 125  129          } else {
 126  130                  struct  hostent *hp;
 127  131  
 128  132                  /*
 129  133                   * Assume IP dot notation or if that fails, gethostbyname()
 130  134                   * If that fails, return
 131  135                   */
 132  136                  if ((inet_aton(server, &sin.sin_addr)) == 0) {
 133  137                          if ((hp = gethostbyname(server)) != NULL) {
 134  138                                  memcpy(&sin.sin_addr.s_addr, hp->h_addr,
↓ open down ↓ 9 lines elided ↑ open up ↑
 144  148                              "Sorry, cannot use ip address format\n");
 145  149                          (void) close(sfd);
 146  150                          return (NULL);
 147  151                  }
 148  152                  sin.sin_family = AF_INET;
 149  153                  /* XXX pass in from smf */
 150  154                  sin.sin_port = htons(6543);
 151  155  
 152  156                  while (connect(sfd, (struct sockaddr *)&sin,
 153  157                      sizeof (sin)) < 0) {
 154      -                        close(sfd);
      158 +                        (void) close(sfd);
 155  159                          if (errno == ECONNREFUSED) {
 156  160                                  /* get a fresh socket and retry */
 157  161                                  sfd = socket(AF_INET, SOCK_STREAM, 0);
 158  162                                  if (sfd < 0) {
 159  163                                          syslog(LOG_DAEMON|LOG_WARNING,
 160  164                                              "socket() call failed: %d", errno);
 161  165                                          return (NULL);
 162  166                                  }
 163      -                                sleep(2);
      167 +                                (void) sleep(2);
 164  168                          } else {
 165  169                                  syslog(LOG_DAEMON|LOG_CRIT,
 166  170                                      "Cannot connect %s - %d", server, errno);
 167  171                                  return (NULL);
 168  172                          }
 169  173                  }
 170  174                  sh = malloc(sizeof (*sh));
 171  175                  sh->sockfd = sfd;
 172  176          }
 173  177          return (sh);
↓ open down ↓ 18 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX