Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Standard library error handling
0003  *
0004  * @file onerror.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdint.h>
0037 #include <stdlib.h>
0038 #include <memory.h>
0039 #include <errno.h>
0040 #include <dlfcn.h>
0041 
0042 #include <atmi.h>
0043 #include <atmi_tls.h>
0044 #include <ndrstandard.h>
0045 #include <ndebug.h>
0046 #include <ndrxdcmn.h>
0047 #include <userlog.h>
0048 #include <xa_cmn.h>
0049 /*---------------------------Externs------------------------------------*/
0050 /*---------------------------Macros-------------------------------------*/
0051 /*---------------------------Enums--------------------------------------*/
0052 /*---------------------------Typedefs-----------------------------------*/
0053 /*---------------------------Globals------------------------------------*/
0054 /*---------------------------Statics------------------------------------*/
0055 /*---------------------------Prototypes---------------------------------*/
0056 
0057 /**
0058  * Object-API wrapper for Nstrerror() - Auto generated.
0059  */
0060 expublic char * ONstrerror(TPCONTEXT_T *p_ctxt, int err) 
0061 {
0062     int did_set = EXFALSE;
0063     char * ret = NULL;
0064 
0065 
0066 #ifdef NDRX_OAPI_DEBUG
0067     NDRX_LOG(log_debug, "ENTRY: Nstrerror() enter, context: %p, current: %p", *p_ctxt, G_atmi_tls);
0068     NDRX_LOG(log_debug, "ENTRY: is_associated_with_thread = %d", 
0069         ((atmi_tls_t *)*p_ctxt)->is_associated_with_thread);
0070 
0071     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_NSTD = %d", 
0072         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_NSTD );
0073 
0074     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_UBF = %d", 
0075         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_UBF );
0076 
0077     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_ATMI = %d", 
0078         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_ATMI );
0079 
0080     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_TRAN = %d", 
0081         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_TRAN );
0082 
0083     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_NOCHK = %d", 
0084         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_NOCHK );
0085 
0086     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_IGN = %d", 
0087         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_IGN );
0088 #endif
0089 
0090  
0091     
0092     if (!((atmi_tls_t *)*p_ctxt)->is_associated_with_thread)
0093     {
0094         /* set the context */
0095         if (EXSUCCEED!=ndrx_tpsetctxt(*p_ctxt, 0, 
0096             CTXT_PRIV_NSTD | CTXT_PRIV_IGN))
0097         {
0098             userlog("ERROR! Nstrerror() failed to set context");
0099             ret = NULL;
0100             goto out;
0101         }
0102         did_set = EXTRUE;
0103     }
0104     else if ((atmi_tls_t *)*p_ctxt != G_atmi_tls)
0105     {
0106         userlog("WARNING! Nstrerror() context %p thinks that it is assocated "
0107                 "with current thread, but thread is associated with %p context!",
0108                 p_ctxt, G_atmi_tls);
0109     }
0110     
0111     ret = Nstrerror(err);
0112 
0113     if (did_set)
0114     {
0115         if (TPMULTICONTEXTS!=ndrx_tpgetctxt(p_ctxt, 0,
0116                 CTXT_PRIV_NSTD | CTXT_PRIV_IGN))
0117         {
0118             userlog("ERROR! Nstrerror() failed to get context");
0119             ret = NULL;
0120             goto out;
0121         }
0122     }
0123 out:
0124 
0125 #ifdef NDRX_OAPI_DEBUG
0126     NDRX_LOG(log_debug, "RETURN: Nstrerror() returns, context: %p, current: %p",
0127         *p_ctxt, G_atmi_tls);
0128 #endif
0129 
0130 
0131     return ret; 
0132 }
0133 
0134 
0135 /**
0136  * Object-API wrapper for _Nget_Nerror_addr() - Auto generated.
0137  */
0138 expublic int * O_Nget_Nerror_addr(TPCONTEXT_T *p_ctxt) 
0139 {
0140     int did_set = EXFALSE;
0141     int * ret = NULL;
0142 
0143 
0144 #ifdef NDRX_OAPI_DEBUG
0145     NDRX_LOG(log_debug, "ENTRY: _Nget_Nerror_addr() enter, context: %p, current: %p", *p_ctxt, G_atmi_tls);
0146     NDRX_LOG(log_debug, "ENTRY: is_associated_with_thread = %d", 
0147         ((atmi_tls_t *)*p_ctxt)->is_associated_with_thread);
0148 
0149     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_NSTD = %d", 
0150         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_NSTD );
0151 
0152     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_UBF = %d", 
0153         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_UBF );
0154 
0155     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_ATMI = %d", 
0156         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_ATMI );
0157 
0158     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_TRAN = %d", 
0159         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_TRAN );
0160 
0161     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_NOCHK = %d", 
0162         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_NOCHK );
0163 
0164     NDRX_LOG(log_debug, "ENTRY: CTXT_PRIV_IGN = %d", 
0165         (CTXT_PRIV_NSTD | CTXT_PRIV_IGN) & CTXT_PRIV_IGN );
0166 #endif
0167 
0168  
0169     
0170     if (!((atmi_tls_t *)*p_ctxt)->is_associated_with_thread)
0171     {
0172         /* set the context */
0173         if (EXSUCCEED!=ndrx_tpsetctxt(*p_ctxt, 0, 
0174             CTXT_PRIV_NSTD | CTXT_PRIV_IGN))
0175         {
0176             userlog("ERROR! _Nget_Nerror_addr() failed to set context");
0177             ret = NULL;
0178             goto out;
0179         }
0180         did_set = EXTRUE;
0181     }
0182     else if ((atmi_tls_t *)*p_ctxt != G_atmi_tls)
0183     {
0184         userlog("WARNING! _Nget_Nerror_addr() context %p thinks that it is assocated "
0185                 "with current thread, but thread is associated with %p context!",
0186                 p_ctxt, G_atmi_tls);
0187     }
0188     
0189     ret = _Nget_Nerror_addr();
0190 
0191     if (did_set)
0192     {
0193         if (TPMULTICONTEXTS!=ndrx_tpgetctxt(p_ctxt, 0,
0194                 CTXT_PRIV_NSTD | CTXT_PRIV_IGN))
0195         {
0196             userlog("ERROR! _Nget_Nerror_addr() failed to get context");
0197             ret = NULL;
0198             goto out;
0199         }
0200     }
0201 out:
0202 
0203 #ifdef NDRX_OAPI_DEBUG
0204     NDRX_LOG(log_debug, "RETURN: _Nget_Nerror_addr() returns, context: %p, current: %p",
0205         *p_ctxt, G_atmi_tls);
0206 #endif
0207 
0208 
0209     return ret; 
0210 }
0211 
0212