Skip to content

Commit

Permalink
Use socket.bind to find a port to listen to.
Browse files Browse the repository at this point in the history
This reduces the chance of conflicting with another process, and possibly fixes clalancette/oz/#201
  • Loading branch information
ndonegan authored and clalancette committed Jan 28, 2016
1 parent 112808b commit 0b447be
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions oz/Guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import stat
import lxml.etree
import logging
import random
import guestfs
import socket
import struct
Expand Down Expand Up @@ -226,7 +225,13 @@ def __init__(self, tdl, config, auto, output_disk, nicmodel, clockoffset,

self.icicle_tmp = os.path.join(self.data_dir, "icicletmp",
self.tdl.name)
self.listen_port = random.randrange(1024, 65535)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind to port 0 which will use a free socket to listen to.
sock.bind(("", 0))
self.listen_port = sock.getsockname()[1]
# Close the socket to free it up for libvirt
sock.close()

self.connect_to_libvirt()

Expand Down

0 comments on commit 0b447be

Please sign in to comment.