diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index df56a77cf832e2aa1d6124e280cfff298ad0e049..e0e9328dd0eca2178ca03baee62eefae5ddbc98c 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -177,6 +177,9 @@ void switchToNixUser()
 {
 #if SETUID_HACK
 
+    /* Don't do anything if this is not a setuid binary. */
+    if (getuid() == geteuid()) return;
+
     /* Here we set the uid and gid to the Nix user and group,
        respectively, IF the current (real) user is a member of the Nix
        group.  Otherwise we just drop all privileges. */