예제 #1
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "zxdump"
	dfltdump := zx.Path(dbg.Home, "dump")
	opts.NewFlag("s", "don't dump right now, wait until next at 5am", &Skip)
	opts.NewFlag("1", "dump once and exit", &Once)
	opts.NewFlag("v", "verbose", &Verbose)
	opts.NewFlag("D", "debug", &Debug)
	opts.NewFlag("x", "expr: files excluded (.*, tmp.* if none given); tmp always excluded.", &Xcludes)
	Dump = dfltdump
	opts.NewFlag("d", "dir: where to keep the dump, or empty if none", &Dump)
	args, err := opts.Parse(os.Args)
	if err != nil {
		dbg.Warn("%s", err)
		opts.Usage()
		dbg.Exits(err)
	}
	if len(Xcludes) == 0 {
		Xcludes = []string{".*", "tmp.*", "*.tmp"}
	}
	Xcludes = append(Xcludes, "tmp")
	if len(args) == 0 {
		dbg.Warn("arguments missing")
		opts.Usage()
		dbg.Exits("usage")
	}
	if Skip && Once {
		dbg.Fatal("can't skip the current dump and dump once now")
	}
	nt := 0
	ec := make(chan bool)
	for i := 0; i < len(args); i++ {
		al := strings.SplitN(args[i], "!", 2)
		if len(al) == 1 {
			al = append(al, al[0])
			al[0] = path.Base(al[0])
		}
		t, err := lfs.New(al[0], al[1], lfs.RO)
		if err != nil {
			dbg.Warn("%s: %s", al[0], err)
			continue
		}
		t.ReadAttrs(true)
		nt++
		go dump(Dump, t, ec)
	}
	if nt == 0 {
		dbg.Fatal("no trees to dump")
	}
	for nt > 0 {
		<-ec
		nt--
	}
}
예제 #2
0
func usage(err error) {
	dbg.Warn("%s", err)
	opts.Usage()
	fmt.Fprintf(os.Stderr, "\tspec is name | name!file | name!file!flags \n")
	fmt.Fprintf(os.Stderr, "\tspec flags are ro | rw | ncro | ncrw \n")
	dbg.Exits(err)
}
예제 #3
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "zxfs"
	quiet := false

	opts.NewFlag("q", "don't print errors to stderr", &quiet)
	opts.NewFlag("D", "debug and zxfs calls", &zxfs.Debug)
	opts.NewFlag("r", "read only", &rflag)
	opts.NewFlag("s", "statistics", &sflag)
	opts.NewFlag("n", "don't use caching (otherwise write-through cache)", &nocaching)
	opts.NewFlag("d", "use delayed writes cache", &delayed)
	opts.NewFlag("Z", "debug zx requests", &zdebug)
	opts.NewFlag("V", "verbose debug and fuse requests", &fs.Debug)
	opts.NewFlag("x", "addr: re-export locally the cached tree to this address, if any", &xaddr)
	opts.NewFlag("m", "use mfs caching", &mfscfs)
	opts.NewFlag("l", "dir: use lfs caching at dir", &lfsdir)
	args, err := opts.Parse(os.Args)
	if err != nil {
		opts.Usage(os.Stderr)
		dbg.Fatal(err)
	}
	zxfs.Debug = zxfs.Debug || fs.Debug
	zxfs.Verb = !quiet || zxfs.Debug
	if fs.Debug {
		fuse.Debug = func(m interface{}) {
			fmt.Fprintf(os.Stderr, "fuse: %v\n", m)
		}
	}
	switch len(args) {
	case 2:
		addr = args[0]
		mntdir = args[1]
	case 1:
		addr = args[0]
	default:
		opts.Usage(os.Stderr)
		dbg.Fatal("usage")
	}
	dprintf("debug on\n")
	xfs, fn, err := mkfs(addr)
	if err != nil {
		dbg.Fatal("%s", err)
	}
	defer fn()
	if nocaching || !delayed {
		err = ncmount(xfs)
	} else {
		dbg.Fatal("delayed write mount is gone")
	}
	if err != nil {
		dbg.Fatal("%s", err)
	}
	dbg.Warn("unmounted: exiting")
}
예제 #4
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "tcmd"
	n := 10
	if len(os.Args) > 1 {
		n, _ = strconv.Atoi(os.Args[1])
	}
	for i := 0; i < n; i++ {
		dbg.Warn("T %d", i)
		time.Sleep(time.Second)
	}
}
예제 #5
0
func fatal(warn bool, args ...interface{}) {

	c := AppCtx()
	dprintf("fatal...\n")
	dump("fatal")
	if c == nil {
		panic("fatal")
	}
	ctxlk.Lock() 
	n := len(ctxs)
	ctxlk.Unlock()
	sts := mkSts(args...)
	efn := func() {
		c.post("exit")
		c.Sts = sts
		c.io.closeAll(sts)
		close(c.Sig, sts)
		close(c.Wait, sts)
		ctxlk.Lock()
		delete(ctxs, runtime.AppId())
		ctxlk.Unlock()
	}
	if n <= 1 {
		dprintf("c %d: dbg fatal (%d args)\n", c.Id, len(args))
		efn()
		close(out)
		close(err)
		<-outdone
		<-errdone
		os.Args = c.Args
		if warn {
			dbg.Fatal(args...)	// never returns
		} else {
			dbg.Exits(args...)	// never returns
		}
	}
	dprintf("c %d: app fatal (%d args, %d apps)\n", c.Id, len(args), n)
	if sts != nil && warn {
		Warn("%s", sts)
	}
	efn()
	panic("fatal")
}
예제 #6
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "zx"
	port = "8002"
	opts.NewFlag("p", "port: tcp server port (8002 by default)", &port)
	wport = "9002"
	opts.NewFlag("w", "port: wax http server port", &wport)
	svc = "zx"
	opts.NewFlag("s", "srv: service name (zx by default)", &svc)
	addr = "*!*!zx"
	opts.NewFlag("a", "addr: service address (*!*!zx by default)", &addr)
	opts.NewFlag("v", "report users logged in/out (verbose)", &Verbose)
	opts.NewFlag("D", "debug", &Debug)
	opts.NewFlag("Z", "verbose debug", &Zdebug)
	opts.NewFlag("M", "debug mutexes", &cfs.DebugLocks)
	nopings := false
	opts.NewFlag("k", "do not use zx keep alives", &nopings)
	args, err := opts.Parse(os.Args)
	if err != nil {
		usage(err)
	}
	if len(args) == 0 {
		usage(errors.New("missing arguments"))
	}
	Debug = Debug || Zdebug
	auth.Debug = Debug
	cfs.Debug = Debug
	rfs.Verb = Verbose
	var trs []zx.Tree
	var ros = map[bool]string{false: "rw", true: "ro"}

	for i := 0; i < len(args); i++ {
		al := strings.Split(args[i], "!")
		if len(al) == 1 {
			al = append(al, al[0])
			al[0] = path.Base(al[0])
		}
		ronly := false
		caching := true
		if len(al) == 3 && strings.Contains(al[2], "ro") {
			ronly = true
		}
		if len(al) == 3 && strings.Contains(al[2], "nc") {
			caching = false
		}
		t, err := lfs.New(al[0], al[1], ronly && !caching)
		if err != nil {
			dbg.Warn("%s: %s", al[0], err)
			continue
		}
		t.ReadAttrs(true)
		t.SaveAttrs(caching)
		t.IOstats = &zx.IOstats{}
		fp, _ := filepath.Abs(al[1])
		if caching {
			dbg.Warn("%s mfs + lfs %s caching", al[0], ros[ronly])
			cache, err := mfs.New("mfs:" + al[0])
			if err != nil {
				dbg.Warn("%s: mfs: %s", al[0], err)
				continue
			}
			cache.IOstats = &zx.IOstats{}
			cache.Dbg = Zdebug
			cache.WstatAll = true // cfs must be able to write it all
			x, err := cfs.New(al[0], cache, t, ronly)
			if err != nil {
				dbg.Warn("%s: cfs: %s", al[0], err)
				continue
			}
			x.IOstats = &zx.IOstats{}
			zxw[al[0]] = fp
			trs = append(trs, x)

		} else {
			dbg.Warn("%s lfs %s uncached", al[0], ros[ronly])
			zxw[al[0]] = fp
			t.Dbg = Debug
			trs = append(trs, t)
		}
	}
	if len(trs) == 0 {
		dbg.Fatal("no trees to serve")
	}

	ds.DefSvc(svc, port)
	Vprintf("%s: serve %s...\n", os.Args[0], addr)
	cc, _, err := ds.Serve(os.Args[0], addr)
	if err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}

	go zxwax()
	for c := range cc {
		go func(c nchan.Conn) {
			ai, err := auth.AtServer(c, "", "zx", "finder")
			if err != nil && err != auth.ErrDisabled {
				Vprintf("%s: auth %s: %s\n", os.Args[0], c.Tag, err)
				close(c.In, err)
				close(c.Out, err)
				return
			}
			srv := rfs.Serve("rfs:"+c.Tag, c, ai, rfs.RW, trs...)
			if false {
				srv.Debug = Debug
			}
			srv.Pings = !nopings

		}(*c)
	}
	if err := cerror(cc); err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}
}
예제 #7
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "zx"
	port = "8002"
	opts.NewFlag("p", "port: tcp server port", &port)
	wport = "9002"
	opts.NewFlag("w", "port: wax http server port", &wport)
	svc = "zx"
	opts.NewFlag("s", "srv: service name", &svc)
	addr = "*!*!zx"
	opts.NewFlag("a", "addr: service address", &addr)
	opts.NewFlag("D", "debug", &Debug)
	opts.NewFlag("Z", "verbose debug", &Zdebug)
	opts.NewFlag("k", "make cfg entries persist in the ns", &Persist)
	opts.NewFlag("N", "use new cfs", &New)
	args, err := opts.Parse(os.Args)
	if err != nil {
		usage(err)
	}
	if len(args) == 0 {
		usage(nil)
	}
	Debug = Debug || Zdebug
	auth.Debug = Debug
	ncfs.Debug = Debug
	cfs.Debug = Debug
	cfs.Cdebug = Zdebug
	cfs.Zdebug = Zdebug
	rfs.Verb = Verbose
	var trs []zx.Tree
	var ros = map[bool]string{false: "rw", true: "ro"}

	for i := 0; i < len(args); i++ {
		al := strings.Split(args[i], "!")
		if len(al) == 1 {
			al = append(al, al[0])
			al[0] = path.Base(al[0])
		}
		ronly := false
		caching := true
		if len(al) == 3 && strings.Contains(al[2], "ro") {
			ronly = true
		}
		if len(al) == 3 && strings.Contains(al[2], "nc") {
			caching = false
		}
		t, err := lfs.New(al[0], al[1], ronly && !caching)
		if err != nil {
			dbg.Warn("%s: %s", al[0], err)
			continue
		}
		t.ReadAttrs(true)
		t.SaveAttrs(caching)
		t.IOstats = &zx.IOstats{}
		fp, _ := filepath.Abs(al[1])
		if New && caching {
			dbg.Warn("%s mfs + lfs %s caching", al[0], ros[ronly])
			cache, err := mfs.New("mfs:" + al[0])
			if err != nil {
				dbg.Warn("%s: mfs: %s", al[0], err)
				continue
			}
			cache.IOstats = &zx.IOstats{}
			cache.Dbg = Zdebug
			x, err := ncfs.New("cfs", cache, t, ronly)
			if err != nil {
				dbg.Warn("%s: cfs: %s", al[0], err)
				continue
			}
			x.IOstats = &zx.IOstats{}
			zxw[al[0]] = fp
			trs = append(trs, x)

		} else if !New && caching {
			dbg.Warn("%s old cfs + lfs %s caching", al[0], ros[ronly])
			x, err := cfs.New("", t, ronly)
			if err != nil {
				dbg.Warn("%s: cfs: %s", al[0], err)
				continue
			}
			x.IOstats = &zx.IOstats{}
			zxw[al[0]] = fp
			trs = append(trs, x)
		} else {
			dbg.Warn("%s lfs %s uncached", al[0], ros[ronly])
			zxw[al[0]] = fp
			t.Dbg = Debug
			trs = append(trs, t)
		}
	}
	if len(trs) == 0 {
		dbg.Fatal("no trees to serve")
	}

	ds.DefSvc(svc, port)
	Vprintf("%s: serve %s...\n", os.Args[0], addr)
	cc, _, err := ds.Serve(os.Args[0], addr)
	if err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}

	go zxwax()
	for c := range cc {
		go func(c nchan.Conn) {
			ai, err := auth.AtServer(c, "", "zx", "finder")
			if err != nil && err != auth.ErrDisabled {
				Vprintf("%s: auth %s: %s\n", os.Args[0], c.Tag, err)
				close(c.In, err)
				close(c.Out, err)
				return
			}
			srv := rfs.Serve("rfs:"+c.Tag, c, ai, rfs.RW, trs...)
			if false {
				srv.Debug = Debug
			}

		}(*c)
	}
	if err := cerror(cc); err != nil {
		dbg.Fatal("%s: serve: %s", os.Args[0], err)
	}
}
예제 #8
0
func main() {
	defer dbg.Exits("")
	os.Args[0] = "repl"
	opts.NewFlag("D", "debug", &sync.Debug)
	opts.NewFlag("V", "verbose debug", &sync.Verb)
	opts.NewFlag("q", "quiet, do not print files pulled/pushed", &quiet)
	opts.NewFlag("1", "pull only", &pullonly)
	opts.NewFlag("2", "push only", &pushonly)
	opts.NewFlag("s", "sleep and sync everyday at 3am", &skip)
	opts.NewFlag("n", "dry run", &dry)
	opts.NewFlag("p", "print the replica state and exit", &print)
	opts.NewFlag("m", "name: make the named repl and exit", &name)
	args, err := opts.Parse(os.Args)
	mk := name != ""
	if err != nil || skip && mk || pullonly && pushonly || dry && mk || print && mk || dry && print {
		if err == nil {
			err = errors.New("incompatible flags")
		}
		dbg.Warn("%s", err)
		opts.Usage()
		dbg.Exits(err)
	}
	if len(args) < 1 {
		dbg.Warn("missing arguments")
		opts.Usage()
		dbg.Exits("usage")
	}
	sync.Debug = sync.Debug || sync.Verb
	cfile := cfgPath(args[0])
	if mk {
		if len(args) != 3 {
			dbg.Warn("wrong number of arguments")
			opts.Usage()
			dbg.Exits("usage")
		}
		laddr, raddr := args[1], args[2]
		r, err := repl.New(name, repl.NoDots, laddr, raddr)
		if err != nil {
			dbg.Fatal(err)
		}
		if err := r.Save(cfile); err != nil {
			dbg.Fatal(err)
		}
		dbg.Warn("%s created", cfile)
		dbg.Exits(nil)
	}
	if len(args) != 1 {
		dbg.Warn("wrong number of arguments")
		opts.Usage()
		dbg.Exits("usage")
	}
	r, err := repl.Load(cfile)
	if err != nil {
		dbg.Fatal("%s: %s", cfile, err)
	}
	if print {
		r.DryRun = true // safety first.
		switch {
		case pullonly:
			r.Ldb.DumpTo(os.Stdout)
		case pushonly:
			r.Rdb.DumpTo(os.Stdout)
		default:
			r.DumpTo(os.Stdout)
		}
		dbg.Exits(nil)
	}
	r.DryRun = dry
	r.Verb = !quiet
	for {
		switch {
		case pullonly:
			err = r.Pull()
		case pushonly:
			err = r.Push()
		default:
			err = r.Sync()
		}
		if err != nil {
			dbg.Warn("%s: %s", r.Name, err)
		}
		if !dry {
			if err = r.Save(cfile); err != nil {
				dbg.Warn("%s: %s", r.Name, err)
			} else {
				dbg.Warn("%s: %s saved", r.Name, cfile)
			}
		}
		if skip {
			waitReplTime(r.Name)
			continue
		}
		dbg.Exits("")
	}
}
예제 #9
0
func main() {
	os.Args[0] = "zxfs"
	quiet := false
	stacks := false

	opts.NewFlag("q", "don't print errors to stderr", &quiet)
	opts.NewFlag("D", "debug zx calls", &zxdebug)
	opts.NewFlag("L", "debug lfs calls", &lfsdebug)
	opts.NewFlag("R", "debug rfs calls", &rfsdebug)
	opts.NewFlag("F", "debug fuse requests", &zxfs.Debug)
	opts.NewFlag("M", "debug mutexes", &cfs.DebugLocks)
	opts.NewFlag("V", "verbose fuse debug", &fs.Debug)
	opts.NewFlag("S", "dump stacks on unmount for debugging", &stacks)
	opts.NewFlag("k", "do not use zx keep alives", &nopings)
	opts.NewFlag("r", "read only", &rflag)
	opts.NewFlag("s", "statistics", &sflag)
	opts.NewFlag("n", "no caching", &nocache)
	opts.NewFlag("l", "dir: use lfs caching at dir", &lfscache)
	opts.NewFlag("m", "dir: use on-memory stat caching, on disk data caching at dir", &mlfscache)
	opts.NewFlag("x", "addr: re-export locally the cached tree to this address", &xaddr)
	args, err := opts.Parse(os.Args)
	if err != nil {
		dbg.Warn("%s", err)
		opts.Usage()
		dbg.Exits(err)
	}
	if nocache && (lfscache != "" || mlfscache != "") {
		dbg.Warn("can't use both caching and non-caching")
		opts.Usage()
		dbg.Exits(err)
	}
	if lfscache != "" && mlfscache != "" {
		dbg.Warn("can use only a single cache type")
		opts.Usage()
		dbg.Exits(err)
	}
	zxfs.Verb = !quiet
	fuse.Debug = func(m interface{}) {
		if fs.Debug {
			fmt.Fprintf(os.Stderr, "fuse: %v\n", m)
		}
	}
	switch len(args) {
	case 2:
		addr = args[0]
		mntdir = args[1]
	case 1:
		addr = args[0]
	default:
		dbg.Warn("wrong number of arguments")
		opts.Usage()
		dbg.Exits("usage")
	}
	dprintf("debug on\n")
	if cfs.DebugLocks {
		dbg.Warn("*** debug locks enabled")
	}
	xfs, fn, err := mkfs(addr, quiet)
	if err != nil {
		dbg.Fatal("%s: %s", addr, err)
	}
	defer fn()
	err = ncmount(xfs)
	if stacks {
		dbg.Warn("*** PANICING ON USER REQUEST (-S) ***")
		panic("stack dump")
	}
	if err != nil {
		dbg.Fatal("%s", err)
	}
	dbg.Warn("unmounted: exiting")
}
예제 #10
0
func main() {
	defer dbg.Exits("errors")
	os.Args[0] = "ql"
	opts.NewFlag("c", "cmd: execute this command and exit", &cmdarg)
	opts.NewFlag("D", "debug", &debug)
	opts.NewFlag("V", "verbose debug", &verb)
	opts.NewFlag("N", "debug ns", &debugNs)
	args, err := opts.Parse(os.Args)
	if err != nil {
		opts.Usage(os.Stderr)
		dbg.Fatal(err)
	}

	cmd.Debug = debugNs
	debugYacc = debug
	debugExec = verb
	cmd.MkNS()

	var in inText
	Interactive = cmd.IsTTY(os.Stdin)
	if Interactive {
		dprintf("interactive\n")
		if xprompt := os.Getenv("prompt"); xprompt != "" {
			prompt = xprompt
		} else {
			os.Setenv("prompt", prompt)
		}
		if xprompt2 := os.Getenv("prompt2"); xprompt2 != "" {
			prompt2 = xprompt2
		} else {
			os.Setenv("prompt2", prompt2)
		}
	} else {
		dprintf("script\n")
		IntrExits = true
	}
	var argv0, iname string
	var argv []string
	if cmdarg != "" {
		in = bytes.NewBufferString(cmdarg + "\n")
		argv0 = "ql"
		iname = "flag-c"
		argv = args
	} else if len(args) == 0 {
		if Interactive {
			SetEnvList("argv0", "ql")
			SetEnvList("argv", args...)
			Argv = args
			rdr := cmd.NewReader(os.Stdin, os.Stdout, prompt)
			Prompter = rdr
			for interactive(bufio.NewReader(rdr)) {
				dprintf("*** interrupted\n")
				rdr.Flush()
			}
			dbg.Exits("")
		}
		iname = "stdin"
		in = bufio.NewReader(os.Stdin)
		argv0 = "ql"
	} else {
		argv0 = args[0]
		iname = args[0]
		argv = args[1:]
		idata, err := ioutil.ReadFile(iname)
		if err != nil {
			dbg.Fatal("open: %s: %s", iname, err)
		}
		in = bytes.NewBuffer(idata)
	}

	SetEnvList("argv0", argv0)
	SetEnvList("argv", argv...)
	Argv = argv
	lexer = newLex(iname, in)
	yyParse(lexer)
	dbg.Exits(os.Getenv("status"))
}