From 4d73a369b7c6b17a0e342b770afece8775c9d252 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 16 Jun 2016 11:49:04 +0200 Subject: [PATCH] hotplug: makedev should be able to set the group of a device node Signed-off-by: John Crispin --- plug/hotplug.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plug/hotplug.c b/plug/hotplug.c index b5ebd07..8595915 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "../procd.h" @@ -120,16 +121,17 @@ static void mkdir_p(char *dir) 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])); @@ -143,6 +145,16 @@ static void handle_makedev(struct blob_attr *msg, struct blob_attr *data) 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); } -- 2.30.2