Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief `aborttrans' aka `abort' command implementation
0003  *
0004  * @file cmd_abort.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 <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039 
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <nstdutil.h>
0043 
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <utlist.h>
0048 #include <Exfields.h>
0049 
0050 #include "xa_cmn.h"
0051 #include <ndrx.h>
0052 #include <nclopt.h>
0053 /*---------------------------Externs------------------------------------*/
0054 /*---------------------------Macros-------------------------------------*/
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 
0062 /**
0063  * Do the call to transaction manager
0064  * @param svcnm - Service name of transaction manager.
0065  * @return SUCCEED/FAIL
0066  */
0067 exprivate int call_tm(char *svcnm, char *tmxid, short tmrmid)
0068 {
0069     UBFH *p_ub = atmi_xa_alloc_tm_call(ATMI_XA_ABORTTRANS);
0070     int ret=EXSUCCEED;
0071     
0072     /* Setup the call buffer... */
0073     if (NULL==p_ub)
0074     {
0075         NDRX_LOG(log_error, "Failed to alloc FB!");        
0076         EXFAIL_OUT(ret);
0077     }
0078     
0079     /* Do The TM call */
0080     if (EXSUCCEED!=Bchg(p_ub, TMXID, 0, tmxid, 0L))
0081     {
0082         fprintf(stderr, "System error!\n");
0083         NDRX_LOG(log_error, "Failed to set TMXID: %s!", 
0084                 Bstrerror(Berror));
0085         EXFAIL_OUT(ret);
0086     }
0087     
0088     if (EXFAIL!=tmrmid)
0089     {
0090         if (EXSUCCEED!=Bchg(p_ub, TMTXRMID, 0, (char *)&tmrmid, 0L))
0091         {
0092             fprintf(stderr, "System error!\n");
0093             NDRX_LOG(log_error, "Failed to set TMTXRMID: %s!", 
0094                     Bstrerror(Berror));
0095             EXFAIL_OUT(ret);
0096         }
0097     }
0098     
0099     /* printf("!!! About to call [%s]", svcnm); */
0100     /* This will return ATMI error */
0101     if (NULL==(p_ub = atmi_xa_call_tm_generic_fb(ATMI_XA_ABORTTRANS, svcnm, EXFALSE, EXFAIL, 
0102         NULL, p_ub)))
0103     {
0104         EXFAIL_OUT(ret);
0105     }
0106     
0107 out:
0108 
0109     if (NULL!=p_ub)
0110     {
0111         tpfree((char *)p_ub);
0112     }
0113 
0114     return ret;
0115 }
0116 
0117 /**
0118  * Abort transaction
0119  * @param p_cmd_map
0120  * @param argc
0121  * @param argv
0122  * @return SUCCEED
0123  */
0124 expublic int cmd_abort(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0125 {
0126     int ret = EXSUCCEED;
0127     char tmxid_real[NDRX_XID_SERIAL_BUFSIZE+1];
0128     char srvcnm_real[MAXTIDENT+1];
0129     short confirm = EXFALSE;
0130     short tmrmid_real = EXFAIL;
0131     ncloptmap_t clopt[] =
0132     {
0133         {'y', BFLD_SHORT, (void *)&confirm, 0, 
0134                                 NCLOPT_OPT | NCLOPT_TRUEBOOL, "Confirm"},
0135         {'t', BFLD_STRING, (void *)srvcnm_real, sizeof(tmxid_real), 
0136                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "TM reference"},
0137         {'x', BFLD_STRING, (void *)tmxid_real, sizeof(tmxid_real), 
0138                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "XID"},
0139         {'g', BFLD_SHORT, (void *)&tmrmid_real, 0, 
0140                                 NCLOPT_OPT|NCLOPT_HAVE_VALUE, "Group No"},
0141         {0}
0142     };
0143     
0144     /* we need to init TP subsystem... */
0145     if (EXSUCCEED!=tpinit(NULL))
0146     {
0147         fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno));
0148         EXFAIL_OUT(ret);
0149     }
0150     
0151     /* parse command line */
0152     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0153     {
0154         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0155         EXFAIL_OUT(ret);
0156     }
0157     
0158     /* Check for confirmation */
0159     if (!ndrx_chk_confirm("Are you sure you want to abort the transaction?", confirm))
0160     {
0161         EXFAIL_OUT(ret);
0162     }
0163     
0164     /* call the transaction manager */
0165     if (EXSUCCEED!=call_tm(srvcnm_real, tmxid_real, tmrmid_real))
0166     {
0167         fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "%s\n", tpstrerror(tperrno));
0168         EXFAIL_OUT(ret);
0169     }
0170     
0171     printf("OK\n");
0172     
0173 out:
0174     return ret;
0175 }
0176 
0177 /* vim: set ts=4 sw=4 et smartindent: */