@@ -44,6 +44,9 @@ struct rexec_ctx {
4444 json_t * cmd ;
4545 int flags ;
4646 struct rexec_response response ;
47+ uint32_t matchtag ;
48+ uint32_t rank ;
49+ char * service_name ;
4750};
4851
4952static void rexec_response_clear (struct rexec_response * resp )
@@ -62,12 +65,16 @@ static void rexec_ctx_destroy (struct rexec_ctx *ctx)
6265 int saved_errno = errno ;
6366 rexec_response_clear (& ctx -> response );
6467 json_decref (ctx -> cmd );
68+ free (ctx -> service_name );
6569 free (ctx );
6670 errno = saved_errno ;
6771 }
6872}
6973
70- static struct rexec_ctx * rexec_ctx_create (flux_cmd_t * cmd , int flags )
74+ static struct rexec_ctx * rexec_ctx_create (flux_cmd_t * cmd ,
75+ const char * service_name ,
76+ uint32_t rank ,
77+ int flags )
7178{
7279 struct rexec_ctx * ctx ;
7380 int valid_flags = SUBPROCESS_REXEC_STDOUT
@@ -80,10 +87,12 @@ static struct rexec_ctx *rexec_ctx_create (flux_cmd_t *cmd, int flags)
8087 }
8188 if (!(ctx = calloc (1 , sizeof (* ctx ))))
8289 return NULL ;
83- if (!(ctx -> cmd = cmd_tojson (cmd )))
90+ if (!(ctx -> cmd = cmd_tojson (cmd ))
91+ || !(ctx -> service_name = strdup (service_name )))
8492 goto error ;
8593 ctx -> flags = flags ;
8694 ctx -> response .pid = -1 ;
95+ ctx -> rank = rank ;
8796 return ctx ;
8897error :
8998 rexec_ctx_destroy (ctx );
@@ -106,7 +115,7 @@ flux_future_t *subprocess_rexec (flux_t *h,
106115 }
107116 if (asprintf (& topic , "%s.exec" , service_name ) < 0 )
108117 return NULL ;
109- if (!(ctx = rexec_ctx_create (cmd , flags )))
118+ if (!(ctx = rexec_ctx_create (cmd , service_name , rank , flags )))
110119 goto error ;
111120 if (!(f = flux_rpc_pack (h ,
112121 topic ,
@@ -122,6 +131,7 @@ flux_future_t *subprocess_rexec (flux_t *h,
122131 rexec_ctx_destroy (ctx );
123132 goto error ;
124133 }
134+ ctx -> matchtag = flux_rpc_get_matchtag (f );
125135 free (topic );
126136 return f ;
127137error :
@@ -223,33 +233,32 @@ bool subprocess_rexec_is_output (flux_future_t *f,
223233 return false;
224234}
225235
226- int subprocess_write (flux_t * h ,
227- const char * service_name ,
228- uint32_t rank ,
229- pid_t pid ,
236+ int subprocess_write (flux_future_t * f_exec ,
230237 const char * stream ,
231238 const char * data ,
232239 int len ,
233240 bool eof )
234241{
242+ struct rexec_ctx * ctx = flux_future_aux_get (f_exec , "flux::rexec" );
243+ flux_t * h = flux_future_get_flux (f_exec );
235244 flux_future_t * f = NULL ;
236245 json_t * io ;
237246 char * topic ;
238247 int rc = -1 ;
239248
240- if (!h || pid < 0 || ! stream || !service_name ) {
249+ if (!stream || !ctx ) {
241250 errno = EINVAL ;
242251 return -1 ;
243252 }
244- if (asprintf (& topic , "%s.write" , service_name ) < 0 )
253+ if (asprintf (& topic , "%s.write" , ctx -> service_name ) < 0 )
245254 return -1 ;
246255 if (!(io = ioencode (stream , "0" , data , len , eof ))
247256 || !(f = flux_rpc_pack (h ,
248257 topic ,
249- rank ,
258+ ctx -> rank ,
250259 FLUX_RPC_NORESPONSE ,
251260 "{s:i s:O}" ,
252- "pid " , pid ,
261+ "matchtag " , ctx -> matchtag ,
253262 "io" , io )))
254263 goto out ;
255264 rc = 0 ;
0 commit comments