[26605] in Source-Commits

home help back first fref pref prev next nref lref last post

/svn/athena r25648 - in trunk/athena/bin/getcluster: . debian

daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Fri Jul 20 17:12:32 2012

Date: Fri, 20 Jul 2012 17:12:30 -0400
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201207202112.q6KLCUFe030480@drugstore.mit.edu>
To: source-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: jdreed
Date: 2012-07-20 17:12:30 -0400 (Fri, 20 Jul 2012)
New Revision: 25648

Modified:
   trunk/athena/bin/getcluster/debian/changelog
   trunk/athena/bin/getcluster/getcluster.1
   trunk/athena/bin/getcluster/getcluster.c
Log:
In getcluster:
  * Add a "-p" flag to print out space-separated key/value pairs for
    things to parse by hand
  * Update man page for new option


Modified: trunk/athena/bin/getcluster/debian/changelog
===================================================================
--- trunk/athena/bin/getcluster/debian/changelog	2012-07-20 21:04:13 UTC (rev 25647)
+++ trunk/athena/bin/getcluster/debian/changelog	2012-07-20 21:12:30 UTC (rev 25648)
@@ -1,8 +1,11 @@
-debathena-getcluster (10.0.3-0debathena2) UNRELEASED; urgency=low
+debathena-getcluster (10.1.0-0debathena1) unstable; urgency=low
 
   * Bump debian/compat to 6
+  * Add a "-p" flag to print out space-separated key/value pairs for
+    things to parse by hand
+  * Update man page for new option
 
- -- Jonathan Reed <jdreed@mit.edu>  Sun, 01 Jul 2012 12:21:33 -0400
+ -- Jonathan Reed <jdreed@mit.edu>  Fri, 20 Jul 2012 17:12:24 -0400
 
 debathena-getcluster (10.0.3-0debathena1) unstable; urgency=low
 

Modified: trunk/athena/bin/getcluster/getcluster.1
===================================================================
--- trunk/athena/bin/getcluster/getcluster.1	2012-07-20 21:04:13 UTC (rev 25647)
+++ trunk/athena/bin/getcluster/getcluster.1	2012-07-20 21:12:30 UTC (rev 25648)
@@ -1,10 +1,11 @@
-.TH GETCLUSTER 1 "11 August 2011"
+.TH GETCLUSTER 1 "20 July 2012" "debathena-clusterinfo" "Hesiod Cluster Information"
 .SH NAME
-getcluster \- retrieve service cluster info from Hesiod as environment vars
+getcluster \- retrieve service cluster info from Hesiod 
 .SH SYNOPSIS
 .B getcluster
 [
-.B \-b
+.B \-b | 
+.B \-p
 ] [
 .B \-d
 ] [
@@ -20,6 +21,14 @@
 to the C shell, or, if the
 .B \-b
 flag is present, in Bourne shell syntax.
+If the 
+.B \-p
+flag is present, the results are written in space-separated key-value
+pairs, suitable for parsing by things that are not shells.  
+.B \-p
+and
+.B \-b
+are mutually exclusive. 
 .B getcluster
 returns an exit status of 2 if no cluster information is available, or
 1 if any other error was encountered.
@@ -164,3 +173,9 @@
 If there exist two unversioned tags of the same name, getcluster will
 pick whichever one comes last (either in Hesiod output or in a local
 file).  This can be regarded as a feature instead of a bug.
+
+.B getcluster 
+does not quote its shell output, nor does it do any checking
+of key names.  This means that if you have a key named "path" or have a
+value with the content of ";rm -rf *", you probably shouldn't eval or
+source its output.

Modified: trunk/athena/bin/getcluster/getcluster.c
===================================================================
--- trunk/athena/bin/getcluster/getcluster.c	2012-07-20 21:04:13 UTC (rev 25647)
+++ trunk/athena/bin/getcluster/getcluster.c	2012-07-20 21:12:30 UTC (rev 25648)
@@ -21,8 +21,8 @@
 
 static void usage(void);
 static void die(const char *f, ...);
-static void shellenv(char **hp, const char *ws_version, int bourneshell);
-static void output_var(const char *var, const char *val, int bourneshell);
+static void shellenv(char **hp, const char *ws_version, int bourneshell, int plaintext);
+static void output_var(const char *var, const char *val, int bourneshell, int plaintext);
 static void upper(char *v);
 static char **readcluster(FILE *f);
 static char **merge(char **l1, char **l2);
@@ -70,7 +70,7 @@
 int main(int argc, char **argv)
 {
   char **hp = NULL, **fp = NULL, **lp = NULL, **or1, **or2;
-  int debug = 0, bourneshell = 0, ch;
+  int debug = 0, bourneshell = 0, plaintext = 0, ch;
   const char *fallbackfile = SYSCONFDIR "/cluster.fallback";
   const char *localfile = SYSCONFDIR "/cluster.local";
   const char *clusterfile = SYSCONFDIR "/cluster";
@@ -81,7 +81,7 @@
   extern int optind;
   extern char *optarg;
 
-  while ((ch = getopt(argc, argv, "bdl:f:h:")) != -1)
+  while ((ch = getopt(argc, argv, "bdpl:f:h:")) != -1)
     {
       switch (ch)
 	{
@@ -91,6 +91,9 @@
 	case 'b':
 	  bourneshell = 1;
 	  break;
+	case 'p':
+	  plaintext = 1;
+	  break;
 	case 'f':
 	  /* Deprecated option, for compatibility. */
 	  fallbackfile = optarg;
@@ -114,6 +117,9 @@
     usage();
   version = (argc == 2) ? argv[1] : argv[0];
 
+  if (bourneshell && plaintext)
+    usage();
+
   if (hostname == NULL)
     {
       /* We only look at the cluster, fallback, and local files when not
@@ -183,7 +189,7 @@
 
   or1 = merge(lp, hp);
   or2 = merge(or1, fp);
-  shellenv(or2, version, bourneshell);
+  shellenv(or2, version, bourneshell, plaintext);
   if (!debug)
     {
       if (hp != NULL)
@@ -251,7 +257,7 @@
 
 static void usage(void)
 {
-  die("Usage: getcluster [-h hostname] [-b] [-d] version");
+  die("Usage: getcluster [-h hostname] [-b|-p] [-d] version");
   exit(1);
 }
 
@@ -291,7 +297,7 @@
  * highest version number.  If there aren't any records left with
  * version numbers and there's one with no version number, output
  * that one. */
-static void shellenv(char **hp, const char *ws_version, int bourneshell)
+static void shellenv(char **hp, const char *ws_version, int bourneshell, int plaintext)
 {
   int *seen, count, i, j, output_time = 0, autoupdate = 0;
   char var[80], val[80], vers[80], flags[80], compvar[80], compval[80];
@@ -395,14 +401,14 @@
 	  if (*vers == '0')
 	    strcpy(val, defaultval);
 	  upper(var);
-	  output_var(var, val, bourneshell);
+	  output_var(var, val, bourneshell, plaintext);
 	}
     }
 
   if (vercmp(new_testing, ws_version) > 0)
-    output_var("NEW_TESTING_RELEASE", new_testing, bourneshell);
+    output_var("NEW_TESTING_RELEASE", new_testing, bourneshell, plaintext);
   if (vercmp(new_production, ws_version) > 0)
-    output_var("NEW_PRODUCTION_RELEASE", new_production, bourneshell);
+    output_var("NEW_PRODUCTION_RELEASE", new_production, bourneshell, plaintext);
   if (output_time)
     {
       /* If we have no time from the environment, make up one
@@ -413,15 +419,17 @@
 	  update_time = now + rand() % UPDATE_INTERVAL;
 	}
       sprintf(timebuf, "%lu", update_time);
-      output_var("UPDATE_TIME", timebuf, bourneshell);
+      output_var("UPDATE_TIME", timebuf, bourneshell, plaintext);
     }
   free(seen);
 }
 
-static void output_var(const char *var, const char *val, int bourneshell)
+static void output_var(const char *var, const char *val, int bourneshell, int plaintext)
 {
   if (bourneshell)
     printf("%s=%s ; export %s ;\n", var, val, var);
+  else if (plaintext)
+    printf("%s %s\n", var, val);
   else
     printf("setenv %s %s ;\n", var, val);
 }


home help back first fref pref prev next nref lref last post