]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: function to get local nl_pid used by netlink event socket
authorLaine Stump <laine@laine.org>
Fri, 4 May 2012 17:19:51 +0000 (13:19 -0400)
committerLaine Stump <laine@laine.org>
Mon, 7 May 2012 18:25:55 +0000 (14:25 -0400)
This value will be needed to set the src_pid when sending netlink
messages to lldpad. It is part of the solution to:

  https://bugzilla.redhat.com/show_bug.cgi?id=816465

Note that libnl's port generation algorithm guarantees that the
nl_socket_get_local_port() will always be > 0 (since it is "getpid() +
(n << 22>" where n is always < 1024), so it is okay to cast the
uint32_t to int (thus allowing us to use -1 as an error sentinel).

src/libvirt_private.syms
src/util/virnetlink.c
src/util/virnetlink.h

index 739d8c4127ff91f020a964954df3cd1085e98dfa..4f34d256108f9ba6d7f584780f2b03a0b0030598 100644 (file)
@@ -1333,6 +1333,7 @@ virNetlinkCommand;
 virNetlinkEventAddClient;
 virNetlinkEventRemoveClient;
 virNetlinkEventServiceIsRunning;
+virNetlinkEventServiceLocalPid;
 virNetlinkEventServiceStop;
 virNetlinkEventServiceStart;
 virNetlinkShutdown;
index d3cf199258b768064622c6d5a85c8e686ba20df3..ac61ff086ef610d3892ff03a17e8ae0a8fac3f12 100644 (file)
@@ -378,6 +378,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:
  *
index c57be821ffdfdd3908cd1a4eacbe9f20a900afb7..bafe8caf83e11391181ab485c36788ab9b212c10 100644 (file)
@@ -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
  */