+ memset(&saddr, 0x00, sizeof(saddr));
+ saddr.sun_family = AF_LOCAL;
+ /* use abstract namespace for socket path */
+ strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
+ addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
+
+ udevd_sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
+ if (udevd_sock == -1) {
+ err("error getting socket: %s", strerror(errno));
+ return -1;
+ }
+
+ /* set receive buffersize */
+ setsockopt(udevd_sock, SOL_SOCKET, SO_RCVBUFFORCE, &buffersize, sizeof(buffersize));
+
+ /* the bind takes care of ensuring only one copy running */
+ retval = bind(udevd_sock, (struct sockaddr *) &saddr, addrlen);
+ if (retval < 0) {
+ err("bind failed: %s", strerror(errno));
+ return -1;
+ }
+
+ /* enable receiving of the sender credentials */
+ setsockopt(udevd_sock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
+
+ return 0;
+}
+
+static int init_uevent_netlink_sock(void)
+{
+ struct sockaddr_nl snl;
+ const int buffersize = 16 * 1024 * 1024;
+ int retval;
+
+ memset(&snl, 0x00, sizeof(struct sockaddr_nl));
+ snl.nl_family = AF_NETLINK;
+ snl.nl_pid = getpid();
+ snl.nl_groups = 0xffffffff;
+
+ uevent_netlink_sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
+ if (uevent_netlink_sock == -1) {
+ err("error getting socket: %s", strerror(errno));
+ return -1;
+ }
+
+ /* set receive buffersize */
+ setsockopt(uevent_netlink_sock, SOL_SOCKET, SO_RCVBUFFORCE, &buffersize, sizeof(buffersize));
+
+ retval = bind(uevent_netlink_sock, (struct sockaddr *) &snl, sizeof(struct sockaddr_nl));
+ if (retval < 0) {
+ err("bind failed: %s", strerror(errno));
+ close(uevent_netlink_sock);
+ uevent_netlink_sock = -1;
+ return -1;
+ }
+ return 0;
+}
+
+static void export_initial_seqnum(void)
+{
+ char filename[PATH_SIZE];
+ int fd;
+ char seqnum[32];
+ ssize_t len = 0;
+
+ strlcpy(filename, sysfs_path, sizeof(filename));
+ strlcat(filename, "/kernel/uevent_seqnum", sizeof(filename));
+ fd = open(filename, O_RDONLY);
+ if (fd >= 0) {
+ len = read(fd, seqnum, sizeof(seqnum)-1);
+ close(fd);
+ }
+ if (len <= 0) {
+ strcpy(seqnum, "0\n");
+ len = 3;
+ }
+ strlcpy(filename, udev_root, sizeof(filename));
+ strlcat(filename, "/" EVENT_SEQNUM, sizeof(filename));
+ create_path(filename);
+ fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644);
+ if (fd >= 0) {
+ write(fd, seqnum, len);
+ close(fd);