X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=fio.c;h=728addd614e70aafa2548a7914619052abe06d9f;hp=a18ca1b63f185fdca01d2ae677cd669fdefb4e58;hb=b71b80d679ddd48d5fd87e3df9f28dab678f9727;hpb=39f22027248f658ade599e89c2fe6afae02ac9d7 diff --git a/fio.c b/fio.c index a18ca1b6..728addd6 100644 --- a/fio.c +++ b/fio.c @@ -61,6 +61,8 @@ static volatile int fio_abort; static int exit_value; static struct itimerval itimer; static pthread_t gtod_thread; +static struct flist_head *cgroup_list; +static char *cgroup_mnt; struct io_log *agg_io_log[2]; @@ -1039,6 +1041,15 @@ static void *thread_main(void *data) */ fio_mutex_remove(td->mutex); + if (td->o.uid != -1U && setuid(td->o.uid)) { + td_verror(td, errno, "setuid"); + goto err; + } + if (td->o.gid != -1U && setgid(td->o.gid)) { + td_verror(td, errno, "setgid"); + goto err; + } + /* * May alter parameters that init_io_u() will use, so we need to * do this first. @@ -1076,7 +1087,7 @@ static void *thread_main(void *data) } } - if (td->o.cgroup_weight && cgroup_setup(td)) + if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt)) goto err; if (nice(td->o.nice) == -1) { @@ -1208,7 +1219,7 @@ err: close_and_free_files(td); close_ioengine(td); cleanup_io_u(td); - cgroup_shutdown(td); + cgroup_shutdown(td, &cgroup_mnt); if (td->o.cpumask_set) { int ret = fio_cpuset_exit(&td->o.cpumask); @@ -1657,6 +1668,9 @@ int main(int argc, char *argv[]) status_timer_arm(); + cgroup_list = smalloc(sizeof(*cgroup_list)); + INIT_FLIST_HEAD(cgroup_list); + run_threads(); if (!fio_abort) { @@ -1668,7 +1682,10 @@ int main(int argc, char *argv[]) } } - cgroup_kill(); + cgroup_kill(cgroup_list); + sfree(cgroup_list); + if (cgroup_mnt) + sfree(cgroup_mnt); fio_mutex_remove(startup_mutex); fio_mutex_remove(writeout_mutex);