def close_filenos(preserve):
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[<NUM_LIT:1>]<EOL>if maxfd == resource.RLIM_INFINITY:<EOL><INDENT>maxfd = <NUM_LIT><EOL><DEDENT>for fileno in range(maxfd):<EOL><INDENT>if fileno not in preserve:<EOL><INDENT>try:<EOL><INDENT>os.close(fileno)<EOL><DEDENT>except OSError as err:<EOL><INDENT>if not err.errno == errno.EBADF:<EOL><INDENT>raise DaemonError(<EOL>'<STR_LIT>'<EOL>.format(fileno, err))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Close unprotected file descriptors

    Close all open file descriptors that are not in preserve.

    If ulimit -nofile is "unlimited", all is defined filenos <= 4096,
    else all is <= the output of resource.getrlimit().

    :param preserve: set with protected files
    :type preserve: set

    :return: None