#include <unistd.h>
#include <stdlib.h>
#include <libgen.h>
+#include <grp.h>
#include "../procd.h"
static void handle_makedev(struct blob_attr *msg, struct blob_attr *data)
{
unsigned int oldumask = umask(0);
- static struct blobmsg_policy mkdev_policy[2] = {
+ static struct blobmsg_policy mkdev_policy[3] = {
+ { .type = BLOBMSG_TYPE_STRING },
{ .type = BLOBMSG_TYPE_STRING },
{ .type = BLOBMSG_TYPE_STRING },
};
- struct blob_attr *tb[2];
+ struct blob_attr *tb[3];
char *minor = hotplug_msg_find_var(msg, "MINOR");
char *major = hotplug_msg_find_var(msg, "MAJOR");
char *subsystem = hotplug_msg_find_var(msg, "SUBSYSTEM");
- blobmsg_parse_array(mkdev_policy, 2, tb, blobmsg_data(data), blobmsg_data_len(data));
+ blobmsg_parse_array(mkdev_policy, 3, tb, blobmsg_data(data), blobmsg_data_len(data));
if (tb[0] && tb[1] && minor && major && subsystem) {
mode_t m = S_IFCHR;
char *d = strdup(blobmsg_get_string(tb[0]));
mknod(blobmsg_get_string(tb[0]),
m | strtoul(blobmsg_data(tb[1]), NULL, 8),
makedev(atoi(major), atoi(minor)));
+ if (tb[2]) {
+ struct group *g = getgrnam(blobmsg_get_string(tb[2]));
+
+ if (g)
+ chown(blobmsg_get_string(tb[0]), 0, g->gr_gid);
+ else
+ ERROR("cannot set group %s for %s\n",
+ blobmsg_get_string(tb[2]),
+ blobmsg_get_string(tb[0]));
+ }
}
umask(oldumask);
}