Skip to content

Commit 1a70599

Browse files
committed
libsubprocess: add flux_subprocess_channel_incref/decref
Problem: It would be useful to take a reference on an output stream of a subprocess so that stream doesn't generate EOF until all references have been dropped. This can be used when multiple sources are being spliced onto a subprocess output to ensure that the subprocess doesn't register completion until the other outputs have also been fully read. Add flux_subprocess_channel_incref/decref which wrap the underlying flux_buffer_read_watcher_incref/decref for the channel in question.
1 parent 86c53f5 commit 1a70599

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/common/libsubprocess/subprocess.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,27 @@ int flux_set_default_subprocess_log (flux_t *h,
12321232
return 0;
12331233
}
12341234

1235+
void flux_subprocess_channel_incref (flux_subprocess_t *p, const char *name)
1236+
{
1237+
struct subprocess_channel *c;
1238+
if (!p || !p->local)
1239+
return;
1240+
if (!(c = zhash_lookup (p->channels, name)))
1241+
return;
1242+
flux_buffer_read_watcher_incref (c->buffer_read_w);
1243+
}
1244+
1245+
void flux_subprocess_channel_decref (flux_subprocess_t *p, const char *name)
1246+
{
1247+
struct subprocess_channel *c;
1248+
if (!p || !p->local)
1249+
return;
1250+
if (!(c = zhash_lookup (p->channels, name)))
1251+
return;
1252+
flux_buffer_read_watcher_decref (c->buffer_read_w);
1253+
}
1254+
1255+
12351256
/*
12361257
* vi: ts=4 sw=4 expandtab
12371258
*/

src/common/libsubprocess/subprocess.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ int flux_subprocess_aux_set (flux_subprocess_t *p,
493493
*/
494494
void *flux_subprocess_aux_get (flux_subprocess_t *p, const char *name);
495495

496+
/*
497+
* Take/drop a reference on a subprocess output channel `name` (e.g. "stdout"
498+
* or "stderr"). EOF will not be produced from this channel the reference
499+
* count drops to zero.
500+
*/
501+
void flux_subprocess_channel_incref (flux_subprocess_t *p, const char *name);
502+
void flux_subprocess_channel_decref (flux_subprocess_t *p, const char *name);
496503

497504
#ifdef __cplusplus
498505
}

0 commit comments

Comments
 (0)