-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
86 lines (65 loc) · 1.69 KB
/
main.go
File metadata and controls
86 lines (65 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: LGPL-3.0
// Copyright (C) 2022 jdwpfs Authors M. G. Dan
package main
import (
// "context"
"context"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/jessevdk/go-flags"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/fs"
jdwpfs "disroot.org/kitzman/jdwpfs/fs"
)
type Options struct {
DebuggedHost string `short:"h" long:"host" description:"host of debugged JVM process"`
DebuggedPort int `short:"p" long:"port" description:"port of debugged JVM process"`
}
func main() {
var opts Options
args, err := flags.ParseArgs(&opts, os.Args)
if err != nil {
os.Exit(0)
}
if len(args) != 2 {
log.Fatalf("mountpoint not supplied: %s\n", args)
}
mountpoint := args[1]
_, err = os.Stat(mountpoint)
if err != nil {
panic(err)
}
absoluteMountpoint, _ := filepath.Abs(mountpoint)
log.Printf("mounting at %s\n", mountpoint)
log.Printf("debugging at %s:%d\n", opts.DebuggedHost, opts.DebuggedPort)
fuseOptions := &fs.Options{
MountOptions: fuse.MountOptions { // these should be tunable
AllowOther: true,
MaxBackground: 8,
FsName: "jdwpfs",
Name: "jdwpfs",
},
UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()),
}
jdwpContext := context.Background()
rootFs, err := jdwpfs.NewJdwpRootfs(jdwpContext, absoluteMountpoint, opts.DebuggedHost, opts.DebuggedPort)
if err != nil {
panic(err)
}
server, err := fs.Mount(mountpoint, rootFs, fuseOptions)
if err != nil {
log.Fatalf("mount failed: %s\n", err)
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
log.Printf("got %s, quitting\n", sig)
server.Unmount()
}();
server.Wait()
}