Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 231 additions & 81 deletions src/mca/iof/base/iof_base_setup.c

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions src/mca/iof/base/iof_base_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* All rights reserved.
* Copyright (c) 2008-2020 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2016-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
* Copyright (c) 2021-2025 Nanook Consulting All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -26,13 +26,20 @@
#include "prte_config.h"
#include "types.h"

#include "src/runtime/prte_globals.h"
#include "src/mca/iof/base/base.h"

struct prte_iof_base_io_conf_t {
int usepty;
bool connect_stdin;

/* private - callers should not modify these fields */
char *slave_stdin;
char *slave_stdout;
char *slave_stderr;

/* When using pty's:
* pty masters are in the 0 position,
* pty slaves are in the 1 position */
int p_stdin[2];
int p_stdout[2];
int p_stderr[2];
Expand All @@ -45,9 +52,11 @@ typedef struct prte_iof_base_io_conf_t prte_iof_base_io_conf_t;
* Do all stdio forwarding that must be done before fork() is called.
* This might include creating pipes or ptys or similar work.
*/
PRTE_EXPORT int prte_iof_base_setup_prefork(prte_iof_base_io_conf_t *opts);
PRTE_EXPORT int prte_iof_base_setup_prefork(prte_iof_base_io_conf_t *opts,
prte_job_t *jdata);

PRTE_EXPORT int prte_iof_base_setup_child(prte_iof_base_io_conf_t *opts, char ***env);
PRTE_EXPORT int prte_iof_base_setup_child(prte_iof_base_io_conf_t *opts,
char ***env);

PRTE_EXPORT int prte_iof_base_setup_parent(const pmix_proc_t *name, prte_iof_base_io_conf_t *opts);

Expand Down
4 changes: 2 additions & 2 deletions src/mca/odls/base/odls_base_default_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ void prte_odls_base_default_launch_local(int fd, short sd, void *cbdata)
} else {
cd->opts.connect_stdin = false;
}
if (PRTE_SUCCESS != (rc = prte_iof_base_setup_prefork(&cd->opts))) {
if (PRTE_SUCCESS != (rc = prte_iof_base_setup_prefork(&cd->opts, jobdat))) {
PRTE_ERROR_LOG(rc);
child->exit_code = rc;
PMIX_RELEASE(cd);
Expand Down Expand Up @@ -2178,7 +2178,7 @@ int prte_odls_base_default_restart_proc(prte_proc_t *child,
} else {
cd->opts.connect_stdin = false;
}
if (PRTE_SUCCESS != (rc = prte_iof_base_setup_prefork(&cd->opts))) {
if (PRTE_SUCCESS != (rc = prte_iof_base_setup_prefork(&cd->opts, jobdat))) {
PRTE_ERROR_LOG(rc);
child->exit_code = rc;
PMIX_RELEASE(cd);
Expand Down
2 changes: 2 additions & 0 deletions src/mca/schizo/prte/help-prun.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ option to the help request as "--help <option>".
| | disable (false) its internal library's GPU |
| | support |
+----------------------+-----------------------------------------------+
| "--pty" | Spawn a pseudo-terminal |
+----------------------+-----------------------------------------------+

+----------------------+-----------------------------------------------+
| | Specific Options |
Expand Down
1 change: 1 addition & 0 deletions src/mca/schizo/prte/schizo_prte.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static struct option prunoptions[] = {
PMIX_OPTION_DEFINE(PRTE_CLI_GPU_SUPPORT, PMIX_ARG_REQD),
PMIX_OPTION_DEFINE(PRTE_CLI_APP_PREFIX, PMIX_ARG_REQD),
PMIX_OPTION_DEFINE(PRTE_CLI_NO_APP_PREFIX, PMIX_ARG_NONE),
PMIX_OPTION_DEFINE(PRTE_CLI_PTY, PMIX_ARG_NONE),

// output options
PMIX_OPTION_DEFINE(PRTE_CLI_OUTPUT, PMIX_ARG_REQD),
Expand Down
22 changes: 22 additions & 0 deletions src/prted/pmix/pmix_server_dyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,28 @@ int prte_pmix_xfer_job_info(prte_job_t *jdata,
jdata->stdin_target = strtoul(info->value.data.string, NULL, 10);
}

#ifdef PMIX_SPAWN_PTY
/*** SPAWN PTY ***/
} else if (PMIX_CHECK_KEY(info, PMIX_SPAWN_PTY)) {
flag = PMIX_INFO_TRUE(info);
prte_set_attribute(&jdata->attributes, PRTE_JOB_PTY, PRTE_ATTR_GLOBAL,
&flag, PMIX_BOOL);
#endif

#ifdef PMIX_PTY_TERMIO
/*** PTY TERMIO ***/
} else if (PMIX_CHECK_KEY(info, PMIX_PTY_TERMIO)) {
prte_set_attribute(&jdata->attributes, PRTE_JOB_PTY_TERMIO, PRTE_ATTR_GLOBAL,
&info->value.data.bo, PMIX_BYTE_OBJECT);
#endif

#ifdef PMIX_PTY_WSIZE
/*** PTY WIN SIZES ***/
} else if (PMIX_CHECK_KEY(info, PMIX_PTY_WSIZE)) {
prte_set_attribute(&jdata->attributes, PRTE_JOB_PTY_WSIZE, PRTE_ATTR_GLOBAL,
&info->value.data.bo, PMIX_BYTE_OBJECT);
#endif

/*** INDEX ARGV ***/
} else if (PMIX_CHECK_KEY(info, PMIX_INDEX_ARGV)) {
flag = PMIX_INFO_TRUE(info);
Expand Down
64 changes: 64 additions & 0 deletions src/prted/prun_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "src/util/pmix_environ.h"
#include "src/util/pmix_getcwd.h"
#include "src/util/pmix_show_help.h"
#include "src/util/pmix_tty.h"

#include "src/class/pmix_pointer_array.h"
#include "src/runtime/prte_progress_threads.h"
Expand Down Expand Up @@ -544,6 +545,69 @@ int prun_common(pmix_cli_result_t *results,
/* we want to be notified upon job completion */
PMIX_INFO_LIST_ADD(ret, jinfo, PMIX_NOTIFY_COMPLETION, &flag, PMIX_BOOL);

#ifdef PMIX_SPAWN_PTY
// see if they want to use a pty
if (pmix_cmd_line_is_taken(results, PRTE_CLI_PTY)) {
PMIX_INFO_LIST_ADD(ret, jinfo, PMIX_SPAWN_PTY, NULL, PMIX_BOOL);
#ifdef PMIX_PTY_TERMIO
{
// pass our termio settings
struct termios terms;
pmix_byte_object_t tbo;
tbo.bytes = malloc(2 * sizeof(struct termios));
tbo.size = 2 * sizeof(struct termios);
ret = pmix_gettermios(STDIN_FILENO, &terms);
if (PMIX_SUCCESS != ret) {
free(tbo.bytes);
PMIX_INFO_LIST_RELEASE(jinfo);
PRTE_UPDATE_EXIT_STATUS(ret);
goto DONE;
}
memcpy(tbo.bytes, &terms, sizeof(struct termios));
memset(&terms, 0, sizeof(struct termios));
ret = pmix_gettermios(STDOUT_FILENO, &terms);
if (PMIX_SUCCESS != ret) {
free(tbo.bytes);
PMIX_INFO_LIST_RELEASE(jinfo);
PRTE_UPDATE_EXIT_STATUS(ret);
goto DONE;
}
memcpy(tbo.bytes+sizeof(struct termios), &terms, sizeof(struct termios));
PMIX_INFO_LIST_ADD(ret, jinfo, PMIX_PTY_TERMIO, &tbo, PMIX_BYTE_OBJECT);
PMIX_BYTE_OBJECT_DESTRUCT(&tbo);
}
#endif
#ifdef PMIX_PTY_WSIZE
{
// pass our window size
struct winsize ws;
pmix_byte_object_t tbo;
tbo.bytes = malloc(2 * sizeof(struct winsize));
tbo.size = 2 * sizeof(struct winsize);
ret = pmix_getwinsz(STDIN_FILENO, &ws);
if (PMIX_SUCCESS != ret) {
free(tbo.bytes);
PMIX_INFO_LIST_RELEASE(jinfo);
PRTE_UPDATE_EXIT_STATUS(ret);
goto DONE;
}
memcpy(tbo.bytes, &ws, sizeof(struct winsize));
memset(&ws, 0, sizeof(struct winsize));
ret = pmix_getwinsz(STDOUT_FILENO, &ws);
if (PMIX_SUCCESS != ret) {
free(tbo.bytes);
PMIX_INFO_LIST_RELEASE(jinfo);
PRTE_UPDATE_EXIT_STATUS(ret);
goto DONE;
}
memcpy(tbo.bytes+sizeof(struct winsize), &ws, sizeof(struct winsize));
PMIX_INFO_LIST_ADD(ret, jinfo, PMIX_PTY_WSIZE, &tbo, PMIX_BYTE_OBJECT);
PMIX_BYTE_OBJECT_DESTRUCT(&tbo);
}
#endif
}
#endif

/* pickup any relevant envars */
ninfo = 4;
PMIX_INFO_CREATE(iptr, ninfo);
Expand Down
6 changes: 6 additions & 0 deletions src/util/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ const char *prte_attr_key_to_str(prte_attribute_key_t key)
return "PRTE-JOB-PMIX-PREFIX";
case PRTE_JOB_FWD_ENVIRONMENT:
return "FWD ENVIRONMENT";
case PRTE_JOB_PTY:
return "PTY";
case PRTE_JOB_PTY_TERMIO:
return "PTY TERMIOS";
case PRTE_JOB_PTY_WSIZE:
return "PTY WSIZES";

case PRTE_PROC_NOBARRIER:
return "PROC-NOBARRIER";
Expand Down
3 changes: 3 additions & 0 deletions src/util/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ typedef uint16_t prte_job_flags_t;
#define PRTE_JOB_PREFIX (PRTE_JOB_START_KEY + 118) // string - PRTE_PREFIX for daemons
#define PRTE_JOB_PMIX_PREFIX (PRTE_JOB_START_KEY + 119) // string - PMIX_PREFIX for daemons
#define PRTE_JOB_FWD_ENVIRONMENT (PRTE_JOB_START_KEY + 120) // bool - forward local environment to procs in this job
#define PRTE_JOB_PTY (PRTE_JOB_START_KEY + 121) // bool - Spawn a pseudo-terminal
#define PRTE_JOB_PTY_TERMIO (PRTE_JOB_START_KEY + 122) // pmix_byte_object_t - termio structs for stdin, stdout
#define PRTE_JOB_PTY_WSIZE (PRTE_JOB_START_KEY + 123) // pmix_byte_object_t - winsize structs for stdin, stdout

#define PRTE_JOB_MAX_KEY (PRTE_JOB_START_KEY + 200)

Expand Down
1 change: 1 addition & 0 deletions src/util/prte_cmd_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ BEGIN_C_DECLS
#define PRTE_CLI_DISABLE_RECOVERY "disable-recovery" // none
#define PRTE_CLI_MEM_ALLOC_KIND "memory-alloc-kinds" // required
#define PRTE_CLI_GPU_SUPPORT "gpu-support" // required
#define PRTE_CLI_PTY "pty" // none

// Placement options
#define PRTE_CLI_MAPBY "map-by" // required
Expand Down
Loading