| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // +build darwin dragonfly freebsd linux netbsd openbsd | 5 // +build darwin dragonfly freebsd linux netbsd openbsd |
| 6 | 6 |
| 7 package main | 7 package main |
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "errors" | 10 "errors" |
| 11 "fmt" | 11 "fmt" |
| 12 "os" |
| 13 "syscall" |
| 12 | 14 |
| 13 "github.com/luci/luci-go/client/internal/logdog/butler/streamserver" | 15 "github.com/luci/luci-go/client/internal/logdog/butler/streamserver" |
| 14 "golang.org/x/net/context" | 16 "golang.org/x/net/context" |
| 15 ) | 17 ) |
| 16 | 18 |
| 17 const ( | 19 const ( |
| 18 // An example stream server URI. | 20 // An example stream server URI. |
| 19 exampleStreamServerURI = streamServerURI("unix:/var/run/butler.sock") | 21 exampleStreamServerURI = streamServerURI("unix:/var/run/butler.sock") |
| 20 ) | 22 ) |
| 21 | 23 |
| 24 // interruptSignals is the set of signals to handle gracefully (e.g., flush, |
| 25 // shutdown). |
| 26 var interruptSignals = []os.Signal{ |
| 27 os.Interrupt, |
| 28 syscall.SIGTERM, |
| 29 } |
| 30 |
| 22 type streamServerURI string | 31 type streamServerURI string |
| 23 | 32 |
| 24 func (u streamServerURI) Parse() (string, error) { | 33 func (u streamServerURI) Parse() (string, error) { |
| 25 typ, value := parseStreamServer(string(u)) | 34 typ, value := parseStreamServer(string(u)) |
| 26 if typ != "unix" { | 35 if typ != "unix" { |
| 27 return "", fmt.Errorf("unsupported URI scheme: [%s]", typ) | 36 return "", fmt.Errorf("unsupported URI scheme: [%s]", typ) |
| 28 } | 37 } |
| 29 if value == "" { | 38 if value == "" { |
| 30 return "", errors.New("empty stream server path") | 39 return "", errors.New("empty stream server path") |
| 31 } | 40 } |
| 32 return value, nil | 41 return value, nil |
| 33 } | 42 } |
| 34 | 43 |
| 35 // Validates that the URI is correct for Windows. | 44 // Validates that the URI is correct for Windows. |
| 36 func (u streamServerURI) Validate() (err error) { | 45 func (u streamServerURI) Validate() (err error) { |
| 37 _, err = u.Parse() | 46 _, err = u.Parse() |
| 38 return | 47 return |
| 39 } | 48 } |
| 40 | 49 |
| 41 // Create a POSIX (UNIX named pipe) stream server | 50 // Create a POSIX (UNIX named pipe) stream server |
| 42 func createStreamServer(ctx context.Context, uri streamServerURI) streamserver.S
treamServer { | 51 func createStreamServer(ctx context.Context, uri streamServerURI) streamserver.S
treamServer { |
| 43 path, err := uri.Parse() | 52 path, err := uri.Parse() |
| 44 if err != nil { | 53 if err != nil { |
| 45 panic("Failed to parse stream server URI.") | 54 panic("Failed to parse stream server URI.") |
| 46 } | 55 } |
| 47 return streamserver.NewNamedPipeServer(ctx, path) | 56 return streamserver.NewNamedPipeServer(ctx, path) |
| 48 } | 57 } |
| OLD | NEW |