Skip to content

Commit

Permalink
Add force option to delete already existing socket file
Browse files Browse the repository at this point in the history
  • Loading branch information
mpotthoff authored and benpye committed May 27, 2019
1 parent d39a069 commit 03781b4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
namedPipe = flag.String("winssh", "", "Named pipe for use with Win32 OpenSSH")
verbose = flag.Bool("verbose", false, "Enable verbose logging")
systrayFlag = flag.Bool("systray", false, "Enable systray integration")
force = flag.Bool("force", false, "Force socket usage (unlink existing socket)")
)

const (
Expand Down Expand Up @@ -209,6 +210,17 @@ func main() {
}()

if *unixSocket != "" {
if *force {
// If the socket file already exists then unlink it
_, err := os.Stat(*unixSocket)
if err == nil || !os.IsNotExist(err) {
err = syscall.Unlink(*unixSocket)
if err != nil {
log.Fatalf("Failed to unlink socket %s, error '%s'\n", *unixSocket, err)
}
}
}

unix, err = net.Listen("unix", *unixSocket)
if err != nil {
log.Fatalf("Could not open socket %s, error '%s'\n", *unixSocket, err)
Expand Down

0 comments on commit 03781b4

Please sign in to comment.