Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
uevent: Fix netlink error while assigning pid in netlink client
Browse files Browse the repository at this point in the history
unix.SockaddrNetlink represents a netlink client with the Pid
being the netlink socket address. This can be assigned the actual
pid of the process, but in case we have two netlink sockets opened
at the same time, this results in errors in binding to the netlink
socket. Assign this to zero which means the kernel takes care of
assigning it.

See http://man7.org/linux/man-pages/man7/netlink.7.html

Fixes #216

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Apr 23, 2018
1 parent bdc70d4 commit 8f828bb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/uevent/uevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package uevent
import (
"bufio"
"io"
"os"
"strings"

"golang.org/x/sys/unix"
Expand All @@ -35,7 +34,9 @@ type ReaderCloser struct {
func NewReaderCloser() (io.ReadCloser, error) {
nl := unix.SockaddrNetlink{
Family: unix.AF_NETLINK,
Pid: uint32(os.Getpid()),
// Passing Pid as 0 here allows the kernel to take care of assigning
// it. This allows multiple netlink sockets to be used.
Pid: uint32(0),
Groups: 1,
}

Expand Down

0 comments on commit 8f828bb

Please sign in to comment.