diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6fcdd874a9f2488f99c3275528dd10cfc26462c9..90a7fac534d8bf23124b75cede593ba9ccf69380 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1325,6 +1325,7 @@ virNetlinkCommand; virNetlinkEventAddClient; virNetlinkEventRemoveClient; virNetlinkEventServiceIsRunning; +virNetlinkEventServiceLocalPid; virNetlinkEventServiceStop; virNetlinkEventServiceStart; virNetlinkShutdown; diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 9bf5a76b027c625501d709c39040dd488f47a529..badf111e62dc9c0c28f8c39a05d431c552260c0b 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -368,6 +368,24 @@ virNetlinkEventServiceIsRunning(void) return server != NULL; } +/** + * virNetlinkEventServiceLocalPid: + * + * Returns the nl_pid value that was used to bind() the netlink socket + * used by the netlink event service, or -1 on error (netlink + * guarantees that this value will always be > 0). + */ +int virNetlinkEventServiceLocalPid(void) +{ + if (!(server && server->netlinknh)) { + netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", + _("netlink event service not running")); + return -1; + } + return (int)nl_socket_get_local_port(server->netlinknh); +} + + /** * virNetlinkEventServiceStart: * diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index c57be821ffdfdd3908cd1a4eacbe9f20a900afb7..bafe8caf83e11391181ab485c36788ab9b212c10 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -61,6 +61,11 @@ int virNetlinkEventServiceStart(void); */ bool virNetlinkEventServiceIsRunning(void); +/** + * virNetlinkEventServiceLocalPid: returns nl_pid used to bind() netlink socket + */ +int virNetlinkEventServiceLocalPid(void); + /** * virNetlinkEventAddClient: register a callback for handling of netlink messages */