saltstack/salt — pull request #1230 by uggedal (2012-05-08 15:12:43+00:00)
Title: Make onlyif and unless run with the same settings as the cmd itself.

The unless and onlyif checks should be executed with the same working
directory, user, group, shell, and environment as the command itself.
Take this example for instance:

createuser --no-superuser --no-createdb --no-createrole joe:
cmd.run:
- unless: psql --tuples-only -c 'SELECT rolname FROM
pg_catalog.pg_roles;' | grep '^joe$'
- user: postgres

Before this fix this state will fail during the unless check since its
beeing executed by root in a normal PostgreSQL setup.

In addition a bug where the effective gid was not reset when the
state returned early was fixed.