Skip to content

Commit 03781b4

Browse files
mpotthoffbenpye
authored andcommitted
Add force option to delete already existing socket file
1 parent d39a069 commit 03781b4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
namedPipe = flag.String("winssh", "", "Named pipe for use with Win32 OpenSSH")
3131
verbose = flag.Bool("verbose", false, "Enable verbose logging")
3232
systrayFlag = flag.Bool("systray", false, "Enable systray integration")
33+
force = flag.Bool("force", false, "Force socket usage (unlink existing socket)")
3334
)
3435

3536
const (
@@ -209,6 +210,17 @@ func main() {
209210
}()
210211

211212
if *unixSocket != "" {
213+
if *force {
214+
// If the socket file already exists then unlink it
215+
_, err := os.Stat(*unixSocket)
216+
if err == nil || !os.IsNotExist(err) {
217+
err = syscall.Unlink(*unixSocket)
218+
if err != nil {
219+
log.Fatalf("Failed to unlink socket %s, error '%s'\n", *unixSocket, err)
220+
}
221+
}
222+
}
223+
212224
unix, err = net.Listen("unix", *unixSocket)
213225
if err != nil {
214226
log.Fatalf("Could not open socket %s, error '%s'\n", *unixSocket, err)

0 commit comments

Comments
 (0)