On 05/04/2012 12:51 PM, Laine Stump wrote:
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, so it is okay to cast
the uint32_t to int (thus allowing us to use -1 as an error sentinel).
I had to look; we always let libnl generate a socket, and indeed the
libnl code:
http://git.infradead.org/users/tgr/libnl.git/blob?f=lib/socket.c#l50
returns a uint32_t, but computes that value as 'pid + (n << 22);', where
n is at most 32, and where pid is at most PID_MAX_LIMIT of 2^22, so the
end result is less than 31 bits and therefore positive when cast to int.
Maybe it would help to tweak the wording a bit:
Note that libnl's port generation algorithm guarantees that the uint32_t
result of nl_socket_get_local_port() will never set the most significant
bit, and therefore will be positive when cast to int, allowing us to use
-1 as an error sentinel.
/**
+ * 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);
Technically, the cast is redundant, but I'm okay if you leave it in.
ACK; this one can technically be applied without test results, although
it doesn't hurt to wait for the rest of the series.
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org