diff options
author | Dima Zavin <dima@android.com> | 2011-08-31 18:07:36 -0700 |
---|---|---|
committer | Dima Zavin <dima@android.com> | 2011-09-02 12:11:17 -0700 |
commit | 2d55e02d0f3c27f0c99ab889ab7b73126280a21c (patch) | |
tree | 160bd0d7677ca899527ec9ab4a6a619c3698c2a8 /libcutils | |
parent | 09e32886e64258c0600e2696e26a2aca559310e2 (diff) | |
download | system_core-2d55e02d0f3c27f0c99ab889ab7b73126280a21c.zip system_core-2d55e02d0f3c27f0c99ab889ab7b73126280a21c.tar.gz system_core-2d55e02d0f3c27f0c99ab889ab7b73126280a21c.tar.bz2 |
libcutils/init: move uevent socket opening code to libcutils
Change-Id: I90adf78c0eb6185505f2bf7b62e96e25ab918345
Signed-off-by: Dima Zavin <dima@android.com>
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; +} |