fs getarg

Love lha at stacken.kth.se
Fri Feb 5 06:29:23 CET 1999


Chuck Lever writes:

> first, "fs wscell" returned the workstation's cellname followed by core
> garbage.  the fix is to change line 2747 of arlad/messages.c:

Fixed that, thanks.

> second, the "newcell" subcommand causes "fs" command to exit quietly when
> an error occurs. the exiting is caused by "return 1;".  i rewrote
> newcell_cmd to use "return 0;" and to print a reasonable error message. 
> the only other subcommand of "fs" that uses "return 1;" is "quit."

The sl stuff in arla should always return 0 if its not supposed to
quit. Fixed some other places too.

I used getarg() to parse the arguments in newcell, will force
getarg to do the right thing any day soon (you have to do
"fs newcell -cell new.cell -server foo -server bar -server baz" now)

Love

Index: fs.c
===================================================================
RCS file: /usr/local/cvsroot/arla/appl/fs.c,v
retrieving revision 1.63
diff -u -w -u -w -r1.63 fs.c
--- fs.c	1999/01/10 02:45:09	1.63
+++ fs.c	1999/02/05 05:18:48
@@ -703,14 +703,56 @@
 static int
 newcell_cmd (int argc, char **argv)
 {
-    argc--;
-    argv++;
+    char *cell = NULL;
+    getarg_strings servers = { 0, NULL };
+    int ret, help = 0;
+    int optind = 0;
 
-    if (argc < 2) {
-	printf ("newcell: Missing required parameter `-cell'\n");
-	return 1;
+    struct getargs ncargs[] = {
+	{"cell", 'c', arg_string,  
+	 NULL, "new cell", NULL},
+	{"servers", 's', arg_strings,
+	 NULL, "server in cell", "one server"},
+	{"help", 'h', arg_flag,
+	 NULL, "get help", NULL},
+        {NULL,      0, arg_end, NULL}}, 
+				  *arg;
+			       
+    arg = ncargs;
+    arg->value = &cell; arg++;
+    arg->value = &servers; arg++;
+    arg->value = &help; arg++;
+
+    if (getarg (ncargs, argc, argv, &optind, ARG_AFSSTYLE)) {
+	arg_printusage(ncargs, "newcell", NULL, ARG_AFSSTYLE);
+	return 0;
     }
-    return fs_newcell (argv[0], argc - 1, argv + 1);
+
+    if (help) {
+	arg_printusage(ncargs, "newcell", NULL, ARG_AFSSTYLE);
+	goto out;
+    }
+
+    if (cell == NULL) {
+	fprintf (stderr, "You have to give a cell\n");
+	goto out;
+    }
+
+    if (servers.num_strings == 0) {
+	fprintf (stderr, "You didn't give servers, will use DNS\n");
+	goto out;
+    }
+
+    ret = fs_newcell (cell, servers.num_strings, servers.strings);
+    if (ret)
+	fprintf (stderr, "fs_newcell failed with %s (%d)\n",
+		 koerr_gettext(ret), ret);
+    
+ out:
+    if (servers.strings)
+	free (servers.strings);
+
+    return 0;
 }
 
 static int





More information about the Arla-drinkers mailing list