def setup(user=None, group=None, file_limit=None, core_dumps=None):
    """Set the processes user, group, and file limits"""

    if file_limit:
        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (file_limit, file_limit))
        except ValueError, ex:
            log.error("Failed to set limit on open files: %s" % ex)
            sys.exit(1)

    if group:
        if not group.isdigit():
            try:
                group = grp.getgrnam(group)[2]
            except KeyError:
                log.error("Unknown group '%s'" % group)
                sys.exit(1)
        else:
            group = int(group)

        try:
            os.setregid(group, group)
        except OSError, ex:
            log.error("Failed to set gid: %s" % ex)
            sys.exit(1)

    if user:
        if not user.isdigit():
            try:
                user = pwd.getpwnam(user)[2]
            except KeyError:
                log.error("Unknown user '%s'" % user)
                sys.exit(1)
        else:
            user = int(user)

        try:
            os.setreuid(user, user)
        except OSError, ex:
            log.error("Failed to set uid: %s" % ex)
            sys.exit(1)

    if core_dumps:
        try:
            resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
        except __HOLE__, ex:
            log.error("Failed to set limit on core dumps: %s" % ex)
            sys.exit(1)
        if not os.path.isdir(core_dumps):
            try:
                os.makedirs(core_dumps)
            except OSError, ex:
                log.error("Failed to create directory %s" % core_dumps)
                sys.exit(1)
        else:
            if not os.access(core_dumps, os.R_OK|os.W_OK|os.X_OK):
                log.error("Insufficient permissions on %s" % core_dumps)
                sys.exit(1)
dataset/ETHPy150Open marineam/nagcat/python/nagcat/util.py/setup