Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 10:12:53

0001 /*
0002  * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
0003  *                         University Research and Technology
0004  *                         Corporation.  All rights reserved.
0005  * Copyright (c) 2004-2011 The University of Tennessee and The University
0006  *                         of Tennessee Research Foundation.  All rights
0007  *                         reserved.
0008  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
0009  *                         University of Stuttgart.  All rights reserved.
0010  * Copyright (c) 2004-2005 The Regents of the University of California.
0011  *                         All rights reserved.
0012  * Copyright (c) 2011 Cisco Systems, Inc.  All rights reserved.
0013  * Copyright (c) 2013      Los Alamos National Security, LLC.  All rights reserved.
0014  * Copyright (c) 2017-2020 Intel, Inc.  All rights reserved.
0015  * Copyright (c) 2021-2022 Nanook Consulting.  All rights reserved.
0016  * $COPYRIGHT$
0017  *
0018  * Additional copyrights may follow
0019  *
0020  * $HEADER$
0021  */
0022 /** @file:
0023  */
0024 
0025 #ifndef MCA_PFEXEC_BASE_H
0026 #define MCA_PFEXEC_BASE_H
0027 
0028 /*
0029  * includes
0030  */
0031 #include "pmix_config.h"
0032 
0033 #include "src/class/pmix_list.h"
0034 #include "src/common/pmix_iof.h"
0035 #include "src/mca/mca.h"
0036 #include "src/mca/pfexec/pfexec.h"
0037 
0038 BEGIN_C_DECLS
0039 
0040 /*
0041  * MCA framework
0042  */
0043 PMIX_EXPORT extern pmix_mca_base_framework_t pmix_pfexec_base_framework;
0044 /*
0045  * Select an available component.
0046  */
0047 PMIX_EXPORT pmix_status_t pmix_pfexec_base_select(void);
0048 
0049 typedef struct {
0050     int usepty;
0051     bool connect_stdin;
0052 
0053     /* private - callers should not modify these fields */
0054     int p_stdin[2];
0055     int p_stdout[2];
0056     int p_stderr[2];
0057 } pmix_pfexec_base_io_conf_t;
0058 
0059 typedef struct {
0060     pmix_list_item_t super;
0061     pmix_event_t ev;
0062     pmix_proc_t proc;
0063     pid_t pid;
0064     bool completed;
0065     int exitcode;
0066     int keepalive[2];
0067     pmix_pfexec_base_io_conf_t opts;
0068     pmix_iof_sink_t stdinsink;
0069     pmix_iof_read_event_t *stdoutev;
0070     pmix_iof_read_event_t *stderrev;
0071 } pmix_pfexec_child_t;
0072 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_child_t);
0073 
0074 typedef struct {
0075     pmix_event_t *handler;
0076     bool active;
0077     pmix_list_t children;
0078     int timeout_before_sigkill;
0079     size_t nextid;
0080     bool selected;
0081 } pmix_pfexec_globals_t;
0082 
0083 PMIX_EXPORT extern pmix_pfexec_globals_t pmix_pfexec_globals;
0084 
0085 /* define a function that will fork/exec a local proc */
0086 typedef pmix_status_t (*pmix_pfexec_base_fork_proc_fn_t)(pmix_app_t *app,
0087                                                          pmix_pfexec_child_t *child, char **env);
0088 
0089 /* define a function type for signaling a local proc */
0090 typedef pmix_status_t (*pmix_pfexec_base_signal_local_fn_t)(pid_t pd, int signum);
0091 
0092 typedef struct {
0093     pmix_object_t super;
0094     pmix_event_t ev;
0095     const pmix_info_t *jobinfo;
0096     size_t njinfo;
0097     const pmix_app_t *apps;
0098     size_t napps;
0099     pmix_pfexec_base_fork_proc_fn_t frkfn;
0100     pmix_spawn_cbfunc_t cbfunc;
0101     void *cbdata;
0102 } pmix_pfexec_fork_caddy_t;
0103 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_fork_caddy_t);
0104 
0105 typedef struct {
0106     pmix_object_t super;
0107     pmix_event_t ev;
0108     pmix_proc_t *proc;
0109     int signal;
0110     pmix_pfexec_base_signal_local_fn_t sigfn;
0111     pmix_lock_t *lock;
0112 } pmix_pfexec_signal_caddy_t;
0113 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_signal_caddy_t);
0114 
0115 PMIX_EXPORT void pmix_pfexec_base_spawn_proc(int sd, short args, void *cbdata);
0116 
0117 PMIX_EXPORT void pmix_pfexec_base_kill_proc(int sd, short args, void *cbdata);
0118 
0119 PMIX_EXPORT void pmix_pfexec_base_signal_proc(int sd, short args, void *cbdata);
0120 
0121 PMIX_EXPORT void pmix_pfexec_check_complete(int sd, short args, void *cbdata);
0122 
0123 #define PMIX_PFEXEC_SPAWN(j, nj, a, na, fn, cbf, cbd)                    \
0124     do {                                                                 \
0125         pmix_pfexec_fork_caddy_t *fcd;                                   \
0126         fcd = PMIX_NEW(pmix_pfexec_fork_caddy_t);                        \
0127         fcd->jobinfo = (j);                                              \
0128         fcd->njinfo = (nj);                                              \
0129         fcd->apps = (a);                                                 \
0130         fcd->napps = (na);                                               \
0131         fcd->frkfn = (fn);                                               \
0132         fcd->cbfunc = (cbf);                                             \
0133         fcd->cbdata = (cbd);                                             \
0134         pmix_event_assign(&(fcd->ev), pmix_globals.evbase, -1, EV_WRITE, \
0135                           pmix_pfexec_base_spawn_proc, fcd);             \
0136         PMIX_POST_OBJECT((fcd));                                         \
0137         pmix_event_active(&((fcd)->ev), EV_WRITE, 1);                    \
0138     } while (0)
0139 
0140 #define PMIX_PFEXEC_KILL(scd, r, fn, lk)                                   \
0141     do {                                                                   \
0142         (scd) = PMIX_NEW(pmix_pfexec_signal_caddy_t);                      \
0143         (scd)->proc = (r);                                                 \
0144         (scd)->sigfn = (fn);                                               \
0145         (scd)->lock = (lk);                                                \
0146         pmix_event_assign(&((scd)->ev), pmix_globals.evbase, -1, EV_WRITE, \
0147                           pmix_pfexec_base_kill_proc, (scd));              \
0148         PMIX_POST_OBJECT((scd));                                           \
0149         pmix_event_active(&((scd)->ev), EV_WRITE, 1);                      \
0150     } while (0)
0151 
0152 #define PMIX_PFEXEC_SIGNAL(scd, r, nm, fn, lk)                             \
0153     do {                                                                   \
0154         (scd) = PMIX_NEW(pmix_pfexec_signal_caddy_t);                      \
0155         (scd)->proc = (r);                                                 \
0156         (scd)->signal = (nm);                                              \
0157         (scd)->sigfn = (fn);                                               \
0158         (scd)->lock = (lk);                                                \
0159         pmix_event_assign(&((scd)->ev), pmix_globals.evbase, -1, EV_WRITE, \
0160                           pmix_pfexec_base_signal_proc, (scd));            \
0161         PMIX_POST_OBJECT((scd));                                           \
0162         pmix_event_active(&((scd)->ev), EV_WRITE, 1);                      \
0163     } while (0)
0164 
0165 typedef struct {
0166     pmix_object_t super;
0167     pmix_event_t ev;
0168     pmix_pfexec_child_t *child;
0169 } pmix_pfexec_cmpl_caddy_t;
0170 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_cmpl_caddy_t);
0171 
0172 #define PMIX_PFEXEC_CHK_COMPLETE(c)                                        \
0173     do {                                                                   \
0174         pmix_pfexec_cmpl_caddy_t *pc = PMIX_NEW(pmix_pfexec_cmpl_caddy_t); \
0175         pc->child = (c);                                                   \
0176         pmix_event_assign(&((pc)->ev), pmix_globals.evbase, -1, EV_WRITE,  \
0177                           pmix_pfexec_check_complete, (pc));               \
0178         PMIX_POST_OBJECT((pc));                                            \
0179         pmix_event_active(&((pc)->ev), EV_WRITE, 1);                       \
0180     } while (0)
0181 
0182 /*
0183  * Struct written up the pipe from the child to the parent.
0184  */
0185 typedef struct {
0186     /* True if the child has died; false if this is just a warning to
0187        be printed. */
0188     bool fatal;
0189     /* Relevant only if fatal==true */
0190     int exit_status;
0191 
0192     /* Length of the strings that are written up the pipe after this
0193        struct */
0194     int file_str_len;
0195     int topic_str_len;
0196     int msg_str_len;
0197 } pmix_pfexec_pipe_err_msg_t;
0198 
0199 PMIX_EXPORT pmix_status_t pmix_pfexec_base_setup_child(pmix_pfexec_child_t *child);
0200 
0201 /*
0202  * Max length of strings from the pmix_pfexec_pipe_err_msg_t
0203  */
0204 #define PMIX_PFEXEC_MAX_FILE_LEN  511
0205 #define PMIX_PFEXEC_MAX_TOPIC_LEN PMIX_PFEXEC_MAX_FILE_LEN
0206 
0207 END_C_DECLS
0208 #endif