Removed gevent requirement for now
This commit is contained in:
parent
786fb7499c
commit
8e82470a5f
@ -11,11 +11,13 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from gevent import monkey
|
# from gevent import monkey
|
||||||
monkey.patch_all()
|
# monkey.patch_all()
|
||||||
|
|
||||||
|
|
||||||
from gevent.server import StreamServer
|
# from gevent.server import StreamServer
|
||||||
|
|
||||||
|
from SocketServer import ThreadingTCPServer, BaseRequestHandler
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import msgpack
|
import msgpack
|
||||||
@ -167,11 +169,16 @@ class SolardTCPHandler(object):
|
|||||||
os.setgid(pw_gid)
|
os.setgid(pw_gid)
|
||||||
os.setuid(pw_uid)
|
os.setuid(pw_uid)
|
||||||
logger.debug("Child forked %d", os.getpid())
|
logger.debug("Child forked %d", os.getpid())
|
||||||
|
self._fix_env(pw_uid)
|
||||||
self.forked = True
|
self.forked = True
|
||||||
self._write_ok(True)
|
self._write_ok(True)
|
||||||
return True
|
return True
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _fix_env(self, pw_uid):
|
||||||
|
pw_dir = pwd.getpwuid(pw_uid).pw_dir
|
||||||
|
os.environ['HOME'] = pw_dir
|
||||||
|
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
try:
|
try:
|
||||||
@ -241,16 +248,12 @@ class SolardTCPHandler(object):
|
|||||||
logger.exception("Got exception")
|
logger.exception("Got exception")
|
||||||
|
|
||||||
|
|
||||||
|
class SolardReqHandler(BaseRequestHandler):
|
||||||
|
|
||||||
class SolardTCPServer(StreamServer):
|
def handle(self):
|
||||||
|
|
||||||
allow_reuse_address = True
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
StreamServer.__init__(self, *args, **kwargs)
|
|
||||||
|
|
||||||
def handle(self, sock, address):
|
|
||||||
close = True
|
close = True
|
||||||
|
sock = self.request
|
||||||
|
address = self.client_address
|
||||||
h = SolardTCPHandler(sock, address)
|
h = SolardTCPHandler(sock, address)
|
||||||
try:
|
try:
|
||||||
logger.debug("New from %s:%d" % address)
|
logger.debug("New from %s:%d" % address)
|
||||||
@ -276,9 +279,19 @@ class SolardTCPServer(StreamServer):
|
|||||||
sock.close()
|
sock.close()
|
||||||
if h.forked:
|
if h.forked:
|
||||||
# if forked we can safely exit now
|
# if forked we can safely exit now
|
||||||
sys.exit()
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
class SolardTCPServer(ThreadingTCPServer):
|
||||||
|
|
||||||
|
allow_reuse_address = True
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
# StreamServer.__init__(self, *args, **kwargs)
|
||||||
|
ThreadingTCPServer.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
s = SolardTCPServer(('0.0.0.0', 5555))
|
s = SolardTCPServer(('0.0.0.0', 5555), SolardReqHandler)
|
||||||
s.serve_forever()
|
s.serve_forever()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user