![]() |
|
|||
0001 /** 0002 * @brief `committrans' aka `commit' command implementation 0003 * 0004 * @file cmd_commit.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) 0068 { 0069 UBFH *p_ub = atmi_xa_alloc_tm_call(ATMI_XA_COMMITTRANS); 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 /* printf("!!! About to call [%s]", svcnm); */ 0089 /* This will return ATMI error */ 0090 if (NULL==(p_ub = atmi_xa_call_tm_generic_fb(ATMI_XA_COMMITTRANS, svcnm, EXFALSE, EXFAIL, 0091 NULL, p_ub))) 0092 { 0093 EXFAIL_OUT(ret); 0094 } 0095 0096 out: 0097 0098 if (NULL!=p_ub) 0099 { 0100 tpfree((char *)p_ub); 0101 } 0102 0103 return ret; 0104 } 0105 0106 /** 0107 * Commit transaction (all or single RMID) 0108 * @param p_cmd_map 0109 * @param argc 0110 * @param argv 0111 * @return SUCCEED 0112 */ 0113 expublic int cmd_commit(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next) 0114 { 0115 int ret = EXSUCCEED; 0116 char tmxid[NDRX_XID_SERIAL_BUFSIZE+1]; 0117 char srvcnm[MAXTIDENT+1]; 0118 short confirm = EXFALSE; 0119 ncloptmap_t clopt[] = 0120 { 0121 {'y', BFLD_SHORT, (void *)&confirm, 0, 0122 NCLOPT_OPT | NCLOPT_TRUEBOOL, "Confirm"}, 0123 {'t', BFLD_STRING, (void *)srvcnm, sizeof(tmxid), 0124 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "TM reference"}, 0125 {'x', BFLD_STRING, (void *)tmxid, sizeof(tmxid), 0126 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "XID"}, 0127 {0} 0128 }; 0129 0130 /* we need to init TP subsystem... */ 0131 if (EXSUCCEED!=tpinit(NULL)) 0132 { 0133 fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno)); 0134 EXFAIL_OUT(ret); 0135 } 0136 0137 /* parse command line */ 0138 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE)) 0139 { 0140 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG); 0141 EXFAIL_OUT(ret); 0142 } 0143 0144 /* Check for confirmation */ 0145 if (!ndrx_chk_confirm("Are you sure you want to commit the transaction?", confirm)) 0146 { 0147 EXFAIL_OUT(ret); 0148 } 0149 0150 /* call the transaction manager */ 0151 if (EXSUCCEED!=call_tm(srvcnm, tmxid)) 0152 { 0153 fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "%s\n", tpstrerror(tperrno)); 0154 EXFAIL_OUT(ret); 0155 } 0156 0157 printf("OK\n"); 0158 0159 out: 0160 return ret; 0161 } 0162 0163 /* vim: set ts=4 sw=4 et smartindent: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |