Skip to content

Commit d9ab558

Browse files
committed
shell: pty: pack shell.output args in RFC 24 data event format
Problem: The shell.output plugin topic args (currently only used in the job shell pty plugin) is mostly in RFC 24 data event format, except that the rank is encoded as an integer instead of a string. This means the plugin args have to be unpacked and repacked into a context suitable for use with iodecode(). Pack shell.output args with a string rank so the object can be passed directly to iodecode(). This will remove unnecessary decode and encode plus memory allocation in the output plugin.
1 parent ce00cca commit d9ab558

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/shell/output.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -726,21 +726,13 @@ static int shell_output_handler (flux_plugin_t *p,
726726
void *arg)
727727
{
728728
struct shell_output *out = arg;
729-
int rank;
730-
const char *stream;
731-
const void *data;
732-
size_t len;
729+
json_t *context;
733730

734-
if (flux_plugin_arg_unpack (args,
735-
FLUX_PLUGIN_ARG_IN,
736-
"{s:s s:i s:s%}",
737-
"stream", &stream,
738-
"rank", &rank,
739-
"data", &data, &len) < 0) {
731+
if (flux_plugin_arg_unpack (args, FLUX_PLUGIN_ARG_IN, "o", &context) < 0) {
740732
shell_log_errno ("shell.output: flux_plugin_arg_unpack");
741733
return -1;
742734
}
743-
return shell_output_write (out, rank, stream, data, len, len == 0);
735+
return shell_output_write_type (out, "data", context);
744736
}
745737

746738
static void shell_output_type_file_cleanup (struct shell_output_type_file *ofp)

src/shell/pty.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ shell_terminus_server_start (flux_shell_t *shell, const char *shell_service)
6969
static void pty_monitor (struct flux_pty *pty, void *data, int len)
7070
{
7171
flux_plugin_arg_t *args;
72-
int rank;
72+
const char *rank;
7373

7474
/* len == 0 indicates pty is closed. If there's a reference on
7575
* stdout, release it here
@@ -81,10 +81,11 @@ static void pty_monitor (struct flux_pty *pty, void *data, int len)
8181
return;
8282
}
8383

84-
rank = ptr2int (flux_pty_aux_get (pty, "rank"));
84+
rank = flux_pty_aux_get (pty, "rank");
8585
if (!(args = flux_plugin_arg_create ())
86-
|| flux_plugin_arg_pack (args, FLUX_PLUGIN_ARG_IN,
87-
"{s:s s:i s:s#}",
86+
|| flux_plugin_arg_pack (args,
87+
FLUX_PLUGIN_ARG_IN,
88+
"{s:s s:s s:s#}",
8889
"stream", "stdout",
8990
"rank", rank,
9091
"data", data, len) < 0) {
@@ -371,12 +372,16 @@ static int pty_init (flux_plugin_t *p,
371372
* ranks do not support interactive attach.
372373
*/
373374
if (capture || rank != 0) {
374-
if (flux_pty_aux_set (pty, "shell", shell, NULL) < 0
375-
|| flux_pty_aux_set (pty, "rank", int2ptr (rank), NULL) < 0
375+
char *rankstr = NULL;
376+
377+
if (asprintf (&rankstr, "%d", rank) < 0
378+
|| flux_pty_aux_set (pty, "shell", shell, NULL) < 0
379+
|| flux_pty_aux_set (pty, "rank", rankstr, free) < 0
376380
|| flux_pty_aux_set (pty,
377381
"capture",
378382
int2ptr (capture),
379383
NULL) < 0) {
384+
free (rankstr);
380385
shell_log_errno ("flux_pty_aux_set");
381386
goto error;
382387
}

0 commit comments

Comments
 (0)