mirror of
https://github.com/tmux/tmux.git
synced 2025-01-11 18:58:47 +00:00
Better error messages with no server.
This commit is contained in:
parent
2b3ba1cfad
commit
e0383f59bd
52
client.c
52
client.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: client.c,v 1.23 2007-11-27 19:23:33 nicm Exp $ */
|
/* $Id: client.c,v 1.24 2007-12-01 11:10:33 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -55,58 +55,46 @@ retry:
|
|||||||
retries++;
|
retries++;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
log_warn("%s: stat", path);
|
goto fail;
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
if (!S_ISSOCK(sb.st_mode)) {
|
if (!S_ISSOCK(sb.st_mode)) {
|
||||||
log_warnx("%s: %s", path, strerror(ENOTSOCK));
|
errno = ENOTSOCK;
|
||||||
return (-1);
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
size = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
|
||||||
if (size >= sizeof sa.sun_path) {
|
if (size >= sizeof sa.sun_path) {
|
||||||
log_warnx("%s: %s", path, strerror(ENAMETOOLONG));
|
errno = ENAMETOOLONG;
|
||||||
return (-1);
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cctx->srv_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
if ((cctx->srv_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
log_warn("%s: socket", path);
|
fatal("socket");
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
if (connect(
|
if (connect(
|
||||||
cctx->srv_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
cctx->srv_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
|
||||||
if (start_server && errno == ECONNREFUSED && retries < 10) {
|
if (start_server && errno == ECONNREFUSED && retries < 10) {
|
||||||
if (unlink(path) != 0) {
|
if (unlink(path) != 0)
|
||||||
log_warn("%s: unlink", path);
|
goto fail;
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
retries++;
|
retries++;
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
log_warn("%s: connect", path);
|
goto fail;
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mode = fcntl(cctx->srv_fd, F_GETFL)) == -1) {
|
if ((mode = fcntl(cctx->srv_fd, F_GETFL)) == -1)
|
||||||
log_warn("%s: fcntl", path);
|
fatal("fcntl");
|
||||||
return (-1);
|
if (fcntl(cctx->srv_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
}
|
fatal("fcntl");
|
||||||
if (fcntl(cctx->srv_fd, F_SETFL, mode|O_NONBLOCK) == -1) {
|
|
||||||
log_warn("%s: fcntl", path);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
cctx->srv_in = buffer_create(BUFSIZ);
|
cctx->srv_in = buffer_create(BUFSIZ);
|
||||||
cctx->srv_out = buffer_create(BUFSIZ);
|
cctx->srv_out = buffer_create(BUFSIZ);
|
||||||
|
|
||||||
if (isatty(STDIN_FILENO)) {
|
if (isatty(STDIN_FILENO)) {
|
||||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) {
|
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
|
||||||
log_warn("ioctl(TIOCGWINSZ)");
|
fatal("ioctl(TIOCGWINSZ)");
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
data.sx = ws.ws_col;
|
data.sx = ws.ws_col;
|
||||||
data.sy = ws.ws_row;
|
data.sy = ws.ws_row;
|
||||||
if (ttyname_r(STDIN_FILENO, data.tty, sizeof data.tty) != 0)
|
if (ttyname_r(STDIN_FILENO, data.tty, sizeof data.tty) != 0)
|
||||||
@ -116,6 +104,10 @@ retry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
log_warn("server not found");
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
5
server.c
5
server.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: server.c,v 1.41 2007-11-27 20:01:30 nicm Exp $ */
|
/* $Id: server.c,v 1.42 2007-12-01 11:10:33 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -65,8 +65,7 @@ server_start(const char *path)
|
|||||||
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
log_warn("fork");
|
fatal("fork");
|
||||||
return (-1);
|
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user