File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 55 "log"
66 "net"
77 "os"
8+ "os/signal"
9+ "syscall"
810
911 "cloud.google.com/go/spanner/apiv1/spannerpb"
1012 "google.golang.org/grpc"
@@ -23,9 +25,22 @@ func main() {
2325 if len (os .Args ) > 2 {
2426 tp = os .Args [2 ]
2527 }
28+ //
2629 if tp == "unix" {
2730 defer func () { _ = os .Remove (name ) }()
31+ // Set up a channel to listen for OS signals that terminate the process,
32+ // so we can clean up the temp file in those cases as well.
33+ sigs := make (chan os.Signal , 1 )
34+ signal .Notify (sigs , syscall .SIGINT , syscall .SIGTERM )
35+ go func () {
36+ // Wait for a signal.
37+ <- sigs
38+ // Delete the temp file.
39+ _ = os .Remove (name )
40+ os .Exit (0 )
41+ }()
2842 }
43+
2944 lis , err := net .Listen (tp , name )
3045 if err != nil {
3146 log .Fatalf ("failed to listen: %v\n " , err )
You can’t perform that action at this time.
0 commit comments