Skip to content

Commit 9005ee6

Browse files
committed
Support for --pid option
1 parent f435532 commit 9005ee6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

main.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"io/ioutil"
9+
"strconv"
910

1011
"github.com/jpillora/chisel/client"
1112
"github.com/jpillora/chisel/server"
@@ -107,7 +108,7 @@ func server(args []string) {
107108
key := flags.String("key", "", "")
108109
authfile := flags.String("authfile", "", "")
109110
proxy := flags.String("proxy", "", "")
110-
pidfile := flags.Bool("pid", "", "")
111+
pidfile := flags.Bool("pid", false, "")
111112
verbose := flags.Bool("v", false, "")
112113

113114
flags.Usage = func() {
@@ -142,13 +143,13 @@ func server(args []string) {
142143
s.Info = true
143144
s.Debug = *verbose
144145

145-
if err = s.Run(*host, *port); err != nil {
146-
log.Fatal(err)
147-
}
148-
149146
if *pidfile == true {
150147
generatePidFile()
151148
}
149+
150+
if err = s.Run(*host, *port); err != nil {
151+
log.Fatal(err)
152+
}
152153
}
153154

154155
var clientHelp = `
@@ -198,6 +199,7 @@ func client(args []string) {
198199
fingerprint := flags.String("fingerprint", "", "")
199200
auth := flags.String("auth", "", "")
200201
keepalive := flags.Duration("keepalive", 0, "")
202+
pidfile := flags.Bool("pid", false, "")
201203
verbose := flags.Bool("v", false, "")
202204
flags.Usage = func() {
203205
fmt.Fprintf(os.Stderr, clientHelp)
@@ -223,19 +225,24 @@ func client(args []string) {
223225

224226
c.Info = true
225227
c.Debug = *verbose
226-
227-
if err = c.Run(); err != nil {
228-
log.Fatal(err)
229-
}
230228

231229
if *pidfile == true {
232230
generatePidFile()
233231
}
232+
233+
if err = c.Run(); err != nil {
234+
log.Fatal(err)
235+
}
236+
}
237+
238+
func toBytes(i int) (result []byte) {
239+
return []byte(strconv.Itoa(i))
234240
}
235241

236242
func generatePidFile() {
237-
err := ioutil.WriteFile("chisel.pid", os.Pid(), 0644)
243+
err := ioutil.WriteFile("chisel.pid", toBytes(os.Getpid()), 0644)
238244
if err != nil {
239245
log.Fatal(err)
240246
}
241247
}
248+

0 commit comments

Comments
 (0)