[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH]xenstore-chmod: handle arbitrary number of perms rather than MAX_PERMS constant
2012/11/19 Ian Campbell <Ian.Campbell@xxxxxxxxxx>: > On Fri, 2012-11-16 at 06:02 +0000, Chunyan Liu wrote: >> Constant MAX_PERMS 16 is too small to use in some occasions, e.g. if >> there are more than 16 domU(s) on one hypervisor (it's easy to >> achieve) and one wants to do xenstore-chmod PATH to all domU(s). So, >> remove MAX_PERMS limitation and make it as arbitrary number of perms. >> >> Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> >> >> diff -r 8b93ac0c93f3 tools/xenstore/xenstore_client.c >> --- a/tools/xenstore/xenstore_client.c Tue Nov 13 11:19:17 2012 +0000 >> +++ b/tools/xenstore/xenstore_client.c Thu Nov 15 16:33:32 2012 +0800 >> @@ -25,7 +25,6 @@ >> #define PATH_SEP '/' >> #define MAX_PATH_LEN 256 >> >> -#define MAX_PERMS 16 >> >> enum mode { >> MODE_unknown, >> @@ -416,31 +415,31 @@ perform(enum mode mode, int optind, int >> break; >> } >> case MODE_chmod: { >> - struct xs_permissions perms[MAX_PERMS]; >> - int nperms = 0; >> + struct xs_permissions *perms; >> /* save path pointer: */ >> char *path = argv[optind++]; >> + int nperms = argc - optind; >> + int i; >> + perms = (struct xs_permissions *)malloc(nperms * >> sizeof(struct xs_permissions)); > > You could just do: > struct xs_permissions perms[nperms]; > and let the compiler allocate enough space on the stack. Will update. >> + if (!perms) >> + err(1, NULL); >> - for (; argv[optind]; optind++, nperms++) >> + for (i = 0; argv[optind]; optind++, i++) >> { >> - if (MAX_PERMS <= nperms) >> - errx(1, "Too many permissions specified. " >> - "Maximum per invocation is %d.", MAX_PERMS); >> - >> - perms[nperms].id = atoi(argv[optind]+1); >> + perms[i].id = atoi(argv[optind]+1); >> >> switch (argv[optind][0]) >> { >> case 'n': >> - perms[nperms].perms = XS_PERM_NONE; >> + perms[i].perms = XS_PERM_NONE; >> break; >> case 'r': >> - perms[nperms].perms = XS_PERM_READ; >> + perms[i].perms = XS_PERM_READ; >> break; >> case 'w': >> - perms[nperms].perms = XS_PERM_WRITE; >> + perms[i].perms = XS_PERM_WRITE; >> break; >> case 'b': >> - perms[nperms].perms = XS_PERM_READ | XS_PERM_WRITE; >> + perms[i].perms = XS_PERM_READ | XS_PERM_WRITE; >> break; >> default: >> errx(1, "Invalid permission specification: '%c'", >> @@ -449,6 +448,7 @@ perform(enum mode mode, int optind, int >> } >> >> do_chmod(path, perms, nperms, upto, recurse, xsh, xth); >> + free(perms); >> break; >> } >> case MODE_watch: { >> >> _______________________________________________ >> Xen-devel mailing list >> Xen-devel@xxxxxxxxxxxxx >> http://lists.xen.org/xen-devel > > > > _______________________________________________> >> + if (!perms) >> + err(1, NULL); >> - for (; argv[optind]; optind++, nperms++) >> + for (i = 0; argv[optind]; optind++, i++) >> { >> - if (MAX_PERMS <= nperms) >> - errx(1, "Too many permissions specified. " >> - "Maximum per invocation is %d.", MAX_PERMS); >> - >> - perms[nperms].id = atoi(argv[optind]+1); >> + perms[i].id = atoi(argv[optind]+1); >> >> switch (argv[optind][0]) >> { >> case 'n': >> - perms[nperms].perms = XS_PERM_NONE; >> + perms[i].perms = XS_PERM_NONE; >> break; >> case 'r': >> - perms[nperms].perms = XS_PERM_READ; >> + perms[i].perms = XS_PERM_READ; >> break; >> case 'w': >> - perms[nperms].perms = XS_PERM_WRITE; >> + perms[i].perms = XS_PERM_WRITE; >> break; >> case 'b': >> - perms[nperms].perms = XS_PERM_READ | XS_PERM_WRITE; >> + perms[i].perms = XS_PERM_READ | XS_PERM_WRITE; >> break; >> default: >> errx(1, "Invalid permission specification: '%c'", >> @@ -449,6 +448,7 @@ perform(enum mode mode, int optind, int >> } >> >> do_chmod(path, perms, nperms, upto, recurse, xsh, xth); >> + free(perms); >> break; >> } >> case MODE_watch: { >> >> _______________________________________________ >> Xen-devel mailing list >> Xen-devel@xxxxxxxxxxxxx >> http://lists.xen.org/xen-devel > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@xxxxxxxxxxxxx > http://lists.xen.org/xen-devel > > Xen-devel mailing list > Xen-devel@xxxxxxxxxxxxx > http://lists.xen.org/xen-devel > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |