Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


   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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 




  26 #include <sys/types.h>
  27 
  28 #include <stddef.h>
  29 #include <stdlib.h>
  30 #include <string.h>
  31 #include <strings.h>
  32 #include <alloca.h>
  33 #include <stdio.h>
  34 #include <unistd.h>
  35 #include <dlfcn.h>
  36 #include <thread.h>
  37 #include <pthread.h>
  38 #include <ctype.h>
  39 
  40 #include <scsi/libsmp.h>
  41 #include <scsi/libsmp_plugin.h>
  42 #include "smp_impl.h"
  43 
  44 __thread smp_errno_t _smp_errno;
  45 __thread char _smp_errmsg[LIBSMP_ERRMSGLEN];
  46 
  47 int
  48 smp_assert(const char *expr, const char *file, int line)
  49 {
  50         char *msg;
  51         size_t len;
  52 
  53         len = snprintf(NULL, 0,
  54             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  55 
  56         msg = alloca(len + 1);
  57 
  58         (void) snprintf(msg, len + 1,
  59             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  60 
  61         (void) write(STDERR_FILENO, msg, strlen(msg));
  62 
  63         abort();
  64         _exit(1);
  65 
  66         /*NOTREACHED*/
  67         return (0);
  68 }
  69 
  70 int
  71 smp_set_errno(smp_errno_t err)
  72 {
  73         _smp_errno = err;
  74         _smp_errmsg[0] = '\0';
  75 
  76         return (-1);
  77 }
  78 
  79 /*
  80  * Internal routine for setting both _smp_errno and _smp_errmsg.  We save
  81  * and restore the UNIX errno across this routing so the caller can use either
  82  * smp_set_errno(), smp_error(), or smp_verror() without this value changing.
  83  */
  84 int
  85 smp_verror(smp_errno_t err, const char *fmt, va_list ap)
  86 {
  87         size_t n;




   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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2019 Joyent, Inc.
  28  */
  29 
  30 #include <sys/types.h>
  31 
  32 #include <stddef.h>
  33 #include <stdlib.h>
  34 #include <string.h>
  35 #include <strings.h>
  36 #include <alloca.h>
  37 #include <stdio.h>
  38 #include <unistd.h>
  39 #include <dlfcn.h>
  40 #include <thread.h>
  41 #include <pthread.h>
  42 #include <ctype.h>
  43 
  44 #include <scsi/libsmp.h>
  45 #include <scsi/libsmp_plugin.h>
  46 #include "smp_impl.h"
  47 
  48 __thread smp_errno_t _smp_errno;
  49 __thread char _smp_errmsg[LIBSMP_ERRMSGLEN];
  50 
  51 int
  52 smp_assert(const char *expr, const char *file, int line)
  53 {
  54         char *msg;
  55         size_t len;
  56 
  57         len = snprintf(NULL, 0,
  58             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  59 
  60         msg = alloca(len + 1);
  61 
  62         (void) snprintf(msg, len + 1,
  63             "ABORT: \"%s\", line %d: assertion failed: %s\n", file, line, expr);
  64 
  65         (void) write(STDERR_FILENO, msg, strlen(msg));
  66 
  67         abort();


  68         /*NOTREACHED*/

  69 }
  70 
  71 int
  72 smp_set_errno(smp_errno_t err)
  73 {
  74         _smp_errno = err;
  75         _smp_errmsg[0] = '\0';
  76 
  77         return (-1);
  78 }
  79 
  80 /*
  81  * Internal routine for setting both _smp_errno and _smp_errmsg.  We save
  82  * and restore the UNIX errno across this routing so the caller can use either
  83  * smp_set_errno(), smp_error(), or smp_verror() without this value changing.
  84  */
  85 int
  86 smp_verror(smp_errno_t err, const char *fmt, va_list ap)
  87 {
  88         size_t n;