def drop_privileges():
  """Drop root privileges down to the specified SETUID_USER.

  N.B. DO NOT USE THE logging MODULE FROM WITHIN THIS FUNCTION.
  This function is run in forked processes right before it calls
  exec, but the fork may have occured while a different thread
  had locked the log. Since it's a forked process, the log will
  be locked forever in the subprocess and thus a logging.X may
  block forever.
  """
  we_are_root = os.getuid() == 0
  if not we_are_root:
    print >>sys.stdout, "[INFO] Not running as root, skipping privilege drop"
    return

  try:
    pw = pwd.getpwnam(SETUID_USER)
  except KeyError:
    print >>sys.stderr, "[ERROR] Couldn't get user information for user " + SETUID_USER
    raise

  try:
    gr = grp.getgrnam(SETGID_GROUP)
  except __HOLE__:
    print >>sys.stderr, "[ERROR] Couldn't get group information for group " + SETGID_GROUP
    raise

  # gid has to be set first
  os.setgid(gr.gr_gid)
  os.setuid(pw.pw_uid)
dataset/ETHPy150Open cloudera/hue/desktop/core/src/desktop/supervisor.py/drop_privileges