diff options
Diffstat (limited to 'libcutils')
-rw-r--r-- | libcutils/uevent.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libcutils/uevent.c b/libcutils/uevent.c index 320f8d1..4add29c 100644 --- a/libcutils/uevent.c +++ b/libcutils/uevent.c @@ -17,7 +17,12 @@ #include <cutils/uevent.h> #include <errno.h> +#include <stdbool.h> +#include <string.h> #include <strings.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> #include <linux/netlink.h> @@ -68,3 +73,29 @@ out: errno = EIO; return -1; } + +int uevent_open_socket(int buf_sz, bool passcred) +{ + struct sockaddr_nl addr; + int on = passcred; + int s; + + memset(&addr, 0, sizeof(addr)); + addr.nl_family = AF_NETLINK; + addr.nl_pid = getpid(); + addr.nl_groups = 0xffffffff; + + s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); + if(s < 0) + return -1; + + setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &buf_sz, sizeof(buf_sz)); + setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); + + if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + close(s); + return -1; + } + + return s; +} |