Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief `svqids' and `svsemdis' commands - return resources ids for the
0003  *   user.
0004  *
0005  * @file cmd_svids.c
0006  */
0007 /* -----------------------------------------------------------------------------
0008  * Enduro/X Middleware Platform for Distributed Transaction Processing
0009  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011  * This software is released under one of the following licenses:
0012  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013  * See LICENSE file for full text.
0014  * -----------------------------------------------------------------------------
0015  * AGPL license:
0016  *
0017  * This program is free software; you can redistribute it and/or modify it under
0018  * the terms of the GNU Affero General Public License, version 3 as published
0019  * by the Free Software Foundation;
0020  *
0021  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024  * for more details.
0025  *
0026  * You should have received a copy of the GNU Affero General Public License along 
0027  * with this program; if not, write to the Free Software Foundation, Inc.,
0028  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029  *
0030  * -----------------------------------------------------------------------------
0031  * A commercial use license is available from Mavimax, Ltd
0032  * contact@mavimax.com
0033  * -----------------------------------------------------------------------------
0034  */
0035 #include <string.h>
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <errno.h>
0039 #include <memory.h>
0040 #include <sys/types.h>
0041 #include <sys/stat.h>
0042 #include <ndrstandard.h>
0043 #include <ndebug.h>
0044 
0045 #include <ndrx.h>
0046 #include <ndrxdcmn.h>
0047 #include <atmi_int.h>
0048 #include <gencall.h>
0049 
0050 #include <nstopwatch.h>
0051 #include <nclopt.h>
0052 #include <sys_unix.h>
0053 #include <utlist.h>
0054 /*---------------------------Externs------------------------------------*/
0055 /*---------------------------Macros-------------------------------------*/
0056 /*---------------------------Enums--------------------------------------*/
0057 /*---------------------------Typedefs-----------------------------------*/
0058 /*---------------------------Globals------------------------------------*/
0059 /*---------------------------Statics------------------------------------*/
0060 /*---------------------------Prototypes---------------------------------*/
0061 
0062 /**
0063  * Print user queue ids
0064  * @param p_cmd_map
0065  * @param argc
0066  * @param argv
0067  * @return SUCCEED
0068  */
0069 expublic int cmd_svqids(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0070 {
0071     int ret=EXSUCCEED;
0072     ndrx_growlist_t list;
0073     int i;
0074     mdrx_sysv_res_t *p_res;
0075     int print_ids=EXFALSE;
0076     int print_keys=EXFALSE;
0077     
0078     ncloptmap_t clopt[] =
0079     {
0080         {'i', BFLD_INT, (void *)&print_ids, sizeof(print_ids), 
0081                                 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print IDs only"},
0082         {'k', BFLD_INT, (void *)&print_keys, sizeof(print_keys), 
0083                                 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print Keys only"},
0084         {0}
0085     };
0086 
0087     memset(&list, 0, sizeof(list));
0088             
0089     /* parse command line */
0090     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0091     {
0092         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0093         EXFAIL_OUT(ret);
0094     }
0095 
0096     if (EXSUCCEED!=ndrx_sys_sysv_user_res(&list, NDRX_SV_RESTYPE_QUE))
0097     {
0098         fprintf(stderr, "Failed to list System V queues\n");
0099         NDRX_LOG(log_error, "Failed to list System V queues");
0100         EXFAIL_OUT(ret);
0101     }
0102     
0103     if (print_ids)
0104     {
0105         fprintf(stderr, "    QUEUE ID\n");
0106         fprintf(stderr, "------------\n");
0107     }
0108     else if (print_keys)
0109     {
0110         fprintf(stderr, "   IPC KEY\n");
0111         fprintf(stderr, "----------\n");
0112     }
0113     else
0114     {
0115         fprintf(stderr, "    QUEUE ID    IPC KEY\n");
0116         fprintf(stderr, "------------ ----------\n");
0117     }
0118         
0119     p_res = (mdrx_sysv_res_t *)list.mem;
0120     
0121     for (i=0; i<=list.maxindexused; i++)
0122     {
0123         if (print_ids)
0124         {
0125             fprintf(stdout, "%12u\n", p_res[i].id);
0126         }
0127         else if (print_keys)
0128         {
0129             fprintf(stdout, "0x%08x\n", p_res[i].key);
0130         }
0131         else
0132         {
0133             fprintf(stdout, "%12u 0x%08x\n", p_res[i].id, p_res[i].key);
0134         }
0135     }
0136     
0137 out:
0138     ndrx_growlist_free(&list);
0139 
0140     return ret;
0141 }
0142 
0143 /**
0144  * Print Semaphore IDs, System V for user.
0145  * @param p_cmd_map
0146  * @param argc
0147  * @param argv
0148  * @return SUCCEED
0149  */
0150 expublic int cmd_svsemids(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0151 {
0152     int ret=EXSUCCEED;
0153     ndrx_growlist_t list;
0154     int i;
0155     mdrx_sysv_res_t *p_res;
0156     int print_ids=EXFALSE;
0157     int print_keys=EXFALSE;
0158     
0159     ncloptmap_t clopt[] =
0160     {
0161         {'i', BFLD_INT, (void *)&print_ids, sizeof(print_ids), 
0162                                 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print IDs only"},
0163         {'k', BFLD_INT, (void *)&print_keys, sizeof(print_keys), 
0164                                 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print Keys only"},
0165         {0}
0166     };
0167 
0168     memset(&list, 0, sizeof(list));
0169             
0170     /* parse command line */
0171     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0172     {
0173         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0174         EXFAIL_OUT(ret);
0175     }
0176 
0177     if (EXSUCCEED!=ndrx_sys_sysv_user_res(&list, NDRX_SV_RESTYPE_SEM))
0178     {
0179         fprintf(stderr, "Failed to list System V semaphores\n");
0180         NDRX_LOG(log_error, "Failed to list System V Semaphores");
0181         EXFAIL_OUT(ret);
0182     }
0183     
0184     if (print_ids)
0185     {
0186         fprintf(stderr, "SEMAPHORE ID\n");
0187         fprintf(stderr, "------------\n");
0188     }
0189     else if (print_keys)
0190     {
0191         fprintf(stderr, "   IPC KEY\n");
0192         fprintf(stderr, "----------\n");
0193     }
0194     else
0195     {
0196         fprintf(stderr, "SEMAPHORE ID    IPC KEY\n");
0197         fprintf(stderr, "------------ ----------\n");
0198     }
0199         
0200     p_res = (mdrx_sysv_res_t *)list.mem;
0201     
0202     for (i=0; i<=list.maxindexused; i++)
0203     {
0204         if (print_ids)
0205         {
0206             fprintf(stdout, "%12u\n", p_res[i].id);
0207         }
0208         else if (print_keys)
0209         {
0210             fprintf(stdout, "0x%08x\n", p_res[i].key);
0211         }
0212         else
0213         {
0214             fprintf(stdout, "%12u 0x%08x\n", p_res[i].id, p_res[i].key);
0215         }
0216     }
0217     
0218 out:
0219     ndrx_growlist_free(&list);
0220 
0221     return ret;
0222 }
0223 
0224 /* vim: set ts=4 sw=4 et smartindent: */