From e0b0d89201bd301f47fbbfcf86545b7e77b16ef3 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 8 Dec 2009 10:10:14 +0100 Subject: [PATCH] Add support for specifying UID/GID Signed-off-by: Jens Axboe --- HOWTO | 5 +++++ fio.1 | 7 +++++++ fio.c | 9 +++++++++ fio.h | 3 +++ init.c | 2 ++ options.c | 12 ++++++++++++ 6 files changed, 38 insertions(+) diff --git a/HOWTO b/HOWTO index 0b40f758..45a96bb1 100644 --- a/HOWTO +++ b/HOWTO @@ -1015,6 +1015,11 @@ cgroup_weight=int Set the weight of the cgroup to this value. See the documentation that comes with the kernel, allowed values are in the range of 100..1000. +uid=int Instead of running as the invoking user, set the user ID to + this value before the thread/process does any work. + +gid=int Set group ID, see uid. + 6.0 Interpreting the output --------------------------- diff --git a/fio.1 b/fio.1 index 2e0a283d..dfca43ef 100644 --- a/fio.1 +++ b/fio.1 @@ -735,6 +735,13 @@ your system doesn't have it mounted, you can do so with: .BI cgroup_weight \fR=\fPint Set the weight of the cgroup to this value. See the documentation that comes with the kernel, allowed values are in the range of 100..1000. +.TP +.BI uid \fR=\fPint +Instead of running as the invoking user, set the user ID to this value before +the thread/process does any work. +.TP +.BI gid \fR=\fPint +Set group ID, see \fBuid\fR. .SH OUTPUT While running, \fBfio\fR will display the status of the created jobs. For example: diff --git a/fio.c b/fio.c index 7d4c96a2..728addd6 100644 --- a/fio.c +++ b/fio.c @@ -1041,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. diff --git a/fio.h b/fio.h index b1af7b1b..3b2dd6ed 100644 --- a/fio.h +++ b/fio.h @@ -277,6 +277,9 @@ struct thread_options { */ char *cgroup; unsigned int cgroup_weight; + + unsigned int uid; + unsigned int gid; }; #define FIO_VERROR_SIZE 128 diff --git a/init.c b/init.c index 873a0ba6..95c7efb4 100644 --- a/init.c +++ b/init.c @@ -181,6 +181,8 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent) td = &threads[thread_number++]; *td = *parent; + td->o.uid = td->o.gid = -1U; + dup_files(td, parent); options_mem_dupe(td); diff --git a/options.c b/options.c index 16908a07..f6280628 100644 --- a/options.c +++ b/options.c @@ -1740,6 +1740,18 @@ static struct fio_option options[] = { .minval = 100, .maxval = 1000, }, + { + .name = "uid", + .type = FIO_OPT_INT, + .off1 = td_var_offset(uid), + .help = "Run job with this user ID", + }, + { + .name = "gid", + .type = FIO_OPT_INT, + .off1 = td_var_offset(gid), + .help = "Run job with this group ID", + }, { .name = NULL, }, -- 2.25.1