<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi all:<div><br></div><div>Sorry to bring this up again... here is what i plan to do, i'm just asking if this make sense.</div><div><br></div><div>(the context is that i start a transient unit, and pass tty fd, and i need to know when the unit is dead, so i can close my fds) `systemd1.Manager.StartTransientUnit` returns a job in the form of `/org/freedesktop/systemd1/job/<job_id>`, so i'm just going to ignore all messages that comes with that Job. Because those comes when the unit is starting up.. the final `dead` of `failed` message comes with Job (0, '/')..</div><div><br></div><div>do that make sense?</div><div><br></div><div>Thanks! </div><div><br></div><div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><br>Alvaro Leiva<br></div></div></div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 18, 2019 at 1:46 PM aleivag <<a href="mailto:aleivag@gmail.com">aleivag@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div>Hi All:<div><br></div><div>i notice a change of behaviour that broke a couple of my scripts between v239 and v240, and wanted to know that maybe i was always assuming the wrong thing, so here it goes:</div><div><br></div><div>so i subscribe to </div><div><br></div><div><div> "type='signal',"</div><div> "sender='org.freedesktop.systemd1',"</div><div> "path='/org/freedesktop/systemd1/unit/myu_2eservice',"</div><div> "interface='org.freedesktop.DBus.Properties',"</div><div> "member='PropertiesChanged'"</div></div><div><br></div><div>on the bus, and then i start a transient unit like `systemd-run --pty --unit myu.service /bin/bash` .</div><div><br></div><div>to do the subscribe to that event i use the following script, (its definitely not important the script i use but just show you for completeness),</div><div><br></div><div>```</div><div>#!/usr/bin/python3</div><div><br></div><div>from pprint import pprint</div><div>import pystemd</div><div>from pystemd.dbuslib import DBus</div><div><br></div><div>with DBus() as bus, pystemd.DBus.Manager(bus=bus, _autoload=True) as man:</div><div> mstr = (</div><div> "type='signal',"</div><div> "sender='org.freedesktop.systemd1',"</div><div> "path='/org/freedesktop/systemd1/unit/myu_2eservice',"</div><div> "interface='org.freedesktop.DBus.Properties',"</div><div> "member='PropertiesChanged'"</div><div> ).encode()</div><div> man.Monitoring.BecomeMonitor([mstr], 0)</div><div> while True:</div><div> bus.wait(1000)</div><div> m = bus.process()</div><div> if m.is_empty():</div><div> continue</div><div><br></div><div> m.process_reply(False)</div><div> if m.get_path() == b'/org/freedesktop/systemd1/unit/myu_2eservice':</div><div> pprint(m.body)</div><div>``` </div><div><br></div><div><br></div><div>on systemd v239 and bellow before the unit is active i got only 2 messages, one `org.freedesktop.systemd1.Service` and one on `org.freedesktop.systemd1.Unit`. the second one notify me that the "SubState" is "running". when the unit ends, i get 2 messages also, and the last one is to tell me that the "SubState" is "dead" </div><div><br></div><div>on v240 on the other part, before the unit ready, i get 4 messages, one on `org.freedesktop.systemd1.Service` -> `org.freedesktop.systemd1.Unit` -> `org.freedesktop.systemd1.Service` -> `org.freedesktop.systemd1.Unit`, where the Unit ones the substate first is "dead" and then is "running", on deactivating, the messages are the same between 239 and 240.</div><div><br></div><div>so i used to tell that the unit had finished, by inspecting the messages on the bus, and then looking for SubState to be any of ("exited", "failed", "dead"), but i cant do that now.</div><div><br></div><div>at the end of the email i copy the dumps on the 2 versions, but my questions are:</div><div><br></div><div>1.- Is this change in behaviour, intended, or a side effect of something else?</div><div>2.- was what i was doing the best way to decide if a transient unit has finished? i'm super temped to instead check when the `org.freedesktop.systemd1.Service.MainPID == 0` i think its the best idea, but maybe you guys have one that is better.</div><div><br></div><div>thanks guys!!</div><div><br></div><div>now i paste the messages:</div><div><br></div><div>on v239</div><div><br></div><div>on start</div><div><div>[b'org.freedesktop.systemd1.Service',</div><div> {b'ControlPID': 0,</div><div> b'ExecMainCode': 0,</div><div> b'ExecMainExitTimestamp': 0,</div><div> b'ExecMainExitTimestampMonotonic': 0,</div><div> b'ExecMainPID': 18328,</div><div> b'ExecMainStartTimestamp': 1550516822984246,</div><div> b'ExecMainStartTimestampMonotonic': 41004687391,</div><div> b'ExecMainStatus': 0,</div><div> b'GID': 4294967295,</div><div> b'MainPID': 18328,</div><div> b'NRestarts': 0,</div><div> b'Result': b'success',</div><div> b'StatusErrno': 0,</div><div> b'StatusText': b'',</div><div> b'UID': 4294967295,</div><div> b'USBFunctionDescriptors': b'',</div><div> b'USBFunctionStrings': b''},</div><div> [b'ExecStartPre',</div><div> b'ExecStart',</div><div> b'ExecStartPost',</div><div> b'ExecReload',</div><div> b'ExecStop',</div><div> b'ExecStopPost']]</div><div>[b'org.freedesktop.systemd1.Unit',</div><div> {b'ActiveEnterTimestamp': 1550516822984291,</div><div> b'ActiveEnterTimestampMonotonic': 41004687437,</div><div> b'ActiveExitTimestamp': 0,</div><div> b'ActiveExitTimestampMonotonic': 0,</div><div> b'ActiveState': b'active',</div><div> b'AssertResult': True,</div><div> b'AssertTimestamp': 1550516822983511,</div><div> b'AssertTimestampMonotonic': 41004686656,</div><div> b'ConditionResult': True,</div><div> b'ConditionTimestamp': 1550516822983509,</div><div> b'ConditionTimestampMonotonic': 41004686655,</div><div> b'InactiveEnterTimestamp': 0,</div><div> b'InactiveEnterTimestampMonotonic': 0,</div><div> b'InactiveExitTimestamp': 1550516822984291,</div><div> b'InactiveExitTimestampMonotonic': 41004687437,</div><div> b'Job': (0, b'/'),</div><div> b'StateChangeTimestamp': 1550516822984291,</div><div> b'StateChangeTimestampMonotonic': 41004687437,</div><div> b'SubState': b'running'},</div><div> []]</div></div><div><br></div><div>on end</div><div><br></div><div><div>[b'org.freedesktop.systemd1.Service',</div><div> {b'ControlPID': 0,</div><div> b'ExecMainCode': 1,</div><div> b'ExecMainExitTimestamp': 1550516877103509,</div><div> b'ExecMainExitTimestampMonotonic': 41058806656,</div><div> b'ExecMainPID': 18328,</div><div> b'ExecMainStartTimestamp': 1550516822984246,</div><div> b'ExecMainStartTimestampMonotonic': 41004687391,</div><div> b'ExecMainStatus': 0,</div><div> b'GID': 4294967295,</div><div> b'MainPID': 0,</div><div> b'NRestarts': 0,</div><div> b'Result': b'success',</div><div> b'StatusErrno': 0,</div><div> b'StatusText': b'',</div><div> b'UID': 4294967295,</div><div> b'USBFunctionDescriptors': b'',</div><div> b'USBFunctionStrings': b''},</div><div> [b'ExecStartPre',</div><div> b'ExecStart',</div><div> b'ExecStartPost',</div><div> b'ExecReload',</div><div> b'ExecStop',</div><div> b'ExecStopPost']]</div><div>[b'org.freedesktop.systemd1.Unit',</div><div> {b'ActiveEnterTimestamp': 1550516822984291,</div><div> b'ActiveEnterTimestampMonotonic': 41004687437,</div><div> b'ActiveExitTimestamp': 1550516877103599,</div><div> b'ActiveExitTimestampMonotonic': 41058806745,</div><div> b'ActiveState': b'inactive',</div><div> b'AssertResult': True,</div><div> b'AssertTimestamp': 1550516822983511,</div><div> b'AssertTimestampMonotonic': 41004686656,</div><div> b'ConditionResult': True,</div><div> b'ConditionTimestamp': 1550516822983509,</div><div> b'ConditionTimestampMonotonic': 41004686655,</div><div> b'InactiveEnterTimestamp': 1550516877103599,</div><div> b'InactiveEnterTimestampMonotonic': 41058806745,</div><div> b'InactiveExitTimestamp': 1550516822984291,</div><div> b'InactiveExitTimestampMonotonic': 41004687437,</div><div> b'Job': (0, b'/'),</div><div> b'StateChangeTimestamp': 1550516877103599,</div><div> b'StateChangeTimestampMonotonic': 41058806745,</div><div> b'SubState': b'dead'},</div><div> []]</div></div><div><br></div><div><br></div><div>and on v240, on activating (please notice 4 message)</div><div><br></div><div>```</div><div><div>[b'org.freedesktop.systemd1.Service',</div><div> {b'ControlPID': 0,</div><div> b'ExecMainCode': 0,</div><div> b'ExecMainExitTimestamp': 0,</div><div> b'ExecMainExitTimestampMonotonic': 0,</div><div> b'ExecMainPID': 7133,</div><div> b'ExecMainStartTimestamp': 1550515398840688,</div><div> b'ExecMainStartTimestampMonotonic': 1922045814,</div><div> b'ExecMainStatus': 0,</div><div> b'GID': 4294967295,</div><div> b'MainPID': 7133,</div><div> b'NRestarts': 0,</div><div> b'Result': b'success',</div><div> b'StatusErrno': 0,</div><div> b'StatusText': b'',</div><div> b'UID': 4294967295},</div><div> [b'ExecStartPre',</div><div> b'ExecStart',</div><div> b'ExecStartPost',</div><div> b'ExecReload',</div><div> b'ExecStop',</div><div> b'ExecStopPost']]</div><div>[b'org.freedesktop.systemd1.Unit',</div><div> {b'ActiveEnterTimestamp': 0,</div><div> b'ActiveEnterTimestampMonotonic': 0,</div><div> b'ActiveExitTimestamp': 0,</div><div> b'ActiveExitTimestampMonotonic': 0,</div><div> b'ActiveState': b'inactive',</div><div> b'AssertResult': True,</div><div> b'AssertTimestamp': 1550515398840037,</div><div> b'AssertTimestampMonotonic': 1922045163,</div><div> b'ConditionResult': True,</div><div> b'ConditionTimestamp': 1550515398840035,</div><div> b'ConditionTimestampMonotonic': 1922045161,</div><div> b'InactiveEnterTimestamp': 0,</div><div> b'InactiveEnterTimestampMonotonic': 0,</div><div> b'InactiveExitTimestamp': 0,</div><div> b'InactiveExitTimestampMonotonic': 0,</div><div> b'InvocationID': [249,</div><div> 205,</div><div> 238,</div><div> 134,</div><div> 209,</div><div> 51,</div><div> 64,</div><div> 133,</div><div> 164,</div><div> 25,</div><div> 160,</div><div> 192,</div><div> 70,</div><div> 197,</div><div> 1,</div><div> 112],</div><div> b'Job': (903, b'/org/freedesktop/systemd1/job/903'),</div><div> b'StateChangeTimestamp': 0,</div><div> b'StateChangeTimestampMonotonic': 0,</div><div> b'SubState': b'dead'},</div><div> [b'Conditions', b'Asserts']]</div><div>[b'org.freedesktop.systemd1.Service',</div><div> {b'ControlPID': 0,</div><div> b'ExecMainCode': 0,</div><div> b'ExecMainExitTimestamp': 0,</div><div> b'ExecMainExitTimestampMonotonic': 0,</div><div> b'ExecMainPID': 7133,</div><div> b'ExecMainStartTimestamp': 1550515398840688,</div><div> b'ExecMainStartTimestampMonotonic': 1922045814,</div><div> b'ExecMainStatus': 0,</div><div> b'GID': 4294967295,</div><div> b'MainPID': 7133,</div><div> b'NRestarts': 0,</div><div> b'Result': b'success',</div><div> b'StatusErrno': 0,</div><div> b'StatusText': b'',</div><div> b'UID': 4294967295},</div><div> [b'ExecStartPre',</div><div> b'ExecStart',</div><div> b'ExecStartPost',</div><div> b'ExecReload',</div><div> b'ExecStop',</div><div> b'ExecStopPost']]</div><div>[b'org.freedesktop.systemd1.Unit',</div><div> {b'ActiveEnterTimestamp': 1550515398840853,</div><div> b'ActiveEnterTimestampMonotonic': 1922045979,</div><div> b'ActiveExitTimestamp': 0,</div><div> b'ActiveExitTimestampMonotonic': 0,</div><div> b'ActiveState': b'active',</div><div> b'AssertResult': True,</div><div> b'AssertTimestamp': 1550515398840037,</div><div> b'AssertTimestampMonotonic': 1922045163,</div><div> b'ConditionResult': True,</div><div> b'ConditionTimestamp': 1550515398840035,</div><div> b'ConditionTimestampMonotonic': 1922045161,</div><div> b'InactiveEnterTimestamp': 0,</div><div> b'InactiveEnterTimestampMonotonic': 0,</div><div> b'InactiveExitTimestamp': 1550515398840853,</div><div> b'InactiveExitTimestampMonotonic': 1922045979,</div><div> b'InvocationID': [249,</div><div> 205,</div><div> 238,</div><div> 134,</div><div> 209,</div><div> 51,</div><div> 64,</div><div> 133,</div><div> 164,</div><div> 25,</div><div> 160,</div><div> 192,</div><div> 70,</div><div> 197,</div><div> 1,</div><div> 112],</div><div> b'Job': (903, b'/org/freedesktop/systemd1/job/903'),</div><div> b'StateChangeTimestamp': 1550515398840853,</div><div> b'StateChangeTimestampMonotonic': 1922045979,</div><div> b'SubState': b'running'},</div><div> [b'Conditions', b'Asserts']]</div></div><div><br></div><div>```</div><div>and on the way out</div><div><br></div><div>```</div><div><div>[b'org.freedesktop.systemd1.Service',</div><div> {b'ControlPID': 0,</div><div> b'ExecMainCode': 1,</div><div> b'ExecMainExitTimestamp': 1550515593404243,</div><div> b'ExecMainExitTimestampMonotonic': 2116609370,</div><div> b'ExecMainPID': 7133,</div><div> b'ExecMainStartTimestamp': 1550515398840688,</div><div> b'ExecMainStartTimestampMonotonic': 1922045814,</div><div> b'ExecMainStatus': 0,</div><div> b'GID': 4294967295,</div><div> b'MainPID': 0,</div><div> b'NRestarts': 0,</div><div> b'Result': b'success',</div><div> b'StatusErrno': 0,</div><div> b'StatusText': b'',</div><div> b'UID': 4294967295},</div><div> [b'ExecStartPre',</div><div> b'ExecStart',</div><div> b'ExecStartPost',</div><div> b'ExecReload',</div><div> b'ExecStop',</div><div> b'ExecStopPost']]</div><div>[b'org.freedesktop.systemd1.Unit',</div><div> {b'ActiveEnterTimestamp': 1550515398840853,</div><div> b'ActiveEnterTimestampMonotonic': 1922045979,</div><div> b'ActiveExitTimestamp': 1550515593404360,</div><div> b'ActiveExitTimestampMonotonic': 2116609486,</div><div> b'ActiveState': b'inactive',</div><div> b'AssertResult': True,</div><div> b'AssertTimestamp': 1550515398840037,</div><div> b'AssertTimestampMonotonic': 1922045163,</div><div> b'ConditionResult': True,</div><div> b'ConditionTimestamp': 1550515398840035,</div><div> b'ConditionTimestampMonotonic': 1922045161,</div><div> b'InactiveEnterTimestamp': 1550515593404360,</div><div> b'InactiveEnterTimestampMonotonic': 2116609486,</div><div> b'InactiveExitTimestamp': 1550515398840853,</div><div> b'InactiveExitTimestampMonotonic': 1922045979,</div><div> b'InvocationID': [249,</div><div> 205,</div><div> 238,</div><div> 134,</div><div> 209,</div><div> 51,</div><div> 64,</div><div> 133,</div><div> 164,</div><div> 25,</div><div> 160,</div><div> 192,</div><div> 70,</div><div> 197,</div><div> 1,</div><div> 112],</div><div> b'Job': (0, b'/'),</div><div> b'StateChangeTimestamp': 1550515593404360,</div><div> b'StateChangeTimestampMonotonic': 2116609486,</div><div> b'SubState': b'dead'},</div><div> [b'Conditions', b'Asserts']]</div></div><div>```</div><div><div><div dir="ltr" class="gmail-m_-570289712728811977gmail_signature"><div dir="ltr"><br>Alvaro Leiva<br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div>