<div dir="ltr"><div>You can call org.freedesktop.systemd1.Manager.GetUnitByPID() to directly get the D-Bus object path based on your PID.<br></div><div><br></div><div><div><div>There is also the magic path "/org/freedesktop/systemd1/unit/self" which always gives properties of the same service (or scope) that you're in.</div></div></div><div><br></div>Finally, it is possible to call sd_pid_get_unit() from sd-login.h to get your unit name (straight from /proc/<pid>/cgroup, with no D-Bus yet), then call .Manager.GetUnit() to translate the name into an object path.<div><div></div><div><br></div><div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 10, 2020 at 6:28 PM Etienne Doms <<a href="mailto:etienne.doms@gmail.com">etienne.doms@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">Hello,<br>
<br>
My service needs to behave a bit differently when it has been<br>
automatically because of a software fault. I use the<br>
"Restart=on-failure", and I understand that I can read the "NRestarts"<br>
property which is incremented whenever the service is restarted.<br>
<br>
The thing is, inside my service, I have no idea if I'm foobar.service,<br>
barfoo.service, etc. and I believe I should be agnostic of that.<br>
<br>
Is there a way to dynamically retrieve<br>
/org/freedesktop/systemd1/unit/foobar_2eservice, so that I can ask<br>
org.freedesktop.systemd1 the NRestarts property value of the<br>
org.freedesktop.systemd1.Service interface?<br>
<br>
Maybe I'm just over-engineering and should just hardcode<br>
"foobar.service" inside my service, but it feels a bit odd to me...<br>
Maybe also I understand nothing about D-Bus, sorry about that.<br>
<br>
Thank you for your support.<br>
<br>
Best regards,<br>
Etienne Doms<br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div>