Acked-by: Latchesar Ionkov <[EMAIL PROTECTED]>
On Nov 10, 2008, at 11:10 AM, Abhishek Kulkarni wrote:
1 file changed, 22 insertions(+), 15 deletions(-)
utils/xgroupset.c | 37 ++++++++++++++++++++++---------------
# HG changeset patch
# User Abhishek Kulkarni <[EMAIL PROTECTED]>
# Date 1226339709 25200
# Node ID 93bad2e749f5322b566e208727c185a457aebff9
# Parent 91ef166ebdf0137351e6db411d3264ea1beb57ac
this patch changes xgroupset such that it now does better input
arguments validation.
changed the usage message since we don't support multiple gname gids
in a single command.
added -p switch for specifying a different port to connect to.
this patch also changes the way in which the admin key is passed
complying to the underlying
changes in the libxcpu group handling functions.
Signed-off-by: Abhishek Kulkarni <[EMAIL PROTECTED]>
diff --git a/utils/xgroupset.c b/utils/xgroupset.c
--- a/utils/xgroupset.c
+++ b/utils/xgroupset.c
@@ -46,13 +46,12 @@
#include "xcpu.h"
extern int spc_chatty;
-static Xkey *adminkey;
void
usage(char *name)
{
- fprintf(stderr, "usage: %s [-h] add [-A adminkey] {-a | nodeset} {-
u | gname gid [gname gid ...]}\n", name);
- fprintf(stderr, " %s [-h] delete [-A adminkey] {-a |
nodeset} {-u | gname [gname ...]}\n", name);
+ fprintf(stderr, "usage: %s [-h] add [-A adminkey] {-a | nodeset} {-
u | gname gid}\n", name);
+ fprintf(stderr, " %s [-h] delete [-A adminkey] {-a |
nodeset} {-u | gname}\n", name);
fprintf(stderr, " %s [-h] flush [-A adminkey] {-a | nodeset}
\n", name);
exit(1);
}
@@ -60,22 +59,22 @@
int
main(int argc, char **argv)
{
- int c, ecode;
+ int c, ecode, port = STAT_PORT;
char cmd[7];
u32 gid;
char *nodeset, *ename, *groupname;
- char *adminkeyfile = "/etc/xcpu/admin_key";
+ char *adminkey = NULL, *end;
Xpnodeset *nds, *nds2;
int allflag = 0, groupfile = 0;
struct group *gr;
- while((c = getopt(argc, argv, "aA:dhu")) != -1) {
+ while((c = getopt(argc, argv, "aA:dhup")) != -1) {
switch(c) {
case 'd':
spc_chatty = 1;
break;
case 'A':
- adminkeyfile = strdup(optarg);
+ adminkey = strdup(optarg);
break;
case 'a':
allflag++;
@@ -83,6 +82,11 @@
case 'u':
groupfile++;
break;
+ case 'p':
+ port = strtol(optarg, &end, 10);
+ if (*end != '\0')
+ usage(argv[0]);
+ break;
case 'h':
default:
usage(argv[0]);
@@ -104,12 +108,15 @@
else
usage(argv[0]);
- if (!allflag && ((nodeset = getenv("NODES")) == NULL))
+ if (!allflag && ((nodeset = getenv("NODES")) == NULL)) {
+ if ((argc - optind) < 1 && !groupfile)
+ usage(argv[0]);
nodeset = argv[optind++];
+ }
if (allflag) {
char statserver[32];
- sprintf(statserver, "localhost!%d", STAT_PORT);
+ sprintf(statserver, "localhost!%d", port);
nds = xp_nodeset_list(NULL);
if (nds == NULL)
nds = xp_nodeset_list(statserver);
@@ -130,10 +137,6 @@
if (!nds)
goto error;
- adminkey = xauth_privkey_create(adminkeyfile);
- if (!adminkey)
- goto error;
-
if (!strcmp("flush", cmd)) {
if (xp_group_flush(nds, adminkey) < 0)
goto error;
@@ -144,9 +147,11 @@
xp_group_del(nds, adminkey, gr->gr_name);
endgrent();
} else {
+ if ((argc - optind) < 1)
+ usage(argv[0]);
groupname = argv[optind++];
if (xp_group_del(nds, adminkey, groupname) < 0)
- goto error;
+ return -1;
}
} else { /* group add */
if (groupfile) {
@@ -155,10 +160,12 @@
xp_group_add(nds, adminkey, gr->gr_name,
gr->gr_gid);
endgrent();
} else {
+ if ((argc - optind) < 2)
+ usage(argv[0]);
groupname = argv[optind++];
gid = strtol(argv[optind++], NULL, 10);
if (xp_group_add(nds, adminkey, groupname, gid) < 0)
- goto error;
+ return -1;
}
}
return 0;