}
switch (usend_msg.type) {
- case UDEVD_UEVENT:
- dbg("udevd message (UEVENT) received");
+ case UDEVD_UDEVSEND:
+ case UDEVD_INITSEND:
+ dbg("udevd event message received");
envbuf_size = size - offsetof(struct udevd_msg, envbuf);
dbg("envbuf_size=%i", envbuf_size);
msg = get_msg_from_envbuf(usend_msg.envbuf, envbuf_size);
if (msg == NULL)
return NULL;
+ msg->type = usend_msg.type;
return msg;
case UDEVD_STOP_EXEC_QUEUE:
dbg("udevd message (STOP_EXEC_QUEUE) received");
}
/* receive the kernel user event message and do some sanity checks */
-static struct uevent_msg *get_uevent_msg(void)
+static struct uevent_msg *get_nl_msg(void)
{
struct uevent_msg *msg;
int bufpos;
msg = get_msg_from_envbuf(&buffer[bufpos], size-bufpos);
if (msg == NULL)
return NULL;
+ msg->type = UDEVD_NL;
/* validate message */
pos = strchr(buffer, '@');
msg = get_udevd_msg();
if (msg) {
/* discard kernel messages if netlink is active */
- if (uevent_nl_active && msg->seqnum != 0) {
+ if (uevent_nl_active && msg->type == UDEVD_UDEVSEND && msg->seqnum != 0) {
dbg("skip uevent_helper message, netlink is active");
free(msg);
continue;
}
if (FD_ISSET(uevent_nl_sock, &workreadfds)) {
- msg = get_uevent_msg();
+ msg = get_nl_msg();
if (msg) {
msg_queue_insert(msg);
/* disable kernel uevent_helper with first netlink message */
* Scan a file, write all variables into the msgbuf and
* fires the message to udevd.
*/
-static int udevsend(char *filename, int sock, int ignore_loops)
+static int udevsend(char *filename, int sock, int disable_loop_detection)
{
+ static struct udevd_msg usend_msg;
+ int usend_msg_len;
+ int bufpos = 0;
struct stat statbuf;
- int fd, bufpos;
+ int fd;
char *fdmap, *ls, *le, *ch;
- struct udevd_msg usend_msg;
- int retval = 0;
- int usend_msg_len;
struct sockaddr_un saddr;
socklen_t addrlen;
-
+ int retval = 0;
+
if (stat(filename,&statbuf) < 0) {
dbg("cannot stat %s: %s\n", filename, strerror(errno));
return 1;
strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
- memset(usend_msg.envbuf, 0, UEVENT_BUFFER_SIZE+256);
- bufpos = 0;
memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
strcpy(usend_msg.magic, UDEV_MAGIC);
+ usend_msg.type = UDEVD_INITSEND;
ls = fdmap;
ch = le = ls;
while (*ch && ch < fdmap + statbuf.st_size) {
- le = strchr(ch,'\n');
+ le = strchr(ch, '\n');
if (!le)
break;
- ch = strchr(ch,'=');
+ ch = strchr(ch, '=');
if (!ch)
break;
/* prevent loops in the scripts we execute */
if (strncmp(ls, "UDEVD_EVENT=", 12) == 0) {
- if (!ignore_loops) {
+ if (!disable_loop_detection) {
dbg("event already handled by udev\n");
retval = -1;
break;
char *event_file = NULL;
DIR *dirstream;
struct dirent *direntry;
- int retval = 1, ignore_loops = 0;
+ int retval = 1;
+ int disable_loop_detection = 0;
int sock;
logging_init("udevinitsend");
break;
case 'l':
- dbg("ignoring loops\n");
- ignore_loops = 1;
+ dbg("disable loop detection, ignore UDEVD_EVENT\n");
+ disable_loop_detection = 1;
break;
- case 'V':
- printf("udevinitsend, version 0.1\n");
- return 0;
-
case 'h':
retval = 0;
}
if (!strcmp(direntry->d_name,".") ||
!strcmp(direntry->d_name,".."))
continue;
- retval = udevsend(direntry->d_name, sock, ignore_loops);
+ retval = udevsend(direntry->d_name, sock, disable_loop_detection);
}
closedir(dirstream);
} else if (event_file) {
- retval = udevsend(event_file, sock, ignore_loops);
+ retval = udevsend(event_file, sock, disable_loop_detection);
}
if (sock != -1)