示例#1
0
    def dup(self):
	import posix

	try: ignore = posix.fdopen
	except: raise AttributeError, 'dup() method unavailable'

	return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
示例#2
0
    def dup(self):
        import posix

        if not hasattr(posix, 'fdopen'):
            raise AttributeError, 'dup() method unavailable'

        return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
示例#3
0
    def dup(self):
        import posix

        if not hasattr(posix, 'fdopen'):
            raise AttributeError, 'dup() method unavailable'

        return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
 def test_dup(self):
     if hasattr(posix, 'dup'):
         fp = open(test_support.TESTFN)
         try:
             fd = posix.dup(fp.fileno())
             self.assert_(isinstance(fd, int))
             os.close(fd)
         finally:
             fp.close()
示例#5
0
    def dup(self):
        import posix

        try:
            ignore = posix.fdopen
        except:
            raise AttributeError, 'dup() method unavailable'

        return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
示例#6
0
 def test_readinto_error(self):
     import _socket, posix, array
     s = _socket.socket()
     buff = array.array("c", "X" * 65)
     fh = posix.fdopen(posix.dup(s.fileno()), 'rb')
     # "Transport endpoint is not connected"
     raises(IOError, fh.readinto, buff)
     fh.close()
     s.close()
示例#7
0
 def test_readinto_error(self):
     import _socket, posix, array
     s = _socket.socket()
     buff = array.array("c", "X" * 65)
     fh = posix.fdopen(posix.dup(s.fileno()), 'rb')
     # "Transport endpoint is not connected"
     raises(IOError, fh.readinto, buff)
     fh.close()
     s.close()
示例#8
0
    def test_EAGAIN(self):
        import _socket, posix
        s1, s2 = _socket.socketpair()
        s2.setblocking(False)
        s1.send("hello")

        f2 = posix.fdopen(posix.dup(s2.fileno()), 'rb', 0)
        data = f2.read(12)
        assert data == "hello"

        f2.close()
        s2.close()
        s1.close()
示例#9
0
    def test_EAGAIN(self):
        import _socket, posix
        s1, s2 = _socket.socketpair()
        s2.setblocking(False)
        s1.send("hello")

        f2 = posix.fdopen(posix.dup(s2.fileno()), 'rb', 0)
        data = f2.read(12)
        assert data == "hello"

        f2.close()
        s2.close()
        s1.close()
def main():
    # stdin is dup'ed to make sure nothing unexpected is written or read from the
    # stream. CellAppMgr is informed of the appropriate file descriptor via its
    # command line arguments.
    fd = posix.dup(0)

    nullFD = posix.open("/dev/null", posix.O_RDWR)
    posix.dup2(nullFD, 0)
    posix.dup2(nullFD, 1)
    posix.dup2(nullFD, 2)

    connection = Connection(fd)

    peerString = connection.socket.getpeername()[0]

    syslog.syslog("Got connection from " + peerString)

    versionNumber, = connection.getStruct("=i")

    if versionNumber not in VERSION_NUMBERS:
        connection.sendMsg(
          "ERROR: Invalid local CellAppMgr version. " \
          "Expected versions %s. Got %d\n" % \
          (str( VERSION_NUMBERS ), versionNumber) )
        sys.exit(0)

    accountNameLen, = connection.getStruct("=i")
    accountName = connection.receive(accountNameLen)

    # Make a unique token that will be sent to the front-end, signed and then
    # returned.
    sentToken = str(time.time()) + str(random.random()) + peerString

    connection.socket.send(
        struct.pack("=Hi", MSG_INIT, len(sentToken)) + sentToken)

    signedTokenLen, = connection.getStruct("=i")
    signedToken = connection.receive(signedTokenLen)

    isVerified, receivedToken, decryptData = verifyToken(signedToken)

    if receivedToken != sentToken:
        syslog.syslog("Authentication failed '%s' at '%s')" %
                      (accountName, peerString))

    if not isVerified:
        connection.sendMsg("ERROR: Authentication failed for GPG key '%s'.\n" %
                           accountName)
        connection.sendMsg(
            "ERROR: Make sure the public GPG key is registered with BigWorld.\n"
        )
        connection.sendMsg(
            "ERROR: To register a key, please contact [email protected]\n"
        )
        syslog.syslog("Authentication failed for '%s' at '%s')" %
                      (accountName, peerString))
        sys.exit(0)

    remoteUID, remotePID, remoteViewerPort = \
     connection.getStruct( "=iiH" )

    syslogPrefix = "CellAppMgr:%s:%s:%d:%d" % \
      (accountName, connection.socket.getpeername()[0],
       remoteUID, remotePID )
    syslog.openlog(syslogPrefix)
    syslog.syslog("Started")
    for line in decryptData.split("\n"):
        syslog.syslog(line)

    # Read the command line arguments
    args = []
    argLen = 1
    while argLen:
        argLen, = connection.getStruct("=i")
        if argLen:
            arg = connection.receive(argLen)
            args.append(arg)

    try:
        # This affects where core files are created.
        os.chdir(os.path.dirname(EXE_PATH))
    except Exception, e:
        pass
示例#11
0
def skip_test_alarm():
    # (tfel): this test is very brittle, because it is supposed to work with our
    # first, very primitive implementation of signal handlers, which does not
    # allow Python code to run in the handler. So we rely on a side-effect on an
    # open file descriptor instead.
    try:
        import _signal
    except ImportError:
        import signal as _signal
    import posix
    import time
    import sys

    # first, we start opening files until the fd is the same as SIGALRM
    fds = []
    dupd_fd = None
    fd = None

    try:
        fd = posix.open(__file__, posix.O_RDONLY)
        while fd < _signal.SIGALRM:
            fds.append(fd)
            fd = posix.open(__file__, posix.O_RDONLY)

        if fd > _signal.SIGALRM:
            dupd_fd = posix.dup(_signal.SIGALRM)
            posix.close(_signal.SIGALRM)
            fd = posix.open(__file__, posix.O_RDONLY)

        # close the unneeded fds
        for oldfd in fds:
            posix.close(oldfd)

        assert fd == _signal.SIGALRM, "fd not equal to SIGALRM"

        # temporary: graalpython doesn't check the argcount for the handler atm
        if sys.implementation.name == "graalpython":
            handler = posix.close
        else:
            handler = lambda s, f: posix.close(s)

        oldhandler = _signal.signal(_signal.SIGALRM, handler)
        assert oldhandler == _signal.SIG_DFL, "oldhandler != SIG_DFL"
        assert _signal.getsignal(
            _signal.SIGALRM) is handler, "getsignal handler != handler"

        # schedule the alarm signal, that will trigger the handler, which
        # will in turn close our file
        _signal.alarm(1)

        # wait for the signal to come in and be handled
        time.sleep(1.5)

        # check for the side-effect
        try:
            posix.read(fd, 1)
        except OSError:
            assert True
        else:
            assert False, "file is still open"
    finally:
        if dupd_fd is not None:
            try:
                posix.close(fd)
            except OSError:
                pass
            posix.dup(dupd_fd)  # duplicates back into just free'd fd
示例#12
0
"""Extended file operations available in POSIX.