From 5729b4bf66afc2aa970c0b634c27a9e1ccbcb555 Mon Sep 17 00:00:00 2001 Message-Id: <5729b4bf66afc2aa970c0b634c27a9e1ccbcb555.1713435167.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 2 May 2015 17:05:20 +0100 Subject: [PATCH] client/tripectl.c: New option `-W' to set `WATCH' list. Organization: Straylight/Edgeware From: Mark Wooding --- client/tripectl.1.in | 14 ++++++++++++++ client/tripectl.c | 22 ++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/client/tripectl.1.in b/client/tripectl.1.in index 523b1f05..e01df128 100644 --- a/client/tripectl.1.in +++ b/client/tripectl.1.in @@ -39,6 +39,8 @@ tripectl \- simple client for TrIPE . .B tripectl .RB [ \-w ] +.RB [ \-W +.IR things ] .RB [ \-\fIoptions ] .RI [ command .RI [ args ]...] @@ -246,6 +248,18 @@ timestamps anyway. .TP .B "\-w, \-\-warnings" Write warnings to standard error even when running noninteractively. +.TP +.BI "\-W, \-\-watch=" things +When running as a client, arrange to receive asynchronous messages as +described by +.IR things , +which should be a trace list suitable for passing to the server's +.B WATCH +command: see +.BR tripe-admin (5) +for more details. This overrides the +.B \-w +flag in noninteractive use. .SS "Interactive use" With no arguments, .B tripectl diff --git a/client/tripectl.c b/client/tripectl.c index f14c137e..e264a734 100644 --- a/client/tripectl.c +++ b/client/tripectl.c @@ -81,6 +81,7 @@ static const char *pidfile = 0; static const char *logname = 0; static FILE *logfp = 0; static unsigned f = 0; +static const char *watch = 0; static int fd; static const char *bgtag = 0; @@ -362,6 +363,7 @@ Options in full:\n\ -f, --logfile=FILE Log messages to FILE.\n\ -t, --no-timestamp When logging to a file, don't emit timestamps.\n\ -w, --warnings Show warnings when running commands.\n\ +-W, --watch=THINGS Watch for THINGS after connecting.\n\ ", fp); } @@ -415,11 +417,12 @@ int main(int argc, char *argv[]) { "logfile", OPTF_ARGREQ, 0, 'f' }, { "no-timestamp", 0, 0, 't' }, { "warnings", 0, 0, 'w' }, + { "watch", OPTF_ARGREQ, 0, 'W' }, { "pidfile", OPTF_ARGREQ, 0, 'P' }, { 0, 0, 0, 0 } }; - i = mdwopt(argc, argv, "+hvuDU:G:d:a:sp:S:lwf:nP:t", opts, 0, 0, 0); + i = mdwopt(argc, argv, "+hvuDU:G:d:a:sp:S:lwW:f:nP:t", opts, 0, 0, 0); if (i < 0) break; switch (i) { @@ -465,6 +468,9 @@ int main(int argc, char *argv[]) case 'w': f |= f_warn; break; + case 'W': + watch = optarg; + break; case 'f': logname = optarg; f |= f_noinput; @@ -578,8 +584,12 @@ int main(int argc, char *argv[]) /* --- If we're meant to be interactive, do that --- */ - if (optind == argc) - setup("WATCH -A+tw"); + if (optind == argc) { + DRESET(&d); + dstr_puts(&d, "watch"); + u_quotify(&d, watch ? watch : "-A+tw"); + setup(d.buf); + } if (!(f & f_noinput) && optind == argc) { selbuf_init(&bu, &sel, STDIN_FILENO, uline, &bu); selbuf_init(&bs, &sel, fd, sline, &bs); @@ -592,7 +602,11 @@ int main(int argc, char *argv[]) /* --- If there's a command, submit it --- */ if (optind < argc) { - setup((f & f_warn) ? "WATCH -A+w" : "WATCH -A"); + DRESET(&d); + dstr_puts(&d, "watch"); + u_quotify(&d, watch ? watch : (f & f_warn) ? "-A+w" : "-A"); + setup(d.buf); + DRESET(&d); while (optind < argc) u_quotify(&d, argv[optind++]); dstr_putc(&d, '\n'); -- [mdw]