Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"9fans.net/go/plumb"
"github.com/rjkroege/edwood/draw"
"github.com/rjkroege/edwood/dumpfile"
"github.com/rjkroege/edwood/server"
"github.com/rjkroege/edwood/util"
)

Expand All @@ -30,9 +31,11 @@ var (
mtpt = flag.String("m", defaultMtpt, "Mountpoint for 9P file server")
swapScrollButtons = flag.Bool("r", false, "Swap scroll buttons")
winsize = flag.String("W", "1024x768", "Window size and position as WidthxHeight[@X,Y]")
remote = flag.String("R", "", "an ssh address in the form user@host:port, when specified causes acme to connect to edit files over an ssh connection")
)

func main() {

// rfork(RFENVG|RFNAMEG); TODO(flux): I'm sure these are vitally(?) important.

// TODO(rjk): Unlimited concurrency please.
Expand All @@ -48,9 +51,16 @@ func main() {

startProfiler()

if *remote != "" {
err := server.StartRemoteSrv(*remote)
if err != nil {
log.Fatal(err)
}
}

// Implicit to preserve existing semantics.
// TODO(rjk): Do this here.
// global = makeglobals()
global = makeglobals()
g := global

// TODO(rjk): Push this code into a separate function.
Expand Down Expand Up @@ -426,7 +436,7 @@ func keyboardthread(g *globals, display draw.Display) {
func waitthread(g *globals, ctx context.Context) {
// There is a race between process exiting and our finding out it was ever created.
// This structure keeps a list of processes that have exited we haven't heard of.
exited := make(map[int]ProcessState)
exited := make(map[server.Execution]ProcessState)

Freecmd := func(c *Command) {
if c != nil {
Expand All @@ -451,7 +461,7 @@ func waitthread(g *globals, ctx context.Context) {
found := false
for _, c := range command {
if c.name == cmd+" " {
if err := c.proc.Kill(); err != nil {
if err := c.e.Kill(); err != nil {
warning(nil, "kill %v: %v\n", cmd, err)
}
found = true
Expand All @@ -466,9 +476,9 @@ func waitthread(g *globals, ctx context.Context) {
i int
c *Command
)
pid := w.Pid()
e := w.Execution()
for i, c = range command {
if c.pid == pid {
if c.e == e {
command = append(command[:i], command[i+1:]...)
break
}
Expand All @@ -478,7 +488,7 @@ func waitthread(g *globals, ctx context.Context) {
t.Commit()
if c == nil {
// command exited before we had a chance to add it to command list
exited[pid] = w
exited[e] = w
} else {
if search(t, []rune(c.name)) {
t.Delete(t.q0, t.q1, true)
Expand All @@ -494,11 +504,11 @@ func waitthread(g *globals, ctx context.Context) {

case c := <-g.ccommand:
// has this command already exited?
if p, ok := exited[c.pid]; ok {
if p, ok := exited[c.e]; ok {
if msg := p.String(); msg != "" {
warning(c.md, "%s\n", msg)
}
delete(exited, c.pid)
delete(exited, c.e)
Freecmd(c)
break
}
Expand Down Expand Up @@ -561,7 +571,7 @@ func newwindowthread(g *globals) {
func killprocs(fs *fileServer) {
fs.close()
for _, c := range command {
c.proc.Kill()
c.e.Kill()
}
}

Expand Down
10 changes: 6 additions & 4 deletions dat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
"math"
"os"
"unicode/utf8"

"9fans.net/go/plan9"
"github.com/rjkroege/edwood/server"
//"9fans.net/go/plumb"
// "github.com/rjkroege/edwood/draw"
// "github.com/rjkroege/edwood/file"
Expand Down Expand Up @@ -67,8 +67,9 @@ const (
Kscrollonedown = KF | 0x21
)

// TODO(knusbaum) duplicates server.ProcessState
type ProcessState interface {
Pid() int
Execution() server.Execution
String() string
Success() bool
}
Expand All @@ -78,8 +79,9 @@ type Range struct {
}

type Command struct {
pid int
proc *os.Process
//pid int
//proc *os.Process
e server.Execution
name string
text string
av []string
Expand Down
5 changes: 3 additions & 2 deletions dumpfile/legacy_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bufio"
"fmt"
"io"
"os"
"regexp"
"strconv"
"strings"

"github.com/rjkroege/edwood/server"
)

// readtrim returns a string read from the file or an error.
Expand Down Expand Up @@ -117,7 +118,7 @@ func loadhelper(rd *bufio.Reader, subl []string, fontname string, numcol, ndumpe
func LoadLegacy(file, home string) (*Content, error) {
// log.Println("LoadLegacy start", file)

f, err := os.Open(file)
f, err := server.EdSrv.Open(file)
if err != nil {
return nil, fmt.Errorf("loading old dumpfile file %s failed: %v", file, err)
}
Expand Down
6 changes: 4 additions & 2 deletions dumpfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"fmt"
"io"
"os"

"github.com/rjkroege/edwood/server"
)

const version = 1
Expand Down Expand Up @@ -81,7 +83,7 @@ type versionedContent struct {

// Load parses the dump file and returns its content.
func Load(file string) (*Content, error) {
f, err := os.Open(file)
f, err := server.EdSrv.Open(file)
if err != nil {
return nil, err
}
Expand All @@ -105,7 +107,7 @@ func decode(r io.Reader) (*Content, error) {

// Save encodes the dump file content and writes it to file.
func (c *Content) Save(file string) error {
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, err := server.EdSrv.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions ecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/rjkroege/edwood/file"
"github.com/rjkroege/edwood/server"
"github.com/rjkroege/edwood/util"
)

Expand Down Expand Up @@ -258,7 +258,7 @@ func e_cmd(t *Text, cp *Cmd) bool {
editerror(Enoname)
}
samename := name == file.Name()
fd, err := os.Open(name)
fd, err := server.EdSrv.Open(name)
if err != nil {
editerror("can't open %v: %v", name, err)
}
Expand Down
4 changes: 2 additions & 2 deletions ecmd_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main

import (
"os"
"path/filepath"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/rjkroege/edwood/dumpfile"
"github.com/rjkroege/edwood/file"
"github.com/rjkroege/edwood/server"
)

// Test for https://github.com/rjkroege/edwood/issues/291
Expand Down Expand Up @@ -110,7 +110,7 @@ func BenchmarkLargeEditTargets10000(t *testing.B) { benchmarkLargeEditTargetsImp
func benchmarkLargeEditTargetsImpl(t *testing.B, nl int) {
dir := t.TempDir()
firstfilename := filepath.Join(dir, "bigfile")
cwd, err := os.Getwd()
cwd, err := server.EdSrv.Getwd()
if err != nil {
t.Fatalf("failed to get current working directory: %v", err)
}
Expand Down
57 changes: 28 additions & 29 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"image"
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
Expand All @@ -17,6 +16,7 @@ import (
"9fans.net/go/plan9/client"
"github.com/rjkroege/edwood/file"
"github.com/rjkroege/edwood/frame"
"github.com/rjkroege/edwood/server"
)

type Exectab struct {
Expand Down Expand Up @@ -521,15 +521,15 @@ func local(et, _, argt *Text, _, _ bool, arg string) {
//
// TODO(flux): Write this in terms of the various cases.
func putfile(oeb *file.ObservableEditableBuffer, q0 int, q1 int, name string) error {
d, err := os.Stat(name)
d, err := server.EdSrv.Stat(name)

// Putting to the same file that we already read from.
if err == nil && name == oeb.Name() {
if !os.SameFile(oeb.Info(), d) || d.ModTime().Sub(oeb.Info().ModTime()) > time.Millisecond {
oeb.UpdateInfo(name, d)
}

if !os.SameFile(oeb.Info(), d) || d.ModTime().Sub(oeb.Info().ModTime()) > time.Millisecond {
if !server.EdSrv.SameFile(oeb.Info(), d) || d.ModTime().Sub(oeb.Info().ModTime()) > time.Millisecond {
// By setting File.info here, a subsequent Put will ignore that
// the disk file was mutated and will write File to the disk file.
oeb.SetInfo(d)
Expand All @@ -544,7 +544,7 @@ func putfile(oeb *file.ObservableEditableBuffer, q0 int, q1 int, name string) er
}
}

fd, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
fd, err := server.EdSrv.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
if err != nil {
return warnError(nil, "can't create file %s: %v", name, err)
}
Expand Down Expand Up @@ -667,7 +667,7 @@ func run(win *Window, s string, rdir string, newns bool, argaddr string, xarg st
}

c := &Command{}
cpid := make(chan *os.Process)
cpid := make(chan server.Execution)
go func() {
err := runproc(win, s, rdir, newns, argaddr, xarg, c, cpid, iseditcmd)
if err != nil && err != errEmptyCmd {
Expand Down Expand Up @@ -840,11 +840,11 @@ func zeroxx(et *Text, t *Text, _ *Text, _, _ bool, _4 string) {
}
}

func runwaittask(c *Command, cpid chan *os.Process) {
c.proc = <-cpid
func runwaittask(c *Command, cpid chan server.Execution) {
c.e = <-cpid

if c.proc != nil { // successful exec
c.pid = c.proc.Pid
if c.e != nil { // successful exec
//c.pid = c.proc.Pid
global.ccommand <- c
} else {
if c.iseditcommand {
Expand All @@ -859,7 +859,7 @@ var errEmptyCmd = fmt.Errorf("empty command")
// runproc. Something with the running of external processes. Executes
// asynchronously.
// TODO(rjk): Must lock win on mutation.
func runproc(win *Window, s string, dir string, newns bool, argaddr string, arg string, c *Command, cpid chan *os.Process, iseditcmd bool) error {
func runproc(win *Window, s string, dir string, newns bool, argaddr string, arg string, c *Command, cpid chan server.Execution, iseditcmd bool) error {
var (
t, name, filename string
incl []string
Expand Down Expand Up @@ -900,21 +900,21 @@ func runproc(win *Window, s string, dir string, newns bool, argaddr string, arg
shell = "rc"
}
rcarg = []string{shell, "-c", t}
cmd := exec.Command(rcarg[0], rcarg[1:]...)
cmd.Dir = dir
cmd.Stdin = sin
cmd.Stdout = sout
cmd.Stderr = serr
err := cmd.Start()
exe, err := server.EdSrv.Run(rcarg[0], rcarg[1:], dir, nil, sin, sout, serr)
if err != nil {
Fail()
return fmt.Errorf("exec %s: %v", shell, err)
}
err = exe.Start()
if err != nil {
Fail()
return fmt.Errorf("exec %s: %v", shell, err)
}
cpid <- cmd.Process
cpid <- exe
go func() {
cmd.Wait()
exe.Wait()
Closeall()
global.cwait <- cmd.ProcessState
global.cwait <- exe.State()
}()
return nil
}
Expand Down Expand Up @@ -1025,22 +1025,21 @@ func runproc(win *Window, s string, dir string, newns bool, argaddr string, arg
Fail()
return errEmptyCmd
}
cmd := exec.Command(c.av[0], c.av[1:]...)
cmd.Dir = dir
cmd.Stdin = sin
cmd.Stdout = sout
cmd.Stderr = serr
cmd.Env = env
err := cmd.Start()
exe, err := server.EdSrv.Run(c.av[0], c.av[1:], dir, env, sin, sout, serr)
if err != nil {
Fail()
return err
}
err = exe.Start()
if err != nil {
Fail()
return err
}
cpid <- cmd.Process
cpid <- exe
go func() {
cmd.Wait()
exe.Wait()
Closeall()
global.cwait <- cmd.ProcessState
global.cwait <- exe.State()
}()
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions file/diskdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package file

import (
"fmt"
"os"
"io/fs"
)

type DiskDetails struct {
Name string
Info os.FileInfo
Info fs.FileInfo
Hash Hash // Used to check if the file has changed on disk since loaded.
isdir bool // Used to track if this File is populated from a directory list. [private]
}
Expand All @@ -29,7 +29,7 @@ func (f *DiskDetails) SetDir(isdir bool) {
}

// UpdateInfo updates File's info to d if file hash hasn't changed.
func (f *DiskDetails) UpdateInfo(filename string, d os.FileInfo) error {
func (f *DiskDetails) UpdateInfo(filename string, d fs.FileInfo) error {
h, err := HashFor(filename)
if err != nil {
return fmt.Errorf("failed to compute hash for %v: %v", filename, err)
Expand Down
Loading