-/* $OpenBSD: server-client.c,v 1.245 2017/10/16 19:30:53 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.246 2017/12/19 15:00:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
}
/* Create a new client. */
-void
+struct client *
server_client_create(int fd)
{
struct client *c;
TAILQ_INSERT_TAIL(&clients, c, entry);
log_debug("new client %p", c);
+ return (c);
}
/* Open client terminal if needed. */
int argc;
char **argv, *cause;
+ if (c->flags & CLIENT_EXIT)
+ return;
+
if (imsg->hdr.len - IMSG_HEADER_SIZE < sizeof data)
fatalx("bad MSG_COMMAND size");
memcpy(&data, imsg->data, sizeof data);
-/* $OpenBSD: server.c,v 1.177 2017/10/12 11:32:27 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.178 2017/12/19 15:00:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
struct cmd_find_state marked_pane;
-static int server_create_socket(void);
static int server_loop(void);
static void server_send_exit(void);
static void server_accept(int, short, void *);
/* Create server socket. */
static int
-server_create_socket(void)
+server_create_socket(char **cause)
{
struct sockaddr_un sa;
size_t size;
mode_t mask;
- int fd;
+ int fd, saved_errno;
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
size = strlcpy(sa.sun_path, socket_path, sizeof sa.sun_path);
if (size >= sizeof sa.sun_path) {
errno = ENAMETOOLONG;
- return (-1);
+ goto fail;
}
unlink(sa.sun_path);
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
- return (-1);
+ goto fail;
mask = umask(S_IXUSR|S_IXGRP|S_IRWXO);
- if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {
+ if (bind(fd, (struct sockaddr *)&sa, sizeof sa) == -1) {
+ saved_errno = errno;
close(fd);
- return (-1);
+ errno = saved_errno;
+ goto fail;
}
umask(mask);
if (listen(fd, 128) == -1) {
+ saved_errno = errno;
close(fd);
- return (-1);
+ errno = saved_errno;
+ goto fail;
}
setblocking(fd, 0);
return (fd);
+
+fail:
+ if (cause != NULL) {
+ xasprintf(cause, "error creating %s (%s)", socket_path,
+ strerror(errno));
+ }
+ return (-1);
+}
+
+/* Server error callback. */
+static enum cmd_retval
+server_start_error(struct cmdq_item *item, void *data)
+{
+ char *error = data;
+
+ cmdq_error(item, "%s", error);
+ free(error);
+
+ return (CMD_RETURN_NORMAL);
}
/* Fork new server. */
int pair[2];
struct job *job;
sigset_t set, oldset;
+ struct client *c;
+ char *cause = NULL;
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
fatal("socketpair failed");
gettimeofday(&start_time, NULL);
- server_fd = server_create_socket();
- if (server_fd == -1)
- fatal("couldn't create socket");
- server_update_socket();
- server_client_create(pair[1]);
+ server_fd = server_create_socket(&cause);
+ if (server_fd != -1)
+ server_update_socket();
+ c = server_client_create(pair[1]);
if (lockfd >= 0) {
unlink(lockfile);
close(lockfd);
}
+ if (cause != NULL) {
+ cmdq_append(c, cmdq_get_callback(server_start_error, cause));
+ c->flags |= CLIENT_EXIT;
+ }
+
start_cfg();
server_add_accept(0);
break;
case SIGUSR1:
event_del(&server_ev_accept);
- fd = server_create_socket();
+ fd = server_create_socket(NULL);
if (fd != -1) {
close(server_fd);
server_fd = fd;
-/* $OpenBSD: tmux.h,v 1.814 2017/11/15 19:59:27 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.815 2017/12/19 15:00:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
const char *server_client_get_key_table(struct client *);
int server_client_check_nested(struct client *);
void server_client_handle_key(struct client *, key_code);
-void server_client_create(int);
+struct client *server_client_create(int);
int server_client_open(struct client *, char **);
void server_client_unref(struct client *);
void server_client_lost(struct client *);