From 15802a5e8330f8aefb87e009f0508c9533f21c93 Mon Sep 17 00:00:00 2001 From: Morris Jette <jette@schedmd.com> Date: Mon, 22 Jul 2013 14:59:46 -0700 Subject: [PATCH] Add UID field to UnkillableStepProgram support for job container Make sure the UnkillableStepProgram runs in a job container owned by the job's owner. --- src/slurmd/slurmstepd/mgr.c | 2 +- src/slurmd/slurmstepd/req.c | 2 +- src/slurmd/slurmstepd/step_terminate_monitor.c | 6 ++++-- src/slurmd/slurmstepd/step_terminate_monitor.h | 7 ++++++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/slurmd/slurmstepd/mgr.c b/src/slurmd/slurmstepd/mgr.c index f0de161542d..4e43e440ca3 100644 --- a/src/slurmd/slurmstepd/mgr.c +++ b/src/slurmd/slurmstepd/mgr.c @@ -1052,7 +1052,7 @@ fail2: * terminated before the switch window can be released by * interconnect_postfini(). */ - step_terminate_monitor_start(job->jobid, job->stepid); + step_terminate_monitor_start(job->jobid, job->stepid, job->uid); if (job->cont_id != 0) { slurm_container_signal(job->cont_id, SIGKILL); slurm_container_wait(job->cont_id); diff --git a/src/slurmd/slurmstepd/req.c b/src/slurmd/slurmstepd/req.c index 4fb25d373dc..926df60d770 100644 --- a/src/slurmd/slurmstepd/req.c +++ b/src/slurmd/slurmstepd/req.c @@ -903,7 +903,7 @@ _handle_terminate(int fd, stepd_step_rec_t *job, uid_t uid) debug("_handle_terminate for step=%u.%u uid=%d", job->jobid, job->stepid, uid); - step_terminate_monitor_start(job->jobid, job->stepid); + step_terminate_monitor_start(job->jobid, job->stepid, job->uid); if (uid != job->uid && !_slurm_authorized_user(uid)) { debug("terminate req from uid %ld for job %u.%u " diff --git a/src/slurmd/slurmstepd/step_terminate_monitor.c b/src/slurmd/slurmstepd/step_terminate_monitor.c index 93f5d56ab34..2c5bf5f2012 100644 --- a/src/slurmd/slurmstepd/step_terminate_monitor.c +++ b/src/slurmd/slurmstepd/step_terminate_monitor.c @@ -58,11 +58,12 @@ static uint16_t timeout; static char *program_name; static uint32_t recorded_jobid = NO_VAL; static uint32_t recorded_stepid = NO_VAL; +static uid_t recorded_uid = 0; static void *_monitor(void *); static int _call_external_program(void); -void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid) +void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid, uid_t uid) { slurm_ctl_conf_t *conf; pthread_attr_t attr; @@ -91,6 +92,7 @@ void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid) running_flag = 1; recorded_jobid = jobid; recorded_stepid = stepid; + recorded_uid = uid; pthread_mutex_unlock(&lock); @@ -201,7 +203,7 @@ static int _call_external_program(void) exit(127); } - if (container_g_add_pid(recorded_jobid, cpid, getuid()) != + if (container_g_add_pid(recorded_jobid, cpid, recorded_uid) != SLURM_SUCCESS) error("container_g_add_pid(%u): %m", recorded_jobid); diff --git a/src/slurmd/slurmstepd/step_terminate_monitor.h b/src/slurmd/slurmstepd/step_terminate_monitor.h index d5b56746a34..984481e21a0 100644 --- a/src/slurmd/slurmstepd/step_terminate_monitor.h +++ b/src/slurmd/slurmstepd/step_terminate_monitor.h @@ -26,6 +26,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. \*****************************************************************************/ +#ifndef _SLURMD_TERM_MONITOR_H +#define _SLURMD_TERM_MONITOR_H + /* * Start a monitor pthread that will wait for a period of time, * as defined in the slurm.conf variable UnkillableStepTimeout, @@ -42,10 +45,12 @@ * If step_terminate_monitor_stop() is called before the time runs * out, the external program will not be called. */ -void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid); +void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid, uid_t uid); /* * Stop the timer in the step terminate monitor pthread, and kill * said pthread. */ void step_terminate_monitor_stop(void); + +#endif /* !_SLURMD_TERM_MONITOR_H */ -- GitLab