func main() { defer app.Exiting() x := app.New() stacks := false opts.NewFlag("F", "debug fuse requests", &zxfs.Debug) opts.NewFlag("D", "debug", &x.Debug) opts.NewFlag("s", "statistics", &sflag) opts.NewFlag("x", "addr: re-export locally the ql tree to this address", &xaddr) opts.NewFlag("S", "dump stacks on unmount for debugging", &stacks) args, err := opts.Parse(x.Args) if err != nil { app.Warn("%s", err) opts.Usage() app.Exits(err) } switch len(args) { case 0: case 1: mntdir = args[1] default: app.Warn("wrong number of arguments") opts.Usage() app.Exits("usage") } dprintf("debug on\n") qfs, err := qlfs.New("qlfs") if err != nil { app.Fatal(err) } qfs.Dbg = x.Debug qfs.Flags.Add("fdebug", &zxfs.Debug) st := &zx.IOstats{} qfs.IOstats = st if xaddr != "" { rfs.Server(qfs, xaddr) } err = zxfs.MountServer(qfs, mntdir) if sflag { st.Averages() app.Warn("%s iostats:\n%s\n", qfs.Name(), st) } if stacks { app.Warn("*** PANICING ON USER REQUEST (-S) ***") panic("stack dump") } if err != nil { app.Fatal("%s", err) } app.Warn("unmounted: exiting") }
func runType(x *xEnv, argv ...string) error { defer app.Exiting() opts := opt.New("{name}") app.Dprintf("type %v\n", argv) args, err := opts.Parse(argv) if err != nil { opts.Usage() app.Exits(dbg.ErrUsage) } for _, n := range args { app.Printf("%s: %s\n", n, x.ntype(n)) } app.Exits(nil) return nil }
func main() { defer app.Exiting() app.New() app.SetIO(app.OSIn(), 0) xp.Run() app.Exits(nil) }
func main() { defer app.Exiting() app.New() app.Close(0) ql.Run() app.Exits(nil) }
func main() { os.Stdin.Close() defer app.Exiting() app.New() app.Close(0) wr.Run() app.Exits(nil) }
// runs here func runExit(x *xEnv, argv ...string) error { app.Dprintf("exit %v\n", argv) s := "" if len(argv) > 1 { s = argv[1] } app.Exits(s) return nil }
func main() { defer app.Exiting() os.Args[0] = "auth" app.New() dfltdir := auth.KeyDir() dir = dfltdir opts.NewFlag("d", "adir: clive auth dir", &dir) opts.NewFlag("f", "force write of key file when file already exists", &force) args, err := opts.Parse(os.Args) if err != nil { app.Warn("%s", err) opts.Usage() app.Exits(err) } if len(args) < 3 { opts.Usage() app.Exits("usage") } name, user, secret := args[0], args[1], args[2] groups := args[3:] file := auth.KeyFile(dir, name) fi, _ := os.Stat(file) if fi != nil && !force { app.Fatal("key file already exists") } err = auth.SaveKey(dir, name, user, secret, groups...) if err != nil { app.Fatal("%s: %s", file, err) } ks, err := auth.LoadKey(dir, name) if err != nil { app.Fatal("can't load key: %s", err) } for _, k := range ks { if k.Uid == user { app.Warn("%s", file) return } } app.Fatal("bad user") }
func main() { defer app.Exiting() app.New() opts.NewFlag("p", "port: port used (8080 by default)", &port) args, err := opts.Parse(os.Args) if err != nil { app.Warn("%s", err) opts.Usage() app.Exits(err) } switch len(args) { case 0: case 1: dir = args[0] default: app.Warn("too many arguments") opts.Usage() app.Exits("usage") } err = http.ListenAndServe(":"+port, http.FileServer(http.Dir(dir))) app.Exits(err) }
func main() { defer app.Exiting() app.New() rem.Run() app.Exits(nil) }
func main() { defer app.Exiting() os.Args[0] = "Q" c := app.New() opts.NewFlag("c", "ignored for compatibility", &dummy) opts.NewFlag("D", "debug", &c.Debug) edir := dbg.Usr opts.NewFlag("e", "env: qlfs environment name (defaults to uid)", &edir) opts.NewFlag("q", "qldir: qlfs root dir (defaults to /n/ql)", &ql) args, err := opts.Parse(os.Args) if err != nil { app.Warn("%s", err) opts.Usage() app.Exits(err) } cmd := "" if len(args) == 0 { app.Warn("no command given") opts.Usage() app.Exits(err) } cmd = strings.Join(args, " ") app.Dprintf("run %s\n", cmd) _, err = os.Stat(path.Join(ql, "Ctl")) if err != nil { app.Fatal("qlfs: %s", err) } env := path.Join(ql, edir) _, err = os.Stat(env) if err != nil { err = os.Mkdir(env, 0775) } if err != nil { app.Fatal("%s", err) } cdir := fmt.Sprintf("%s/%d", env, os.Getpid()) if err := os.Mkdir(cdir, 0755); err != nil { app.Fatal("%s", err) } var b bytes.Buffer io.Copy(&b, os.Stdin) if err := ioutil.WriteFile(path.Join(cdir, "in"), b.Bytes(), 0644); err != nil { os.RemoveAll(cdir) app.Fatal("writing in: %s", err) } if err := ioutil.WriteFile(path.Join(cdir, "cmd"), []byte(cmd), 0644); err != nil { os.RemoveAll(cdir) app.Fatal("writing cmd: %s", err) } oc := make(chan bool, 2) pfd, err := os.Open(path.Join(cdir, "pout")) if err != nil { app.Warn("out: %s", err) oc <- true } else { go func() { io.Copy(os.Stdout, pfd) pfd.Close() oc <- true }() } efd, err := os.Open(path.Join(cdir, "perr")) if err != nil { app.Warn("err: %s", err) oc <- true } else { go func() { io.Copy(os.Stderr, efd) efd.Close() oc <- true }() } <-oc <-oc sts, err := ioutil.ReadFile(path.Join(cdir, "wait")) os.RemoveAll(cdir) if err != nil { app.Exits(err) } s := string(sts) if s == "success" { s = "" } app.Exits(s) }