def run_as_user(self, user_name, script_file, script_binary, script_arguments):
        """Runs the specified script with the same arguments as the specified user.

        This will run the entire Python script so that it is executing as the specified user.
        It will also add in the '--no-change-user' option which can be used by the script being executed with the
        next process that it was the result of restart so that it probably shouldn't do that again.

        Note, in some system implementations, the current process is replaced by the new process, so this method
        does not ever return to the caller.

        @param user_name: The user to run as, typically 'root' or 'Administrator'.
        @param script_file: The path to the Python script file that was executed if it can be determined.  If it cannot
            then this will be None and script_binary will be supplied.
        @param script_binary:  The binary that is being executed.  This is only supplied if script_file is None.
            On some systems, such as Windows running a script frozen by py2exe, the script is embedded in an actual
            executable.
        @param script_arguments: The arguments passed in on the command line that need to be used for the new
            command line.

        @return The status code for the executed script, if it returns at all.

        @type user_name: str
        @type script_file: str|None
        @type script_binary: str|None
        @type script_arguments: list<str>

        @rtype int

        @raise CannotExecuteAsUser: Indicates that the current process could not change the specified user for
            some reason to execute the script.
        """
        if os.geteuid() != 0:
            raise CannotExecuteAsUser('Must be root to change users')
        if script_file is None:
            raise CannotExecuteAsUser('Must supply script file to execute')
        if self.__no_change_user:
            raise CannotExecuteAsUser('Multiple attempts of changing user detected -- a bug must be causing loop.')

        # Use sudo to re-execute this script with the correct user.  We also pass in --no-change-user to prevent
        # us from re-executing the script again to change the user, to
        # head of any potential bugs that could cause infinite loops.
        arguments = ['sudo', '-u', user_name, sys.executable, script_file, '--no-change-user'] + script_arguments

        print >>sys.stderr, ('Running as %s' % user_name)
        return os.execvp("sudo", arguments)
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/platform_posix.py/PosixPlatformController.run_as_user/original