/* nl2mdev - netlink wrapper for busybox's mdev * gcc -std=c99 -pedantic -Wall -O2 nl2mdev.c -o nl2mdev */ #define _XOPEN_SOURCE 500 #include #include #include #include #include #include #include #include #include #include void die(char *s) { write(2,s,strlen(s)); exit(1); } int main(int argc, char *argv[]) { struct sockaddr_nl nls; struct pollfd pfd; char buf[512]; signal(SIGCHLD, SIG_IGN); // Open hotplug event netlink socket memset(&nls,0,sizeof(struct sockaddr_nl)); nls.nl_family = AF_NETLINK; nls.nl_pid = getpid(); nls.nl_groups = -1; pfd.events = POLLIN; pfd.fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); if (pfd.fd==-1) die("Not root\n"); // Listen to netlink socket if (bind(pfd.fd, (void *)&nls, sizeof(struct sockaddr_nl))) die("Bind failed\n"); while (-1!=poll(&pfd, 1, -1)) { int i, len = recv(pfd.fd, buf, sizeof(buf), MSG_DONTWAIT); if (len == -1) die("recv\n"); if (!fork()) { unsigned int count = 0; char **env = calloc(9, sizeof(char *)); i = 0; while (i