root/opal/mca/pmix/pmix4x/pmix/src/mca/plog/stdfd/plog_stdfd.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. init
  2. finalize
  3. mylog

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2007      Sun Microsystems, Inc.  All rights reserved.
  13  * Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  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  /* HAVE_SYS_TIME_H */
  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 /* Static API's */
  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 /* Module def */
  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     /* if there is no data, then we don't handle it */
  81     if (NULL == data || 0 == ndata) {
  82         return PMIX_ERR_NOT_AVAILABLE;
  83     }
  84 
  85     /* if we are not a gateway, then we don't handle this */
  86     if (!PMIX_PROC_IS_GATEWAY(pmix_globals.mypeer)) {
  87         return PMIX_ERR_TAKE_NEXT_OPTION;
  88     }
  89 
  90     /* check to see if there are any relevant directives */
  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     /* check to see if there are any stdfd entries */
 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             /* flag that we did this one */
 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             /* flag that we did this one */
 116             PMIX_INFO_OP_COMPLETED(&data[n]);
 117             rc = PMIX_SUCCESS;
 118         }
 119     }
 120 
 121     return rc;
 122 }

/* [<][>][^][v][top][bottom][index][help] */