diff --git a/src/srun/io.c b/src/srun/io.c index ae9a7c5f6a843bb8c809ff9f4f7f2375a995784e..243f6f653a728f9bf6fc1aa7ec9488de7d3fa68f 100644 --- a/src/srun/io.c +++ b/src/srun/io.c @@ -626,6 +626,20 @@ io_thr_create(job_t *job) return SLURM_SUCCESS; } +static bool +_is_fd_ready(int fd) +{ + struct pollfd pfd[1]; + int rc; + + pfd[0].fd = fd; + pfd[0].events = POLLIN; + + rc = poll(pfd, 1, 10); + + return ((rc == 1) && (pfd[0].revents & POLLIN)); +} + static void _accept_io_stream(job_t *job, int i) @@ -644,6 +658,17 @@ _accept_io_stream(job_t *job, int i) slurm_io_stream_header_t hdr; Buf buffer; + /* + * Return early if fd is not now ready + * This ensures that we never block when trying + * to read the io header below. + * + * (XXX: This should eventually be fixed by making + * reads of IO headers nonblocking) + */ + if (!_is_fd_ready(fd)) + return; + while ((sd = accept(fd, &addr, &size)) < 0) { if (errno == EINTR) continue; @@ -660,6 +685,8 @@ _accept_io_stream(job_t *job, int i) sin = (struct sockaddr_in *) &addr; inet_ntop(AF_INET, &sin->sin_addr, buf, INET_ADDRSTRLEN); + debug3("Accepted IO connection: ip=%s sd=%d", buf, sd); + buffer = init_buf(len); size_read = _readn(sd, buffer->head, len); if (size_read != len) { diff --git a/src/srun/msg.c b/src/srun/msg.c index fe9c5b26e0f0a5c330a52ca85dce78c9f95f1240..09515cb76ce37ae14852e498a518bea9b2435487 100644 --- a/src/srun/msg.c +++ b/src/srun/msg.c @@ -64,8 +64,8 @@ static time_t time_first_launch = 0; -static int tasks_exited = 0; -static uint32_t slurm_user_id; +static int tasks_exited = 0; +static uid_t slurm_uid; static void _accept_msg_connection(job_t *job, int fdnum); static void _confirm_launch_complete(job_t *job); @@ -412,8 +412,10 @@ static char * _taskid2hostname (int task_id, job_t * job) static void _handle_msg(job_t *job, slurm_msg_t *msg) { - uid_t req_uid = slurm_auth_uid(msg->cred); - if ((req_uid != slurm_user_id) && (req_uid != 0)) { + uid_t req_uid = slurm_auth_uid(msg->cred); + uid_t uid = getuid(); + + if ((req_uid != slurm_uid) && (req_uid != 0) && (req_uid != uid)) { error ("Security violation, slurm message from uid %u", (unsigned int) req_uid); return; @@ -547,7 +549,7 @@ msg_thr(void *arg) job_t *job = (job_t *) arg; debug3("msg thread pid = %ld", getpid()); - slurm_user_id = slurm_get_slurm_user_id(); + slurm_uid = (uid_t) slurm_get_slurm_user_id(); _msg_thr_poll(job); return (void *)1; } diff --git a/src/srun/opt.c b/src/srun/opt.c index 1e89c7a19ad4d9b976b17306fdb1628534b69386..c3d7b0fb6aea8537d5920666f85d3e6294f6418e 100644 --- a/src/srun/opt.c +++ b/src/srun/opt.c @@ -852,7 +852,7 @@ static void _opt_args(int ac, char **av) break; case OPT_CDDIR: - free(opt.cwd); + xfree(opt.cwd); opt.cwd = strdup(arg); break;