Print this page
patch cleanup
6659 nvlist_free(NULL) is a no-op


   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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 #include "librcm_impl.h"
  29 #include "librcm_event.h"
  30 
  31 #ifdef  DEBUG
  32 static int rcm_debug = 1;
  33 #define dprintf(args) if (rcm_debug) (void) fprintf args
  34 #else
  35 #define dprintf(args) /* nothing */
  36 #endif  /* DEBUG */
  37 
  38 static int extract_info(nvlist_t *, rcm_info_t **);
  39 static int rcm_daemon_is_alive();
  40 static int rcm_common(int, rcm_handle_t *, char **, uint_t, void *,
  41     rcm_info_t **);
  42 static int rcm_direct_call(int, rcm_handle_t *, char **, uint_t, void *,
  43     rcm_info_t **);
  44 static int rcm_daemon_call(int, rcm_handle_t *, char **, uint_t, void *,
  45     rcm_info_t **);
  46 static int rcm_generate_nvlist(int, rcm_handle_t *, char **, uint_t, void *,
  47     char **, size_t *);


 528                 }
 529         }
 530 
 531         if (infop)
 532                 rcm_free_info(infop);
 533 
 534         return (result);
 535 }
 536 
 537 /*
 538  * RCM helper functions exposed to librcm callers.
 539  */
 540 
 541 /* Free linked list of registration info */
 542 void
 543 rcm_free_info(rcm_info_t *info)
 544 {
 545         while (info) {
 546                 rcm_info_t *tmp = info->next;
 547 
 548                 if (info->info)
 549                         nvlist_free(info->info);
 550                 free(info);
 551 
 552                 info = tmp;
 553         }
 554 }
 555 
 556 /* return the next tuple in the info structure */
 557 rcm_info_tuple_t *
 558 rcm_info_next(rcm_info_t *info, rcm_info_tuple_t *tuple)
 559 {
 560         if (info == NULL) {
 561                 errno = EINVAL;
 562                 return (NULL);
 563         }
 564 
 565         if (tuple == NULL) {
 566                 return ((rcm_info_tuple_t *)info);
 567         }
 568         return ((rcm_info_tuple_t *)tuple->next);


1243                 goto out;
1244         }
1245 
1246         if (infop)
1247                 *infop = info;
1248         else
1249                 rcm_free_info(info);
1250 
1251         if (daemon_errno) {
1252                 if (daemon_errno > 0) {
1253                         errno = daemon_errno;
1254                         error = RCM_FAILURE;
1255                 } else {
1256                         error = daemon_errno;
1257                 }
1258         }
1259 
1260 out:
1261         if (nvl_packed)
1262                 free(nvl_packed);
1263         if (ret)
1264                 nvlist_free(ret);
1265         dprintf((stderr, "daemon call is done. error = %d, errno = %s\n", error,
1266             strerror(errno)));
1267         return (error);
1268 }
1269 
1270 /*
1271  * Extract registration info from event data.
1272  * Return 0 on success and -1 on failure.
1273  */
1274 static int
1275 extract_info(nvlist_t *nvl, rcm_info_t **infop)
1276 {
1277         rcm_info_t *info = NULL;
1278         rcm_info_t *prev = NULL;
1279         rcm_info_t *tmp = NULL;
1280         char *buf;
1281         uint_t buflen;
1282         nvpair_t *nvp = NULL;
1283 


1433 
1434         /* Pack the nvlist */
1435         if (errno = nvlist_pack(nvl, nvl_packed, nvl_size, NV_ENCODE_NATIVE,
1436             0)) {
1437                 dprintf((stderr, "failed (nvlist_pack=%s).\n",
1438                     strerror(errno)));
1439                 goto fail;
1440         }
1441 
1442         /* If an argument was packed intermediately, free the buffer */
1443         if (buf)
1444                 free(buf);
1445 
1446         /* Free the unpacked version of the nvlist and return the packed list */
1447         nvlist_free(nvl);
1448         return (0);
1449 
1450 fail:
1451         if (buf)
1452                 free(buf);
1453         if (nvl)
1454                 nvlist_free(nvl);
1455         if (*nvl_packed)
1456                 free(*nvl_packed);
1457         *nvl_packed = NULL;
1458         *nvl_size = 0;
1459         return (-1);
1460 }
1461 
1462 /* check if rcm_daemon is up and running */
1463 static int
1464 rcm_daemon_is_alive()
1465 {
1466         int lasttry;
1467         struct stat st;
1468         nvlist_t *nvl;
1469         char *buf = NULL;
1470         size_t buflen = 0;
1471         int delay = 300;
1472         const int maxdelay = 10000;     /* 10 sec */
1473 




   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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 


  26 #include "librcm_impl.h"
  27 #include "librcm_event.h"
  28 
  29 #ifdef  DEBUG
  30 static int rcm_debug = 1;
  31 #define dprintf(args) if (rcm_debug) (void) fprintf args
  32 #else
  33 #define dprintf(args) /* nothing */
  34 #endif  /* DEBUG */
  35 
  36 static int extract_info(nvlist_t *, rcm_info_t **);
  37 static int rcm_daemon_is_alive();
  38 static int rcm_common(int, rcm_handle_t *, char **, uint_t, void *,
  39     rcm_info_t **);
  40 static int rcm_direct_call(int, rcm_handle_t *, char **, uint_t, void *,
  41     rcm_info_t **);
  42 static int rcm_daemon_call(int, rcm_handle_t *, char **, uint_t, void *,
  43     rcm_info_t **);
  44 static int rcm_generate_nvlist(int, rcm_handle_t *, char **, uint_t, void *,
  45     char **, size_t *);


 526                 }
 527         }
 528 
 529         if (infop)
 530                 rcm_free_info(infop);
 531 
 532         return (result);
 533 }
 534 
 535 /*
 536  * RCM helper functions exposed to librcm callers.
 537  */
 538 
 539 /* Free linked list of registration info */
 540 void
 541 rcm_free_info(rcm_info_t *info)
 542 {
 543         while (info) {
 544                 rcm_info_t *tmp = info->next;
 545 

 546                 nvlist_free(info->info);
 547                 free(info);
 548 
 549                 info = tmp;
 550         }
 551 }
 552 
 553 /* return the next tuple in the info structure */
 554 rcm_info_tuple_t *
 555 rcm_info_next(rcm_info_t *info, rcm_info_tuple_t *tuple)
 556 {
 557         if (info == NULL) {
 558                 errno = EINVAL;
 559                 return (NULL);
 560         }
 561 
 562         if (tuple == NULL) {
 563                 return ((rcm_info_tuple_t *)info);
 564         }
 565         return ((rcm_info_tuple_t *)tuple->next);


1240                 goto out;
1241         }
1242 
1243         if (infop)
1244                 *infop = info;
1245         else
1246                 rcm_free_info(info);
1247 
1248         if (daemon_errno) {
1249                 if (daemon_errno > 0) {
1250                         errno = daemon_errno;
1251                         error = RCM_FAILURE;
1252                 } else {
1253                         error = daemon_errno;
1254                 }
1255         }
1256 
1257 out:
1258         if (nvl_packed)
1259                 free(nvl_packed);

1260         nvlist_free(ret);
1261         dprintf((stderr, "daemon call is done. error = %d, errno = %s\n", error,
1262             strerror(errno)));
1263         return (error);
1264 }
1265 
1266 /*
1267  * Extract registration info from event data.
1268  * Return 0 on success and -1 on failure.
1269  */
1270 static int
1271 extract_info(nvlist_t *nvl, rcm_info_t **infop)
1272 {
1273         rcm_info_t *info = NULL;
1274         rcm_info_t *prev = NULL;
1275         rcm_info_t *tmp = NULL;
1276         char *buf;
1277         uint_t buflen;
1278         nvpair_t *nvp = NULL;
1279 


1429 
1430         /* Pack the nvlist */
1431         if (errno = nvlist_pack(nvl, nvl_packed, nvl_size, NV_ENCODE_NATIVE,
1432             0)) {
1433                 dprintf((stderr, "failed (nvlist_pack=%s).\n",
1434                     strerror(errno)));
1435                 goto fail;
1436         }
1437 
1438         /* If an argument was packed intermediately, free the buffer */
1439         if (buf)
1440                 free(buf);
1441 
1442         /* Free the unpacked version of the nvlist and return the packed list */
1443         nvlist_free(nvl);
1444         return (0);
1445 
1446 fail:
1447         if (buf)
1448                 free(buf);

1449         nvlist_free(nvl);
1450         if (*nvl_packed)
1451                 free(*nvl_packed);
1452         *nvl_packed = NULL;
1453         *nvl_size = 0;
1454         return (-1);
1455 }
1456 
1457 /* check if rcm_daemon is up and running */
1458 static int
1459 rcm_daemon_is_alive()
1460 {
1461         int lasttry;
1462         struct stat st;
1463         nvlist_t *nvl;
1464         char *buf = NULL;
1465         size_t buflen = 0;
1466         int delay = 300;
1467         const int maxdelay = 10000;     /* 10 sec */
1468