0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
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
0073 if (NULL==p_ub)
0074 {
0075 NDRX_LOG(log_error, "Failed to alloc FB!");
0076 EXFAIL_OUT(ret);
0077 }
0078
0079
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
0100
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
0119
0120
0121
0122
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
0145 if (EXSUCCEED!=tpinit(NULL))
0146 {
0147 fprintf(stderr, "Failed to tpinit(): %s\n", tpstrerror(tperrno));
0148 EXFAIL_OUT(ret);
0149 }
0150
0151
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
0159 if (!ndrx_chk_confirm("Are you sure you want to abort the transaction?", confirm))
0160 {
0161 EXFAIL_OUT(ret);
0162 }
0163
0164
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