Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief `pqa' print queues, all
0003  *
0004  * @file cmd_pqa.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 <errno.h>
0038 #include <memory.h>
0039 #include <sys/types.h>
0040 #include <sys/stat.h>
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043 
0044 #include <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048 
0049 #include <nstopwatch.h>
0050 #include <nclopt.h>
0051 #include <sys_unix.h>
0052 #include <utlist.h>
0053 /*---------------------------Externs------------------------------------*/
0054 /*---------------------------Macros-------------------------------------*/
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 
0062 /**
0063  * Print header
0064  * @return
0065  */
0066 exprivate void print_hdr(void)
0067 {
0068     fprintf(stderr, "MSG QUEUED Q NAME\n");
0069     fprintf(stderr, "---------- ---------------------------------"
0070                     "------------------------------------\n");
0071 }
0072 
0073 /**
0074  * Get service listings
0075  * @param p_cmd_map
0076  * @param argc
0077  * @param argv
0078  * @return SUCCEED
0079  */
0080 expublic int cmd_pqa(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0081 {
0082     int ret=EXSUCCEED;
0083     short print_all = EXFALSE;
0084     struct mq_attr att;
0085     string_list_t* qlist = NULL;
0086     string_list_t* elt = NULL;  
0087     ncloptmap_t clopt[] =
0088     {
0089         {'a', BFLD_SHORT, (void *)&print_all, 0, 
0090                                 NCLOPT_OPT | NCLOPT_TRUEBOOL, "Print all"},
0091         {0}
0092     };
0093     
0094     /* parse command line */
0095     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0096     {
0097         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0098         EXFAIL_OUT(ret);
0099     }
0100 
0101     /* Print header at first step! */
0102     print_hdr();
0103     
0104     qlist = ndrx_sys_mqueue_list_make(G_config.qpath, &ret);
0105     
0106     if (EXSUCCEED!=ret)
0107     {
0108         NDRX_LOG(log_error, "posix queue listing failed!");
0109         EXFAIL_OUT(ret);
0110     }
0111     
0112     LL_FOREACH(qlist,elt)
0113     {
0114         if (!print_all)
0115         {
0116             /* if not print all, then skip this queue */
0117             if (0!=strncmp(elt->qname, 
0118                     G_config.qprefix, strlen(G_config.qprefix)))
0119             {
0120                 continue;
0121             }
0122         }
0123         if (EXSUCCEED!=ndrx_get_q_attr(elt->qname, &att))
0124         {
0125             /* skip this one... */
0126             continue;
0127         }
0128 
0129         fprintf(stdout, "%10d %s\n", (int)att.mq_curmsgs, elt->qname);
0130     }
0131 
0132 out:
0133     if (NULL!=qlist)
0134     {
0135         ndrx_string_list_free(qlist);
0136     }
0137     return ret;
0138 }
0139 /* vim: set ts=4 sw=4 et smartindent: */