1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
4  *                         University Research and Technology
5  *                         Corporation.  All rights reserved.
6  * Copyright (c) 2004-2006 The University of Tennessee and The University
7  *                         of Tennessee Research Foundation.  All rights
8  *                         reserved.
9  * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
10  *                         University of Stuttgart.  All rights reserved.
11  * Copyright (c) 2004-2005 The Regents of the University of California.
12  *                         All rights reserved.
13  * Copyright (c) 2007-2012 Cisco Systems, Inc.  All rights reserved.
14  * Copyright (c) 2010-2016 Los Alamos National Security, LLC.
15  *                         All rights reserved.
16  * Copyright (c) 2014-2020 Intel, Inc.  All rights reserved.
17  * Copyright (c) 2015      Research Organization for Information Science
18  *                         and Technology (RIST). All rights reserved.
19  * $COPYRIGHT$
20  *
21  * Additional copyrights may follow
22  *
23  * $HEADER$
24  */
25 
26 #include "pmix_config.h"
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <ctype.h>
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34 #ifdef HAVE_NETDB_H
35 #include <netdb.h>
36 #endif
37 #ifdef HAVE_SYS_PARAM_H
38 #include <sys/param.h>
39 #endif
40 #include <errno.h>
41 #include <signal.h>
42 
43 #include "src/mca/pinstalldirs/base/base.h"
44 #include "src/class/pmix_object.h"
45 #include "src/class/pmix_pointer_array.h"
46 #include "src/util/argv.h"
47 #include "src/util/cmd_line.h"
48 #include "src/util/error.h"
49 #include "src/util/error.h"
50 #include "src/util/keyval_parse.h"
51 #include "src/util/output.h"
52 #include "src/util/show_help.h"
53 #include "src/mca/base/base.h"
54 #include "src/runtime/pmix_rte.h"
55 
56 #include "pinfo.h"
57 #include "support.h"
58 
59 /*
60  * Public variables
61  */
62 
63 pmix_cmd_line_t *pmix_info_cmd_line = NULL;
64 
65 const char *pmix_info_type_base = "base";
66 
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69     int ret = 0;
70     bool acted = false;
71     bool want_all = false;
72     int i;
73     pmix_pointer_array_t mca_types;
74     pmix_pointer_array_t component_map;
75     pmix_info_component_map_t *map;
76 
77     /* protect against problems if someone passes us thru a pipe
78      * and then abnormally terminates the pipe early */
79     signal(SIGPIPE, SIG_IGN);
80 
81     /* initialize the output system */
82     if (!pmix_output_init()) {
83         return PMIX_ERROR;
84     }
85 
86     /* initialize install dirs code */
87     if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_pinstalldirs_base_framework, 0))) {
88         fprintf(stderr, "pmix_pinstalldirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of PMIX_SUCCESS)\n",
89                 __FILE__, __LINE__, ret);
90         return ret;
91     }
92     if (PMIX_SUCCESS != (ret = pmix_pinstall_dirs_base_init(NULL, 0))) {
93         fprintf(stderr, "pmix_pinstalldirs_base_init() failed -- process will likely abort (%s:%d, returned %d instead of PMIX_SUCCESS)\n",
94                 __FILE__, __LINE__, ret);
95         return ret;
96     }
97 
98     /* initialize the help system */
99     pmix_show_help_init();
100 
101     /* keyval lex-based parser */
102     if (PMIX_SUCCESS != (ret = pmix_util_keyval_parse_init())) {
103         fprintf(stderr, "pmix_util_keyval_parse_init failed with %d\n", ret);
104         return PMIX_ERROR;
105     }
106 
107     /* Setup the parameter system */
108     if (PMIX_SUCCESS != (ret = pmix_mca_base_var_init())) {
109         fprintf(stderr, "pmix_mca_base_var_init failed with %d\n", ret);
110         return PMIX_ERROR;
111     }
112 
113     /* register params for pmix */
114     if (PMIX_SUCCESS != (ret = pmix_register_params())) {
115         fprintf(stderr, "pmix_register_params failed with %d\n", ret);
116         return PMIX_ERROR;
117     }
118 
119     pmix_info_cmd_line = PMIX_NEW(pmix_cmd_line_t);
120     if (NULL == pmix_info_cmd_line) {
121         ret = errno;
122         pmix_show_help("help-pmix-info.txt", "lib-call-fail", true,
123                        "pmix_cmd_line_create", __FILE__, __LINE__, NULL);
124         exit(ret);
125     }
126 
127     if (PMIX_SUCCESS != (ret = pmix_info_init(argc, argv, pmix_info_cmd_line))) {
128         return ret;
129     }
130 
131     /* setup the mca_types array */
132     PMIX_CONSTRUCT(&mca_types, pmix_pointer_array_t);
133     pmix_pointer_array_init(&mca_types, 256, INT_MAX, 128);
134     pmix_info_register_types(&mca_types);
135 
136     /* init the component map */
137     PMIX_CONSTRUCT(&component_map, pmix_pointer_array_t);
138     pmix_pointer_array_init(&component_map, 64, INT_MAX, 32);
139 
140     /* Register PMIx's params */
141     if (PMIX_SUCCESS != (ret = pmix_info_register_framework_params(&component_map))) {
142         if (PMIX_ERR_BAD_PARAM == ret) {
143             /* output what we got */
144             pmix_info_do_params(true, pmix_cmd_line_is_taken(pmix_info_cmd_line, "internal"),
145                                 &mca_types, &component_map, NULL);
146         }
147         exit(1);
148     }
149 
150 
151     /* Execute the desired action(s) */
152     want_all = pmix_cmd_line_is_taken(pmix_info_cmd_line, "all");
153     if (want_all) {
154         pmix_info_out("Package", "package", PMIX_PACKAGE_STRING);
155         pmix_info_show_pmix_version(pmix_info_ver_full);
156     }
157     if (want_all || pmix_cmd_line_is_taken(pmix_info_cmd_line, "path")) {
158         pmix_info_do_path(want_all, pmix_info_cmd_line);
159         acted = true;
160     }
161     if (want_all || pmix_cmd_line_is_taken(pmix_info_cmd_line, "arch")) {
162         pmix_info_do_arch();
163         acted = true;
164     }
165     if (want_all || pmix_cmd_line_is_taken(pmix_info_cmd_line, "hostname")) {
166         pmix_info_do_hostname();
167         acted = true;
168     }
169     if (want_all || pmix_cmd_line_is_taken(pmix_info_cmd_line, "config")) {
170         pmix_info_do_config(true);
171         acted = true;
172     }
173     if (want_all || pmix_cmd_line_is_taken(pmix_info_cmd_line, "param") ||
174         pmix_cmd_line_is_taken(pmix_info_cmd_line, "params")) {
175         pmix_info_do_params(want_all, pmix_cmd_line_is_taken(pmix_info_cmd_line, "internal"),
176                             &mca_types, &component_map, pmix_info_cmd_line);
177         acted = true;
178     }
179     if (pmix_cmd_line_is_taken(pmix_info_cmd_line, "type")) {
180         pmix_info_do_type(pmix_info_cmd_line);
181         acted = true;
182     }
183 
184     /* If no command line args are specified, show default set */
185 
186     if (!acted) {
187         pmix_info_out("Package", "package", PMIX_PACKAGE_STRING);
188         pmix_info_show_pmix_version(pmix_info_ver_full);
189         pmix_info_show_path(pmix_info_path_prefix, pmix_pinstall_dirs.prefix);
190         pmix_info_do_arch();
191         pmix_info_do_hostname();
192         pmix_info_do_config(false);
193         pmix_info_show_component_version(&mca_types, &component_map, pmix_info_type_all,
194                                          pmix_info_component_all, pmix_info_ver_full,
195                                          pmix_info_ver_all);
196     }
197 
198 
199     /* All done */
200     pmix_info_close_components();
201     PMIX_RELEASE(pmix_info_cmd_line);
202     PMIX_DESTRUCT(&mca_types);
203     for (i=0; i < component_map.size; i++) {
204         if (NULL != (map = (pmix_info_component_map_t*)pmix_pointer_array_get_item(&component_map, i))) {
205             PMIX_RELEASE(map);
206         }
207     }
208     PMIX_DESTRUCT(&component_map);
209 
210     pmix_info_finalize();
211 
212     return 0;
213 }
214