Print this page
10100 Illumos is confused about calloc() arguments


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.


  25  */
  26 
  27 #include <stdlib.h>
  28 #include <strings.h>
  29 #include <unistd.h>
  30 #include <stddef.h>
  31 #include <assert.h>
  32 #include <sys/types.h>
  33 #include <sys/socket.h>
  34 #include <thread.h>
  35 #include <synch.h>
  36 #include <libilb_impl.h>
  37 #include <libilb.h>
  38 
  39 /* Assertion: the calling thread has a hold on the handle */
  40 static void
  41 i_ilb_socket_set_err(ilb_handle_t h, ilb_status_t err)
  42 {
  43         ilb_handle_impl_t       *hi = (ilb_handle_impl_t *)h;
  44 
  45         if (h == ILB_INVALID_HANDLE)
  46                 return;
  47         hi->h_valid = B_FALSE;
  48         hi->h_error = err;
  49 }
  50 
  51 ilb_status_t
  52 ilb_open(ilb_handle_t *hp)
  53 {
  54         ilb_handle_impl_t       *hi = NULL;
  55         int                     s = -1;
  56         struct sockaddr_un sa = {AF_UNIX, SOCKET_PATH};
  57         ilb_status_t            rc = ILB_STATUS_OK;
  58         int                     sobufsz;
  59 
  60         if (hp == NULL)
  61                 return (ILB_STATUS_EINVAL);
  62 
  63         hi = calloc(sizeof (*hi), 1);
  64         if (hi == NULL)
  65                 return (ILB_STATUS_ENOMEM);
  66 
  67         if (cond_init(&hi->h_cv, USYNC_THREAD, NULL) != 0) {
  68                 rc = ILB_STATUS_INTERNAL;
  69                 goto out;
  70         }
  71 
  72         if (mutex_init(&hi->h_lock, USYNC_THREAD | LOCK_ERRORCHECK, NULL)
  73             != 0) {
  74                 rc = ILB_STATUS_INTERNAL;
  75                 goto out;
  76         }
  77 
  78         hi->h_busy = B_FALSE;
  79 
  80         if ((s = socket(PF_UNIX, SOCK_SEQPACKET, 0)) == -1 ||
  81             connect(s, (struct sockaddr *)&sa, sizeof (sa.sun_path))
  82             == -1) {
  83                 rc = ILB_STATUS_SOCKET;




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Copyright (c) 2018, Joyent, Inc.
  27  */
  28 
  29 #include <stdlib.h>
  30 #include <strings.h>
  31 #include <unistd.h>
  32 #include <stddef.h>
  33 #include <assert.h>
  34 #include <sys/types.h>
  35 #include <sys/socket.h>
  36 #include <thread.h>
  37 #include <synch.h>
  38 #include <libilb_impl.h>
  39 #include <libilb.h>
  40 
  41 /* Assertion: the calling thread has a hold on the handle */
  42 static void
  43 i_ilb_socket_set_err(ilb_handle_t h, ilb_status_t err)
  44 {
  45         ilb_handle_impl_t       *hi = (ilb_handle_impl_t *)h;
  46 
  47         if (h == ILB_INVALID_HANDLE)
  48                 return;
  49         hi->h_valid = B_FALSE;
  50         hi->h_error = err;
  51 }
  52 
  53 ilb_status_t
  54 ilb_open(ilb_handle_t *hp)
  55 {
  56         ilb_handle_impl_t       *hi = NULL;
  57         int                     s = -1;
  58         struct sockaddr_un sa = {AF_UNIX, SOCKET_PATH};
  59         ilb_status_t            rc = ILB_STATUS_OK;
  60         int                     sobufsz;
  61 
  62         if (hp == NULL)
  63                 return (ILB_STATUS_EINVAL);
  64 
  65         hi = calloc(1, sizeof (*hi));
  66         if (hi == NULL)
  67                 return (ILB_STATUS_ENOMEM);
  68 
  69         if (cond_init(&hi->h_cv, USYNC_THREAD, NULL) != 0) {
  70                 rc = ILB_STATUS_INTERNAL;
  71                 goto out;
  72         }
  73 
  74         if (mutex_init(&hi->h_lock, USYNC_THREAD | LOCK_ERRORCHECK, NULL)
  75             != 0) {
  76                 rc = ILB_STATUS_INTERNAL;
  77                 goto out;
  78         }
  79 
  80         hi->h_busy = B_FALSE;
  81 
  82         if ((s = socket(PF_UNIX, SOCK_SEQPACKET, 0)) == -1 ||
  83             connect(s, (struct sockaddr *)&sa, sizeof (sa.sun_path))
  84             == -1) {
  85                 rc = ILB_STATUS_SOCKET;