-
Notifications
You must be signed in to change notification settings - Fork 3
/
vnetd.go
82 lines (68 loc) · 1.58 KB
/
vnetd.go
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
// Copyright © 2015-2018 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by the GPL-2 license described in the
// LICENSE file.
package main
import (
"fmt"
"os"
"strings"
"syscall"
"github.com/platinasystems/goes/cmd"
"github.com/platinasystems/goes/lang"
)
type vnetd string
var Vnetd vnetd = "vnet-platina-mk1"
func (vnetd) String() string { return "vnetd" }
func (vnetd) Usage() string { return "vnetd" }
func (vnetd) Apropos() lang.Alt {
return lang.Alt{
lang.EnUS: "Platina's Mk1 TOR driver daemon",
}
}
func (vnetd) Kind() cmd.Kind { return cmd.Daemon }
func (c vnetd) Main(args ...string) error {
pn, err := c.Path()
if err != nil {
return err
}
if len(args) == 1 && strings.TrimLeft(args[0], "-") == "path" {
fmt.Println(pn)
return nil
}
return syscall.Exec(pn, append([]string{string(c)}, args...),
os.Environ())
}
func (c vnetd) License() error {
return c.Main("-license")
}
func (c vnetd) Patents() error {
return c.Main("-patents")
}
func (c vnetd) Version() error {
return c.Main("-version")
}
func (c vnetd) Path() (string, error) {
cn := string(c)
self, err := os.Readlink("/proc/self/exe")
if err != nil {
return "", err
}
if self == "/usr/bin/goes" {
pn := "/usr/lib/goes/" + cn
_, err = os.Stat(pn)
if err == nil {
return pn, nil
}
perr := err.(*os.PathError)
return "", fmt.Errorf("%s: %s", perr.Path, perr.Err)
}
for _, pn := range []string{
"./" + cn,
"/usr/lib/goes/" + cn,
} {
if _, err := os.Stat(pn); err == nil {
return pn, nil
}
}
return "", fmt.Errorf("%s not found", cn)
}