Skip to content

Commit 6ecabe9

Browse files
authored
Merge pull request #5183 from grondo/issue#5175
flux-job: ignore stdin instead of aborting when unable to create stdin watcher
2 parents 89a77b3 + 22c433c commit 6ecabe9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/cmd/flux-job.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "src/common/libutil/read_all.h"
4747
#include "src/common/libutil/monotime.h"
4848
#include "src/common/libutil/fsd.h"
49+
#include "src/common/libutil/fdutils.h"
4950
#include "src/common/libidset/idset.h"
5051
#include "src/common/libeventlog/eventlog.h"
5152
#include "src/common/libioencode/ioencode.h"
@@ -1887,7 +1888,7 @@ void attach_signal_cb (flux_reactor_t *r, flux_watcher_t *w,
18871888
*/
18881889
void restore_stdin_flags (void)
18891890
{
1890-
(void)fcntl (STDIN_FILENO, F_SETFL, stdin_flags);
1891+
(void)fd_set_flags (STDIN_FILENO, stdin_flags);
18911892
}
18921893

18931894
static void attach_send_shell_completion (flux_future_t *f, void *arg)
@@ -2093,21 +2094,31 @@ static void attach_setup_stdin (struct attach_ctx *ctx)
20932094
/* flux_buffer_read_watcher_create() requires O_NONBLOCK on
20942095
* stdin */
20952096

2096-
if ((stdin_flags = fcntl (STDIN_FILENO, F_GETFL)) < 0)
2097-
log_err_exit ("fcntl F_GETFL stdin");
2097+
if ((stdin_flags = fd_set_nonblocking (STDIN_FILENO)) < 0)
2098+
log_err_exit ("unable to set stdin nonblocking");
20982099
if (atexit (restore_stdin_flags) != 0)
20992100
log_err_exit ("atexit");
2100-
if (fcntl (STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK) < 0)
2101-
log_err_exit ("fcntl F_SETFL stdin");
21022101

21032102
w = flux_buffer_read_watcher_create (flux_get_reactor (ctx->h),
21042103
STDIN_FILENO,
21052104
1 << 20,
21062105
attach_stdin_cb,
21072106
flags,
21082107
ctx);
2109-
if (!w)
2108+
if (!w) {
2109+
/* Users have reported rare occurrences of an EINVAL error
2110+
* from flux_buffer_read_watcher_create(), the cause of which
2111+
* is not understood (See issue #5175). In many cases, perhaps all,
2112+
* stdin is not used by the job, so aborting `flux job attach`
2113+
* is an unnecessary failure. Therefore, just ignore stdin when
2114+
* errno is EINVAL here:
2115+
*/
2116+
if (errno == EINVAL) {
2117+
log_msg ("Warning: ignoring stdin: failed to create watcher");
2118+
return;
2119+
}
21102120
log_err_exit ("flux_buffer_read_watcher_create");
2121+
}
21112122

21122123
if (!(ctx->stdin_rpcs = zlist_new ()))
21132124
log_err_exit ("zlist_new");

0 commit comments

Comments
 (0)