Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 09:02:00

0001 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
0002 /*
0003  * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
0004  *                         University Research and Technology
0005  *                         Corporation.  All rights reserved.
0006  * Copyright (c) 2004-2005 The University of Tennessee and The University
0007  *                         of Tennessee Research Foundation.  All rights
0008  *                         reserved.
0009  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
0010  *                         University of Stuttgart.  All rights reserved.
0011  * Copyright (c) 2004-2005 The Regents of the University of California.
0012  *                         All rights reserved.
0013  * Copyright (c) 2011-2015 Los Alamos National Security, LLC. All rights
0014  *                         reserved.
0015  * Copyright (c) 2016-2020 Intel, Inc.  All rights reserved.
0016  * Copyright (c) 2021-2024 Nanook Consulting  All rights reserved.
0017  * $COPYRIGHT$
0018  *
0019  * Additional copyrights may follow
0020  *
0021  * $HEADER$
0022  */
0023 /**
0024  * @file
0025  *
0026  * The PMIx Fork/Exec Subsystem
0027  *
0028  */
0029 
0030 #ifndef PMIX_PFEXEC_H
0031 #define PMIX_PFEXEC_H
0032 
0033 #include "pmix_config.h"
0034 
0035 #include "src/class/pmix_list.h"
0036 #include "src/common/pmix_iof.h"
0037 #include "src/server/pmix_server_ops.h"
0038 
0039 BEGIN_C_DECLS
0040 
0041 typedef struct {
0042     int usepty;
0043     bool connect_stdin;
0044 
0045     /* private - callers should not modify these fields */
0046     int p_stdin[2];
0047     int p_stdout[2];
0048     int p_stderr[2];
0049 } pmix_pfexec_base_io_conf_t;
0050 
0051 typedef struct {
0052     pmix_list_item_t super;
0053     pmix_event_t ev;
0054     pmix_proc_t proc;
0055     pid_t pid;
0056     bool completed;
0057     int exitcode;
0058     int keepalive[2];
0059     pmix_pfexec_base_io_conf_t opts;
0060     pmix_iof_sink_t stdinsink;
0061     pmix_iof_read_event_t *stdoutev;
0062     pmix_iof_read_event_t *stderrev;
0063 } pmix_pfexec_child_t;
0064 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_child_t);
0065 
0066 typedef struct {
0067     pmix_event_t *handler;
0068     bool active;
0069     pmix_list_t children;
0070     int timeout_before_sigkill;
0071     size_t nextid;
0072     bool selected;
0073 } pmix_pfexec_globals_t;
0074 
0075 PMIX_EXPORT extern pmix_pfexec_globals_t pmix_pfexec_globals;
0076 
0077 typedef struct {
0078     pmix_object_t super;
0079     pmix_event_t ev;
0080     pmix_proc_t *proc;
0081     int signal;
0082     pmix_lock_t *lock;
0083 } pmix_pfexec_signal_caddy_t;
0084 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_signal_caddy_t);
0085 
0086 PMIX_EXPORT int pmix_pfexec_base_open(void);
0087 
0088 PMIX_EXPORT int pmix_pfexec_register(void);
0089 
0090 PMIX_EXPORT int pmix_pfexec_base_close(void);
0091 
0092 PMIX_EXPORT pmix_status_t pmix_pfexec_base_spawn_job(pmix_setup_caddy_t *fcd);
0093 
0094 PMIX_EXPORT void pmix_pfexec_base_spawn_proc(int sd, short args, void *cbdata);
0095 
0096 PMIX_EXPORT void pmix_pfexec_base_kill_proc(int sd, short args, void *cbdata);
0097 
0098 PMIX_EXPORT void pmix_pfexec_base_signal_proc(int sd, short args, void *cbdata);
0099 
0100 PMIX_EXPORT void pmix_pfexec_check_complete(int sd, short args, void *cbdata);
0101 
0102 #define PMIX_PFEXEC_SPAWN(fcd)                                           \
0103     do {                                                                 \
0104         pmix_event_assign(&(fcd->ev), pmix_globals.evbase, -1, EV_WRITE, \
0105                           pmix_pfexec_base_spawn_proc, fcd);             \
0106         PMIX_POST_OBJECT((fcd));                                         \
0107         pmix_event_active(&((fcd)->ev), EV_WRITE, 1);                    \
0108     } while (0)
0109 
0110 #define PMIX_PFEXEC_KILL(r, lk)                                            \
0111     do {                                                                   \
0112         pmix_pfexec_signal_caddy_t *scd;                                   \
0113         (scd) = PMIX_NEW(pmix_pfexec_signal_caddy_t);                      \
0114         (scd)->proc = (r);                                                 \
0115         (scd)->lock = (lk);                                                \
0116         pmix_event_assign(&((scd)->ev), pmix_globals.evbase, -1, EV_WRITE, \
0117                           pmix_pfexec_base_kill_proc, (scd));              \
0118         PMIX_POST_OBJECT((scd));                                           \
0119         pmix_event_active(&((scd)->ev), EV_WRITE, 1);                      \
0120     } while (0)
0121 
0122 #define PMIX_PFEXEC_SIGNAL(scd, r, nm, fn, lk)                             \
0123     do {                                                                   \
0124         pmix_pfexec_signal_caddy_t *scd;                                   \
0125         (scd) = PMIX_NEW(pmix_pfexec_signal_caddy_t);                      \
0126         (scd)->proc = (r);                                                 \
0127         (scd)->signal = (nm);                                              \
0128         (scd)->lock = (lk);                                                \
0129         pmix_event_assign(&((scd)->ev), pmix_globals.evbase, -1, EV_WRITE, \
0130                           pmix_pfexec_base_signal_proc, (scd));            \
0131         PMIX_POST_OBJECT((scd));                                           \
0132         pmix_event_active(&((scd)->ev), EV_WRITE, 1);                      \
0133     } while (0)
0134 
0135 typedef struct {
0136     pmix_object_t super;
0137     pmix_event_t ev;
0138     pmix_pfexec_child_t *child;
0139 } pmix_pfexec_cmpl_caddy_t;
0140 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pfexec_cmpl_caddy_t);
0141 
0142 #define PMIX_PFEXEC_CHK_COMPLETE(c)                                        \
0143     do {                                                                   \
0144         pmix_pfexec_cmpl_caddy_t *pc = PMIX_NEW(pmix_pfexec_cmpl_caddy_t); \
0145         pc->child = (c);                                                   \
0146         pmix_event_assign(&((pc)->ev), pmix_globals.evbase, -1, EV_WRITE,  \
0147                           pmix_pfexec_check_complete, (pc));               \
0148         PMIX_POST_OBJECT((pc));                                            \
0149         pmix_event_active(&((pc)->ev), EV_WRITE, 1);                       \
0150     } while (0)
0151 
0152 /*
0153  * Struct written up the pipe from the child to the parent.
0154  */
0155 typedef struct {
0156     /* True if the child has died; false if this is just a warning to
0157        be printed. */
0158     bool fatal;
0159     /* Relevant only if fatal==true */
0160     int exit_status;
0161 
0162     /* Length of the strings that are written up the pipe after this
0163        struct */
0164     int file_str_len;
0165     int topic_str_len;
0166     int msg_str_len;
0167 } pmix_pfexec_pipe_err_msg_t;
0168 
0169 PMIX_EXPORT pmix_status_t pmix_pfexec_base_setup_child(pmix_pfexec_child_t *child);
0170 
0171 /*
0172  * Max length of strings from the pmix_pfexec_pipe_err_msg_t
0173  */
0174 #define PMIX_PFEXEC_MAX_FILE_LEN  511
0175 #define PMIX_PFEXEC_MAX_TOPIC_LEN PMIX_PFEXEC_MAX_FILE_LEN
0176 
0177 END_C_DECLS
0178 
0179 #endif /* MCA_PFEXEC_H */