libsubprocess: do not allow short writes with flux_subprocess_write()
#5548
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was pulled off some other work.
Currently,
flux_subprocess_write()
writes any bytes it can to the destination buffer, which could result in a short write (return code <len
). However, a check for a short write is not done is most places (a check forrc < 0
seems to be the common case), and where it is checked it is immediately promoted to a fatal error. In some cases (such as the job-ingest pipeline) a short write can be dangerous since it isn't recovered and writing only part of a line "hangs" the protocol.In the interest of simplicity, add a check for the available buffer space in
flux_subprocess_write()
and return immediately with return code-1
anderrno
set toENOSPC
if there is not enough space for all the data. Update any callers that attempt to handle a short write as a special case.In the future we'll need a more sophisticated buffered write function anyway that can handle flow control and/or a chain of buffers instead of adding short-write handling at each caller (e.g. see #5542)