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>


   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 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"


  28 
  29 #include <scsi/libses.h>
  30 #include "ses_impl.h"
  31 
  32 __thread ses_errno_t _ses_errno;
  33 __thread char _ses_errmsg[1024];
  34 __thread char _ses_nverr_member[256];
  35 
  36 static void ses_vpanic(const char *, va_list) __NORETURN;
  37 
  38 static void
  39 ses_vpanic(const char *fmt, va_list ap)
  40 {
  41         int oserr = errno;
  42         char msg[BUFSIZ];
  43         size_t len;
  44 
  45         (void) snprintf(msg, sizeof (msg), "ABORT: ");
  46         len = strlen(msg);
  47         (void) vsnprintf(msg + len, sizeof (msg) - len, fmt, ap);
  48 
  49         if (strchr(fmt, '\n') == NULL) {
  50                 len = strlen(msg);
  51                 (void) snprintf(msg + len, sizeof (msg) - len, ": %s\n",
  52                     strerror(oserr));
  53         }
  54 
  55         (void) write(STDERR_FILENO, msg, strlen(msg));
  56 
  57 abort:
  58         abort();
  59         _exit(1);
  60 }
  61 
  62 /*PRINTFLIKE1*/
  63 void
  64 ses_panic(const char *fmt, ...)
  65 {
  66         va_list ap;
  67 
  68         va_start(ap, fmt);
  69         ses_vpanic(fmt, ap);
  70         va_end(ap);
  71 }
  72 
  73 int
  74 ses_assert(const char *expr, const char *file, int line)
  75 {
  76         ses_panic("\"%s\", line %d: assertion failed: %s\n", file, line, expr);
  77 
  78         /*NOTREACHED*/
  79         return (0);




   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 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2019 Joyent, Inc.
  29  */
  30 
  31 #include <scsi/libses.h>
  32 #include "ses_impl.h"
  33 
  34 __thread ses_errno_t _ses_errno;
  35 __thread char _ses_errmsg[1024];
  36 __thread char _ses_nverr_member[256];
  37 
  38 static void ses_vpanic(const char *, va_list) __NORETURN;
  39 
  40 static void
  41 ses_vpanic(const char *fmt, va_list ap)
  42 {
  43         int oserr = errno;
  44         char msg[BUFSIZ];
  45         size_t len;
  46 
  47         (void) snprintf(msg, sizeof (msg), "ABORT: ");
  48         len = strlen(msg);
  49         (void) vsnprintf(msg + len, sizeof (msg) - len, fmt, ap);
  50 
  51         if (strchr(fmt, '\n') == NULL) {
  52                 len = strlen(msg);
  53                 (void) snprintf(msg + len, sizeof (msg) - len, ": %s\n",
  54                     strerror(oserr));
  55         }
  56 
  57         (void) write(STDERR_FILENO, msg, strlen(msg));
  58 

  59         abort();

  60 }
  61 
  62 /*PRINTFLIKE1*/
  63 void
  64 ses_panic(const char *fmt, ...)
  65 {
  66         va_list ap;
  67 
  68         va_start(ap, fmt);
  69         ses_vpanic(fmt, ap);
  70         va_end(ap);
  71 }
  72 
  73 int
  74 ses_assert(const char *expr, const char *file, int line)
  75 {
  76         ses_panic("\"%s\", line %d: assertion failed: %s\n", file, line, expr);
  77 
  78         /*NOTREACHED*/
  79         return (0);