aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/auxstats/main.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-23 05:12:11 +0000
committerrsc <devnull@localhost>2004-04-23 05:12:11 +0000
commitf0f4401f0cfc654646bdf21849627ebcbd5d82b5 (patch)
tree037270d81e83f96e788914a298c45bf4b5768f33 /src/cmd/auxstats/main.c
parentd72054aa270d6f3d539e830ef9892138a255872a (diff)
downloadplan9port-f0f4401f0cfc654646bdf21849627ebcbd5d82b5.tar.gz
plan9port-f0f4401f0cfc654646bdf21849627ebcbd5d82b5.tar.bz2
plan9port-f0f4401f0cfc654646bdf21849627ebcbd5d82b5.zip
stats helper
Diffstat (limited to 'src/cmd/auxstats/main.c')
-rw-r--r--src/cmd/auxstats/main.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/cmd/auxstats/main.c b/src/cmd/auxstats/main.c
new file mode 100644
index 00000000..a3624824
--- /dev/null
+++ b/src/cmd/auxstats/main.c
@@ -0,0 +1,123 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include "dat.h"
+
+Biobuf bout;
+
+void
+usage(void)
+{
+ fprint(2, "usage: auxstats [system [executable]]\n");
+ exits("usage");
+}
+
+int pid;
+
+void
+notifyf(void *v, char *msg)
+{
+ USED(v);
+
+ if(strcmp(msg, "child") == 0)
+ noted(NCONT);
+ postnote(PNPROC, pid, msg);
+ exits(nil);
+}
+
+void
+main(int argc, char **argv)
+{
+ char *sys, *exe;
+ int i;
+ Waitmsg *w;
+
+ ARGBEGIN{
+ default:
+ usage();
+ }ARGEND
+
+ notify(notifyf);
+
+ sys = nil;
+ exe = nil;
+ if(argc > 0)
+ sys = argv[0];
+ if(argc > 1)
+ exe = argv[1];
+ if(argc > 2)
+ usage();
+
+ if(sys){
+ if(exe == nil)
+ exe = "auxstats";
+ for(;;){
+ switch(pid = fork()){
+ case -1:
+ sysfatal("fork: %r");
+ case 0:
+ rfork(RFNOTEG);
+ execlp("ssh", "ssh", "-C", sys, exe, nil);
+ _exit(12);
+ default:
+ if((w = wait()) == nil)
+ sysfatal("wait: %r");
+ if(w->pid != pid)
+ sysfatal("wait got wrong pid");
+ if(atoi(w->msg) == 12)
+ sysfatal("exec ssh failed");
+ free(w);
+ fprint(2, "stats: %s hung up; sleeping 60\n", sys);
+ sleep(60*1000);
+ fprint(2, "stats: redialing %s\n", sys);
+ break;
+ }
+ }
+ }
+
+ for(i=0; statfn[i]; i++)
+ statfn[i](1);
+
+ Binit(&bout, 1, OWRITE);
+ for(;;){
+ Bflush(&bout);
+ sleep(900);
+ for(i=0; statfn[i]; i++)
+ statfn[i](0);
+ }
+}
+
+char buf[16384];
+char *line[100];
+char *tok[100];
+int nline, ntok;
+
+void
+readfile(int fd)
+{
+ int n;
+
+ if(fd == -1){
+ nline = 0;
+ return;
+ }
+
+ seek(fd, 0, 0);
+ n = read(fd, buf, sizeof buf-1);
+ if(n < 0)
+ n = 0;
+ buf[n] = 0;
+
+ nline = getfields(buf, line, nelem(line), 0, "\n");
+}
+
+void
+tokens(int i)
+{
+ if(i >= nline){
+ ntok = 0;
+ return;
+ }
+ ntok = tokenize(line[i], tok, nelem(tok));
+}
+