diff --git a/supervisorctl.py b/supervisorctl.py index d7d30009d92340e6ce71f94ad5bbc20be48b5ffc_c3VwZXJ2aXNvcmN0bC5weQ==..c4309c21038eefdc8031168d9c2241db0b30c6c2_c3VwZXJ2aXNvcmN0bC5weQ== 100644 --- a/supervisorctl.py +++ b/supervisorctl.py @@ -4,7 +4,7 @@ import json from typing import Any, Set, Tuple -from ovms import cmbdef, iodef, mbxqio, prvdef, psldef, starlet, lnmdef +from ovms import cmbdef, dvidef, iodef, lnmdef, mbxqio, prvdef, psldef, starlet from ovms.rtl import lib supervisorctl_pwd = '' @@ -8,6 +8,7 @@ from ovms.rtl import lib supervisorctl_pwd = '' +supervisorctl_mbxreply = '' supervisord_table_name = b'SUPERVISORD_TABLE' programs_name: Set[str] = set() @@ -43,5 +44,5 @@ cmd.Cmd.__init__(self, completekey, stdin, stdout) def write_cmd(self, cmd: dict) -> Any: - global supervisorctl_pwd + global supervisorctl_pwd, supervisorctl_mbxreply cmd['pwd'] = supervisorctl_pwd @@ -47,4 +48,5 @@ cmd['pwd'] = supervisorctl_pwd + cmd['mbxreply'] = supervisorctl_mbxreply jscmd = json.dumps(cmd) self.mcmd.write(jscmd.encode('ascii'), iodef.IO_M_READERCHECK) return json.loads( @@ -48,7 +50,8 @@ jscmd = json.dumps(cmd) self.mcmd.write(jscmd.encode('ascii'), iodef.IO_M_READERCHECK) return json.loads( - self.mcmd_r.read(4096, iodef.IO_M_WRITERCHECK) # type: ignore + # self.mcmd_r.read(4096, iodef.IO_M_WRITERCHECK) # type: ignore + self.mcmd_r.read(4096) # type: ignore ) def do_EOF(self, line): @@ -157,7 +160,7 @@ ) -def mbx_init() -> Tuple[int, int]: +def mbx_init() -> Tuple[int, int, str]: s, chancmd = starlet.crembx( prmflg=1, lognam='SUPERVISORD_CMD', @@ -168,11 +171,11 @@ flags=cmbdef.CMB_M_WRITEONLY, ) s, chancmd_r = starlet.crembx( - prmflg=1, - lognam='SUPERVISORD_CMD_REPLY', + prmflg=0, + # lognam='SUPERVISORD_CMD_REPLY', maxmsg=32 * 1024, bufquo=64 * 1024, promsk=0x0000FF00, acmode=psldef.PSL_C_USER, flags=cmbdef.CMB_M_READONLY, ) @@ -173,7 +176,8 @@ maxmsg=32 * 1024, bufquo=64 * 1024, promsk=0x0000FF00, acmode=psldef.PSL_C_USER, flags=cmbdef.CMB_M_READONLY, ) + mbxunit = lib.getdvi(dvidef.DVI__UNIT, chancmd_r)[1] @@ -179,5 +183,5 @@ - return chancmd, chancmd_r + return chancmd, chancmd_r, f'MBA{mbxunit}:' def main(): @@ -181,7 +185,7 @@ def main(): - global supervisorctl_pwd, programs_name + global supervisorctl_pwd, supervisorctl_mbxreply, programs_name parser = argparse.ArgumentParser(description='supervisorctl') parser.add_argument( '-p', @@ -213,7 +217,7 @@ starlet.setprv(1, prvdef.PRV_M_PRMMBX | prvdef.PRV_M_SYSNAM) logicals_init() - chan, chan_r = mbx_init() + chan, chan_r, supervisorctl_mbxreply = mbx_init() with ( mbxqio.MBXQIO(channel=chan) as mcmd, mbxqio.MBXQIO(channel=chan_r) as mcmd_r, diff --git a/supervisord.py b/supervisord.py index d7d30009d92340e6ce71f94ad5bbc20be48b5ffc_c3VwZXJ2aXNvcmQucHk=..c4309c21038eefdc8031168d9c2241db0b30c6c2_c3VwZXJ2aXNvcmQucHk= 100644 --- a/supervisord.py +++ b/supervisord.py @@ -581,7 +581,7 @@ ) -def mbx_init() -> Tuple[int, int, int, int]: +def mbx_init() -> Tuple[int, int, int]: global logger logger.info('Creating mailbox') s, chan = starlet.crembx( @@ -605,14 +605,4 @@ acmode=psldef.PSL_C_USER, flags=cmbdef.CMB_M_READONLY, ) - - s, chancmd_r = starlet.crembx( - prmflg=1, - lognam='SUPERVISORD_CMD_REPLY', - maxmsg=32 * 1024, - bufquo=64 * 1024, - promsk=0x0000FF00, - acmode=psldef.PSL_C_USER, - flags=cmbdef.CMB_M_WRITEONLY, - ) logger.info(f'Mailbox created {mbxunt}') @@ -618,5 +608,5 @@ logger.info(f'Mailbox created {mbxunt}') - return chan, mbxunt, chancmd, chancmd_r + return chan, mbxunt, chancmd # , chancmd_r class AstParam(object): @@ -649,14 +639,15 @@ return astctxt -def send_cmd_reply(fcmd_r: mbxqio.MBXQIO, cmdreply: dict): - jscmd = json.dumps(cmdreply) - try: - fcmd_r.write( - jscmd.encode('ascii'), - iodef.IO_M_READERCHECK | iodef.IO_M_NOW, - ) - except OSError: - pass +def send_cmd_reply(mbxreply_name: str, cmdreply: dict): + with mbxqio.MBXQIO(mbxname=mbxreply_name) as fcmd_r: + jscmd = json.dumps(cmdreply) + try: + fcmd_r.write( + jscmd.encode('ascii'), + iodef.IO_M_READERCHECK | iodef.IO_M_NOW, + ) + except OSError: + pass @@ -661,7 +652,7 @@ -def dispatch_cmd(res: bytes, fcmd_r: mbxqio.MBXQIO): +def dispatch_cmd(res: bytes): global supervisorctl_pwd jscmd = json.loads(res) pwd = jscmd['pwd'] jscmd['pwd'] = '*****' @@ -664,7 +655,8 @@ global supervisorctl_pwd jscmd = json.loads(res) pwd = jscmd['pwd'] jscmd['pwd'] = '*****' + fcmd_r = jscmd['mbxreply'] if pwd != supervisorctl_pwd: logging.info('Invalid password') send_cmd_reply(fcmd_r, {'error': 'Invalid password'}) @@ -726,7 +718,7 @@ send_cmd_reply(fcmd_r, {'result': lst}) -def dispatch_ast(astparam: AstParam, fcmd_r: mbxqio.MBXQIO): +def dispatch_ast(astparam: AstParam): iosb: iosbdef.IOSB_r_io_64 | None iosb = astparam.iosb @@ -754,7 +746,7 @@ assert iosb is not None and buff is not None res = buff.raw[: iosb.iosb_r_devdepend.iosb_r_bcnt_16.iosb_w_bcnt] pid = iosb.iosb_r_devdepend.iosb_r_bcnt_16.iosb_l_dev_depend - dispatch_cmd(res, fcmd_r) + dispatch_cmd(res) case AstParamType.TIMER: global current_tick current_tick += 1 @@ -780,9 +772,9 @@ val.kill() -def run(chan: int, chancmd: int, chancmd_r: int): +def run(chan: int, chancmd: int): global timer_delay, timer_astctx astparam: AstParam with ( mbxqio.MBXQIO(channel=chan) as fterm, mbxqio.MBXQIO(channel=chancmd) as fcmd, @@ -784,9 +776,8 @@ global timer_delay, timer_astctx astparam: AstParam with ( mbxqio.MBXQIO(channel=chan) as fterm, mbxqio.MBXQIO(channel=chancmd) as fcmd, - mbxqio.MBXQIO(channel=chancmd_r) as fcmd_r, ): t_astctxt = qio_procterm(fterm) # noqa: F841 c_astctxt = qio_cmd(fcmd) # noqa: F841 @@ -815,7 +806,7 @@ continue if iosb and not stsdef.vms_status_success(iosb.iosb_w_status): raise IOError(iosb.iosb_w_status) - dispatch_ast(astparam, fcmd_r) + dispatch_ast(astparam) if astparam.ptype == AstParamType.PROCTERM: t_astctxt = qio_procterm(fterm) # noqa: F841 elif astparam.ptype == AstParamType.CMD: @@ -1050,8 +1041,8 @@ Program.programs[name] = p logicals_init() - chan, Program.mbxunt, chancmd, chancmd_r = mbx_init() - run(chan, chancmd, chancmd_r) + chan, Program.mbxunt, chancmd = mbx_init() + run(chan, chancmd) if __name__ == '__main__':