Permalink
Browse files

Diodshowmount display results in hostlist format

  • Loading branch information...
1 parent a1e7f62 commit ce612d1d33b12b72ec8d3e279724dff4bc585e32 @garlick garlick committed May 21, 2012
Showing with 27 additions and 7 deletions.
  1. +5 −1 utils/diodshowmount.8.in
  2. +22 −6 utils/diodshowmount.c
View
@@ -6,7 +6,8 @@ diodshowmount \- list diod server connections
.SH DESCRIPTION
.B diodshowmount
connects to a \fBdiod\fR server on \fIIP:PORT\fR and displays a list of
-clients connected to that server, one per line.
+clients connected to that server in hostlist format, with domain name
+suffixes stripped.
.SH OPTIONS
.TP
.I "-s, --server NAME"
@@ -21,5 +22,8 @@ Try to attach to the server as the specified user (default your effective uid).
.TP
.I "-t, --timeout SECS"
Force timeout after specified number of seconds (default no timeout).
+.TP
+.I "-l, --long"
+List clients one per line without removing domain name suffixes, if any.
.SH "SEE ALSO"
diod (8)
View
@@ -53,14 +53,15 @@
#include "diod_sock.h"
#include "diod_auth.h"
-#define OPTIONS "s:m:u:t:"
+#define OPTIONS "s:m:u:t:l"
#if HAVE_GETOPT_LONG
#define GETOPT(ac,av,opt,lopt) getopt_long (ac,av,opt,lopt,NULL)
static const struct option longopts[] = {
{"server", required_argument, 0, 's'},
{"msize", required_argument, 0, 'm'},
{"uid", required_argument, 0, 'u'},
{"timeout", required_argument, 0, 't'},
+ {"long", no_argument, 0, 'l'},
{0, 0, 0, 0},
};
#else
@@ -78,6 +79,7 @@ usage (void)
" -m,--msize msize (default 65536)\n"
" -u,--uid authenticate as uid (default is your euid)\n"
" -t,--timeout SECS give up after specified seconds\n"
+" -l,--long list clients one per line and don't strip domain\n"
);
exit (1);
}
@@ -95,6 +97,7 @@ main (int argc, char *argv[])
char buf[80], *host, *p;
hostlist_t hl;
hostlist_iterator_t itr;
+ int lopt = 0;
diod_log_init (argv[0]);
@@ -113,6 +116,9 @@ main (int argc, char *argv[])
case 't': /* --timeout SECS */
topt = strtoul (optarg, NULL, 10);
break;
+ case 'l': /* --long */
+ lopt = 1;
+ break;
default:
usage ();
}
@@ -143,15 +149,25 @@ main (int argc, char *argv[])
while (npc_gets (fid, buf, sizeof(buf))) { // inefficient (fix libnpclient)
if ((p = strchr (buf, ' ')))
*p = '\0';
+ if (!lopt && (p = strchr (buf, '.')))
+ *p = '\0';
if (!hostlist_push_host (hl, buf))
err_exit ("hostlist_push_host");
}
hostlist_uniq (hl);
- if (!(itr = hostlist_iterator_create (hl)))
- err_exit ("hostlist_iterator_create");
- while ((host = hostlist_next (itr)))
- printf ("%s\n", host);
- hostlist_iterator_destroy (itr);
+ if (lopt) {
+ if (!(itr = hostlist_iterator_create (hl)))
+ err_exit ("hostlist_iterator_create");
+ while ((host = hostlist_next (itr)))
+ printf ("%s\n", host);
+ hostlist_iterator_destroy (itr);
+ } else {
+ char s[1024];
+
+ if (hostlist_ranged_string (hl, sizeof (s), s) < 0)
+ msg_exit ("hostlist output would be too long (use -l)");
+ printf ("%s\n", s);
+ }
hostlist_destroy (hl);
if (npc_clunk (fid) < 0)

0 comments on commit ce612d1

Please sign in to comment.