Merge branch 'winfio'
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 93482f5294ed55c245e25a0e98f8151fe7354ced..9c556705f124d1365afca2aac2e3712b61a1a2c7 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <limits.h>
 #include <signal.h>
 #include <time.h>
 #include <locale.h>
@@ -988,7 +989,7 @@ void reset_all_stats(struct thread_data *td)
                td->io_issues[i] = 0;
                td->ts.total_io_u[i] = 0;
        }
-       
+
        fio_gettime(&tv, NULL);
        td->ts.runtime[0] = 0;
        td->ts.runtime[1] = 0;
@@ -1069,14 +1070,18 @@ 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;
-       }
+       /*
+        * A new gid requires privilege, so we need to do this before setting
+        * the uid.
+        */
        if (td->o.gid != -1U && setgid(td->o.gid)) {
                td_verror(td, errno, "setgid");
                goto err;
        }
+       if (td->o.uid != -1U && setuid(td->o.uid)) {
+               td_verror(td, errno, "setuid");
+               goto err;
+       }
 
        /*
         * May alter parameters that init_io_u() will use, so we need to