- size = build_hotplugmsg(&msg, action, devpath, subsystem, seq);
-
- /* prepare message with credentials to authenticate ourself */
- iov.iov_base = &msg;
- iov.iov_len = size;
-
- smsg.msg_name = &saddr;
- smsg.msg_namelen = addrlen;
- smsg.msg_iov = &iov;
- smsg.msg_iovlen = 1;
- smsg.msg_control = cred_msg;
- smsg.msg_controllen = CMSG_LEN(sizeof(struct ucred));;
- smsg.msg_flags = 0;
-
- cmsg = CMSG_FIRSTHDR(&smsg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_CREDENTIALS;
- cmsg->cmsg_len = sizeof(cred_msg);
- cred = (struct ucred *) CMSG_DATA(cmsg);
- cred->uid = getuid();
- cred->gid = getgid();
- cred->pid = getpid();
- cred->pid = getpid();
+ memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
+ strcpy(usend_msg.magic, UDEV_MAGIC);
+ usend_msg.type = UDEVD_UEVENT_UDEVSEND;
+
+ /* copy all keys to send buffer */
+ for (i = 0; envp[i]; i++) {
+ const char *key;
+ int keylen;
+
+ key = envp[i];
+ keylen = strlen(key);
+
+ /* prevent loops in the scripts we execute */
+ if (strncmp(key, "UDEVD_EVENT=", 12) == 0) {
+ dbg("seems that the event source is not the kernel, just exit");
+ goto exit;
+ }
+
+ if (bufpos + keylen >= UEVENT_BUFFER_SIZE-1) {
+ err("environment buffer too small, probably not called by the kernel");
+ continue;
+ }
+
+ /* remember the SUBSYSTEM */
+ if (strncmp(key, "SUBSYSTEM=", 10) == 0)
+ subsystem = &key[10];
+
+ dbg("add '%s' to env[%i] buffer", key, i);
+ strcpy(&usend_msg.envbuf[bufpos], key);
+ bufpos += keylen + 1;
+ }
+ /* older kernels passed the SUBSYSTEM only as the first argument */
+ if (!subsystem && argc == 2) {
+ bufpos += sprintf(&usend_msg.envbuf[bufpos], "SUBSYSTEM=%s", argv[1]) + 1;
+ dbg("add 'SUBSYSTEM=%s' to env[%i] buffer from argv", argv[1], i);
+ }
+
+ usend_msg_len = offsetof(struct udevd_msg, envbuf) + bufpos;
+ dbg("usend_msg_len=%i", usend_msg_len);