<div dir="ltr"><div><div><div>Thanks for the help. <br><br></div>I am developing in go lang and found a perfect binding in dbusbindings.<br><br></div>The logind dbus api was not intutive at first, but figured it out after some examples.<br><br><br></div>Posting the go lang POC of above loginctl code to get active display. (So anyone following this thread can spend less effort).<br><br><br><br><br>package main<br><br>import (<br> "fmt"<br> "os"<br><br> "<a href="http://github.com/godbus/dbus">github.com/godbus/dbus</a>"<br>)<br><br>func main() {<br> conn, err := dbus.SystemBus()<br> if err != nil {<br> fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)<br> os.Exit(1)<br> }<br><br> logindDest := "org.freedesktop.login1"<br> loginPath := dbus.ObjectPath("/org/freedesktop/login1")<br><br> logindObj := conn.Object(logindDest, loginPath)<br><br> var seat0Path dbus.ObjectPath<br> err = logindObj.Call(logindDest+".Manager.GetSeat", 0, "seat0").Store(&seat0Path)<br><br> if err != nil {<br> os.Exit(1)<br> }<br><br> seat0Obj := conn.Object(logindDest, seat0Path)<br> activeSession, err := seat0Obj.GetProperty(logindDest + ".Seat.ActiveSession")<br> if err != nil {<br> os.Exit(1)<br> }<br><br> activeSessionPath := activeSession.Value().([]interface{})[1].(dbus.ObjectPath)<br><br> activeSessionObj := conn.Object(logindDest, activeSessionPath)<br> display, err := activeSessionObj.GetProperty(logindDest + ".Session.Display")<br> if err != nil {<br> os.Exit(1)<br> }<br> fmt.Println(display)<br><br> // node, err := introspect.Call(conn.Object("org.freedesktop.login1", "/org/freedesktop/login1/session/c2"))<br> // if err != nil {<br> // panic(err)<br> // }<br> // data, _ := json.MarshalIndent(node, "", " ")<br> // os.Stdout.Write(data)<br>}<br><br><div><br><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 11, 2017 at 1:18 PM, Michal Srb <span dir="ltr"><<a href="mailto:msrb@suse.com" target="_blank">msrb@suse.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Friday, August 11, 2017 12:29:01 PM CEST Sai Prasanna wrote:<br>
> Thanks Michal. How to use Dbus API directly to get the same results?.<br>
> I think loginctl is missing in some old distros.<br>
<br>
</span>Just pick a library that suits you:<br>
<a href="https://www.freedesktop.org/wiki/Software/DBusBindings/" rel="noreferrer" target="_blank">https://www.freedesktop.org/<wbr>wiki/Software/DBusBindings/</a><br>
<br>
The logind dbus api:<br>
<a href="https://www.freedesktop.org/wiki/Software/systemd/logind/" rel="noreferrer" target="_blank">https://www.freedesktop.org/<wbr>wiki/Software/systemd/logind/</a><br>
<br>
There is also C library that can get you some of the information without dbus:<br>
<a href="https://www.freedesktop.org/software/systemd/man/sd-login.html" rel="noreferrer" target="_blank">https://www.freedesktop.org/<wbr>software/systemd/man/sd-login.<wbr>html</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Michal Srb<br>
</font></span></blockquote></div><br></div>