Skip to content

Commit d3818f3

Browse files
committed
Allow port number to be 0, in which case print out port number
allocated by the system along with the PID.
1 parent 1d92eb4 commit d3818f3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

python/rtpp_notify_client.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def main():
8080
if len(spath) != 2:
8181
raise ValueError('TCP listening socket not in the form "IP:port": ' + spath[0])
8282
spath[1] = int(spath[1])
83-
if spath[1] <= 0 or spath[1] > 65535:
84-
raise ValueError('TCP listening port not in the range 1-65535: %d' % spath[1])
83+
if spath[1] < 0 or spath[1] > 65535:
84+
raise ValueError('TCP listening port not in the range 0-65535: %d' % spath[1])
8585
stype = 'tcp'
8686
continue
8787
if o == '-S':
@@ -111,9 +111,14 @@ def main():
111111

112112
if daemonize:
113113
dob = Daemonizer(logfile = logfile)
114+
if stype != 'unix':
115+
dob.extra_rsize = 5
114116
if dob.amiparent:
115-
dob.waitchild()
116-
print(F'{dob.childpid}')
117+
portnum = dob.waitchild()
118+
out = F'{dob.childpid}'
119+
if stype != 'unix' and spath[1] == 0:
120+
out += F' {portnum[1]}'
121+
print(out)
117122
sys.exit(0)
118123

119124
ch = cli_handler(file_out)
@@ -127,7 +132,11 @@ def main():
127132
Timeout(ch.done, timeout)
128133
ED2.regSignal(SIGTERM, ch.done)
129134
if daemonize:
130-
dob.childreport()
135+
if stype == 'unix':
136+
pnum = None
137+
else:
138+
pnum = '%.5d' % (cs.address[1],)
139+
dob.childreport(pnum)
131140
ED2.loop()
132141
if ch.exception is not None:
133142
raise ch.exception

0 commit comments

Comments
 (0)