Example #1
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." %
                               fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)
        os.umask(old_umask)

        # change the owner and group of the file if the worker will run as
        # a different user or group, so that the worker can modify the file
        if cfg.uid != os.geteuid() or cfg.gid != os.getegid():
            util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            # In Python 3.8, open() emits RuntimeWarning if buffering=1 for binary mode.
            # Because we never write to this file, pass 0 to switch buffering off.
            self._tmp = os.fdopen(fd, 'w+b', 0)
        except:
            os.close(fd)
            raise

        self.spinner = 0
Example #2
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." %
                               fdir)
        # 如何你的应用程序需要一个临时文件来存储数据
        # 但不需要同其他程序共享,那么用TemporaryFile函数创建临时文件是最好的选择。
        # 其他的应用程序是无法找到或打开这个文件的,
        # 因为它并没有引用文件系统表。用这个函数创建的临时文件,关闭后会自动删除。
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
        os.umask(old_umask)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
Example #3
0
    def __init__(self, age, ppid, socket, app, timeout, cfg):
        """\
        This is called pre-fork so it shouldn't do anything to the
        current process. If there's a need to make process wide
        changes you'll want to do that in ``self.init_process()``.
        """
        self.age = age
        self.ppid = ppid
        self.socket = socket
        self.app = app
        self.timeout = timeout
        self.cfg = cfg
        self.booted = False

        self.nr = 0
        self.max_requests = cfg.max_requests or sys.maxint
        self.alive = True
        self.spinner = 0
        self.log = logging.getLogger(__name__)
        self.debug = cfg.debug
        self.address = self.socket.getsockname()

        self.fd, self.tmpname = tempfile.mkstemp(prefix="wgunicorn-")
        util.chown(self.tmpname, cfg.uid, cfg.gid)
        self.tmp = os.fdopen(self.fd, "r+b")
Example #4
0
 def __init__(self, age, ppid, socket, app, timeout, conf):
     self.nr = 0
     self.age = age
     self.ppid = ppid
     self.debug = conf['debug']
     self.conf = conf
     self.socket = socket
     self.timeout = timeout
     self.fd, self.tmpname = tempfile.mkstemp(prefix="wgunicorn-")
     util.chown(self.tmpname, conf.uid, conf.gid)
     self.tmp = os.fdopen(self.fd, "r+b")
     self.app = app
     self.alive = True
     self.log = logging.getLogger(__name__)
     self.spinner = 0
     self.address = self.socket.getsockname()
Example #5
0
    def __init__(self, cfg):
        fd, name = tempfile.mkstemp(prefix="wgunicorn-")

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
Example #6
0
    def __init__(self, cfg):
        fd, name = tempfile.mkstemp(prefix="wgunicorn-")

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
        os.umask(old_umask)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
        os.umask(old_umask)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
Example #9
0
    def __init__(self, cfg):
        old_umask = os.umask(cfg.umask)
        fdir = cfg.worker_tmp_dir
        if fdir and not os.path.isdir(fdir):
            raise RuntimeError("%s doesn't exist. Can't create workertmp." %
                               fdir)
        fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)
        os.umask(old_umask)

        # change the owner and group of the file if the worker will run as
        # a different user or group, so that the worker can modify the file
        if cfg.uid != os.geteuid() or cfg.gid != os.getegid():
            util.chown(name, cfg.uid, cfg.gid)

        # unlink the file so we don't leak tempory files
        try:
            if not IS_CYGWIN:
                util.unlink(name)
            self._tmp = os.fdopen(fd, 'w+b', 1)
        except:
            os.close(fd)
            raise

        self.spinner = 0
Example #10
0
def __worker_tmp_init__(self, cfg):
    old_umask = os.umask(cfg.umask)
    fdir = cfg.worker_tmp_dir
    if fdir and not os.path.isdir(fdir):
        raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
    fd, name = tempfile.mkstemp(prefix="wgunicorn-", dir=fdir)

    # avoid os.chown when running via snap with strict confinement
    # ref : https://github.com/benoitc/gunicorn/issues/2059
    if cfg.uid != os.geteuid() or cfg.gid != os.getegid():
        # allows the process to write to the file
        util.chown(name, cfg.uid, cfg.gid)
    os.umask(old_umask)

    # unlink the file so we don't leak tempory files
    try:
        if not IS_CYGWIN:
            util.unlink(name)
        self._tmp = os.fdopen(fd, 'w+b', 1)
    except:
        os.close(fd)
        raise

    self.spinner = 0
Example #11
0
 def bind(self, sock):
     old_umask = os.umask(self.conf.umask)
     sock.bind(self.cfg_addr)
     util.chown(self.cfg_addr, self.conf.uid, self.conf.gid)
     os.umask(old_umask)
Example #12
0
 def bind(self, sock):
     old_umask = os.umask(self.conf.umask)
     sock.bind(self.cfg_addr)
     util.chown(self.cfg_addr, self.conf.uid, self.conf.gid)
     os.umask(old_umask)
Example #13
0
 def bind(self, sock):
     old_umask = os.umask(self.conf['umask'])
     sock.bind(self.address)
     util.chown(self.address, self.conf.uid, self.conf.gid)
     os.umask(old_umask)