This source file includes following definitions.
- init
- finalize
- mylog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "pmix_config.h"
22 #include "pmix_common.h"
23
24 #include <string.h>
25 #ifdef HAVE_SYS_TIME_H
26 #include <sys/time.h>
27 #endif
28 #include <stdarg.h>
29
30 #include "src/util/argv.h"
31 #include "src/util/error.h"
32 #include "src/util/name_fns.h"
33 #include "src/util/show_help.h"
34 #include "src/common/pmix_iof.h"
35
36 #include "src/mca/plog/base/base.h"
37 #include "plog_stdfd.h"
38
39
40
41 static int init(void);
42 static void finalize(void);
43 static pmix_status_t mylog(const pmix_proc_t *source,
44 const pmix_info_t data[], size_t ndata,
45 const pmix_info_t directives[], size_t ndirs,
46 pmix_op_cbfunc_t cbfunc, void *cbdata);
47
48
49 pmix_plog_module_t pmix_plog_stdfd_module = {
50 .name = "stdfd",
51 .init = init,
52 .finalize = finalize,
53 .log = mylog
54 };
55
56
57 static int init(void)
58 {
59 char *mychannels = "stdout,stderr";
60
61 pmix_plog_stdfd_module.channels = pmix_argv_split(mychannels, ',');
62 return PMIX_SUCCESS;
63 }
64
65 static void finalize(void)
66 {
67 pmix_argv_free(pmix_plog_stdfd_module.channels);
68 }
69
70 static pmix_status_t mylog(const pmix_proc_t *source,
71 const pmix_info_t data[], size_t ndata,
72 const pmix_info_t directives[], size_t ndirs,
73 pmix_op_cbfunc_t cbfunc, void *cbdata)
74 {
75 size_t n;
76 pmix_status_t rc;
77 pmix_byte_object_t bo;
78 pmix_iof_flags_t flags= {0};
79
80
81 if (NULL == data || 0 == ndata) {
82 return PMIX_ERR_NOT_AVAILABLE;
83 }
84
85
86 if (!PMIX_PROC_IS_GATEWAY(pmix_globals.mypeer)) {
87 return PMIX_ERR_TAKE_NEXT_OPTION;
88 }
89
90
91 for (n=0; n < ndirs; n++) {
92 if (0 == strncmp(directives[n].key, PMIX_LOG_TIMESTAMP, PMIX_MAX_KEYLEN)) {
93 flags.timestamp = directives[n].value.data.time;
94 } else if (0 == strncmp(directives[n].key, PMIX_LOG_XML_OUTPUT, PMIX_MAX_KEYLEN)) {
95 flags.xml = PMIX_INFO_TRUE(&directives[n]);
96 } else if (0 == strncmp(directives[n].key, PMIX_LOG_TAG_OUTPUT, PMIX_MAX_KEYLEN)) {
97 flags.tag = PMIX_INFO_TRUE(&directives[n]);
98 }
99 }
100
101
102 rc = PMIX_ERR_TAKE_NEXT_OPTION;
103 for (n=0; n < ndata; n++) {
104 if (0 == strncmp(data[n].key, PMIX_LOG_STDERR, PMIX_MAX_KEYLEN)) {
105 bo.bytes = data[n].value.data.string;
106 bo.size = strlen(bo.bytes);
107 pmix_iof_write_output(source, PMIX_FWD_STDERR_CHANNEL, &bo, &flags);
108
109 PMIX_INFO_OP_COMPLETED(&data[n]);
110 rc = PMIX_SUCCESS;
111 } else if (0 == strncmp(data[n].key, PMIX_LOG_STDOUT, PMIX_MAX_KEYLEN)) {
112 bo.bytes = data[n].value.data.string;
113 bo.size = strlen(bo.bytes);
114 pmix_iof_write_output(source, PMIX_FWD_STDOUT_CHANNEL, &bo, &flags);
115
116 PMIX_INFO_OP_COMPLETED(&data[n]);
117 rc = PMIX_SUCCESS;
118 }
119 }
120
121 return rc;
122 }