Skip to content

Commit 78e30cf

Browse files
committed
Allow child to pass some data to parent along with the init_ok token.
1 parent 5ddf6e3 commit 78e30cf

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

python/sippyapi/system/Daemonizer.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Daemonizer():
3838
ssock = None
3939
report_token = 'init_ok\n'
4040
logfile = None
41+
extra_rsize = 0
4142

4243
def __init__(self, logfile = None, tweakhup = False):
4344
if tweakhup:
@@ -86,13 +87,18 @@ def __init__(self, logfile = None, tweakhup = False):
8687

8788
def waitchild(self):
8889
assert(self.amiparent)
89-
status = self.ssock.recv(len(self.report_token)).decode('ascii')
90+
status = self.ssock.recv(len(self.report_token) + self.extra_rsize).decode('ascii')
91+
if self.extra_rsize > 0:
92+
ext_status = status[-self.extra_rsize:]
93+
status = status[:-self.extra_rsize]
9094
if status == self.report_token:
91-
return status
95+
if self.extra_rsize == 0:
96+
return status
97+
return (status, ext_status)
9298
if status is None:
9399
estatus = 'NULL'
94100
else:
95-
estatus = F'"{status}"'
101+
estatus = F'"{status[:-self.extra_rsize]}"'
96102
report_token = self.report_token
97103
if report_token[-1] == '\n':
98104
report_token = report_token[:-1]
@@ -106,9 +112,13 @@ def waitchild(self):
106112
break
107113
raise DChildProcessError(emsg, self.logfile) from None
108114

109-
def childreport(self):
115+
def childreport(self, extra = None):
110116
assert(not self.amiparent)
111-
self.ssock.send(self.report_token.encode('ascii'))
117+
assert(extra == None or len(extra) == self.extra_rsize)
118+
rep = self.report_token
119+
if extra:
120+
rep += extra
121+
self.ssock.send(rep.encode('ascii'))
112122

113123
if __name__ == '__main__':
114124
dob = Daemonizer()

0 commit comments

Comments
 (0)