From 38b752c1d8338b78c86eb863c028cc058708828f Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 28 Aug 2007 08:30:36 +0000 Subject: [PATCH] Remove old sockets after error. --- TODO | 1 + tmux.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index bd9aed27..e5f6a9a4 100644 --- a/TODO +++ b/TODO @@ -14,3 +14,4 @@ - mouse handling and some other bits elinks needs - scrollback - server doesn't handle SIGTERM anymore... +- sleep(1) to wait for server frankly sucks diff --git a/tmux.c b/tmux.c index ead0062d..b3ef4fa3 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.4 2007-08-27 13:53:55 nicm Exp $ */ +/* $Id: tmux.c,v 1.5 2007-08-28 08:30:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -155,6 +155,8 @@ main(int argc, char **argv) xfree(path); /* Start server if necessary. */ + n = 0; +restart: if (stat(socket_path, &sb) != 0) { if (errno != ENOENT) err(1, "%s", socket_path); @@ -169,8 +171,13 @@ main(int argc, char **argv) } /* Connect to server. */ - if ((server_fd = connect_server()) == -1) + if ((server_fd = connect_server()) == -1) { + if (errno == ECONNREFUSED && n++ < 5) { + unlink(socket_path); + goto restart; + } errx(1, "couldn't find server"); + } if ((mode = fcntl(server_fd, F_GETFL)) == -1) err(1, "fcntl"); if (fcntl(server_fd, F_SETFL, mode|O_NONBLOCK) == -1)