diff --git a/src/slurmd/fname.c b/src/slurmd/fname.c index 349a9bd332df8890fb5d674d8e3092a1909e9cb2..6027fd7f8293692a64bd4e7426201c9d68402ad0 100644 --- a/src/slurmd/fname.c +++ b/src/slurmd/fname.c @@ -31,6 +31,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> #include "src/slurmd/job.h" #include "src/slurmd/fname.h" diff --git a/src/slurmd/req.c b/src/slurmd/req.c index d2bae00a9e5527a89b9f6117baaf4c31b974cc5b..81f41d3447ada597a5d35b74262e009841e9440b 100644 --- a/src/slurmd/req.c +++ b/src/slurmd/req.c @@ -52,6 +52,7 @@ static void _rpc_batch_job(slurm_msg_t *, slurm_addr *); static void _rpc_kill_tasks(slurm_msg_t *, slurm_addr *); static void _rpc_reattach_tasks(slurm_msg_t *, slurm_addr *); static void _rpc_revoke_credential(slurm_msg_t *, slurm_addr *); +static void _rpc_update_time(slurm_msg_t *, slurm_addr *); static void _rpc_shutdown(slurm_msg_t *msg, slurm_addr *cli_addr); static int _rpc_ping(slurm_msg_t *, slurm_addr *); static int _launch_tasks(launch_tasks_request_msg_t *, slurm_addr *); @@ -80,6 +81,10 @@ slurmd_req(slurm_msg_t *msg, slurm_addr *cli) _rpc_revoke_credential(msg, cli); slurm_free_revoke_credential_msg(msg->data); break; + case REQUEST_UPDATE_JOB_TIME: + _rpc_update_time(msg, cli); + slurm_free_update_job_time_msg(msg->data); + break; case REQUEST_SHUTDOWN: case REQUEST_SHUTDOWN_IMMEDIATE: _rpc_shutdown(msg, cli); @@ -413,3 +418,28 @@ _rpc_revoke_credential(slurm_msg_t *msg, slurm_addr *cli) slurm_send_rc_msg(msg, rc); } + +static void +_rpc_update_time(slurm_msg_t *msg, slurm_addr *cli) +{ + int rc = SLURM_SUCCESS; + uid_t req_uid = slurm_auth_uid(msg->cred); + job_time_msg_t *req = (job_time_msg_t *) msg->data; + + if ((req_uid != conf->slurm_user_id) && (req_uid != 0)) { + rc = ESLURM_USER_ID_MISSING; + error("Security violation, uid %u can't update time limit", + (unsigned int) req_uid); + } else { + rc = shm_update_job_timelimit(req->job_id, + req->expiration_time); + if (rc < 0) { + error("updating lifetime for job %d: %m", + req->job_id); + rc = ESLURM_INVALID_JOB_ID; + } else + debug("reset job %d lifetime", req->job_id); + } + + slurm_send_rc_msg(msg, rc); +} diff --git a/src/slurmd/shm.c b/src/slurmd/shm.c index dda1eb6e69d1c40f92307cd838eeba5b02872f40..4a0f9380bdc981bd4e2c0ef633798ed5c582cb5a 100644 --- a/src/slurmd/shm.c +++ b/src/slurmd/shm.c @@ -618,6 +618,28 @@ shm_step_addrs(uint32_t jobid, uint32_t stepid, return retval; } +int +shm_update_job_timelimit(uint32_t jobid, time_t newlim) +{ + int i, found = 0, retval = SLURM_SUCCESS; + + _shm_lock(); + for (i = 0; i < MAX_JOB_STEPS; i++) { + job_step_t *s = &slurmd_shm->step[i]; + if (s->jobid == jobid) { + slurmd_shm->step[i].timelimit = newlim; + found = 1; + } + } + _shm_unlock(); + + if (found == 0) { + slurm_seterrno(ESRCH); + retval = SLURM_FAILURE; + } + return retval; +} + int shm_update_step_timelimit(uint32_t jobid, uint32_t stepid, time_t newlim) { diff --git a/src/slurmd/shm.h b/src/slurmd/shm.h index 758514e59278dbbf3667f3c79387ec10241e2d37..36ff999b0618d8ab25ffe942cee29e68330bf55c 100644 --- a/src/slurmd/shm.h +++ b/src/slurmd/shm.h @@ -241,6 +241,12 @@ int shm_step_addrs(uint32_t jobid, uint32_t stepid, slurm_addr *ioaddr, slurm_addr *respaddr, srun_key_t *key); +/* + * update job timelimit for all steps associated with the specified jobid + */ +int shm_update_job_timelimit(uint32_t jobid, time_t newlim); + + /* * update job step timelimit */