* amd/get_args.c (show_usage): separate function to print usage
authorErez Zadok <ezk@cs.sunysb.edu>
Fri, 14 Jan 2005 04:50:38 +0000 (04:50 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Fri, 14 Jan 2005 04:50:38 +0000 (04:50 +0000)
string.
(get_args) Call show_usage() from get_args when needed, then exit.

* amd/get_args.c (get_version_string): print also domain, host,
and hostd.
(get_args): print version string at the very end, after all other
values had been initialized.  Patch from Christos Zoulas
<christos@zoulas.com>.

AUTHORS
ChangeLog
NEWS
amd/get_args.c

diff --git a/AUTHORS b/AUTHORS
index bf0f023de713e8d0d595e2392a061daf8abd0b9d..499008e517217da5d1d6bfe74554290e3f230893 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -177,7 +177,8 @@ local media mounts.
 October 12, 2004: patch to support two new amd.conf options, domain_strip
 and auto_attrcache.  Patch to cleanup NFS attribute-cache flag computation.
 Patch to fix an inconsistency in timeouts in the RPC code between socket and
-TLI implementations.
+TLI implementations.  Patch to print version string (amd -v) after all
+options had been initialized, so we can print domain, host, and hostd.
 
 * Bill Paul <wpaul@ctr.columbia.edu>
 
index d8a868caf29400e4e91d7634e00e79c5bc996341..47d5c63e88c92880f9234c7b3346e87f3b220236 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2005-01-13  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * amd/get_args.c (show_usage): separate function to print usage
+       string.
+       (get_args) Call show_usage() from get_args when needed, then exit.
+
+       * amd/get_args.c (get_version_string): print also domain, host,
+       and hostd.
+       (get_args): print version string at the very end, after all other
+       values had been initialized.  Patch from Christos Zoulas
+       <christos@zoulas.com>.
+
        * conf/transp/transp_sockets.c (check_pmap_up, get_nfs_version),
        conf/transp/transp_tli.c (check_pmap_up): correct an inconsistency
        in timeouts in the RPC code between socket and TLI
diff --git a/NEWS b/NEWS
index 65c47b657365af5809557044b1193e8d595873c1..59d0b24c35eee54c254f72fe55684f8067837d59 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -56,6 +56,9 @@
 - support escaped slashes, needed for SMB mounts.  Use '\\\/\\\/' in a
   string to get a double slash.
 
+- amd -v now prints domain, host, and hostd values: foo, example.com, and
+  foo.example.com, respectively.
+
 - bugs fixed:
        * various memory management problems (leaks, etc)
        * fixed nfsx support
index 28f20c65ebcdd28e91793b37c51dad946dd792fd..72a94d6f8d05c45a6f42db93eb32bf1b4a32df60 100644 (file)
@@ -37,7 +37,7 @@
  * SUCH DAMAGE.
  *
  *
- * $Id: get_args.c,v 1.24 2005/01/03 20:56:45 ezk Exp $
+ * $Id: get_args.c,v 1.25 2005/01/14 04:50:38 ezk Exp $
  *
  */
 
@@ -60,6 +60,7 @@ int usage = 0;
 int use_conf_file = 0;         /* default don't use amd.conf file */
 char *mnttab_file_name = NULL; /* symbol must be available always */
 
+
 /*
  * Return the version string (dynamic buffer)
  */
@@ -98,6 +99,8 @@ get_version_string(void)
   strcat(vers, tmpbuf);
   sprintf(tmpbuf, "full_os=%s, os=%s, osver=%s, vendor=%s.\n",
          gopt.op_sys_full, gopt.op_sys, gopt.op_sys_ver, gopt.op_sys_vendor);
+  sprintf(tmpbuf, "domain=%s, host=%s, hostd=%s.\n",
+         hostdomain, am_get_hostname(), hostd);
   strcat(vers, tmpbuf);
 
   strcat(vers, "Map support for: ");
@@ -120,6 +123,40 @@ get_version_string(void)
 }
 
 
+static void
+show_usage(void)
+{
+  fprintf(stderr,
+         "Usage: %s [-nprvHS] [-a mount_point] [-c cache_time] [-d domain]\n\
+\t[-k kernel_arch] [-l logfile%s\n\
+\t[-t timeout.retrans] [-w wait_timeout] [-A arch] [-C cluster_name]\n\
+\t[-o op_sys_ver] [-O op_sys_name]\n\
+\t[-F conf_file] [-T conf_tag]", am_get_progname(),
+#ifdef HAVE_SYSLOG
+# ifdef LOG_DAEMON
+         "|\"syslog[:facility]\"]"
+# else /* not LOG_DAEMON */
+         "|\"syslog\"]"
+# endif /* not LOG_DAEMON */
+#else /* not HAVE_SYSLOG */
+         "]"
+#endif /* not HAVE_SYSLOG */
+         );
+
+#ifdef HAVE_MAP_NIS
+  fputs(" [-y nis-domain]\n", stderr);
+#else /* not HAVE_MAP_NIS */
+  fputc('\n', stderr);
+#endif /* HAVE_MAP_NIS */
+
+  show_opts('x', xlog_opt);
+#ifdef DEBUG
+  show_opts('D', dbg_opt);
+#endif /* DEBUG */
+  fprintf(stderr, "\t[directory mapname [-map_options]] ...\n");
+}
+
+
 void
 get_args(int argc, char *argv[])
 {
@@ -127,6 +164,7 @@ get_args(int argc, char *argv[])
   FILE *fp = stdin;
   char getopt_arguments[] = "+nprvSa:c:d:k:l:o:t:w:x:y:C:D:F:T:O:HA:";
   char *getopt_args;
+  int print_version = 0;       /* 1 means we should print version info */
 
 #ifdef HAVE_GNU_GETOPT
   getopt_args = getopt_arguments;
@@ -201,8 +239,11 @@ get_args(int argc, char *argv[])
       break;
 
     case 'v':
-      fputs(get_version_string(), stderr);
-      exit(0);
+      /*
+       * defer to print version info after every variable had been
+       * initialized.
+       */
+      print_version++;
       break;
 
     case 'w':
@@ -246,7 +287,8 @@ get_args(int argc, char *argv[])
       break;
 
     case 'H':
-      goto show_usage;
+      show_usage();
+      exit(1);
       break;
 
     case 'O':
@@ -306,8 +348,10 @@ get_args(int argc, char *argv[])
   }
 #endif /* HAVE_MAP_LDAP */
 
-  if (usage)
-    goto show_usage;
+  if (usage) {
+    show_usage();
+    exit(1);
+  }
 
   while (optind <= argc - 2) {
     char *dir = argv[optind++];
@@ -352,10 +396,10 @@ get_args(int argc, char *argv[])
      * If the kernel architecture was not specified
      * then use the machine architecture.
      */
-    if (gopt.karch == 0)
+    if (gopt.karch == NULL)
       gopt.karch = gopt.arch;
 
-    if (gopt.cluster == 0)
+    if (gopt.cluster == NULL)
       gopt.cluster = hostdomain;
 
     if (gopt.amfs_auto_timeo <= 0)
@@ -364,37 +408,13 @@ get_args(int argc, char *argv[])
       gopt.amfs_auto_retrans = AMFS_AUTO_RETRANS;
     if (gopt.amfs_auto_retrans <= 0)
       gopt.amfs_auto_retrans = 3;      /* XXX */
-    return;
   }
 
-show_usage:
-  fprintf(stderr,
-         "Usage: %s [-nprvHS] [-a mount_point] [-c cache_time] [-d domain]\n\
-\t[-k kernel_arch] [-l logfile%s\n\
-\t[-t timeout.retrans] [-w wait_timeout] [-A arch] [-C cluster_name]\n\
-\t[-o op_sys_ver] [-O op_sys_name]\n\
-\t[-F conf_file] [-T conf_tag]", am_get_progname(),
-#ifdef HAVE_SYSLOG
-# ifdef LOG_DAEMON
-         "|\"syslog[:facility]\"]"
-# else /* not LOG_DAEMON */
-         "|\"syslog\"]"
-# endif /* not LOG_DAEMON */
-#else /* not HAVE_SYSLOG */
-         "]"
-#endif /* not HAVE_SYSLOG */
-         );
-
-#ifdef HAVE_MAP_NIS
-  fputs(" [-y nis-domain]\n", stderr);
-#else /* not HAVE_MAP_NIS */
-  fputc('\n', stderr);
-#endif /* HAVE_MAP_NIS */
+  /* finally print version string and exit, if asked for */
+  if (print_version) {
+    fputs(get_version_string(), stderr);
+    exit(0);
+  }
 
-  show_opts('x', xlog_opt);
-#ifdef DEBUG
-  show_opts('D', dbg_opt);
-#endif /* DEBUG */
-  fprintf(stderr, "\t[directory mapname [-map_options]] ...\n");
-  exit(1);
+  return;
 }