Yes, sad to say, I do have to ask you to change this to a putenv - it's more portable than setenv.
I recommend something like:
```
static char env[] = "CFENGINE_TEST_OVERRIDE_WORKDIR=/tmp/lastseen_migration_test.XXXXXX";
char *dir = strchr(env, '=') + 1; /* start of the path */
mkdtemp(dir);
strlcpy(CFWORKDIR, dir, CF_BUFSIZE);
putenv(env);
mkdir(dir, S_IRWXU | S_IRWXG | S_IRWX0);
```