Skip to content

Commit e6b108f

Browse files
authored
Merge pull request #6538 from grondo/shell-pty-fixes
shell: minor fixes for shell pty plugin
2 parents ce00cca + 3f5b928 commit e6b108f

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
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: 24 additions & 12 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) {
@@ -154,10 +155,11 @@ static int pty_getopt (flux_shell_t *shell,
154155
int *capture,
155156
int *interactive)
156157
{
157-
char *s;
158+
char *s = NULL;
158159
const char *ranks;
159160
char rbuf [21];
160-
json_t *o;
161+
json_t *o = NULL;
162+
*targets = NULL;
161163

162164
/* Only create a session for rank 0 if the pty option was specified
163165
*/
@@ -173,7 +175,7 @@ static int pty_getopt (flux_shell_t *shell,
173175

174176
if (!(o = json_loads (s, JSON_DECODE_ANY, NULL))) {
175177
shell_log_error ("Unable to parse pty shell option: %s", s);
176-
return -1;
178+
goto error;
177179
}
178180
if (json_is_object (o)) {
179181
json_error_t error;
@@ -187,7 +189,7 @@ static int pty_getopt (flux_shell_t *shell,
187189
"capture", capture,
188190
"interactive", interactive) < 0) {
189191
shell_die (1, "invalid shell pty option: %s", error.text);
190-
return -1;
192+
goto error;
191193
}
192194

193195
if (*interactive) {
@@ -222,7 +224,7 @@ static int pty_getopt (flux_shell_t *shell,
222224
}
223225
if (!(*targets = shell_taskids_intersect (shell, shell_rank, ranks))) {
224226
shell_log_error ("pty: shell_taskids_intersect");
225-
return -1;
227+
goto error;
226228
}
227229

228230
/* If interactive, then always ensure rank 0 is in the set of targets
@@ -234,7 +236,14 @@ static int pty_getopt (flux_shell_t *shell,
234236
shell_warn ("pty: adding pty to rank 0 for interactive support");
235237
idset_set (*targets, 0);
236238
}
239+
free (s);
240+
json_decref (o);
237241
return 1;
242+
error:
243+
free (s);
244+
json_decref (o);
245+
idset_destroy (*targets);
246+
return -1;
238247
}
239248

240249
static void server_empty (struct flux_terminus_server *ts, void *arg)
@@ -300,7 +309,6 @@ static int pty_init (flux_plugin_t *p,
300309
}
301310
}
302311

303-
304312
/* Create a pty session for each local target
305313
*/
306314
rank = idset_first (targets);
@@ -371,12 +379,16 @@ static int pty_init (flux_plugin_t *p,
371379
* ranks do not support interactive attach.
372380
*/
373381
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
382+
char *rankstr = NULL;
383+
384+
if (asprintf (&rankstr, "%d", rank) < 0
385+
|| flux_pty_aux_set (pty, "shell", shell, NULL) < 0
386+
|| flux_pty_aux_set (pty, "rank", rankstr, free) < 0
376387
|| flux_pty_aux_set (pty,
377388
"capture",
378389
int2ptr (capture),
379390
NULL) < 0) {
391+
free (rankstr);
380392
shell_log_errno ("flux_pty_aux_set");
381393
goto error;
382394
}

0 commit comments

Comments
 (0)